EquipWash.lua 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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. local function getEquipLockAttrInfo(equipGrid)
  32. if not equipGrid or not equipGrid.attr or #equipGrid.attr <= 1 then
  33. return
  34. end
  35. local num = 0
  36. local idxList = {}
  37. for idx, attrInfo in ipairs(equipGrid.attr) do
  38. if attrInfo[4] and attrInfo[4] == 1 then
  39. num = num + 1
  40. idxList[idx] = idx
  41. end
  42. end
  43. return num, idxList
  44. end
  45. -- 查询装备图鉴 全部信息
  46. function fenjieQuey(human, inputList)
  47. local indexTable = { }
  48. for i = 1, inputList[0] do
  49. local index = inputList[i]
  50. local equipGrid = human.db.equipBag[index]
  51. if not equipGrid then
  52. return
  53. end
  54. if not EquipRareExcel[equipGrid.quality] then return end
  55. if indexTable[index] then
  56. -- 重复id
  57. return
  58. end
  59. indexTable[index] = true
  60. end
  61. local itemList = { }
  62. for i = 1, inputList[0] do
  63. local index = inputList[i]
  64. local equipGrid = human.db.equipBag[index]
  65. local equipConfig = EquipExcel[equipGrid.id]
  66. if not equipConfig then return end
  67. for k, v in ipairs(EquipRareExcel[equipGrid.quality].disassembly) do
  68. itemList[v[1]] = itemList[v[1]] or 0
  69. itemList[v[1]] = itemList[v[1]] + v[2]
  70. end
  71. end
  72. local msgRet = Msg.gc.GC_EQUIP_FEN_JIE_QUERY
  73. local len = 0
  74. for k, v in pairs(itemList) do
  75. len = len + 1
  76. Grid.makeItem(msgRet.list[len], k, v)
  77. end
  78. msgRet.list[0] = len
  79. Msg.send(msgRet, human.fd)
  80. end
  81. -- 查询装备图鉴 全部信息
  82. function fenjieDo(human, inputList)
  83. local indexTable = { }
  84. for i = 1, inputList[0] do
  85. local index = inputList[i]
  86. local equipGrid = human.db.equipBag[index]
  87. if not equipGrid then
  88. return
  89. end
  90. if not EquipRareExcel[equipGrid.quality] then return end
  91. if indexTable[index] then
  92. -- 重复id
  93. return
  94. end
  95. indexTable[index] = true
  96. end
  97. local itemList = { }
  98. for i = 1, inputList[0] do
  99. local index = inputList[i]
  100. local equipGrid = human.db.equipBag[index]
  101. local equipConfig = EquipExcel[equipGrid.id]
  102. if not equipConfig then return end
  103. for k, v in ipairs(EquipRareExcel[equipGrid.quality].disassembly) do
  104. itemList[v[1]] = itemList[v[1]] or 0
  105. itemList[v[1]] = itemList[v[1]] + v[2]
  106. end
  107. EquipLogic.delEquip(human, index, "equip_fenjie")
  108. HeroGrowUp.onCallback(human, HeroGrowUp.TASKTYPE21, 1)
  109. end
  110. BagLogic.addItemList(human, itemList, "equip_fenjie")
  111. local msgRet = Msg.gc.GC_EQUIP_FEN_JIE_DO
  112. Msg.send(msgRet, human.fd)
  113. end
  114. -- 洗练查询
  115. function randomQuery(human, bagIndex, heroUuid, pos)
  116. local equipGrid = getEquipGrid(human, bagIndex, heroUuid, pos)
  117. if not equipGrid then return end
  118. local rareExcel = EquipRareExcel[equipGrid.quality]
  119. if not rareExcel then return end
  120. local attrLockNum = getEquipLockAttrInfo(equipGrid)
  121. local msgRet = Msg.gc.GC_EQUIP_RAMDOM_QUERY
  122. Grid.makeItem(msgRet.equipOld, equipGrid.id, 1, nil, equipGrid, bagIndex)
  123. -- 当前洗练属性
  124. local washAttr = equipGrid.washAttr
  125. local washQuality = equipGrid.washQuality
  126. msgRet.equipNew[0] = 0
  127. if washAttr and washQuality then
  128. local washEquipGrid = EquipLogicGrid.createTempGrid(equipGrid.id, equipGrid.washAttr, equipGrid.washQuality)
  129. Grid.makeItem(msgRet.equipNew[1], washEquipGrid.id, 1, nil, washEquipGrid, bagIndex)
  130. msgRet.equipNew[0] = 1
  131. end
  132. msgRet.needItem[0] = #rareExcel.rebirth
  133. for i = 1, msgRet.needItem[0] do
  134. -- Grid.makeItem(msgRet.needItem[i], rareExcel.rebirth[i][1], rareExcel.rebirth[i][2])
  135. local itemCnt = rareExcel.rebirth[i][2]
  136. if attrLockNum and attrLockNum > 0 then
  137. itemCnt = itemCnt * (attrLockNum + 1)
  138. end
  139. Grid.makeItem(msgRet.needItem[i], rareExcel.rebirth[i][1], itemCnt)
  140. end
  141. Msg.send(msgRet, human.fd)
  142. end
  143. -- 已穿戴的装备
  144. function putList(human, pos)
  145. local msgRet = Msg.gc.GC_EQUIP_PUT_LIST
  146. local cnt = 0
  147. for index = 1, human.db.heroBag[0] do
  148. local heroGrid = human.db.heroBag[index]
  149. if heroGrid and heroGrid.lv >= 2 then
  150. -- 所有部位
  151. if pos == 0 then
  152. for i = 1, ItemDefine.EQUIP_MAX_CNT do
  153. local equipGrid = heroGrid.equip and heroGrid.equip[i]
  154. if equipGrid then
  155. cnt = cnt + 1
  156. local net = msgRet.putList[cnt]
  157. if i ~= ItemDefine.EQUIP_SUBTYPE_SHUIJIN then
  158. Grid.makeItem(net.equip, equipGrid.id, 1, nil, equipGrid)
  159. net.pos = i
  160. end
  161. if cnt >= 10 then
  162. msgRet.isEnd = 0
  163. msgRet.putList[0] = cnt
  164. Msg.send(msgRet, human.fd)
  165. cnt = 0
  166. end
  167. end
  168. end
  169. else
  170. local equipGrid = heroGrid.equip and heroGrid.equip[pos]
  171. if equipGrid then
  172. cnt = cnt + 1
  173. local net = msgRet.putList[cnt]
  174. if i ~= ItemDefine.EQUIP_SUBTYPE_SHUIJIN then
  175. Grid.makeItem(net.equip, equipGrid.id, 1, nil, equipGrid)
  176. net.pos = pos
  177. end
  178. if cnt >= 10 then
  179. msgRet.isEnd = 0
  180. msgRet.putList[0] = cnt
  181. Msg.send(msgRet, human.fd)
  182. cnt = 0
  183. end
  184. end
  185. end
  186. end
  187. end
  188. msgRet.isEnd = 1
  189. msgRet.putList[0] = cnt
  190. Msg.send(msgRet, human.fd)
  191. end
  192. -- 洗练
  193. function randomDo(human, bagIndex, heroUuid, pos)
  194. local equipGrid = getEquipGrid(human, bagIndex, heroUuid, pos)
  195. if not equipGrid then return end
  196. local rareExcel = EquipRareExcel[equipGrid.quality]
  197. if not rareExcel then return end
  198. local attrLockNum, idxList = getEquipLockAttrInfo(equipGrid)
  199. for i = 1, #rareExcel.rebirth do
  200. local needItemID = rareExcel.rebirth[i][1]
  201. local needItemCnt = rareExcel.rebirth[i][2]
  202. if attrLockNum and attrLockNum > 0 then
  203. needItemCnt = needItemCnt * (attrLockNum + 1)
  204. end
  205. local nowItemCnt = BagLogic.getItemCnt(human, needItemID)
  206. if nowItemCnt < needItemCnt then
  207. return Broadcast.sendErr(human, Util.format(Lang.XIANZHI_NO_ITEM, ItemDefine.getValue(needItemID,"name")))
  208. end
  209. end
  210. for i = 1, #rareExcel.rebirth do
  211. local needItemID = rareExcel.rebirth[i][1]
  212. local needItemCnt = rareExcel.rebirth[i][2]
  213. if attrLockNum and attrLockNum > 0 then
  214. needItemCnt = needItemCnt * (attrLockNum + 1)
  215. end
  216. BagLogic.delItem(human, needItemID, needItemCnt, "equip_wash")
  217. end
  218. local excludeAttrList
  219. if idxList then
  220. excludeAttrList = {}
  221. for idx in pairs(idxList) do
  222. local attrType = equipGrid.attr[idx] and equipGrid.attr[idx][1]
  223. if attrType then
  224. excludeAttrList[attrType] = 1
  225. end
  226. end
  227. end
  228. local attr, quality = EquipLogic.randomAttr(equipGrid.id, true, equipGrid.quality, excludeAttrList)
  229. for idx in pairs(idxList or {}) do
  230. if attr[idx] and equipGrid.attr[idx] then
  231. attr[idx][1] = equipGrid.attr[idx][1] -- attrType
  232. attr[idx][2] = equipGrid.attr[idx][2] -- attrValue
  233. attr[idx][3] = equipGrid.attr[idx][3] -- color
  234. end
  235. end
  236. equipGrid.washAttr = attr
  237. equipGrid.washQuality = quality
  238. HeroGrowUp.onCallback(human, HeroGrowUp.TASKTYPE19, 1)
  239. Broadcast.sendErr(human, Lang.EQUIP_WASH_RANDOM_SUC)
  240. randomQuery(human, bagIndex, heroUuid, pos)
  241. TriggerLogic.PublishEvent(TriggerDefine.EQUIP_REFINEMENT, human.db._id, 1)
  242. end
  243. -- 洗练保存
  244. function randomSave(human, bagIndex, heroUuid, pos)
  245. local equipGrid, heroGrid, heroIndex = getEquipGrid(human, bagIndex, heroUuid, pos)
  246. if not equipGrid then return end
  247. local washAttr = equipGrid.washAttr
  248. local washQuality = equipGrid.washQuality
  249. if not washAttr or not washQuality then return end
  250. -- equipGrid.attr = washAttr
  251. local _, idxList = getEquipLockAttrInfo(equipGrid)
  252. for idx, attrInfo in ipairs(washAttr) do
  253. if not idxList or not idxList[idx] then
  254. equipGrid.attr[idx] = attrInfo
  255. end
  256. end
  257. equipGrid.quality = washQuality
  258. equipGrid.washAttr = nil
  259. equipGrid.washQuality = nil
  260. EquipLogic.checkAttr(equipGrid)
  261. -- 更新背包的
  262. if not heroGrid then
  263. EquipLogic.sendEquipChange(human, bagIndex, equipGrid, EquipLogic.EQUIP_BAG_OP_CHANGE)
  264. end
  265. Broadcast.sendErr(human, Lang.EQUIP_WASH_SAVE_SUC)
  266. randomQuery(human, bagIndex, heroUuid, pos)
  267. --刷新属性
  268. if heroGrid and heroIndex and heroGrid.id then
  269. -- if not heroGrid or not heroIndex or not then
  270. -- return Broadcast.sendErr(human, Lang.DRILL_CHOOSE_FRIEND_ERR_INFO)
  271. -- end
  272. ObjHuman.doCalcHero(human, heroIndex)
  273. HeroLogic.sendHeroBagDynamic(human, heroGrid.id, heroIndex)
  274. end
  275. end
  276. -- 锁定/解锁装备洗练属性
  277. function LockEquipAttr(human, bagIndex, heroUuid, pos, opType, attrIdx)
  278. if opType ~= 0 and opType ~= 1 then
  279. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  280. end
  281. local equipGrid = getEquipGrid(human, bagIndex, heroUuid, pos)
  282. if not equipGrid then
  283. return Broadcast.sendErr(human, Lang.EQUIP_GRID_ERR)
  284. end
  285. if not equipGrid.attr or #equipGrid.attr <= 1 then
  286. return Broadcast.sendErr(human, Lang.EQUIP_ATTR_CANNOT_LOCK)
  287. end
  288. -- 洗练结束才能锁定
  289. if equipGrid.washAttr then
  290. return Broadcast.sendErr(human, Lang.EQUIP_ATTR_CANNOT_LOCK)
  291. end
  292. if not equipGrid.attr[attrIdx] then
  293. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  294. end
  295. local attrLockNum, idxList = getEquipLockAttrInfo(equipGrid)
  296. if not attrLockNum then
  297. Broadcast.sendErr(human, Lang.EQUIP_ATTR_CANNOT_LOCK)
  298. end
  299. if opType == 1 then
  300. if attrLockNum + 1 >= #equipGrid.attr then
  301. return Broadcast.sendErr(human, Lang.EQUIP_ATTR_CANNOT_LOCK_ALL)
  302. end
  303. if idxList[attrIdx] then
  304. return Broadcast.sendErr(human, Lang.EQUIP_ATTR_LOCKED)
  305. end
  306. else
  307. if not idxList[attrIdx] then
  308. return Broadcast.sendErr(human, Lang.EQUIP_ATTR_UNLOCK)
  309. end
  310. end
  311. -- 更新数据
  312. equipGrid.attr[attrIdx][4] = opType
  313. -- 推送数据给客户端
  314. randomQuery(human, bagIndex, heroUuid, pos)
  315. end
  316. -- 取消装备未选择的洗练属性
  317. function CancelEquipRandomAttr(human, bagIndex, heroUuid, pos)
  318. local equipGrid = getEquipGrid(human, bagIndex, heroUuid, pos)
  319. if not equipGrid then
  320. return Broadcast.sendErr(human, Lang.EQUIP_GRID_ERR)
  321. end
  322. equipGrid.washAttr = nil
  323. equipGrid.washQuality = nil
  324. randomQuery(human, bagIndex, heroUuid, pos)
  325. end