EquipWash.lua 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. -- 装备图鉴
  2. local Msg = require("core.Msg")
  3. local EquipExcel = require("excel.equip").equip
  4. local EquipRareExcel = require("excel.equip").rare
  5. local ItemDefine = require("bag.ItemDefine")
  6. local Grid = require("bag.Grid")
  7. local EquipLogic = require("equip.EquipLogic")
  8. local BagLogic = require("bag.BagLogic")
  9. local EquipLogicGrid = require("equip.EquipLogicGrid")
  10. local Lang = require("common.Lang")
  11. local Broadcast = require("broadcast.Broadcast")
  12. local HeroLogic = require("hero.HeroLogic")
  13. local Util = require("common.Util")
  14. local HeroGrowUp = require("absAct.HeroGrowUp")
  15. local ObjHuman = require("core.ObjHuman")
  16. local TriggerLogic = require("trigger.TriggerLogic")
  17. local TriggerDefine = require("trigger.TriggerDefine")
  18. -- 取出合适的装备
  19. local function getEquipGrid(human, bagIndex, heroUuid, pos)
  20. local equipGrid = human.db.equipBag[bagIndex]
  21. if not equipGrid then
  22. -- 取英雄身上的
  23. local heroGrid, heroIndex = HeroLogic.getHeroGridByUuid(human, heroUuid)
  24. if not heroGrid then return end
  25. equipGrid = heroGrid.equip and heroGrid.equip[pos]
  26. return equipGrid, heroGrid, heroIndex
  27. end
  28. return equipGrid, nil, nil
  29. end
  30. -- 查询装备图鉴 全部信息
  31. function fenjieQuey(human, inputList)
  32. local indexTable = { }
  33. for i = 1, inputList[0] do
  34. local index = inputList[i]
  35. local equipGrid = human.db.equipBag[index]
  36. if not equipGrid then
  37. return
  38. end
  39. if not EquipRareExcel[equipGrid.quality] then return end
  40. if indexTable[index] then
  41. -- 重复id
  42. return
  43. end
  44. indexTable[index] = true
  45. end
  46. local itemList = { }
  47. for i = 1, inputList[0] do
  48. local index = inputList[i]
  49. local equipGrid = human.db.equipBag[index]
  50. local equipConfig = EquipExcel[equipGrid.id]
  51. if not equipConfig then return end
  52. for k, v in ipairs(EquipRareExcel[equipGrid.quality].disassembly) do
  53. itemList[v[1]] = itemList[v[1]] or 0
  54. itemList[v[1]] = itemList[v[1]] + v[2]
  55. end
  56. end
  57. local msgRet = Msg.gc.GC_EQUIP_FEN_JIE_QUERY
  58. local len = 0
  59. for k, v in pairs(itemList) do
  60. len = len + 1
  61. Grid.makeItem(msgRet.list[len], k, v)
  62. end
  63. msgRet.list[0] = len
  64. Msg.send(msgRet, human.fd)
  65. end
  66. -- 查询装备图鉴 全部信息
  67. function fenjieDo(human, inputList)
  68. local indexTable = { }
  69. for i = 1, inputList[0] do
  70. local index = inputList[i]
  71. local equipGrid = human.db.equipBag[index]
  72. if not equipGrid then
  73. return
  74. end
  75. if not EquipRareExcel[equipGrid.quality] then return end
  76. if indexTable[index] then
  77. -- 重复id
  78. return
  79. end
  80. indexTable[index] = true
  81. end
  82. local itemList = { }
  83. for i = 1, inputList[0] do
  84. local index = inputList[i]
  85. local equipGrid = human.db.equipBag[index]
  86. local equipConfig = EquipExcel[equipGrid.id]
  87. if not equipConfig then return end
  88. for k, v in ipairs(EquipRareExcel[equipGrid.quality].disassembly) do
  89. itemList[v[1]] = itemList[v[1]] or 0
  90. itemList[v[1]] = itemList[v[1]] + v[2]
  91. end
  92. EquipLogic.delEquip(human, index, "equip_fenjie")
  93. HeroGrowUp.onCallback(human, HeroGrowUp.TASKTYPE21, 1)
  94. end
  95. BagLogic.addItemList(human, itemList, "equip_fenjie")
  96. local msgRet = Msg.gc.GC_EQUIP_FEN_JIE_DO
  97. Msg.send(msgRet, human.fd)
  98. end
  99. -- 洗练查询
  100. function randomQuery(human, bagIndex, heroUuid, pos)
  101. local equipGrid = getEquipGrid(human, bagIndex, heroUuid, pos)
  102. if not equipGrid then return end
  103. local rareExcel = EquipRareExcel[equipGrid.quality]
  104. if not rareExcel then return end
  105. local msgRet = Msg.gc.GC_EQUIP_RAMDOM_QUERY
  106. Grid.makeItem(msgRet.equipOld, equipGrid.id, 1, nil, equipGrid, bagIndex)
  107. -- 当前洗练属性
  108. local washAttr = equipGrid.washAttr
  109. local washQuality = equipGrid.washQuality
  110. msgRet.equipNew[0] = 0
  111. if washAttr and washQuality then
  112. local washEquipGrid = EquipLogicGrid.createTempGrid(equipGrid.id, equipGrid.washAttr, equipGrid.washQuality)
  113. Grid.makeItem(msgRet.equipNew[1], washEquipGrid.id, 1, nil, washEquipGrid, bagIndex)
  114. msgRet.equipNew[0] = 1
  115. end
  116. msgRet.needItem[0] = #rareExcel.rebirth
  117. for i = 1, msgRet.needItem[0] do
  118. Grid.makeItem(msgRet.needItem[i], rareExcel.rebirth[i][1], rareExcel.rebirth[i][2])
  119. end
  120. Msg.send(msgRet, human.fd)
  121. end
  122. -- 已穿戴的装备
  123. function putList(human, pos)
  124. local msgRet = Msg.gc.GC_EQUIP_PUT_LIST
  125. local cnt = 0
  126. for index = 1, human.db.heroBag[0] do
  127. local heroGrid = human.db.heroBag[index]
  128. if heroGrid and heroGrid.lv >= 2 then
  129. -- 所有部位
  130. if pos == 0 then
  131. for i = 1, ItemDefine.EQUIP_MAX_CNT do
  132. local equipGrid = heroGrid.equip and heroGrid.equip[i]
  133. if equipGrid then
  134. cnt = cnt + 1
  135. local net = msgRet.putList[cnt]
  136. if i ~= ItemDefine.EQUIP_SUBTYPE_SHUIJIN then
  137. Grid.makeItem(net.equip, equipGrid.id, 1, nil, equipGrid)
  138. net.pos = i
  139. end
  140. if cnt >= 10 then
  141. msgRet.isEnd = 0
  142. msgRet.putList[0] = cnt
  143. Msg.send(msgRet, human.fd)
  144. cnt = 0
  145. end
  146. end
  147. end
  148. else
  149. local equipGrid = heroGrid.equip and heroGrid.equip[pos]
  150. if equipGrid then
  151. cnt = cnt + 1
  152. local net = msgRet.putList[cnt]
  153. if i ~= ItemDefine.EQUIP_SUBTYPE_SHUIJIN then
  154. Grid.makeItem(net.equip, equipGrid.id, 1, nil, equipGrid)
  155. net.pos = pos
  156. end
  157. if cnt >= 10 then
  158. msgRet.isEnd = 0
  159. msgRet.putList[0] = cnt
  160. Msg.send(msgRet, human.fd)
  161. cnt = 0
  162. end
  163. end
  164. end
  165. end
  166. end
  167. msgRet.isEnd = 1
  168. msgRet.putList[0] = cnt
  169. Msg.send(msgRet, human.fd)
  170. end
  171. -- 洗练
  172. function randomDo(human, bagIndex, heroUuid, pos)
  173. local equipGrid = getEquipGrid(human, bagIndex, heroUuid, pos)
  174. if not equipGrid then return end
  175. local rareExcel = EquipRareExcel[equipGrid.quality]
  176. if not rareExcel then return end
  177. for i = 1, #rareExcel.rebirth do
  178. local needItemID = rareExcel.rebirth[i][1]
  179. local needItemCnt = rareExcel.rebirth[i][2]
  180. local nowItemCnt = BagLogic.getItemCnt(human, needItemID)
  181. if nowItemCnt < needItemCnt then
  182. return Broadcast.sendErr(human, Util.format(Lang.XIANZHI_NO_ITEM, ItemDefine.getValue(needItemID,"name")))
  183. end
  184. end
  185. for i = 1, #rareExcel.rebirth do
  186. local needItemID = rareExcel.rebirth[i][1]
  187. local needItemCnt = rareExcel.rebirth[i][2]
  188. BagLogic.delItem(human, needItemID, needItemCnt, "equip_wash")
  189. end
  190. local attr, quality = EquipLogic.randomAttr(equipGrid.id, true, equipGrid.quality)
  191. equipGrid.washAttr = attr
  192. equipGrid.washQuality = quality
  193. HeroGrowUp.onCallback(human, HeroGrowUp.TASKTYPE19, 1)
  194. Broadcast.sendErr(human, Lang.EQUIP_WASH_RANDOM_SUC)
  195. randomQuery(human, bagIndex, heroUuid, pos)
  196. TriggerLogic.PublishEvent(TriggerDefine.EQUIP_REFINEMENT, human.db._id, 1)
  197. end
  198. -- 洗练保存
  199. function randomSave(human, bagIndex, heroUuid, pos)
  200. local equipGrid, heroGrid, heroIndex = getEquipGrid(human, bagIndex, heroUuid, pos)
  201. if not equipGrid then return end
  202. local washAttr = equipGrid.washAttr
  203. local washQuality = equipGrid.washQuality
  204. if not washAttr or not washQuality then return end
  205. equipGrid.attr = washAttr
  206. equipGrid.quality = washQuality
  207. equipGrid.washAttr = nil
  208. equipGrid.washQuality = nil
  209. EquipLogic.checkAttr(equipGrid)
  210. -- 更新背包的
  211. if not heroGrid then
  212. EquipLogic.sendEquipChange(human, bagIndex, equipGrid, EquipLogic.EQUIP_BAG_OP_CHANGE)
  213. end
  214. Broadcast.sendErr(human, Lang.EQUIP_WASH_SAVE_SUC)
  215. randomQuery(human, bagIndex, heroUuid, pos)
  216. --刷新属性
  217. if heroGrid and heroIndex and heroGrid.id then
  218. -- if not heroGrid or not heroIndex or not then
  219. -- return Broadcast.sendErr(human, Lang.DRILL_CHOOSE_FRIEND_ERR_INFO)
  220. -- end
  221. ObjHuman.doCalcHero(human, heroIndex)
  222. HeroLogic.sendHeroBagDynamic(human, heroGrid.id, heroIndex)
  223. end
  224. end