PetRPCtr.lua 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. local PetRPCtr = class("PetRPCtr", require("RPBase"))
  2. local BitUtil = require("BitUtil")
  3. local advenceLvStage
  4. local qiyueSlotUnlockCost
  5. function PetRPCtr:ctor()
  6. if not qiyueSlotUnlockCost then
  7. local val = GlobalConfig.Instance:GetConfigStrValue(350)
  8. if val ~= "" and val ~= nil then
  9. qiyueSlotUnlockCost = CommonUtil.DeserializeGlobalStrToTable(val)
  10. end
  11. end
  12. end
  13. function PetRPCtr:RefreshPetLvUpState(id)
  14. if not advenceLvStage then
  15. local val = GlobalConfig.Instance:GetConfigStrValue(208)
  16. if val ~= "" and val ~= nil then
  17. advenceLvStage = CommonUtil.DeserializeGlobalStrToTable(val)
  18. end
  19. end
  20. local petData = ManagerContainer.DataMgr.PetDataMgr:GetPetDataById(id)
  21. if not petData.isBattle then
  22. ManagerContainer.RedPointSimpleMgr:RPNotify(Enum.RPNotifyType.PetLvUp, false)
  23. return
  24. end
  25. local petExpData = ManagerContainer.CfgMgr:GetPetExpCfgDataById(petData.level + 1)
  26. if not petExpData then
  27. ManagerContainer.RedPointSimpleMgr:RPNotify(Enum.RPNotifyType.PetLvUp, false)
  28. return
  29. end
  30. local expCost = petExpData["experience"..petData.quality] or 0
  31. local zenyCost = petExpData["CostMoney"..petData.quality] or 0
  32. local zenyOwned = CommonUtil.GetOwnResCountByItemId(Enum.ItemIds.Coin)
  33. local expOwned = ManagerContainer.DataMgr.UserData:GetResById(Enum.ItemIds.PetExp) or 0
  34. local isZenyLack = zenyCost > zenyOwned
  35. local isExpLack = expCost > expOwned
  36. local curMaxLv = tonumber(advenceLvStage[petData.advanceLevel + 1] or 0)
  37. local canLvUp = not isZenyLack and not isExpLack and petData.level < curMaxLv
  38. ManagerContainer.RedPointSimpleMgr:RPNotify(Enum.RPNotifyType.PetLvUp, canLvUp)
  39. return canLvUp
  40. end
  41. function PetRPCtr:RefreshPetAdvenceState(id)
  42. if not advenceLvStage then
  43. local val = GlobalConfig.Instance:GetConfigStrValue(208)
  44. if val ~= "" and val ~= nil then
  45. advenceLvStage = CommonUtil.DeserializeGlobalStrToTable(val)
  46. end
  47. end
  48. local petData = ManagerContainer.DataMgr.PetDataMgr:GetPetDataById(id)
  49. if not petData.isBattle then
  50. ManagerContainer.RedPointSimpleMgr:RPNotify(Enum.RPNotifyType.PetAdvance, false)
  51. return
  52. end
  53. local petProgressCfgData = ManagerContainer.CfgMgr:GetPetProgressCfgDataById(petData.cfgId)
  54. local nextAdvenceLv = petData.advanceLevel + 1
  55. if nextAdvenceLv > #advenceLvStage then
  56. ManagerContainer.RedPointSimpleMgr:RPNotify(Enum.RPNotifyType.PetAdvance, false)
  57. return false
  58. end
  59. local curMaxLv = tonumber(advenceLvStage[petData.advanceLevel + 1] or 0)
  60. if petData.level < curMaxLv then
  61. ManagerContainer.RedPointSimpleMgr:RPNotify(Enum.RPNotifyType.PetAdvance, false)
  62. return false
  63. end
  64. if petData.level >= curMaxLv and nextAdvenceLv >= #advenceLvStage then
  65. ManagerContainer.RedPointSimpleMgr:RPNotify(Enum.RPNotifyType.PetAdvance, false)
  66. return false
  67. end
  68. local zenyCost = petProgressCfgData.CostMoney[nextAdvenceLv]
  69. local zenyOwned = CommonUtil.GetOwnResCountByItemId(Enum.ItemIds.Coin)
  70. local petDatasSource = ManagerContainer.DataMgr.PetDataMgr:GetPetDatas()
  71. local curPetCfgData = ManagerContainer.CfgMgr:GetPetProgressCfgDataById(petData.cfgId)
  72. local nextAdvenceLv = petData.advanceLevel + 1
  73. local filters = curPetCfgData["Condition"..nextAdvenceLv.."1"]
  74. local list = {}
  75. if filters then
  76. local qulity = filters[1] and filters[1][2] or nil
  77. local advanceLevel = filters[2] and filters[2][2] or nil
  78. local natureType = filters[3] and filters[3][2] or nil
  79. list = CommonUtil.ArrayFilterSelections(petDatasSource, Enum.FilterType.AND, {"quality", "advanceLevel", "natureType", "isBattle", "qiyueHeroId"}, {qulity, advanceLevel, natureType, false, 0})
  80. end
  81. local canAdvence = #list >= 2 and zenyCost <= zenyOwned
  82. ManagerContainer.RedPointSimpleMgr:RPNotify(Enum.RPNotifyType.PetAdvance, canAdvence)
  83. return canAdvence
  84. end
  85. function PetRPCtr:RefreshSkillUpState(id)
  86. local petData = ManagerContainer.DataMgr.PetDataMgr:GetPetDataById(id)
  87. if not petData.isBattle then
  88. ManagerContainer.RedPointSimpleMgr:RPNotify(Enum.RPNotifyType.PetSkillUp, false)
  89. return
  90. end
  91. local cfgData = ManagerContainer.CfgMgr:GetPetDataById(petData.cfgId)
  92. local canSkillUp = false
  93. for i = 1, #petData.skillList do
  94. local skillRate = cfgData["Skill"..i.."Rate"]
  95. if skillRate then
  96. if petData.skillList[i].level < #skillRate then
  97. canSkillUp = true
  98. break
  99. end
  100. end
  101. end
  102. local skillUpCost = GlobalConfig.Instance:GetConfigIntValue(207)
  103. local zenyOwned = CommonUtil.GetOwnResCountByItemId(Enum.ItemIds.Coin)
  104. local petDatasSource = ManagerContainer.DataMgr.PetDataMgr:GetPetDatas()
  105. local list = CommonUtil.ArrayFilterSelections(petDatasSource, Enum.FilterType.AND, {"cfgId", "isBattle", "qiyueHeroId"}, {petData.cfgId, false, 0})
  106. canSkillUp = canSkillUp and skillUpCost <= zenyOwned and #list > 0
  107. ManagerContainer.RedPointSimpleMgr:RPNotify(Enum.RPNotifyType.PetSkillUp, canSkillUp)
  108. return canSkillUp
  109. end
  110. function PetRPCtr:RefresgPetRelationState(relationCfgId)
  111. local advanceLimit = 5
  112. if not advenceLvStage then
  113. local val = GlobalConfig.Instance:GetConfigStrValue(208)
  114. if val ~= "" and val ~= nil then
  115. advenceLvStage = CommonUtil.DeserializeGlobalStrToTable(val)
  116. end
  117. end
  118. advanceLimit = #advenceLvStage
  119. local relationCfgData = ManagerContainer.CfgMgr:GetPetPartnerDataById(relationCfgId)
  120. local relationData = ManagerContainer.DataMgr.PetDataMgr:GetPetRelationDataByCfgId(relationCfgId)
  121. local petDatas = ManagerContainer.DataMgr.PetDataMgr:GetPetDatas()
  122. local idx = nil
  123. local condition = relationCfgData['Condition1']
  124. if condition then
  125. for k,v in pairs(condition) do
  126. local advenceNum = {}
  127. local cfgId = v[1]
  128. local num = v[2]
  129. advenceNum[#advenceNum + 1] = num
  130. if #advenceNum > 0 then
  131. for i = 1, advanceLimit do
  132. if i > advenceNum[1] and not CommonUtil.EleInTable(i, advenceNum) then
  133. advenceNum[#advenceNum + 1] = i
  134. end
  135. end
  136. end
  137. local list = CommonUtil.ArrayFilterSelections(petDatas, Enum.FilterType.AND, {"cfgId", "advanceLevel","isRelevant"}, {cfgId, advenceNum, false})
  138. --local friendDatas = clone(ManagerContainer.DataMgr.PetDataMgr:GetCurFriendSupportDatas())
  139. if relationData then
  140. local v1 = relationData.relationPets[k]
  141. for i = #list, 1, -1 do
  142. local v2 = list[i]
  143. local needBreak = false
  144. while(true) do
  145. if v1.uid == 0 and v2.id == v1.petId then
  146. table.remove(list, i)
  147. break
  148. end
  149. if v1.cfgId == 0 then
  150. if idx == nil then idx = {} end
  151. idx[k] = k
  152. needBreak = true
  153. break
  154. end
  155. if v2.advanceLevel > v1.advanceLevel then
  156. if idx == nil then idx = {} end
  157. if not CommonUtil.EleInTable(k, idx) then
  158. idx[#idx + 1] = k
  159. needBreak = true
  160. end
  161. end
  162. break
  163. end
  164. if needBreak or (idx and #idx >= 3) then
  165. break
  166. end
  167. end
  168. else
  169. if #list > 0 then
  170. if idx == nil then idx = {} end
  171. idx[k] = k
  172. end
  173. end
  174. --if (not idx or #idx < 3) and friendDatas then
  175. -- if relationData then
  176. -- local v1 = relationData.relationPets[k]
  177. -- for _,v2 in pairs(friendDatas) do
  178. -- local uid = v2.uid
  179. -- for i = #v2.supportPets, 1, -1 do
  180. -- local v3 = v2.supportPets[i]
  181. -- local needBreak = false
  182. -- if v3.cfgId == cfgId then
  183. -- while(true) do
  184. -- if v1.uid == uid and v3.id == v1.petId then
  185. -- table.remove(v2.supportPets, i)
  186. -- break
  187. -- end
  188. --
  189. -- if v1.cfgId == 0 then
  190. -- if idx == nil then idx = {} end
  191. -- idx[k] = k
  192. -- needBreak = true
  193. -- break
  194. -- end
  195. --
  196. -- if v3.advanceLevel > v1.advanceLevel then
  197. --
  198. -- if idx == nil then idx = {} end
  199. -- if not CommonUtil.EleInTable(k, idx) then
  200. -- idx[k] = k
  201. -- needBreak = true
  202. -- end
  203. -- end
  204. -- break
  205. -- end
  206. -- if idx == nil then idx = {} end
  207. -- if needBreak or #idx >= 3 then
  208. -- break
  209. -- end
  210. -- end
  211. -- end
  212. -- end
  213. -- else
  214. -- for _,v2 in pairs(friendDatas) do
  215. -- for i = #v2.supportPets, 1, -1 do
  216. -- local v3 = v2.supportPets[i]
  217. -- if v3.cfgId == cfgId then
  218. -- if idx == nil then idx = {} end
  219. -- idx[k] = k
  220. -- break
  221. -- end
  222. -- end
  223. -- end
  224. -- end
  225. --end
  226. end
  227. end
  228. --ManagerContainer.RedPointSimpleMgr:RPNotify(Enum.RPNotifyType.PetRelation, idx ~= nil and #idx > 0)
  229. return idx
  230. end
  231. function PetRPCtr:GetPetCultivatingState(id)
  232. local result = self:RefreshPetLvUpState(id)
  233. if result then
  234. return true
  235. end
  236. local result = self:RefreshPetAdvenceState(id)
  237. if result then
  238. return true
  239. end
  240. local result = self:RefreshSkillUpState(id)
  241. if result then
  242. return true
  243. end
  244. end
  245. function PetRPCtr:RefreshRelationRPState()
  246. local relationCfgDatas = ManagerContainer.CfgMgr:GetAllPetPartnerDatas()
  247. local relationRedPoint = false
  248. for _,v in pairs(relationCfgDatas) do
  249. local idxList = ManagerContainer.RedPointMgr.PetRPCtr:RefresgPetRelationState(v.Id)
  250. if idxList and next(idxList) then
  251. relationRedPoint = true
  252. break
  253. end
  254. end
  255. ManagerContainer.RedPointSimpleMgr:RPNotify(Enum.RPNotifyType.PetRelation, relationRedPoint)
  256. end
  257. function PetRPCtr:RefreshPetStampRPState()
  258. self.stampInsertRp = {}
  259. self.stampLvUpRp = {}
  260. self.stampAdvanceRp = {}
  261. local battlePets = ManagerContainer.DataMgr.PetDataMgr.petAttrData:GetAllBattlePetDatas()
  262. if #battlePets == 0 then
  263. ManagerContainer.RedPointSimpleMgr:RPNotify(Enum.RPNotifyType.PetStampInsert, false)
  264. ManagerContainer.RedPointSimpleMgr:RPNotify(Enum.RPNotifyType.PetStampLvUp, false)
  265. ManagerContainer.RedPointSimpleMgr:RPNotify(Enum.RPNotifyType.PetStampAdvance, false)
  266. return
  267. end
  268. local function IsCostEnough(costs)
  269. for i = 1, #costs do
  270. local cost = costs[i]
  271. if cost then
  272. local ownCount = CommonUtil.GetOwnResCountByItemId(cost[1])
  273. if ownCount < cost[2] then
  274. return false
  275. end
  276. end
  277. end
  278. return true
  279. end
  280. local canInsert, canLvUp, canAdvance = false, false, false
  281. for _,v in pairs(battlePets) do
  282. local petId = v.id
  283. if not self.stampInsertRp[petId] then
  284. self.stampInsertRp[petId] = {}
  285. end
  286. if not self.stampLvUpRp[petId] then
  287. self.stampLvUpRp[petId] = {}
  288. end
  289. if not self.stampAdvanceRp[petId] then
  290. self.stampAdvanceRp[petId] = {}
  291. end
  292. local slots = v.slots
  293. for i = 1, 6 do
  294. local slot = slots[i]
  295. local idx = i
  296. local stampId = slot and slot.stampId or 0
  297. local stamps = ManagerContainer.DataMgr.PetDataMgr.petStampData:GetAllPetStampDatasByTypeExcludeId(idx, stampId)
  298. if stampId == 0 then
  299. if #stamps > 0 then
  300. self.stampInsertRp[petId][idx] = true
  301. if not canInsert then
  302. canInsert = true
  303. end
  304. end
  305. else
  306. local stampData = ManagerContainer.DataMgr.PetDataMgr.petStampData:GetPetStampDataMapById(stampId)
  307. if stampData then
  308. local cfgData = stampData.cfgData
  309. local isMaxLv = stampData.lv >= cfgData.MaxLevel
  310. local canAdvance1 = cfgData.Advance > 0
  311. if not isMaxLv then
  312. local lvCfgData = ManagerContainer.CfgMgr:GetPetEquipExpCfgDataByLvAndCfgId(stampData.lv, stampData.cfgId)
  313. if lvCfgData then
  314. local result = IsCostEnough(lvCfgData.Cost)
  315. if result then
  316. self.stampLvUpRp[petId][idx] = true
  317. if not canLvUp then
  318. canLvUp = true
  319. end
  320. end
  321. end
  322. elseif isMaxLv and canAdvance1 then
  323. local result = IsCostEnough(cfgData.AdvanceCost)
  324. if result then
  325. self.stampAdvanceRp[petId][idx] = true
  326. if not canAdvance then
  327. canAdvance = true
  328. end
  329. end
  330. end
  331. end
  332. end
  333. end
  334. end
  335. ManagerContainer.RedPointSimpleMgr:RPNotify(Enum.RPNotifyType.PetStampInsert, canInsert)
  336. ManagerContainer.RedPointSimpleMgr:RPNotify(Enum.RPNotifyType.PetStampLvUp, canLvUp)
  337. ManagerContainer.RedPointSimpleMgr:RPNotify(Enum.RPNotifyType.PetStampAdvance, canAdvance)
  338. end
  339. function PetRPCtr:GetPetSlotInsertRPState(petId, idx)
  340. if idx then
  341. return self.stampInsertRp and (self.stampInsertRp[petId] and self.stampInsertRp[petId][idx]) or false
  342. else
  343. if self.stampLvUpRp and self.stampInsertRp[petId] then
  344. for _,v in pairs(self.stampInsertRp[petId]) do
  345. if v then
  346. return true
  347. end
  348. end
  349. end
  350. return false
  351. end
  352. end
  353. function PetRPCtr:GetPetSlotLvUpRPState(petId, idx)
  354. if idx then
  355. return self.stampLvUpRp and (self.stampLvUpRp[petId] and self.stampLvUpRp[petId][idx]) or false
  356. else
  357. if self.stampLvUpRp and self.stampLvUpRp[petId] then
  358. for _,v in pairs(self.stampLvUpRp[petId]) do
  359. if v then
  360. return true
  361. end
  362. end
  363. end
  364. return false
  365. end
  366. end
  367. function PetRPCtr:GetPetSlotAdvanceRPState(petId, idx)
  368. if idx then
  369. return self.stampAdvanceRp and (self.stampAdvanceRp[petId] and self.stampAdvanceRp[petId][idx]) or false
  370. else
  371. if self.stampAdvanceRp and self.stampAdvanceRp[petId] then
  372. for _,v in pairs(self.stampAdvanceRp[petId]) do
  373. if v then
  374. return true
  375. end
  376. end
  377. end
  378. return false
  379. end
  380. end
  381. local function CalcUnlockSlot(slotList)
  382. local state = false
  383. local idx = #slotList + 1
  384. local cost = qiyueSlotUnlockCost[idx]
  385. if not cost then
  386. return false
  387. end
  388. local costId = tonumber(cost[1])
  389. local costNum = tonumber(cost[2])
  390. local count = CommonUtil.GetOwnResCountByItemId(costId)
  391. return count >= costNum
  392. end
  393. function PetRPCtr:RefreshBattlePetQiyueRPState(petData)
  394. local qiyueFunc = ManagerContainer.UIFuncUnlockMgr:GetFuncLockStatusById(77)
  395. if not qiyueFunc then
  396. return false
  397. end
  398. if not petData or petData.heroId == 0 then return false end
  399. local heroData = CommonUtil.GetHeroLogicDataByUid(petData.heroId)
  400. if not heroData then return false end
  401. local hasFreePet = false
  402. local petDatas = ManagerContainer.DataMgr.PetDataMgr:GetPetDatas()
  403. for i = 1, #petDatas do
  404. if not petDatas[i].isBattle and petDatas[i].qiyueHeroId == 0 then
  405. hasFreePet = true
  406. break
  407. end
  408. end
  409. local slotList = heroData.petQiyueData.slotList
  410. if CalcUnlockSlot(slotList) then
  411. return true
  412. end
  413. if heroData.battlePetId > 0 then
  414. if #slotList > 0 then
  415. for j = 1, #slotList do
  416. local slotData = slotList[j]
  417. if slotData.petId == 0 and hasFreePet then
  418. return true
  419. end
  420. end
  421. end
  422. end
  423. return false
  424. end
  425. function PetRPCtr:RefreshTotalQiyueRPState()
  426. local qiyueFunc = ManagerContainer.UIFuncUnlockMgr:GetFuncLockStatusById(77)
  427. if not qiyueFunc then
  428. ManagerContainer.RedPointSimpleMgr:RPNotify(Enum.RPNotifyType.PetQiyueFunc, false)
  429. return
  430. end
  431. local hasFreePet = false
  432. local petDatas = ManagerContainer.DataMgr.PetDataMgr:GetPetDatas()
  433. for i = 1, #petDatas do
  434. if not petDatas[i].isBattle and petDatas[i].qiyueHeroId == 0 then
  435. hasFreePet = true
  436. break
  437. end
  438. end
  439. for i = 1, 6 do
  440. local heroData = CommonUtil.GetHeroLogicDataByUid(i)
  441. if i == 1 then
  442. local slotList = heroData.petQiyueData.slotList
  443. if CalcUnlockSlot(slotList) then
  444. ManagerContainer.RedPointSimpleMgr:RPNotify(Enum.RPNotifyType.PetQiyueFunc, true)
  445. return
  446. end
  447. if #slotList > 0 then
  448. if heroData.battlePetId > 0 then
  449. for j = 1, #slotList do
  450. local slotData = slotList[j]
  451. if slotData.petId == 0 and hasFreePet then
  452. ManagerContainer.RedPointSimpleMgr:RPNotify(Enum.RPNotifyType.PetQiyueFunc, true)
  453. return
  454. end
  455. end
  456. end
  457. end
  458. else
  459. if heroData.owned then
  460. local slotList = heroData.petQiyueData.slotList
  461. if CalcUnlockSlot(slotList) then
  462. ManagerContainer.RedPointSimpleMgr:RPNotify(Enum.RPNotifyType.PetQiyueFunc, true)
  463. return
  464. end
  465. if #slotList > 0 then
  466. if heroData.battlePetId > 0 then
  467. for j = 1, #slotList do
  468. local slotData = slotList[j]
  469. if slotData.petId == 0 and hasFreePet then
  470. ManagerContainer.RedPointSimpleMgr:RPNotify(Enum.RPNotifyType.PetQiyueFunc, true)
  471. return
  472. end
  473. end
  474. end
  475. end
  476. end
  477. end
  478. end
  479. ManagerContainer.RedPointSimpleMgr:RPNotify(Enum.RPNotifyType.PetQiyueFunc, false)
  480. end
  481. function PetRPCtr:Dispose()
  482. end
  483. return PetRPCtr