KeepSakeBookData.lua 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. local KeepSakeBookData = class("CardHandBook", require("DataBase"))
  2. function KeepSakeBookData:ctor()
  3. self.data = {}
  4. self.totalCount = 0
  5. self.normalCount = 0
  6. self.miniCount = 0
  7. self.mvpCount = 0
  8. self.data.keepSakeMaps = {}
  9. self.data.keepSakeMaterials = {}
  10. end
  11. function KeepSakeBookData:InitDatas(keepSakes, materials)
  12. self:RefreshDatas(keepSakes, materials)
  13. ManagerContainer.DataMgr.UserData:CalcKeepSakeAttrs()
  14. for i = 2, 6 do
  15. local data = ManagerContainer.DataMgr.PartnerData:GetPartnerDataByUniqueId(i)
  16. if data and data.owned then
  17. local fellowData = ManagerContainer.LuaActorDataMgr:GetFellowActorData(data.id,data.configId)
  18. ManagerContainer.DataMgr.PartnerData:CalcKeepSakeAttrs(fellowData, data, true)
  19. end
  20. end
  21. end
  22. function KeepSakeBookData:RefreshDatas(keepSakes, materials, isChange)
  23. local data = ProtocalDataNormal.ParseKeepSakeData(keepSakes)
  24. for _,v in pairs(data) do
  25. if not self.data.keepSakeMaps[v.keepSakeId] then
  26. self.totalCount = self.totalCount + 1
  27. local cfgData = ManagerContainer.CfgMgr:GetKeepSakeCfgDataById(v.keepSakeId)
  28. if cfgData then
  29. if cfgData.CollectionLevel == 2 then
  30. self.normalCount = self.normalCount + 1
  31. elseif cfgData.CollectionLevel == 3 then
  32. self.miniCount = self.miniCount + 1
  33. elseif cfgData.CollectionLevel == 4 then
  34. self.mvpCount = self.mvpCount + 1
  35. end
  36. end
  37. end
  38. local lastLv = self.data.keepSakeMaps[v.keepSakeId] or 0
  39. local isLvUp = lastLv < v.keepSakeLevel
  40. self.data.keepSakeMaps[v.keepSakeId] = v.keepSakeLevel
  41. if isLvUp and isChange then
  42. ManagerContainer.DataMgr.UserData:AddKeepSakeLvUpAttrs(v.keepSakeId, v.keepSakeLevel)
  43. ManagerContainer.DataMgr.PartnerData:AddKeepSakeLvUpAttrs(v.keepSakeId, v.keepSakeLevel)
  44. end
  45. end
  46. for _,v in pairs(materials) do
  47. self.data.keepSakeMaterials[v.key] = v.value
  48. end
  49. local rpState = false
  50. local list = ManagerContainer.CfgMgr:GetAllKeepSakeCfgDatas()
  51. for _,v in pairs(list) do
  52. local result = self:CanKeepSakeLvUp(v.Id)
  53. if result then
  54. rpState = true
  55. break
  56. end
  57. end
  58. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.RED_POINT_MGR_NOTICE, Enum.RPNotifyType.KeepSakeCollect, rpState)
  59. end
  60. function KeepSakeBookData:GetMaterialById(costId)
  61. return self.data.keepSakeMaterials[costId] or 0
  62. end
  63. function KeepSakeBookData:GetMaterialDatas()
  64. return self.data.keepSakeMaterials
  65. end
  66. function KeepSakeBookData:CanKeepSakeLvUp(id)
  67. local cfgData = ManagerContainer.CfgMgr:GetKeepSakeCfgDataById(id)
  68. local lv = self.data.keepSakeMaps[id] or 0
  69. local cost = cfgData["MaterialLevel"..(lv + 1)]
  70. if not cost then
  71. return false
  72. end
  73. for _,v in pairs(cost) do
  74. local costId = v[1]
  75. local costNum = v[2]
  76. if costNum > self:GetMaterialById(costId) then
  77. return false
  78. end
  79. end
  80. return true
  81. end
  82. function KeepSakeBookData:IsKeepSakeMaxLv(id)
  83. local cfgData = ManagerContainer.CfgMgr:GetKeepSakeCfgDataById(id)
  84. local lv = self.data.keepSakeMaps[id] or 0
  85. local cost = cfgData["MaterialLevel"..(lv + 1)]
  86. if not cost then
  87. return true
  88. end
  89. return false
  90. end
  91. function KeepSakeBookData:QueryKeepSakeHandBook()
  92. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_ONLINE_GET_KEEP_SAKE_REQ, {})
  93. end
  94. function KeepSakeBookData:SendKeepSakeLevelUpReq(id)
  95. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_KEEP_SAKE_LEVEL_UP_REQ, {keep_sake_id = id})
  96. end
  97. function KeepSakeBookData:QueryKeepSakeRank(id)
  98. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_KEEP_SAKE_RANK_REQ, {keep_sake_id = id})
  99. end
  100. function KeepSakeBookData:GetKeepSakeHandBookQualityCountByType(type)
  101. if type == Enum.CollectQualityType.ALL then
  102. return self.totalCount
  103. elseif type == Enum.CollectQualityType.NORMAL then
  104. return self.normalCount
  105. elseif type == Enum.CollectQualityType.MINIBOSS then
  106. return self.miniCount
  107. elseif type == Enum.CollectQualityType.MVP then
  108. return self.mvpCount
  109. end
  110. return 0
  111. end
  112. function KeepSakeBookData:GetKeepSakeBookDataById(id)
  113. return self.data.keepSakeMaps[id]
  114. end
  115. function KeepSakeBookData:GetKeepSakeMaps()
  116. return self.data.keepSakeMaps
  117. end
  118. function KeepSakeBookData:RegisterNetEvents()
  119. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_ONLINE_GET_KEEP_SAKE_ACK, function(data)
  120. self:InitDatas(data.role_keep_sake.keep_sake, data.role_keep_sake.material)
  121. end)
  122. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_KEEP_SAKE_CHANGE_NTF, function(data)
  123. self:RefreshDatas({data.keep_sake}, data.materials, true)
  124. end)
  125. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_KEEP_SAKE_LEVEL_UP_ACK, function(data)
  126. if data.error == Enum.NetErrorCode.ERROR_OK then
  127. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.KEEPSAKE_LEVEL_UP_SUCCESS_NTF)
  128. end
  129. end)
  130. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_KEEP_SAKE_RANK_ACK, function(data)
  131. if data.error == Enum.NetErrorCode.ERROR_OK then
  132. if data.player_info then
  133. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.CARD_HANDBOOK_RANK_REFRESH, data.player_info, data.achievement_time)
  134. end
  135. end
  136. end)
  137. end
  138. function KeepSakeBookData:Clear()
  139. self.data = {}
  140. self.totalCount = 0
  141. self.normalCount = 0
  142. self.miniCount = 0
  143. self.mvpCount = 0
  144. self.data.keepSakeMaps = {}
  145. self.data.keepSakeMaterials = {}
  146. end
  147. function KeepSakeBookData:Destroy()
  148. if self.Clear then
  149. self:Clear()
  150. end
  151. self:UnRegisterNetEvents()
  152. end
  153. function KeepSakeBookData:UnRegisterNetEvents()
  154. end
  155. return KeepSakeBookData