HeroEquip.lua 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854
  1. -- 英雄装备相关逻辑
  2. local Lang = require("common.Lang")
  3. local HeroExcel = require("excel.hero")
  4. local EquipExcel = require("excel.equip")
  5. local Msg = require("core.Msg")
  6. local ObjHuman = require("core.ObjHuman")
  7. local HeroDefine = require("hero.HeroDefine")
  8. local HeroLogic = require("hero.HeroLogic")
  9. local ItemDefine = require("bag.ItemDefine")
  10. local Grid = require("bag.Grid")
  11. local BagLogic = require("bag.BagLogic")
  12. local Broadcast = require("broadcast.Broadcast")
  13. local RoleAttr = require("role.RoleAttr")
  14. local Util = require("common.Util")
  15. local ItemExcel = require("excel.item").item
  16. local FuwenLogic = require("fuwen.FuwenLogic")
  17. local EquipLogic = require("equip.EquipLogic")
  18. function query(human, heroID, heroIndex)
  19. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  20. if heroGrid == nil then
  21. return
  22. end
  23. local msgRet = Msg.gc.GC_HERO_EQUIP_QUERY
  24. msgRet.id = heroID
  25. msgRet.index = heroIndex
  26. local cnt = 0
  27. for i = 1, ItemDefine.EQUIP_MAX_CNT do
  28. local equipGrid = heroGrid.equip and heroGrid.equip[i]
  29. if equipGrid then
  30. cnt = cnt + 1
  31. if i == ItemDefine.EQUIP_SUBTYPE_SHUIJIN then -- 水晶比较特殊
  32. Grid.makeItem(msgRet.equips[cnt], equipGrid.id, 1, heroGrid.shuijingAttrID)
  33. else
  34. Grid.makeItem(msgRet.equips[cnt], equipGrid.id, 1, nil, equipGrid, -1, Grid.getOpflagAtBag(heroGrid.equip[i].id))
  35. end
  36. end
  37. local dot = isEquipDotByPos(human, heroGrid, i)
  38. msgRet.equipDot[i] = dot or 0
  39. end
  40. msgRet.equipDot[0] = ItemDefine.EQUIP_MAX_CNT
  41. msgRet.equips[0] = cnt
  42. cnt = 0
  43. for i = 1, 2 do
  44. -- 尝试解锁符文
  45. FuwenLogic.fuwenGridUnlock(human, heroID, heroIndex, i)
  46. if heroGrid.fuwen and
  47. heroGrid.fuwen[i] and
  48. heroGrid.fuwen[i].id ~= nil then
  49. cnt = cnt + 1
  50. msgRet.fuwens[cnt].pos = i
  51. Grid.makeItem(msgRet.fuwens[cnt].fuwen, heroGrid.fuwen[i].id, 1,nil,heroGrid.fuwen[i],-1, Grid.getOpflagAtBag(heroGrid.fuwen[i].id))
  52. end
  53. msgRet.fuwenGrid[i] = 1
  54. if heroGrid.fuwen == nil or
  55. heroGrid.fuwen[i] == nil then
  56. msgRet.fuwenGrid[i] = 0
  57. end
  58. local dot = FuwenLogic.isFuwenDotByPos(human, heroGrid, i) == true and 1 or 0
  59. msgRet.fuwenDot[i] = dot
  60. end
  61. msgRet.fuwenGrid[0] = 2
  62. msgRet.fuwenDot[0] = 2
  63. msgRet.fuwens[0] = cnt
  64. Msg.send(msgRet, human.fd)
  65. end
  66. function putOn(human, heroID, heroIndex, bagIndex, noCalc)
  67. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  68. if heroGrid == nil then return end
  69. if bagIndex == 0 then return end
  70. local equipGrid = human.db.equipBag[bagIndex]
  71. if not equipGrid or type(equipGrid) ~= "table" then return end
  72. local equipID = equipGrid.id
  73. local equipConfig = EquipExcel.equip[equipID]
  74. if equipConfig == nil then return end
  75. if heroGrid.star < equipConfig.star then
  76. local errDesc = Util.format(Lang.EQUIP_PUT_ON_STAR_ERR, equipConfig.star)
  77. return Broadcast.sendErr(human, errDesc)
  78. end
  79. local pos = equipConfig.subType
  80. if pos == ItemDefine.EQUIP_SUBTYPE_SHUIJIN then return end
  81. local msgRet = Msg.gc.GC_HERO_EQUIP_PUTON
  82. msgRet.heroID = heroID
  83. msgRet.heroIndex = heroIndex
  84. Grid.makeItem(msgRet.equip, equipID, 1, nil, equipGrid, bagIndex, Grid.getOpflagAtBag(equipID))
  85. if heroGrid.equip == nil or
  86. heroGrid.equip[pos] == nil then
  87. heroGrid.equip = heroGrid.equip or { }
  88. heroGrid.equip[pos] = equipGrid
  89. -- 穿戴者
  90. equipGrid.putUuid = heroGrid.uuid
  91. -- 新穿装备
  92. EquipLogic.delEquip(human, bagIndex, "equip_puton")
  93. else
  94. -- 同一件装备
  95. if heroGrid.equip[pos].uuid == equipGrid.uuid then
  96. return Msg.send(msgRet, human.fd)
  97. end
  98. -- 替换装备
  99. EquipLogic.delEquip(human, bagIndex, "equip_puton")
  100. local unEquipGrid = heroGrid.equip[pos]
  101. unEquipGrid.putUuid = nil
  102. EquipLogic.addByEquipGrid(human, unEquipGrid, "equip_puton", true)
  103. heroGrid.equip[pos] = equipGrid
  104. equipGrid.putUuid = heroGrid.uuid
  105. end
  106. if noCalc ~= true then
  107. -- 计算属性
  108. ObjHuman.doCalcHero(human, heroIndex)
  109. HeroLogic.sendHeroBagDynamic(human, heroID, heroIndex)
  110. HeroLogic.refreshDot(human, heroGrid.uuid)
  111. end
  112. -- 通知客户端
  113. Msg.send(msgRet, human.fd)
  114. end
  115. --
  116. function putOnHero(human, heroID, heroIndex, putHeroID, putHeroIndex, putHeroPos)
  117. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  118. if heroGrid == nil then return end
  119. local putHeroGrid = HeroLogic.getHeroGrid(human, putHeroID, putHeroIndex)
  120. if putHeroGrid == nil then return end
  121. -- 同一个英雄
  122. if heroGrid.uuid == putHeroGrid.uuid then return end
  123. -- 部位有没有装备
  124. if putHeroGrid.equip == nil then return end
  125. local putEquipGrid = putHeroGrid.equip[putHeroPos]
  126. if not putEquipGrid then return end
  127. local equipID = putEquipGrid.id
  128. local equipConfig = EquipExcel.equip[equipID]
  129. if equipConfig == nil then return end
  130. if heroGrid.star < equipConfig.star then
  131. local errDesc = Util.format(Lang.EQUIP_PUT_ON_STAR_ERR, equipConfig.star)
  132. return Broadcast.sendErr(human, errDesc)
  133. end
  134. local pos = equipConfig.subType
  135. if pos == ItemDefine.EQUIP_SUBTYPE_SHUIJIN then return end
  136. if heroGrid.equip == nil or
  137. heroGrid.equip[pos] == nil then
  138. heroGrid.equip = heroGrid.equip or { }
  139. -- 穿戴者
  140. heroGrid.equip[pos] = putEquipGrid
  141. putEquipGrid.putUuid = heroGrid.uuid
  142. else
  143. -- 同一件装备
  144. if heroGrid.equip[pos].uuid == putHeroGrid.uuid then
  145. return Msg.send(msgRet, human.fd)
  146. end
  147. --放入到背包
  148. local unEquipGrid = heroGrid.equip[pos]
  149. unEquipGrid.putUuid = nil
  150. EquipLogic.addByEquipGrid(human, unEquipGrid, "equip_puton", true)
  151. -- 设置新装备
  152. heroGrid.equip[pos] = putEquipGrid
  153. putEquipGrid.putUuid = heroGrid.uuid
  154. end
  155. -- 老英雄脱去此装备
  156. putHeroGrid.equip[putHeroPos] = nil
  157. -- 计算属性
  158. ObjHuman.doCalcHero(human, heroIndex)
  159. HeroLogic.sendHeroBagDynamic(human, heroID, heroIndex)
  160. HeroLogic.refreshDot(human, heroGrid.uuid)
  161. ObjHuman.doCalcHero(human, putHeroIndex)
  162. HeroLogic.sendHeroBagDynamic(human, putHeroID, putHeroIndex)
  163. HeroLogic.refreshDot(human, putHeroGrid.uuid)
  164. -- 通知客户端
  165. local msgRet = Msg.gc.GC_HERO_EQUIP_PUTON
  166. msgRet.heroID = heroID
  167. msgRet.heroIndex = heroIndex
  168. Grid.makeItem(msgRet.equip, equipID, 1, nil, equipGrid, 0, Grid.getOpflagAtBag(equipID))
  169. Msg.send(msgRet, human.fd)
  170. end
  171. function putOff(human, heroID, heroIndex, pos, noCalc, noSend)
  172. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  173. if heroGrid == nil then
  174. return
  175. end
  176. if pos == ItemDefine.EQUIP_SUBTYPE_SHUIJIN then return end
  177. if heroGrid.equip == nil or heroGrid.equip[pos] == nil then
  178. return
  179. end
  180. -- 判断背包空间
  181. if not EquipLogic.checkEmptyCnt(human, 1) then
  182. return
  183. end
  184. -- 改db
  185. local equipGrid = heroGrid.equip[pos]
  186. heroGrid.equip[pos] = nil
  187. equipGrid.putUuid = nil
  188. EquipLogic.addByEquipGrid(human, equipGrid, "equip_putoff", true)
  189. if noCalc ~= true then
  190. -- 计算属性
  191. ObjHuman.doCalcHero(human,heroIndex)
  192. HeroLogic.sendHeroBagDynamic(human, heroID, heroIndex)
  193. HeroLogic.refreshDot(human, heroGrid.uuid)
  194. end
  195. if not noSend then
  196. -- 通知客户端
  197. local msgRet = Msg.gc.GC_HERO_EQUIP_PUTOFF
  198. msgRet.heroID = heroID
  199. msgRet.heroIndex = heroIndex
  200. msgRet.pos = pos
  201. Msg.send(msgRet, human.fd)
  202. end
  203. end
  204. -- 一键穿装
  205. function putOnQuick(human, heroID, heroIndex, equipID1, equipID2, equipID3, equipID4, equipID6)
  206. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  207. if heroGrid == nil then
  208. return
  209. end
  210. putOn(human, heroID, heroIndex, equipID1, true)
  211. putOn(human, heroID, heroIndex, equipID2, true)
  212. putOn(human, heroID, heroIndex, equipID3, true)
  213. putOn(human, heroID, heroIndex, equipID4, true)
  214. putOn(human, heroID, heroIndex, equipID6, true)
  215. ObjHuman.doCalcHero(human,heroIndex)
  216. HeroLogic.sendHeroBagDynamic(human, heroID, heroIndex)
  217. HeroLogic.refreshDot(human, heroGrid.uuid)
  218. end
  219. -- 一键脱装
  220. function putOffQuick(human, heroID, heroIndex, noSendDy)
  221. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  222. if heroGrid == nil then
  223. return
  224. end
  225. putOff(human, heroID, heroIndex, ItemDefine.EQUIP_SUBTYPE_WEAPON, true)
  226. putOff(human, heroID, heroIndex, ItemDefine.EQUIP_SUBTYPE_CLOTH, true)
  227. putOff(human, heroID, heroIndex, ItemDefine.EQUIP_SUBTYPE_SHOES, true)
  228. putOff(human, heroID, heroIndex, ItemDefine.EQUIP_SUBTYPE_SHIPIN, true)
  229. putOff(human, heroID, heroIndex, ItemDefine.EQUIP_SUBTYPE_SHENQI, true)
  230. if not noSendDy then
  231. ObjHuman.doCalcHero(human,heroIndex)
  232. HeroLogic.sendHeroBagDynamic(human, heroID, heroIndex)
  233. end
  234. end
  235. function doCalcHero(obj,attrs)
  236. local equip = obj.equip
  237. if not equip then return end
  238. local mathFloor = math.floor
  239. local equipSuitCntTable = nil
  240. for i = 1,ItemDefine.EQUIP_MAX_CNT do
  241. local equipGrid = equip[i]
  242. if equipGrid then
  243. local equipID = equipGrid.id
  244. local equipConfig = EquipExcel.equip[equipID]
  245. local baseRate = EquipLogic.getEquipBaseRate(equipGrid.quality)
  246. -- 水晶
  247. if equipConfig.subType == ItemDefine.EQUIP_SUBTYPE_SHUIJIN then
  248. for _,v in ipairs(EquipExcel.shuijingAttr[obj.shuijingAttrID].attr) do
  249. RoleAttr.updateValue(v[1],v[2],attrs)
  250. end
  251. else
  252. for _,v in ipairs(equipConfig.base) do
  253. RoleAttr.updateValue(v[1],mathFloor(v[2] * baseRate),attrs)
  254. end
  255. -- 随机属性
  256. for key, value in pairs(equipGrid.attr) do
  257. RoleAttr.updateValue(key, mathFloor(value * baseRate) ,attrs)
  258. end
  259. local heroID = obj.id
  260. local heroConfig = HeroExcel.hero[heroID]
  261. if equipConfig.camp == heroConfig.camp then
  262. -- 阵营专属属性
  263. for _,v in ipairs(equipConfig.campAttr) do
  264. RoleAttr.updateValue(v[1],v[2],attrs)
  265. end
  266. end
  267. if equipConfig.job == heroConfig.job then
  268. -- 职业专属属性
  269. for _,v in ipairs(equipConfig.jobAttr) do
  270. RoleAttr.updateValue(v[1],v[2],attrs)
  271. end
  272. end
  273. if equipConfig.suit ~= 0 then
  274. equipSuitCntTable = equipSuitCntTable or {}
  275. equipSuitCntTable[equipConfig.suit] = equipSuitCntTable[equipConfig.suit] or {cnt = 0}
  276. equipSuitCntTable[equipConfig.suit].equipID = equipID
  277. equipSuitCntTable[equipConfig.suit].cnt = equipSuitCntTable[equipConfig.suit].cnt + 1
  278. end
  279. end
  280. end
  281. end
  282. -- 套装属性
  283. if equipSuitCntTable then
  284. for k, v in pairs(equipSuitCntTable) do
  285. if v.cnt > 1 then
  286. local equipIDTemp = v.equipID
  287. local equipConfigTemp = EquipExcel.equip[equipIDTemp]
  288. for i = 1, #equipConfigTemp.suitIm do
  289. local keyTemp = equipConfigTemp.suitIm[i][1]
  290. local valTemp = equipConfigTemp.suitIm[i][2]
  291. if v.cnt > i then
  292. RoleAttr.updateValue(keyTemp,valTemp,attrs)
  293. end
  294. end
  295. end
  296. end
  297. end
  298. end
  299. -- 激活水晶
  300. function jihuoShuijing(human, heroID, heroIndex)
  301. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  302. if heroGrid == nil then
  303. return
  304. end
  305. if heroGrid.lv < HeroDefine.JIHUO_SHUIJING_NEEDLV then
  306. return
  307. end
  308. local pos = ItemDefine.EQUIP_SUBTYPE_SHUIJIN
  309. if heroGrid.equip ~= nil and heroGrid.equip[pos] then
  310. return
  311. end
  312. --存db
  313. local equipID = HeroDefine.DEFAULT_SHUIJING_GET -- todo 20011
  314. local equipConfig = EquipExcel.equip[equipID]
  315. if not equipConfig then return end
  316. heroGrid.equip = heroGrid.equip or {}
  317. heroGrid.equip[pos] = equipID
  318. local randIdCnt = #equipConfig.shuijingAttrID
  319. local indexTemp = math.random(1,randIdCnt)
  320. local attrID = equipConfig.shuijingAttrID[indexTemp]
  321. heroGrid.shuijingAttrID = attrID
  322. -- 计算属性
  323. ObjHuman.doCalcHero(human,heroIndex)
  324. HeroLogic.sendHeroBagDynamic(human, heroID, heroIndex)
  325. -- 通知客户端
  326. local msgRet = Msg.gc.GC_HERO_EQUIP_PUTON
  327. msgRet.heroID = heroID
  328. msgRet.heroIndex = heroIndex
  329. Grid.makeItem(msgRet.equip, equipID, 1, heroGrid.shuijingAttrID)
  330. Msg.send(msgRet, human.fd)
  331. end
  332. -- 水晶转换的信息查询
  333. function shuijingTransQuery(human, heroID, heroIndex)
  334. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  335. if heroGrid == nil then
  336. return
  337. end
  338. local pos = ItemDefine.EQUIP_SUBTYPE_SHUIJIN
  339. if heroGrid.equip == nil or heroGrid.equip[pos] == nil then
  340. return
  341. end
  342. local equipID = heroGrid.equip[pos]
  343. local shuijingTransConfig = EquipExcel.shuijingTransNeed[equipID]
  344. if not shuijingTransConfig then return end
  345. local msgRet = Msg.gc.GC_SHUIJING_TRANS_QUERY
  346. msgRet.heroID = heroID
  347. msgRet.heroIndex = heroIndex
  348. msgRet.needJinbi = shuijingTransConfig.money
  349. msgRet.needItemCnt = shuijingTransConfig.jinghua
  350. Msg.send(msgRet, human.fd)
  351. end
  352. -- 水晶转换
  353. function shuijingTransDo(human, heroID, heroIndex)
  354. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  355. if heroGrid == nil then
  356. return
  357. end
  358. local pos = ItemDefine.EQUIP_SUBTYPE_SHUIJIN
  359. if heroGrid.equip == nil or heroGrid.equip[pos] == nil then
  360. return
  361. end
  362. local equipID = heroGrid.equip[pos]
  363. local shuijingTransConfig = EquipExcel.shuijingTransNeed[equipID]
  364. if not shuijingTransConfig then return end
  365. -- 材料判断
  366. local needJinbi = shuijingTransConfig.money
  367. if human.db.jinbi < needJinbi then
  368. return Broadcast.sendErr(human, Lang.COMMON_NO_JINBI)
  369. end
  370. local needItemCnt = shuijingTransConfig.jinghua
  371. local nowItemCnt = BagLogic.getItemCnt(human, ItemDefine.ITEM_SHUIJING_UPLEVEL_ID)
  372. if nowItemCnt< needItemCnt then
  373. local strName = ItemDefine.getValue(ItemDefine.ITEM_SHUIJING_UPLEVEL_ID, "name")
  374. local strRet = Util.format(Lang.COMMON_NO_ITEM, strName)
  375. return Broadcast.sendErr(human, strRet)
  376. end
  377. -- 扣道具
  378. BagLogic.delItem(human, ItemDefine.ITEM_SHUIJING_UPLEVEL_ID, needItemCnt, "shuijing_change")
  379. ObjHuman.updateJinbi(human, -needJinbi, "shuijing_change")
  380. local msgRet = Msg.gc.GC_SHUIJING_TRANS_DO
  381. msgRet.heroID = heroID
  382. msgRet.heroIndex = heroIndex
  383. -- 存db之前,先随机获得下一个水晶的属性
  384. local equipConfig = EquipExcel.equip[equipID]
  385. if not equipConfig then return end
  386. local randIdCnt = #equipConfig.shuijingAttrID
  387. local indexTemp = math.random(1,randIdCnt)
  388. -- todo 单单这样子会有漏洞。。。玩家可以把水晶A洗练出的属性保存到水晶B那里,需要注意!!太忙了,之后修改
  389. human.tempAttrID = equipConfig.shuijingAttrID[indexTemp]
  390. -- 通知客户端
  391. Grid.makeItem(msgRet.equip, equipID, 1, human.tempAttrID)
  392. Msg.send(msgRet, human.fd)
  393. end
  394. -- 水晶转换保存
  395. function shuijingTransSave(human, heroID, heroIndex)
  396. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  397. if heroGrid == nil then
  398. return
  399. end
  400. local pos = ItemDefine.EQUIP_SUBTYPE_SHUIJIN
  401. if heroGrid.equip == nil or heroGrid.equip[pos] == nil then
  402. return
  403. end
  404. if human.tempAttrID == nil then
  405. return
  406. end
  407. local equipID = heroGrid.equip[pos]
  408. -- 改db
  409. heroGrid.shuijingAttrID = human.tempAttrID
  410. human.tempAttrID = nil
  411. -- 计算属性并发送
  412. ObjHuman.doCalcHero(human,heroIndex)
  413. HeroLogic.sendHeroBagDynamic(human, heroID, heroIndex)
  414. -- 通知客户端
  415. local msgRet = Msg.gc.GC_HERO_EQUIP_PUTON
  416. msgRet.heroID = heroID
  417. msgRet.heroIndex = heroIndex
  418. Grid.makeItem(msgRet.equip, equipID, 1, heroGrid.shuijingAttrID)
  419. Msg.send(msgRet, human.fd)
  420. local msgRet = Msg.gc.GC_SHUIJING_TRANS_SAVE
  421. Msg.send(msgRet, human.fd)
  422. end
  423. -- 水晶升级查询
  424. function shuijingUpLvQuery(human, mainType, heroID, heroIndex)
  425. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  426. if heroGrid == nil then
  427. return
  428. end
  429. local pos = ItemDefine.EQUIP_SUBTYPE_SHUIJIN
  430. if heroGrid.equip == nil or heroGrid.equip[pos] == nil then
  431. return
  432. end
  433. local equipID = heroGrid.equip[pos]
  434. local shuijingUpNeedConfig = EquipExcel.shuijingUpNeed[equipID]
  435. if not shuijingUpNeedConfig then return end
  436. -- 上限判断
  437. local nextID = shuijingUpNeedConfig.nextID
  438. if nextID == 0 then return end
  439. local msgRet = Msg.gc.GC_SHUIJING_UPLV_QUERY
  440. msgRet.heroID = heroID
  441. msgRet.heroIndex = heroIndex
  442. msgRet.needJinbi = 0
  443. msgRet.needItemCnt = 0
  444. msgRet.needZuanshi = 0
  445. local nextID = shuijingUpNeedConfig.nextID
  446. if nextID ~= 0 then
  447. local tempConfig = EquipExcel.shuijingUpNeed[nextID]
  448. msgRet.needJinbi = tempConfig.money
  449. msgRet.needItemCnt = tempConfig.jinghua
  450. msgRet.needZuanshi = tempConfig.zuanshi
  451. end
  452. msgRet.equip[0] = 1
  453. local attrID = heroGrid.shuijingAttrID
  454. local tempAttrID = EquipExcel.shuijingAttr[attrID].lockNextID
  455. Grid.makeItem(msgRet.equip[1], nextID, 1, tempAttrID)
  456. Msg.send(msgRet, human.fd)
  457. end
  458. -- 水晶升级
  459. function shuijingUpLvDo(human, mainType, heroID, heroIndex)
  460. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  461. if heroGrid == nil then
  462. return
  463. end
  464. local pos = ItemDefine.EQUIP_SUBTYPE_SHUIJIN
  465. if heroGrid.equip == nil or heroGrid.equip[pos] == nil then
  466. return
  467. end
  468. local equipID = heroGrid.equip[pos]
  469. local shuijingUpNeedConfig = EquipExcel.shuijingUpNeed[equipID]
  470. if not shuijingUpNeedConfig then return end
  471. -- 上限判断
  472. local nextID = shuijingUpNeedConfig.nextID
  473. if nextID == 0 then return end
  474. local nextConfig = EquipExcel.shuijingUpNeed[nextID]
  475. if nextConfig == nil then return end
  476. -- 材料判断
  477. local needJinbi = nextConfig.money
  478. if human.db.jinbi < needJinbi then
  479. return Broadcast.sendErr(human, Lang.COMMON_NO_JINBI)
  480. end
  481. local needItemCnt = nextConfig.jinghua
  482. local nowItemCnt = BagLogic.getItemCnt(human, ItemDefine.ITEM_SHUIJING_UPLEVEL_ID)
  483. if nowItemCnt< needItemCnt then
  484. local strName = ItemDefine.getValue(ItemDefine.ITEM_SHUIJING_UPLEVEL_ID, "name")
  485. local strRet = Util.format(Lang.COMMON_NO_ITEM, strName)
  486. return Broadcast.sendErr(human, strRet)
  487. end
  488. if mainType == HeroDefine.SHUIJING_UP_LV_LOCK then
  489. local needZuanshi = nextConfig.zuanshi
  490. if not ObjHuman.checkRMB(human, needZuanshi) then
  491. return
  492. end
  493. end
  494. -- 扣道具
  495. BagLogic.delItem(human, ItemDefine.ITEM_SHUIJING_UPLEVEL_ID, needItemCnt, "shuijing_change")
  496. ObjHuman.updateJinbi(human, -needJinbi, "shuijing_change")
  497. if mainType == HeroDefine.SHUIJING_UP_LV_LOCK then
  498. local needZuanshi = shuijingUpNeedConfig.zuanshi
  499. ObjHuman.decZuanshi(human, -needZuanshi, "shuijing_change")
  500. end
  501. --改db
  502. heroGrid.equip[pos] = nextID
  503. if mainType == HeroDefine.SHUIJING_UP_LV_LOCK then
  504. local attrID = heroGrid.shuijingAttrID
  505. heroGrid.shuijingAttrID = EquipExcel.shuijingAttr[attrID].lockNextID
  506. else
  507. local equipConfig = EquipExcel.equip[nextID]
  508. if not equipConfig then return end
  509. local randIdCnt = #equipConfig.shuijingAttrID
  510. local indexTemp = math.random(1,randIdCnt)
  511. heroGrid.shuijingAttrID = equipConfig.shuijingAttrID[indexTemp]
  512. end
  513. -- 计算属性并发送
  514. ObjHuman.doCalcHero(human,heroIndex)
  515. HeroLogic.sendHeroBagDynamic(human, heroID, heroIndex)
  516. -- 通知客户端
  517. local msgRet = Msg.gc.GC_HERO_EQUIP_PUTON
  518. msgRet.heroID = heroID
  519. msgRet.heroIndex = heroIndex
  520. Grid.makeItem(msgRet.equip, nextID, 1, heroGrid.shuijingAttrID)
  521. Msg.send(msgRet, human.fd)
  522. local msgRet = Msg.gc.GC_SHUIJING_UPLV_DO
  523. msgRet.heroID = heroID
  524. msgRet.heroIndex = heroIndex
  525. Grid.makeItem(msgRet.equip, nextID, 1, heroGrid.shuijingAttrID)
  526. Msg.send(msgRet, human.fd)
  527. end
  528. -- 神器升级查询
  529. function shenqiUpLvQuery(human, heroID, heroIndex)
  530. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  531. if heroGrid == nil then
  532. return
  533. end
  534. local pos = ItemDefine.EQUIP_SUBTYPE_SHENQI
  535. if heroGrid.equip == nil or heroGrid.equip[pos] == nil then
  536. return
  537. end
  538. local equipID = heroGrid.equip[pos]
  539. local shenqiUpNeedConfig = EquipExcel.shenqiUpNeed[equipID]
  540. if not shenqiUpNeedConfig then return end
  541. -- 上限判断
  542. local nextID = shenqiUpNeedConfig.nextID
  543. if nextID == 0 then return end
  544. -- 下发信息
  545. local msgRet = Msg.gc.GC_SHENQI_UPLV_QUERY
  546. msgRet.heroID = heroID
  547. msgRet.heroIndex = heroIndex
  548. msgRet.needExp = shenqiUpNeedConfig.needExp
  549. Grid.makeItem(msgRet.equip, nextID, 1)
  550. Msg.send(msgRet, human.fd)
  551. end
  552. -- 神器升级
  553. function shenqiUpLvDo(human, heroID, heroIndex, equipIDList, equipCntList)
  554. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  555. if heroGrid == nil then
  556. return
  557. end
  558. local pos = ItemDefine.EQUIP_SUBTYPE_SHENQI
  559. if heroGrid.equip == nil or heroGrid.equip[pos] == nil then
  560. return
  561. end
  562. local equipID = heroGrid.equip[pos]
  563. local shenqiUpNeedConfig = EquipExcel.shenqiUpNeed[equipID]
  564. if not shenqiUpNeedConfig then return end
  565. -- 上限判断
  566. local nextID = shenqiUpNeedConfig.nextID
  567. if nextID == 0 then return end
  568. -- 判断消耗
  569. if equipIDList[0] ~= equipCntList[0] then
  570. return
  571. end
  572. for i=1, equipIDList[0] do
  573. local needEquipCnt = equipCntList[i]
  574. local nowEquipCnt = BagLogic.getItemCnt(human, equipIDList[i])
  575. if nowEquipCnt < needEquipCnt then
  576. return
  577. end
  578. end
  579. local totalExp = 0
  580. for i=1, equipIDList[0] do
  581. local id = equipIDList[i]
  582. local equipConfig = EquipExcel.equip[id]
  583. if equipConfig then
  584. local nowExp = equipConfig.shenqiExp
  585. local nowCnt = equipCntList[i]
  586. totalExp = totalExp + math.floor(nowExp * nowCnt)
  587. else
  588. local itemConfig = ItemExcel[id]
  589. if not itemConfig or (id ~= ItemDefine.ITEM_SHENQI_EXP_ID1 and
  590. id ~= ItemDefine.ITEM_SHENQI_EXP_ID2) then
  591. return
  592. end
  593. local nowExp = itemConfig.effect
  594. local nowCnt = equipCntList[i]
  595. totalExp = totalExp + math.floor(nowExp * nowCnt)
  596. end
  597. end
  598. local needExp = shenqiUpNeedConfig.needExp
  599. if totalExp < needExp then
  600. return Broadcast.sendErr(human, Lang.EQUIP_SHENQI_UP_ERR_EXP)
  601. end
  602. -- 扣道具
  603. for i=1, equipIDList[0] do
  604. local needEquipCnt = equipCntList[i]
  605. BagLogic.delItem(human, equipIDList[i], needEquipCnt, "shenqi_upLv")
  606. end
  607. -- 改db
  608. heroGrid.equip[pos] = nextID
  609. local backExp = totalExp - needExp
  610. local backCnt = math.floor(backExp/10)
  611. -- 返还物
  612. if backCnt > 0 then
  613. BagLogic.addItem(human, HeroDefine.DEFAULT_SHENQI_UPLV_BACK, backCnt, "shenqi_upLv_back", noSend)
  614. end
  615. -- 计算属性
  616. ObjHuman.doCalcHero(human,heroIndex)
  617. HeroLogic.sendHeroBagDynamic(human, heroID, heroIndex)
  618. -- 通知客户端
  619. local msgRet = Msg.gc.GC_HERO_EQUIP_PUTON
  620. msgRet.heroID = heroID
  621. msgRet.heroIndex = heroIndex
  622. Grid.makeItem(msgRet.equip, nextID, 1)
  623. Msg.send(msgRet, human.fd)
  624. local msgRet = Msg.gc.GC_SHENQI_UPLV_DO
  625. msgRet.heroID = heroID
  626. msgRet.heroIndex = heroIndex
  627. if backCnt > 0 then
  628. msgRet.equip[0] = 1
  629. Grid.makeItem(msgRet.equip[1], HeroDefine.DEFAULT_SHENQI_UPLV_BACK,backCnt)
  630. else
  631. msgRet.equip[0] = 0
  632. end
  633. Msg.send(msgRet, human.fd)
  634. end
  635. -- 比较2件装备信息,返回较好的装备id
  636. function cmpEquip(equipID1, equipID2, heroConfig)
  637. if not equipID1 then return equipID2 end
  638. if not equipID2 then return equipID1 end
  639. if equipID1 == equipID2 then
  640. return equipID1
  641. end
  642. local config1 = EquipExcel.equip[equipID1]
  643. if not config1 then return equipID2 end
  644. local config2 = EquipExcel.equip[equipID2]
  645. if not config2 then return equipID1 end
  646. if config1.rare ~= config2.rare then
  647. return (config1.rare > config2.rare) and equipID1 or equipID2
  648. end
  649. if config1.level ~= config2.level then
  650. return (config1.level > config2.level) and equipID1 or equipID2
  651. end
  652. if heroConfig then -- 专属装备判断 阵营 职业
  653. if config1.camp == heroConfig.camp then return equipID1 end
  654. if config2.camp == heroConfig.camp then return equipID2 end
  655. if config1.job == heroConfig.job then return equipID1 end
  656. if config2.job == heroConfig.job then return equipID2 end
  657. end
  658. return equipID1
  659. end
  660. -- 根据部位和伙伴信息获取背包最好的装备id
  661. function getBagBestEquipID(human, pos, heroConfig)
  662. local bestEquipID = nil
  663. for k, equipGrid in pairs(human.db.equipBag) do
  664. local config = EquipExcel.equip[equipGrid.id]
  665. if config and config.subType == pos then
  666. bestEquipID = cmpEquip(bestEquipID, equipGrid.id, heroConfig)
  667. end
  668. end
  669. return bestEquipID
  670. end
  671. -- 是否有装备红点
  672. function isEquipDot(human, heroGrid)
  673. if human.db.lv < 9 then
  674. return false
  675. end
  676. if not heroGrid then return end
  677. local heroConfig = HeroExcel.hero[heroGrid.id]
  678. if not heroConfig then return end
  679. for pos = 1, ItemDefine.EQUIP_MAX_CNT do
  680. if pos ~= ItemDefine.EQUIP_SUBTYPE_SHUIJIN then
  681. local equipGrid = heroGrid.equip and heroGrid.equip[pos]
  682. if equipGrid == nil and EquipLogic.getEquipByPos(human, heroGrid.star, pos) then
  683. return true
  684. end
  685. end
  686. end
  687. end
  688. -- 是否有装备红点
  689. function isEquipDotByPos(human, heroGrid, pos)
  690. if human.db.lv < 9 then
  691. return false
  692. end
  693. if not heroGrid then return end
  694. local heroConfig = HeroExcel.hero[heroGrid.id]
  695. if not heroConfig then return end
  696. if pos ~= ItemDefine.EQUIP_SUBTYPE_SHUIJIN then
  697. local equipGrid = heroGrid.equip and heroGrid.equip[pos]
  698. if equipGrid == nil and EquipLogic.getEquipByPos(human, heroGrid.star, pos) then
  699. return 1
  700. end
  701. end
  702. end
  703. function getEquipAndFuwenByHeroIndex(human,heroID,heroIndex)
  704. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  705. if not heroGrid then return end
  706. local heroConfig = HeroExcel.hero[heroGrid.id]
  707. if not heroConfig then return end
  708. local equipTb = {}
  709. for pos = 1, ItemDefine.EQUIP_MAX_CNT do
  710. if pos ~= ItemDefine.EQUIP_SUBTYPE_SHUIJIN then
  711. local equipID = heroGrid.equip and heroGrid.equip[pos] and heroGrid.equip[pos].id
  712. equipTb[pos] = equipID
  713. end
  714. end
  715. local fuwenTb = {}
  716. for pos = 1,2 do
  717. local fuwenIndex = heroGrid.fuwen and heroGrid.fuwen[pos]
  718. fuwenTb[pos] = fuwenIndex
  719. end
  720. return equipTb,fuwenTb
  721. end