PetDataMgr.lua 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. local PetDataMgr = class("PetDataMgr",require("DataBase"))
  2. local PetAttrData = require("Pet/PetAttrData")
  3. local PetRelationData = require("Pet/PetRelationData")
  4. local PetCollectBookData = require("Pet/PetCollectBookData")
  5. local PetStampData = require("Pet/PetStampData")
  6. function PetDataMgr:ctor()
  7. self.data = {}
  8. self.petAttrData = PetAttrData:new()
  9. self.petRelationData = PetRelationData:new()
  10. self.petCollectBookData = PetCollectBookData:new()
  11. self.petStampData = PetStampData:new()
  12. end
  13. function PetDataMgr:InitData()
  14. end
  15. function PetDataMgr:GetPetDatas()
  16. return self.petAttrData:GetPetDatas()
  17. end
  18. function PetDataMgr:GetPetDataById(id)
  19. return self.petAttrData:GetPetDataById(id)
  20. end
  21. function PetDataMgr:GetPetCountById(id)
  22. return self.petAttrData:GetPetCountById(id)
  23. end
  24. function PetDataMgr:GetPetDataByIdAndLv(id,lv,skillLv)
  25. return self.petAttrData:GetPetDataByIdAndLv(id,lv,skillLv)
  26. end
  27. function PetDataMgr:GetPetDataByQulityAndLv(quality,lv,skillLv)
  28. return self.petAttrData:GetPetDataByQulityAndLv(quality,lv,skillLv)
  29. end
  30. function PetDataMgr:GetPetCountByIdAndLv(id,lv,skillLv)
  31. return self.petAttrData:GetPetCountByIdAndLv(id,lv,skillLv)
  32. end
  33. function PetDataMgr:GetPetCountByQulityAndLv(quality,lv,skillLv)
  34. return self.petAttrData:GetPetCountByQulityAndLv(quality,lv,skillLv)
  35. end
  36. function PetDataMgr:GetPetActorData(id)
  37. return self.petAttrData:GetPetActorData(id)
  38. end
  39. function PetDataMgr:SendPetLvUp(id)
  40. return self.petAttrData:SendPetLvUp(id)
  41. end
  42. function PetDataMgr:SendPetAdvence(id, costList)
  43. return self.petAttrData:SendPetAdvence(id, costList)
  44. end
  45. function PetDataMgr:GetNextSortId(id, isAdd)
  46. return self.petAttrData:GetNextSortId(id, isAdd)
  47. end
  48. function PetDataMgr:SendPetDecompose(ids)
  49. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_PET_DECOMPOSE_REQ, {pet_id_list = ids})
  50. end
  51. function PetDataMgr:SendPetSkillUp(id, matId)
  52. self.petAttrData:SendPetSkillUp(id, matId)
  53. end
  54. function PetDataMgr:SendPetBattle(map)
  55. self.petAttrData:SendPetBattle(map)
  56. end
  57. function PetDataMgr:QueryPetRelation()
  58. self.petRelationData:QueryPetRelation()
  59. end
  60. function PetDataMgr:GetAllPetRelationDatas()
  61. return self.petRelationData:GetAllPetRelationDatas()
  62. end
  63. function PetDataMgr:GetPetRelationDataByCfgId(cfgId)
  64. return self.petRelationData:GetPetRelationDataByCfgId(cfgId)
  65. end
  66. function PetDataMgr:GetRelationPlayerNameByUid(uid)
  67. return self.petRelationData:GetRelationPlayerNameByUid(uid)
  68. end
  69. function PetDataMgr:QueryAssistList(cfgId)
  70. return self.petRelationData:QueryAssistList(cfgId)
  71. end
  72. function PetDataMgr:GetCurFriendSupportDatas()
  73. return self.petRelationData:GetCurFriendSupportDatas()
  74. end
  75. function PetDataMgr:GetMySupportPets()
  76. return self.petRelationData:GetMySupportPets()
  77. end
  78. function PetDataMgr:SendMySupport(list)
  79. return self.petRelationData:SendMySupport(list)
  80. end
  81. function PetDataMgr:DeleteMySupportPets(list)
  82. self.petRelationData:DeleteMySupportPets(list)
  83. end
  84. function PetDataMgr:SendPetRelationActive(datas)
  85. return self.petRelationData:SendPetRelationActive(datas)
  86. end
  87. function PetDataMgr:GetReplacePetRelationDataByUidAndPetId(uid, petId)
  88. return self.petRelationData:GetReplacePetRelationDataByUidAndPetId(uid,petId)
  89. end
  90. function PetDataMgr:GetMySupportSlotCDTime(idx)
  91. return self.petRelationData:GetMySupportSlotCDTime(idx)
  92. end
  93. function PetDataMgr:QueryFirstRank(cfgId)
  94. self.petCollectBookData:QueryFirstRank(cfgId)
  95. end
  96. function PetDataMgr:RefreshAllPetRPState()
  97. local petDatas = self:GetPetDatas()
  98. for _,v in pairs(petDatas) do
  99. ManagerContainer.RedPointMgr.PetRPCtr:GetPetCultivatingState(v.id)
  100. end
  101. ManagerContainer.RedPointMgr.PetRPCtr:RefreshRelationRPState()
  102. ManagerContainer.RedPointMgr.PetRPCtr:RefreshPetStampRPState()
  103. end
  104. function PetDataMgr:RefreshMasterAttr(id)
  105. self.petAttrData:RefreshMasterAttr(id)
  106. end
  107. function PetDataMgr:GetPetCurSkillTotalFightPower(id)
  108. local petData = self:GetPetDataById(id)
  109. if not petData then
  110. return 0
  111. end
  112. local totalPower = 0
  113. for _,v in pairs(petData.skillList) do
  114. local cfgId = v.cfgId
  115. local level = v.level
  116. local cfgData = ManagerContainer.CfgMgr:GetSkillCfgById(cfgId)
  117. if cfgData then
  118. totalPower = totalPower + level * cfgData.AddFight
  119. end
  120. end
  121. return math.floor(totalPower/10)
  122. end
  123. function PetDataMgr:GetPetStampTotalFightPower(id)
  124. local petData = self:GetPetDataById(id)
  125. if not petData then
  126. return 0
  127. end
  128. local totalPower = 0
  129. for _,v in pairs(petData.slots) do
  130. local id = v.stampId
  131. local stampData = self.petStampData:GetPetStampDataMapById(id)
  132. if stampData then
  133. local lvCfgData = ManagerContainer.CfgMgr:GetPetEquipExpCfgDataByLvAndCfgId(stampData.lv, stampData.cfgId)
  134. if lvCfgData then
  135. totalPower = totalPower + lvCfgData.FightPower
  136. end
  137. end
  138. end
  139. return math.floor(totalPower/10)
  140. end
  141. function PetDataMgr:GetTotalFightPower(id)
  142. local relationTotalFightPower = ManagerContainer.DataMgr.UserData:GetPetRelationTotalFightPower()
  143. local skillTotalFightPower = self:GetPetCurSkillTotalFightPower(id)
  144. local stampTotalFightPower = self:GetPetStampTotalFightPower(id)
  145. local petData = self.petAttrData:GetPetDataById(id)
  146. if nil ~= petData.pet_svrfight_power and petData.pet_svrfight_power > 0 then
  147. return petData.pet_svrfight_power
  148. end
  149. if petData.heroId > 0 then
  150. local masterData = CommonUtil.GetHeroLogicDataByUid(petData.heroId)
  151. if masterData.isBattle then
  152. return tonumber(tostring(masterData.petFightPower))
  153. else
  154. return petData.baseFightPower + relationTotalFightPower + skillTotalFightPower + stampTotalFightPower
  155. end
  156. end
  157. return petData.baseFightPower + relationTotalFightPower + skillTotalFightPower + stampTotalFightPower
  158. end
  159. function PetDataMgr:GetActivedPetCount(type)
  160. return self.petCollectBookData:GetActivedPetCount(type)
  161. end
  162. function PetDataMgr:GetPetCollectBoolState(cfgId)
  163. return self.petCollectBookData:GetPetCollectBoolState(cfgId)
  164. end
  165. function PetDataMgr:GetPetCollectRewardState(cfgId)
  166. return self.petCollectBookData:GetPetCollectRewardState(cfgId)
  167. end
  168. function PetDataMgr:SendPetReward(cfgId, idx, petId)
  169. self.petCollectBookData:SendPetReward(cfgId, idx, petId)
  170. end
  171. function PetDataMgr:RecalcBattlePetRelationAttr(isBattle, id)
  172. self.petRelationData:RecalcBattlePetRelationAttr(isBattle, id)
  173. end
  174. function PetDataMgr:GetSomePetMaxAdvLvByCfgId(cfgId)
  175. return self.petAttrData:GetSomePetMaxAdvLvByCfgId(cfgId)
  176. end
  177. function PetDataMgr:InitPetRelationAttrs()
  178. return self.petRelationData:AddPetRelationAttrs()
  179. end
  180. function PetDataMgr:GetRelationRPStates()
  181. return self.petRelationData:GetRelationRPStates()
  182. end
  183. function PetDataMgr:RefreshRelationRPStates()
  184. return self.petRelationData:RefreshRelationRPStates()
  185. end
  186. local lockIds = {42,43,44,45,46,47}
  187. function PetDataMgr:GetBattleUnlockSlotCount()
  188. local unlockCount = 0
  189. for i = 1,#lockIds do
  190. local unLockState, val, content = ManagerContainer.UIFuncUnlockMgr:GetFuncLockStatusById(lockIds[i])
  191. if unLockState then
  192. unlockCount = unlockCount + 1
  193. end
  194. end
  195. return unlockCount
  196. end
  197. function PetDataMgr:SendStampLvUpReq(id)
  198. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_PET_EQUIP_LEVEL_UP_REQ, {pet_equip_id = id})
  199. end
  200. function PetDataMgr:SendStampUpReq(petId, list)
  201. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_PET_EQUIP_UP_REQ, {pet_id = petId, slot_list = list})
  202. end
  203. function PetDataMgr:SendStampDownReq(petId, slotIdx)
  204. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_PET_EQUIP_DOWN_REQ, {pet_id = petId, slot_index = slotIdx})
  205. end
  206. function PetDataMgr:UpdatePetQiyueData(data)
  207. --LogHRWarning("UpdatePetQiyueData "..Inspect(data))
  208. local heroData = CommonUtil.GetHeroLogicDataByUid(data.hero_id)
  209. if not heroData then return end
  210. heroData.petQiyueData = ProtocalDataNormal.ParsePetQiyueData(heroData.petQiyueData, data.qiyue_info)
  211. self.petAttrData:UpdatePetExtGoShowData1(heroData)
  212. end
  213. function PetDataMgr:SendQiyueUnlockReq(heroId)
  214. --LogHRWarning("SendQiyueUnlockReq")
  215. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_PET_QIYUE_SLOT_UNLOCK_REQ, {hero_id = heroId})
  216. end
  217. function PetDataMgr:OnQiyueUnlockAck(data)
  218. --LogHRWarning("OnQiyueUnlockAck ")
  219. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.QIYUE_PET_CHANGE_SUCCESS)
  220. end
  221. function PetDataMgr:SendQiyueSlotInReq(heroId, slotIdx, petId)
  222. --LogHRWarning("SendQiyueSlotInReq")
  223. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_PET_QIYUE_SLOT_IN_REQ, {hero_id = heroId, slot_idx = slotIdx, pet_id = petId})
  224. end
  225. function PetDataMgr:OnQiyueSlotInAck(data)
  226. --LogHRWarning("OnQiyueSlotInAck")
  227. self.qiyueSuccess = data.error == Enum.NetErrorCode.ERROR_OK
  228. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.QIYUE_PET_CHANGE_SUCCESS)
  229. self.qiyueSuccess = false
  230. end
  231. function PetDataMgr:IsQiyueSuccess()
  232. return self.qiyueSuccess
  233. end
  234. function PetDataMgr:SendQiyueSlotOutReq(heroId, slotIdx)
  235. --LogHRWarning("SendQiyueSlotOutReq")
  236. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_PET_QIYUE_SLOT_OUT_REQ, {hero_id = heroId, slot_idx = slotIdx})
  237. end
  238. function PetDataMgr:OnQiyueSlotOutAck(data)
  239. --LogHRWarning("OnQiyueSlotOutAck")
  240. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.QIYUE_PET_CHANGE_SUCCESS)
  241. end
  242. function PetDataMgr:RefreshPetQiyueAttrs(data)
  243. if data.error ~= Enum.NetErrorCode.ERROR_OK then return end
  244. self.curQiyueAttrs = {}
  245. for i = 1, #data.actor_list do
  246. local actorData = data.actor_list[i]
  247. if not actorData.is_hero_pet and actorData.actor_id > 0 then
  248. self.curQiyueAttrs[actorData.actor_id] = {}
  249. for k,v in pairs(actorData.attr_list) do
  250. self.curQiyueAttrs[actorData.actor_id][v.key] = v.value
  251. end
  252. end
  253. end
  254. --LogHRWarning(Inspect(self.curQiyueAttrs))
  255. end
  256. function PetDataMgr:GetQiyueAttrsById(id)
  257. return self.curQiyueAttrs[id]
  258. end
  259. function PetDataMgr:QueryQiyueBattlePetAttrReq()
  260. --LogHRWarning("QueryQiyueBattlePetAttrReq")
  261. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_PET_QIYUE_BATTLE_PET_ATTR_REQ, {})
  262. end
  263. function PetDataMgr:OnQueryQiyueBattlePetAttrAck(data)
  264. --LogHRWarning("OnQueryQiyueBattlePetAttrAck "..Inspect(data))
  265. self:RefreshPetQiyueAttrs(data)
  266. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.QUERY_PET_QIYUE_ATTRS_SUCCESS)
  267. end
  268. function PetDataMgr:QueryPetDetailInfos(petIdList)
  269. local needQuery = false
  270. local list = {}
  271. for i = 1, #petIdList do
  272. local data = self.petAttrData:GetPetDataById(petIdList[i])
  273. if not data.is_queried then
  274. list[#list + 1] = petIdList[i]
  275. end
  276. end
  277. if #list > 0 then
  278. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_PET_DETAIL_INFO_REQ, {pet_id_list = petIdList})
  279. else
  280. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.PET_DETAIL_QUERY_SUCCESS)
  281. end
  282. end
  283. function PetDataMgr:RegisterNetEvents()
  284. self.petAttrData:RegisterNetEvents()
  285. self.petRelationData:RegisterNetEvents()
  286. self.petCollectBookData:RegisterNetEvents()
  287. self.petStampData:RegisterNetEvents()
  288. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_STARTUP_INFO_PET_NTF, function(data)
  289. if self.petStampData then
  290. self.petStampData:InitPetStampData(data.role_pet_info.pet_equip_list)
  291. end
  292. if data.role_pet_info then
  293. self.petAttrData:InitData(data.role_pet_info.pet_list)
  294. end
  295. if data.role_pet_info then
  296. --self.petRelationData:InitData(data.role_pet_info)
  297. ManagerContainer.LuaTimerMgr:AddLuaTimer(1000, 1, function ()
  298. self.petRelationData:InitData(data.role_pet_info)
  299. self.petRelationData:RefreshMySupportPets(data.role_pet_info.assist_list)
  300. end, nil)
  301. end
  302. -- if data.role_pet_info then
  303. -- self.petRelationData:RefreshMySupportPets(data.role_pet_info.assist_list)
  304. -- end
  305. if self.petCollectBookData then
  306. self.petCollectBookData:InitData(data.role_pet_info.pet_manual_reward_list)
  307. end
  308. end)
  309. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_PET_CHANGE_NTF, function(data)
  310. local slotChanged = self.petAttrData:RefreshData(data.pet_list, data.del_pet_list)
  311. self.petCollectBookData:InitData(data.pet_manual_list)
  312. if slotChanged then
  313. ManagerContainer.RedPointMgr.PetRPCtr:RefreshPetStampRPState()
  314. end
  315. end)
  316. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_PET_DECOMPOSE_ACK, function(data)
  317. if data.error == Enum.NetErrorCode.ERROR_OK then
  318. CommonUtil.ACKShowRewardList(data.item_list)
  319. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.PET_DECOMPOSE_SUCCESS_NTF)
  320. end
  321. end)
  322. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_PET_QIYUE_DATA_NTF, function(data)
  323. self:UpdatePetQiyueData(data)
  324. end)
  325. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_PET_QIYUE_SLOT_UNLOCK_ACK, function(data)
  326. self:OnQiyueUnlockAck(data)
  327. ManagerContainer.RedPointMgr.PetRPCtr:RefreshTotalQiyueRPState()
  328. end)
  329. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_PET_QIYUE_SLOT_IN_ACK, function(data)
  330. self:OnQiyueSlotInAck(data)
  331. ManagerContainer.RedPointMgr.PetRPCtr:RefreshTotalQiyueRPState()
  332. end)
  333. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_PET_QIYUE_SLOT_OUT_ACK, function(data)
  334. self:OnQiyueSlotOutAck(data)
  335. ManagerContainer.RedPointMgr.PetRPCtr:RefreshTotalQiyueRPState()
  336. end)
  337. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_PET_DETAIL_INFO_ACK, function(data)
  338. self.petAttrData:InitPetDetailDatas(data.pet_info_list)
  339. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.PET_DETAIL_QUERY_SUCCESS)
  340. end)
  341. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_PET_QIYUE_BATTLE_PET_ATTR_ACK, function(data)
  342. self:OnQueryQiyueBattlePetAttrAck(data)
  343. end)
  344. end
  345. function PetDataMgr:Clear()
  346. self.data = {}
  347. self.petAttrData:Clear()
  348. self.petRelationData:Clear()
  349. self.petCollectBookData:Clear()
  350. self.petStampData:Clear()
  351. end
  352. function PetDataMgr:Destroy()
  353. if self.Clear then
  354. self:Clear()
  355. end
  356. self:UnRegisterNetEvents()
  357. self.petAttrData:Destroy()
  358. self.petAttrData = nil
  359. self.petRelationData:Destroy()
  360. self.petRelationData = nil
  361. self.petCollectBookData:Destroy()
  362. self.petCollectBookData = nil
  363. self.petStampData:Destroy()
  364. self.petStampData = nil
  365. end
  366. function PetDataMgr:UnRegisterNetEvents()
  367. end
  368. return PetDataMgr