UIPetAdvenceCtr.lua 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. local UIPetAdvenceCtr = class("UIPetAdvenceCtr", require("UICtrBase"))
  2. local advenceLvStage
  3. function UIPetAdvenceCtr:Init(view)
  4. self.view = view
  5. local val = GlobalConfig.Instance:GetConfigStrValue(208)
  6. if val ~= "" and val ~= nil then
  7. advenceLvStage = CommonUtil.DeserializeGlobalStrToTable(val)
  8. end
  9. end
  10. function UIPetAdvenceCtr:SetData(data)
  11. self.asyncIdx = 0
  12. if data == nil then return end
  13. self.data = data
  14. self.selectionedList = {self.data}
  15. end
  16. function UIPetAdvenceCtr:GetAsyncIdx()
  17. self.asyncIdx = self.asyncIdx + 1
  18. return self.asyncIdx
  19. end
  20. function UIPetAdvenceCtr:GetData()
  21. return self.data
  22. end
  23. function UIPetAdvenceCtr:GetCurAdvenceMaxLv()
  24. if next(advenceLvStage) == nil then
  25. return 0
  26. end
  27. if not self.curPetData then
  28. self.curPetData = ManagerContainer.DataMgr.PetDataMgr:GetPetDataById(self.data)
  29. end
  30. return tonumber(advenceLvStage[self.curPetData.advanceLevel + 1] or 0), tonumber(advenceLvStage[self.curPetData.advanceLevel + 2] or 0)
  31. end
  32. function UIPetAdvenceCtr:GetCurPetAttr(key)
  33. local actorData = ManagerContainer.DataMgr.PetDataMgr:GetPetActorData(self.data)
  34. return actorData:GetFinalAttr(key)
  35. end
  36. function UIPetAdvenceCtr:AddSelection(id)
  37. if not id then return end
  38. local targetPetData = ManagerContainer.DataMgr.PetDataMgr:GetPetDataById(id)
  39. local curPetCfgData = ManagerContainer.CfgMgr:GetPetProgressCfgDataById(self.curPetData.cfgId)
  40. local nextAdvenceLv = self.curPetData.advanceLevel + 1
  41. local idxList = {}
  42. for i = 1, 2 do
  43. local inCondition = true
  44. local condition = curPetCfgData["Condition"..nextAdvenceLv..i]
  45. if condition then
  46. for k,v in pairs(condition) do
  47. local type = v[1]
  48. local num = v[2]
  49. if type == Enum.PetRelationConditionType.Type then
  50. if targetPetData.quality ~= num then
  51. inCondition = false
  52. break
  53. end
  54. elseif type == Enum.PetRelationConditionType.Advence then
  55. if targetPetData.advanceLevel ~= num then
  56. inCondition = false
  57. break
  58. end
  59. elseif type == Enum.PetRelationConditionType.Nature then
  60. if targetPetData.natureType ~= num then
  61. inCondition = false
  62. break
  63. end
  64. end
  65. end
  66. end
  67. if inCondition then
  68. idxList[#idxList + 1] = i + 1
  69. end
  70. end
  71. local emptyIdx = 0
  72. for i = 1, #idxList do
  73. local idx = idxList[i]
  74. if self.selectionedList[idx] == nil then
  75. emptyIdx = idx
  76. break
  77. end
  78. end
  79. local lastSelectedId
  80. if emptyIdx > 0 then
  81. lastSelectedId = nil
  82. else
  83. emptyIdx = idxList[1]
  84. lastSelectedId = self.selectionedList[emptyIdx]
  85. end
  86. self:RemoveSelection(emptyIdx)
  87. self.selectionedList[emptyIdx] = id
  88. if self.showDatas then
  89. for j = 1, #self.showDatas do
  90. if self.showDatas[j].id == id then
  91. self.showDatas[j].selected = emptyIdx
  92. end
  93. end
  94. end
  95. return lastSelectedId
  96. end
  97. function UIPetAdvenceCtr:SetChildController(ctr)
  98. self.childCtr = ctr
  99. end
  100. function UIPetAdvenceCtr:RemoveSelection(idx)
  101. if idx == 1 then return end
  102. if self.selectionedList[idx] == nil then return end
  103. local id = self.selectionedList[idx]
  104. if self.showDatas then
  105. for j = 1, #self.showDatas do
  106. if self.showDatas[j].id == id then
  107. self.showDatas[j].selected = nil
  108. end
  109. end
  110. end
  111. self.selectionedList[idx] = nil
  112. end
  113. function UIPetAdvenceCtr:GetSelections()
  114. return self.selectionedList
  115. end
  116. function UIPetAdvenceCtr:GetSelectionsLegnth()
  117. return #self.selectionedList
  118. end
  119. function UIPetAdvenceCtr:IsInSelections(id)
  120. return CommonUtil.EleInTable(id, self.selectionedList)
  121. end
  122. function UIPetAdvenceCtr:SetShowDatas(datas)
  123. self.showDatas = datas
  124. end
  125. function UIPetAdvenceCtr:GetSelectionPetData(id)
  126. for _, v in pairs(self.showDatas) do
  127. if v.id == id then
  128. return v
  129. end
  130. end
  131. return
  132. end
  133. function UIPetAdvenceCtr:RefreshPetDatas()
  134. if not self.petAdvenceLimit then
  135. local val = GlobalConfig.Instance:GetConfigStrValue(346)
  136. if val ~= "" and val ~= nil then
  137. self.petAdvenceLimit = CommonUtil.DeserializeGlobalStrToTable(val)
  138. end
  139. end
  140. local petDatasSource = ManagerContainer.DataMgr.PetDataMgr:GetPetDatas()
  141. local petDatas = petDatasSource
  142. local curPetData = ManagerContainer.DataMgr.PetDataMgr:GetPetDataById(self.data)
  143. local curPetCfgData = ManagerContainer.CfgMgr:GetPetProgressCfgDataById(curPetData.cfgId)
  144. local limitIdx = 0
  145. if self.petAdvenceLimit then
  146. for i = #self.petAdvenceLimit, 1, -1 do
  147. --local adv = tonumber(self.petAdvenceLimit[i][1])
  148. local adv = tonumber(self.petAdvenceLimit[i])
  149. --LogError("=================curPetData.advanceLevel = "..curPetData.advanceLevel.."===========")
  150. --LogError("===========adv = "..self.petAdvenceLimit[i][0].."======curPetData.advanceLevel = "..curPetData.advanceLevel.."===========")
  151. --LogError("===========adv = "..self.petAdvenceLimit[i].."=======")
  152. if curPetData.advanceLevel >= adv then
  153. limitIdx = i
  154. break
  155. end
  156. end
  157. end
  158. local function IsAdvenceMatLimit(matCfgId)
  159. if not self.petAdvenceLimit then return false end
  160. local needDel = false
  161. for i = #self.petAdvenceLimit, 1, -1 do
  162. local adv = tonumber(self.petAdvenceLimit[i][1])
  163. local cfgId = tonumber(self.petAdvenceLimit[i][2])
  164. if i == limitIdx and matCfgId == cfgId then
  165. return false
  166. end
  167. if i ~= limitIdx and matCfgId == cfgId then
  168. needDel = true
  169. end
  170. end
  171. return needDel
  172. end
  173. local nextAdvenceLv = curPetData.advanceLevel + 1
  174. local typeNum, advenceNum, natureNum = {},{},{}
  175. for i = 1, 2 do
  176. local condition = curPetCfgData["Condition"..nextAdvenceLv..i]
  177. if condition then
  178. for k,v in pairs(condition) do
  179. local type = v[1]
  180. local num = v[2]
  181. if type == Enum.PetRelationConditionType.Type then
  182. typeNum[#typeNum + 1] = num
  183. elseif type == Enum.PetRelationConditionType.Advence then
  184. advenceNum[#advenceNum + 1] = num
  185. elseif type == Enum.PetRelationConditionType.Nature then
  186. natureNum[#natureNum + 1] = num
  187. end
  188. end
  189. end
  190. end
  191. local list = CommonUtil.ArrayFilterSelections(petDatas, Enum.FilterType.AND, {"quality", "advanceLevel", "natureType", "qiyueHeroId"}, {typeNum, advenceNum, natureNum, 0})
  192. if list ~= nil then
  193. for i = #list, 1, -1 do
  194. local needDel = IsAdvenceMatLimit(list[i].cfgId)
  195. if needDel then
  196. table.remove(list, i)
  197. end
  198. end
  199. CommonUtil.ArraySortSelections(list, Enum.TableSortRule.Up, "isBattle", "isSupport", "isRelevant", "cfgId")
  200. for k,v in pairs(self.selectionedList) do
  201. local data
  202. for j = 1, #list do
  203. if list[j].id == v then
  204. if k == 1 then
  205. data = table.remove(list, j)
  206. else
  207. list[j].selected = k
  208. end
  209. break
  210. end
  211. end
  212. if k == 1 then
  213. if data then
  214. data.selected = 1
  215. data.isBattle = false
  216. table.insert(list, 1, data)
  217. else
  218. if not self.curPetData then
  219. self.curPetData = ManagerContainer.DataMgr.PetDataMgr:GetPetDataById(v)
  220. end
  221. data = clone(self.curPetData)
  222. data.selected = 1
  223. data.isBattle = false
  224. table.insert(list, 1, data)
  225. end
  226. end
  227. end
  228. for k,v in pairs(list) do
  229. v.idx = k
  230. end
  231. end
  232. if list == nil then
  233. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("NoCardTips3")
  234. end
  235. -- LogHRWarning(Inspect(list))
  236. return list
  237. end
  238. function UIPetAdvenceCtr:SendPetAdvence()
  239. local list = {}
  240. for k,v in pairs(self.selectionedList) do
  241. if k > 1 then
  242. list[#list + 1] = v
  243. end
  244. end
  245. ManagerContainer.DataMgr.PetDataMgr:SendPetAdvence(self.data, list)
  246. end
  247. function UIPetAdvenceCtr:GetPetDataById(id)
  248. if self.childCtr and self.childCtr.GetPetDataById then
  249. return self.childCtr:GetPetDataById(id)
  250. end
  251. return nil
  252. end
  253. function UIPetAdvenceCtr:WasSkillUp(petData)
  254. for _,v in pairs(petData.skillList) do
  255. if v.level > 1 then
  256. return true
  257. end
  258. end
  259. return false
  260. end
  261. function UIPetAdvenceCtr:IsAdvenceFree()
  262. local vipLv = ManagerContainer.DataMgr.UserData:GetVipLv()
  263. local vipCfg = ManagerContainer.CfgMgr:GetVipCfgById(vipLv)
  264. local boliShooLv = ManagerContainer.DataMgr.BoliShopData:GetCurLv()
  265. local boliShopCfg = ManagerContainer.CfgMgr:GetBoLiVipCfgById(boliShooLv)
  266. return vipCfg and vipCfg.PetAdvance >= 1 or boliShopCfg.PetAdvance >= 1
  267. end
  268. function UIPetAdvenceCtr:OnDispose()
  269. self.showDatas = nil
  270. self.selectionedList = nil
  271. self.childCtr = nil
  272. self.data = nil
  273. self.view = nil
  274. end
  275. return UIPetAdvenceCtr