EquipWash.lua 8.6 KB

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