UIPetContractAttributeCtr.lua 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. local UIPetContractAttributeCtr = class("UIPetContractAttributeCtr", require("UICtrBase"))
  2. local sameNatureTypeAdd = 0
  3. local sortAttrKey
  4. local lockIds = {42,43,44,45,46,47}
  5. function UIPetContractAttributeCtr:Init(view)
  6. self.view = view
  7. end
  8. function UIPetContractAttributeCtr:SetData(data)
  9. self.asyncIdx = 0
  10. self.data = data
  11. sameNatureTypeAdd = GlobalConfig.Instance:GetConfigIntValue(351)* 0.01
  12. sortAttrKey = {}
  13. for k,v in pairs(Enum.HeroAttrType) do
  14. sortAttrKey[#sortAttrKey + 1] = v
  15. end
  16. table.sort(sortAttrKey, function (a,b)
  17. return a < b
  18. end)
  19. --self:RefreshAllQiyueAttrs()
  20. self:RefreshCurPetBattleLock()
  21. end
  22. function UIPetContractAttributeCtr:GetAsyncIdx()
  23. self.asyncIdx = self.asyncIdx + 1
  24. return self.asyncIdx
  25. end
  26. function UIPetContractAttributeCtr:GetData()
  27. return self.data
  28. end
  29. function UIPetContractAttributeCtr:RefreshCurPetBattleLock()
  30. self.unlockCount = 0
  31. for i = 1,#lockIds do
  32. local unLockState, val, content = ManagerContainer.UIFuncUnlockMgr:GetFuncLockStatusById(lockIds[i])
  33. if unLockState then
  34. self.unlockCount = self.unlockCount + 1
  35. else
  36. self.curLockContent = content
  37. break
  38. end
  39. end
  40. end
  41. function UIPetContractAttributeCtr:GetUnlockCount()
  42. return self.unlockCount
  43. end
  44. local function CalcPetQiyueAddAttrs(masterPetId, slotList)
  45. local baseAttrs = {}
  46. local addAttrs = {}
  47. local hasQiyue = false
  48. local masterData = ManagerContainer.DataMgr.PetDataMgr:GetPetDataById(masterPetId)
  49. if not masterData then return baseAttrs, addAttrs, hasQiyue end
  50. for i = 1, #slotList do
  51. local data = slotList[i]
  52. if data.petId > 0 then
  53. local percent = 0
  54. local petData = ManagerContainer.DataMgr.PetDataMgr:GetPetDataById(data.petId)
  55. local petCfgData = ManagerContainer.CfgMgr:GetPetDataById(petData.cfgId)
  56. local actorData = ManagerContainer.DataMgr.PetDataMgr:GetPetActorData(data.petId)
  57. if petData and petCfgData then
  58. if masterData.natureType == petData.natureType then
  59. percent = percent + sameNatureTypeAdd
  60. end
  61. percent = percent + petCfgData.contract * 0.01 + petData.totalSkillUpCount * petCfgData.understand * 0.01
  62. end
  63. for j = 1, #sortAttrKey do
  64. local key = sortAttrKey[j]
  65. if key >= Enum.HeroAttrType.Life and key <= Enum.HeroAttrType.CastAcceleration then
  66. local num = SDataUtil.InvConvert(actorData:GetFinalAttr(key))
  67. num = num*percent * 0.01
  68. if num > 0 then
  69. if not baseAttrs[key] then baseAttrs[key] = {key, 0, 0} end
  70. baseAttrs[key][2] = baseAttrs[key][2] + num
  71. end
  72. elseif key >= Enum.HeroAttrType.Nature_None_Damage_Percent then
  73. local num = SDataUtil.InvConvert(actorData:GetFinalAttr(key))
  74. num = num*percent * 0.01
  75. if num > 0 then
  76. if not addAttrs[key] then addAttrs[key] = {key, 0, 0} end
  77. addAttrs[key][2] = addAttrs[key][2] + num
  78. end
  79. end
  80. end
  81. hasQiyue = true
  82. end
  83. end
  84. return baseAttrs, addAttrs, hasQiyue
  85. end
  86. function UIPetContractAttributeCtr:RefreshAllQiyueAttrs()
  87. sortAttrKey = {}
  88. for k,v in pairs(Enum.HeroAttrType) do
  89. sortAttrKey[#sortAttrKey + 1] = v
  90. end
  91. table.sort(sortAttrKey, function (a,b)
  92. return a < b
  93. end)
  94. local heroDatas = {}
  95. for i = 1, 6 do
  96. local data = CommonUtil.GetHeroLogicDataByUid(i)
  97. if data.isBattle then
  98. heroDatas[#heroDatas + 1] = data
  99. end
  100. end
  101. CommonUtil.ArraySortSelections(heroDatas, {Enum.TableSortRule.Up, Enum.TableSortRule.Down, Enum.TableSortRule.Down}, "id", "isBattle", "owned")
  102. self.battlePetDatas = {}
  103. self.totalQiyueBaseAttrs = {}
  104. self.totalQiyueAddAttrs = {}
  105. local totalQiyueBaseAttrs = {}
  106. local totalQiyueAddAttrs = {}
  107. self.hasQiyueList = {}
  108. self.petQiyueBaseAttrs = {}
  109. self.petQiyueAddAttrs = {}
  110. for i = 1, 4 do
  111. local data = heroDatas[i]
  112. if data then
  113. local qiyueData = data.petQiyueData
  114. local baseAttrs, addAttrs, hasQiyue = CalcPetQiyueAddAttrs(data.battlePetId, qiyueData.slotList)
  115. self.petQiyueBaseAttrs[i] = {}
  116. self.petQiyueAddAttrs[i] = {}
  117. self.hasQiyueList[i] = hasQiyue
  118. self.battlePetDatas[i] = ManagerContainer.DataMgr.PetDataMgr:GetPetDataById(data.battlePetId)
  119. if baseAttrs then
  120. -- LogHRWarning(Inspect(baseAttrs))
  121. for k, v in pairs(baseAttrs) do
  122. self.petQiyueBaseAttrs[i][#self.petQiyueBaseAttrs[i] + 1] = v
  123. if not totalQiyueBaseAttrs[v[1]] then totalQiyueBaseAttrs[v[1]] = {v[1], 0, 0} end
  124. totalQiyueBaseAttrs[v[1]][2] = totalQiyueBaseAttrs[v[1]][2] + v[2]
  125. end
  126. end
  127. if addAttrs then
  128. -- LogHRWarning(Inspect(addAttrs))
  129. for k, v in pairs(addAttrs) do
  130. self.petQiyueAddAttrs[i][#self.petQiyueAddAttrs[i] + 1] = v
  131. if not totalQiyueAddAttrs[v[1]] then totalQiyueAddAttrs[v[1]] = {v[1], 0, 0} end
  132. totalQiyueAddAttrs[v[1]][2] = totalQiyueAddAttrs[v[1]][2] + v[2]
  133. end
  134. end
  135. end
  136. end
  137. -- LogHRWarning(Inspect(totalQiyueAddAttrs))
  138. for k, v in pairs(totalQiyueBaseAttrs) do
  139. self.totalQiyueBaseAttrs[#self.totalQiyueBaseAttrs + 1] = v
  140. end
  141. for k, v in pairs(totalQiyueAddAttrs) do
  142. self.totalQiyueAddAttrs[#self.totalQiyueAddAttrs + 1] = v
  143. end
  144. end
  145. local function PetHasQiyue(masterPetId, slotList)
  146. local hasQiyue = false
  147. local masterData = ManagerContainer.DataMgr.PetDataMgr:GetPetDataById(masterPetId)
  148. if not masterData then return hasQiyue end
  149. for i = 1, #slotList do
  150. local data = slotList[i]
  151. if data.petId > 0 then
  152. hasQiyue = true
  153. break
  154. end
  155. end
  156. return hasQiyue
  157. end
  158. function UIPetContractAttributeCtr:RefreshQiyueAttrs()
  159. self.battlePetDatas = {}
  160. self.totalQiyueBaseAttrs = {}
  161. self.totalQiyueAddAttrs = {}
  162. self.hasQiyueList = {}
  163. self.petQiyueBaseAttrs = {}
  164. self.petQiyueAddAttrs = {}
  165. local heroDatas = {}
  166. for i = 1, 6 do
  167. local data = CommonUtil.GetHeroLogicDataByUid(i)
  168. if data.isBattle then
  169. heroDatas[#heroDatas + 1] = data
  170. end
  171. end
  172. CommonUtil.ArraySortSelections(heroDatas, {Enum.TableSortRule.Up, Enum.TableSortRule.Down, Enum.TableSortRule.Down}, "id", "isBattle", "owned")
  173. local totalQiyueBaseAttrs = {}
  174. local totalQiyueAddAttrs = {}
  175. for i = 1, 4 do
  176. local heroData = heroDatas[i]
  177. if heroData then
  178. local qiyueData = heroData.petQiyueData
  179. self.petQiyueBaseAttrs[i] = {}
  180. self.petQiyueAddAttrs[i] = {}
  181. self.hasQiyueList[i] = PetHasQiyue(heroData.battlePetId, qiyueData.slotList)
  182. self.battlePetDatas[i] = ManagerContainer.DataMgr.PetDataMgr:GetPetDataById(heroData.battlePetId)
  183. if heroData.battlePetId > 0 then
  184. local curQiyueAttrs = ManagerContainer.DataMgr.PetDataMgr:GetQiyueAttrsById(heroData.battlePetId)
  185. if curQiyueAttrs then
  186. for j = 1, #sortAttrKey do
  187. local key = sortAttrKey[j]
  188. if key >= Enum.HeroAttrType.Life and key <= Enum.HeroAttrType.CastAcceleration then
  189. local num = curQiyueAttrs[key]
  190. if num and num > 0 then
  191. self.petQiyueBaseAttrs[i][#self.petQiyueBaseAttrs[i] + 1] = {key, num, 0}
  192. if not totalQiyueBaseAttrs[key] then totalQiyueBaseAttrs[key] = {key, 0, 0} end
  193. totalQiyueBaseAttrs[key][2] = totalQiyueBaseAttrs[key][2] + num
  194. end
  195. elseif key >= Enum.HeroAttrType.Nature_None_Damage_Percent then
  196. local num = curQiyueAttrs[key]
  197. if num and num > 0 then
  198. num = num * 0.0001
  199. self.petQiyueAddAttrs[i][#self.petQiyueAddAttrs[i] + 1] = {key, num, 0}
  200. if not totalQiyueAddAttrs[key] then totalQiyueAddAttrs[key] = {key, 0, 0} end
  201. totalQiyueAddAttrs[key][2] = totalQiyueAddAttrs[key][2] + num
  202. end
  203. end
  204. end
  205. end
  206. end
  207. end
  208. end
  209. for i = 1, #sortAttrKey do
  210. local key = sortAttrKey[i]
  211. local num = totalQiyueBaseAttrs[key]
  212. if num then
  213. self.totalQiyueBaseAttrs[#self.totalQiyueBaseAttrs + 1] = num
  214. end
  215. local num = totalQiyueAddAttrs[key]
  216. if num then
  217. self.totalQiyueAddAttrs[#self.totalQiyueAddAttrs + 1] = num
  218. end
  219. end
  220. end
  221. function UIPetContractAttributeCtr:GetTotalQiyueAttrs()
  222. return self.totalQiyueBaseAttrs, self.totalQiyueAddAttrs
  223. end
  224. function UIPetContractAttributeCtr:GetPetQiyueAttrsByIdx(idx)
  225. return self.petQiyueBaseAttrs[idx], self.petQiyueAddAttrs[idx]
  226. end
  227. function UIPetContractAttributeCtr:IsPetHaveQiyueByIdx(idx)
  228. return self.hasQiyueList[idx]
  229. end
  230. function UIPetContractAttributeCtr:GetBattlePetDataByIdx(idx)
  231. return self.battlePetDatas[idx]
  232. end
  233. function UIPetContractAttributeCtr:QueryPetDetailInfo()
  234. ManagerContainer.DataMgr.PetDataMgr:QueryQiyueBattlePetAttrReq()
  235. end
  236. function UIPetContractAttributeCtr:OnDispose()
  237. sortAttrKey = {}
  238. self.totalQiyueAttrs = nil
  239. self.petQiyueAttrList = nil
  240. self.hasQiyueList = nil
  241. self.battlePetDatas = nil
  242. self.data = nil
  243. self.view = nil
  244. end
  245. return UIPetContractAttributeCtr