SkillEquipData.lua 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. local SkillEquipData = class("SkillEquipData", require("DataBase"))
  2. function SkillEquipData:ctor()
  3. self.data = {}
  4. end
  5. function SkillEquipData:InitData(skillEquipList)
  6. -- ---假数据测试
  7. -- skillEquipList = {}
  8. -- skillEquipList.skill_equip_list = {}
  9. -- for i = 1, 10 do
  10. -- local data = {id = i, config_id = 14199 + i, star_level = 0}
  11. -- skillEquipList.skill_equip_list[#skillEquipList.skill_equip_list + 1] = data
  12. -- end
  13. -- ---
  14. -- LogHRWarning(Inspect(skillEquipList))
  15. self.data.skillEquips = {}
  16. self.data.skillEquipMaps = {}
  17. if not skillEquipList or not skillEquipList.skill_equip_list then return end
  18. for i = 1, #skillEquipList.skill_equip_list do
  19. local data = ProtocalDataNormal.ParseSkillEquipData(skillEquipList.skill_equip_list[i])
  20. self.data.skillEquips[#self.data.skillEquips + 1] = data
  21. self.data.skillEquipMaps[data.id] = data
  22. end
  23. end
  24. function SkillEquipData:GetSkillEquips()
  25. return self.data.skillEquips
  26. end
  27. function SkillEquipData:GetSkillEquipDataByUid(id)
  28. return self.data.skillEquipMaps[id]
  29. end
  30. function SkillEquipData:GetSkillEquipDatasFilterJobData(jobData)
  31. local list = {}
  32. for i = 1, #self.data.skillEquips do
  33. local data = self.data.skillEquips[i]
  34. if data.jobType == jobData.JobType and data.jobBranch == jobData.JobBranch and data.jobStage == jobData.JobStage then
  35. list[#list + 1] = data
  36. end
  37. end
  38. return list
  39. end
  40. function SkillEquipData:SkillEquipDataCanLvUp(data)
  41. if not data or data.id == 0 then return false end
  42. local cfgData = ManagerContainer.CfgMgr:GetArtifactCfgDataByCfgId(data.cfgId)
  43. if not cfgData then
  44. return false
  45. end
  46. local cost = cfgData.Condition[data.starLv + 1]
  47. if not cost then return false end
  48. local costId = cost[1][1]
  49. local list = {}
  50. for i = 1, #self.data.skillEquips do
  51. local data = self.data.skillEquips[i]
  52. if data.cfgId == costId then
  53. list[#list + 1] = data
  54. end
  55. end
  56. if #list == 0 then
  57. return false
  58. end
  59. if cost[2] then
  60. local ownRes = CommonUtil.GetOwnResCountByItemId(cost[2][1])
  61. if ownRes < cost[2][2] then
  62. return false
  63. end
  64. end
  65. return true
  66. end
  67. function SkillEquipData:SkillEquipSlotCanLvUp(id)
  68. local heroData = CommonUtil.GetHeroLogicDataByUid(id)
  69. if not heroData then return false end
  70. local skillEquipSlot = heroData.skillEquipSlot
  71. local slotList = skillEquipSlot.slotList
  72. if not slotList then return false end
  73. local curSkillEquipData = slotList[1]
  74. if not curSkillEquipData then return false end
  75. local cost = ManagerContainer.CfgMgr:GetArtifactExpCfgCostByLv(curSkillEquipData.slotLv)
  76. local lack = false
  77. if cost then
  78. for i = 1, #cost do
  79. local cst = cost[i]
  80. if cst then
  81. local cfgData = ManagerContainer.CfgMgr:GetItemById(cst[1])
  82. if cfgData then
  83. local ownNum = CommonUtil.GetOwnResCountByItemId(cst[1])
  84. if ownNum < cst[2] then
  85. return false
  86. end
  87. end
  88. end
  89. end
  90. end
  91. return true
  92. end
  93. function SkillEquipData:RefreshSkillEquipData(data)
  94. -- LogHRWarning(Inspect(data))
  95. local addEquips = {}
  96. for i = 1, #data.skill_equip_change_list do
  97. local id = data.skill_equip_change_list[i].skill_equip_data.id
  98. local data1 = self.data.skillEquipMaps[id]
  99. if not data1 then
  100. if data.skill_equip_change_list[i].add then
  101. data1 = ProtocalDataNormal.ParseSkillEquipData(data.skill_equip_change_list[i].skill_equip_data)
  102. self.data.skillEquipMaps[data1.id] = data1
  103. self.data.skillEquips[#self.data.skillEquips + 1] = data1
  104. addEquips[#addEquips + 1] = {data1.cfgId, 1, data1.starLv}
  105. end
  106. else
  107. if not data.skill_equip_change_list[i].add then
  108. self.data.skillEquipMaps[id] = nil
  109. local result, idx = CommonUtil.EleInTable(data1, self.data.skillEquips)
  110. if idx then
  111. table.remove(self.data.skillEquips, idx)
  112. end
  113. else
  114. data1.starLv = data.skill_equip_change_list[i].skill_equip_data.star_level
  115. end
  116. end
  117. end
  118. if next(addEquips) ~= nil then
  119. if not data.ignore then
  120. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_SKILL_EQUIP_ADD_LIST, addEquips)
  121. end
  122. end
  123. end
  124. function SkillEquipData:SendSkillEquipStarUpReq(heroId, skillEquipId, costIds)
  125. self.heroId = heroId
  126. self.skillEquipId = skillEquipId
  127. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_SKILL_EQUIP_LEVEL_UP_REQ, {hero_id = heroId, skill_equip_id = skillEquipId, select_cost = costIds})
  128. end
  129. function SkillEquipData:SCSkillEquipLvUpAck(data)
  130. if data.error ~= Enum.NetErrorCode.ERROR_OK then return end
  131. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.SKILL_EQUIP_LV_UP_REFRESH)
  132. ManagerContainer.RedPointMgr.HeroRPCtr:RefreshRoleSkillEquipRPById(self.heroId)
  133. end
  134. function SkillEquipData:SendSkillEquipUpReq(heroId, slotIdx, skillEquipId)
  135. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_SKILL_EQUIP_UP_REQ, {hero_id = heroId, slot_index = slotIdx - 1, skill_equip_id = skillEquipId})
  136. end
  137. function SkillEquipData:SCSkillEquipUpAck(data)
  138. if data.error ~= Enum.NetErrorCode.ERROR_OK then return end
  139. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.SKILL_EQUIP_SLOT_REFRESH)
  140. end
  141. function SkillEquipData:SendSkillEquipDownReq(heroId, slotIdx)
  142. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_SKILL_EQUIP_DOWN_REQ, {hero_id = heroId, slot_index = slotIdx - 1})
  143. end
  144. function SkillEquipData:SCSkillEquipDownAck(data)
  145. if data.error ~= Enum.NetErrorCode.ERROR_OK then return end
  146. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.SKILL_EQUIP_SLOT_REFRESH)
  147. end
  148. function SkillEquipData:SendSkillEquipSlotLevelUpReq(heroId, slotIdx)
  149. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_SKILL_EQUIP_SLOT_LEVEL_UP_REQ, {hero_id = heroId, slot_index = slotIdx - 1})
  150. end
  151. function SkillEquipData:SCSkillEquipSlotLvUpAck(data)
  152. if data.error ~= Enum.NetErrorCode.ERROR_OK then return end
  153. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.SKILL_EQUIP_SLOT_LVUP_REFRESH)
  154. end
  155. function SkillEquipData:SCSkillEquipSlotNtf(slotData)
  156. -- LogHRWarning(Inspect(slotData))
  157. local heroId = slotData.hero_id
  158. local heroData = CommonUtil.GetHeroLogicDataByUid(heroId)
  159. if not heroData then return end
  160. local skillEquipSlot = heroData.skillEquipSlot
  161. local slotList = skillEquipSlot.slotList
  162. local isUpOrDown = false
  163. local lvUp = false
  164. for i = 1, #slotData.slot.slot_list do
  165. local data = slotList[i]
  166. if not data then
  167. isUpOrDown = true
  168. data = {}
  169. slotList[i] = data
  170. end
  171. local data1 = slotData.slot.slot_list[i]
  172. if data.id ~= data1.skill_equip_id then
  173. isUpOrDown = true
  174. end
  175. data.id = data1.skill_equip_id
  176. data.cfgId = data1.skill_equip_config_id
  177. if data1.slot_level > (data and data.slotLv or 0) or data1.skill_equip_star_level > (data and data.starLv or 0) then
  178. lvUp = true
  179. end
  180. data.starLv = data1.skill_equip_star_level
  181. data.slotLv = data1.slot_level
  182. data.slotAttrs = {}
  183. for _,v1 in pairs(data1.slot_attrs) do
  184. data.slotAttrs[v1.key] = v1.value
  185. end
  186. local cfgData = ManagerContainer.CfgMgr:GetArtifactCfgDataByCfgId(data.cfgId)
  187. data.maxStarLv = cfgData and cfgData.ArtifactMaxLevel or 0
  188. data.quality = cfgData and cfgData.Quality or 0
  189. data.jobType = cfgData and cfgData.JobType or 0
  190. data.jobBranch = cfgData and cfgData.JobBranch or 0
  191. data.jobStage = cfgData and cfgData.JobStage or 0
  192. end
  193. CommonUtil.UpdateHeroExtGoShowData(heroData)
  194. if isUpOrDown or lvUp then
  195. ManagerContainer.RedPointMgr.HeroRPCtr:RefreshRoleSkillEquipRP()
  196. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.SKILL_EQUIP_RP_REFRESH)
  197. end
  198. --刷新伙伴角色形象
  199. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.PARTNER_EQUIP_REFRESH,heroId)
  200. end
  201. function SkillEquipData:SendSkillEquipDecomposeReq(ids)
  202. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_SKILL_EQUIP_DECOMPOSE_REQ, {skill_equip_id = ids})
  203. end
  204. function SkillEquipData:SCSkillEquipDecomposeAck(data)
  205. if data.error ~= Enum.NetErrorCode.ERROR_OK then return end
  206. CommonUtil.ACKShowRewardList(data.item_list)
  207. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.SKILL_EQUIP_DECOMPOSE_REFRESH)
  208. ManagerContainer.RedPointMgr.HeroRPCtr:RefreshRoleSkillEquipRP()
  209. end
  210. function SkillEquipData:SCSkillEquipReforgeAck(data)
  211. if data.error ~= Enum.NetErrorCode.ERROR_OK then return end
  212. local data1 = self:GetSkillEquipDataByUid(data.new_id)
  213. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.SKILL_EQUIP_REFORGE_SUCCESS, data1)
  214. end
  215. function SkillEquipData:SendSkillEquipReforgeReq(id)
  216. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_SKILL_EQUIP_REMADE_REQ, {skill_equip_id = id})
  217. end
  218. function SkillEquipData:SCSkillEquipPoolAck(data)
  219. -- LogHRWarning(Inspect(data))
  220. if data.error ~= Enum.NetErrorCode.ERROR_OK then return end
  221. if not self.randomPoolStruct then
  222. self.randomPoolStruct = {}
  223. end
  224. self.randomPoolStruct.curId = data.cur_id
  225. self.randomPoolStruct.poolIdList = data.pool_id_list
  226. self.randomPoolStruct.nextPool = data.next_pool
  227. self.randomPoolStruct.nextBegin = data.next_begin
  228. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.SKILL_EQUIP_POOL_REFRESH)
  229. end
  230. function SkillEquipData:SendSkillEquipPoolReq()
  231. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_SKILL_EQUIP_POOL_REQ, {})
  232. end
  233. function SkillEquipData:SCSkillEquipShiftAck(data)
  234. -- LogHRWarning("SCSkillEquipShiftAck "..Inspect(data))
  235. if data.error ~= Enum.NetErrorCode.ERROR_OK then return end
  236. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.SKILL_EQUIP_SHIFT_REFRESH)
  237. end
  238. function SkillEquipData:SendSkillEquipShiftReq(srcId, dstId)
  239. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_SKILL_EQUIP_SHIFT_REQ, {src_id = srcId, dst_id = dstId})
  240. end
  241. function SkillEquipData:GetCurRandomPool()
  242. return self.randomPoolStruct
  243. end
  244. function SkillEquipData:RegisterNetEvents()
  245. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_SKILL_EQUIP_LEVEL_UP_ACK, self.SCSkillEquipLvUpAck, self)
  246. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_SKILL_EQUIP_UP_ACK, self.SCSkillEquipUpAck, self)
  247. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_SKILL_EQUIP_DOWN_ACK, self.SCSkillEquipDownAck, self)
  248. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_SKILL_EQUIP_CHANGE_NTF, self.RefreshSkillEquipData, self)
  249. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_SKILL_EQUIP_SLOT_LEVEL_UP_ACK, self.SCSkillEquipSlotLvUpAck, self)
  250. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_SKILL_EQUIP_SLOT_DATA_NTF, self.SCSkillEquipSlotNtf, self)
  251. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_SKILL_EQUIP_DECOMPOSE_ACK, self.SCSkillEquipDecomposeAck, self)
  252. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_SKILL_EQUIP_REMADE_ACK, self.SCSkillEquipReforgeAck, self)
  253. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_SKILL_EQUIP_POOL_ACK, self.SCSkillEquipPoolAck, self)
  254. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_SKILL_EQUIP_SHIFT_ACK, self.SCSkillEquipShiftAck, self)
  255. end
  256. function SkillEquipData:Clear()
  257. self.data = {}
  258. self.randomPoolStruct = nil
  259. end
  260. function SkillEquipData:Destroy()
  261. if self.Clear then
  262. self:Clear()
  263. end
  264. self:UnRegisterNetEvents()
  265. end
  266. function SkillEquipData:UnRegisterNetEvents()
  267. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_SKILL_EQUIP_LEVEL_UP_ACK)
  268. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_SKILL_EQUIP_UP_ACK)
  269. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_SKILL_EQUIP_DOWN_ACK)
  270. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_SKILL_EQUIP_CHANGE_NTF)
  271. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_SKILL_EQUIP_SLOT_LEVEL_UP_ACK)
  272. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_SKILL_EQUIP_SLOT_DATA_NTF)
  273. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_SKILL_EQUIP_DECOMPOSE_ACK)
  274. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_SKILL_EQUIP_REMADE_ACK)
  275. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_SKILL_EQUIP_POOL_ACK)
  276. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_SKILL_EQUIP_SHIFT_ACK)
  277. end
  278. return SkillEquipData