UIPetLvUpCtr.lua 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. local UIPetLvUpCtr = class("UIPetLvUpCtr", require("UICtrBase"))
  2. local advenceLvStage
  3. local lastAttrs = {}
  4. local newAttrs = {}
  5. local commonSkillMatId = 819
  6. function UIPetLvUpCtr:Init(view)
  7. self.view = view
  8. local val = GlobalConfig.Instance:GetConfigStrValue(208)
  9. if val ~= "" and val ~= nil then
  10. advenceLvStage = CommonUtil.DeserializeGlobalStrToTable(val)
  11. end
  12. commonSkillMatId = GlobalConfig.Instance:GetConfigIntValue(313)
  13. end
  14. function UIPetLvUpCtr:SetData(data)
  15. self.asyncIdx = 0
  16. if data == nil then return end
  17. self.data = data
  18. end
  19. function UIPetLvUpCtr:GetCurPetData()
  20. local id = self.data
  21. self.curPetData = ManagerContainer.DataMgr.PetDataMgr:GetPetDataById(id)
  22. return self.curPetData
  23. end
  24. function UIPetLvUpCtr:GetCurPetMaxLv()
  25. if next(advenceLvStage) == nil then
  26. return 0
  27. end
  28. return tonumber(advenceLvStage[self.curPetData.advanceLevel + 1] or 0), self.curPetData.advanceLevel + 1 == #advenceLvStage
  29. end
  30. function UIPetLvUpCtr:GetPetMaxLv()
  31. return ManagerContainer.CfgMgr:GetPetExpCfgMaxData()
  32. end
  33. function UIPetLvUpCtr:GetCurAdvenceMaxLv()
  34. if next(advenceLvStage) == nil then
  35. return 0
  36. end
  37. if not self.curPetData then
  38. self.curPetData = ManagerContainer.DataMgr.PetDataMgr:GetPetDataById(self.data)
  39. end
  40. return tonumber(advenceLvStage[self.curPetData.advanceLevel] or 0), tonumber(advenceLvStage[self.curPetData.advanceLevel + 1] or 0)
  41. end
  42. function UIPetLvUpCtr:GetSimpleSecondAttrs()
  43. local id = self.data
  44. local actorData = ManagerContainer.DataMgr.PetDataMgr:GetPetActorData(id)
  45. if not actorData then
  46. return
  47. end
  48. if self.simpleAttrs == nil then
  49. self.simpleAttrs = {}
  50. end
  51. self.simpleAttrs[Enum.HeroAttrType.Life] = actorData:GetFinalAttr(Enum.HeroAttrType.Life)
  52. self.simpleAttrs[Enum.HeroAttrType.Sp] = actorData:GetFinalAttr(Enum.HeroAttrType.Sp)
  53. self.simpleAttrs[Enum.HeroAttrType.Attack] = actorData:GetFinalAttr(Enum.HeroAttrType.Attack)
  54. self.simpleAttrs[Enum.HeroAttrType.MagicAttack] = actorData:GetFinalAttr(Enum.HeroAttrType.MagicAttack)
  55. self.simpleAttrs[Enum.HeroAttrType.Defense] = actorData:GetFinalAttr(Enum.HeroAttrType.Defense)
  56. self.simpleAttrs[Enum.HeroAttrType.MagicDefense] = actorData:GetFinalAttr(Enum.HeroAttrType.MagicDefense)
  57. return self.simpleAttrs
  58. end
  59. function UIPetLvUpCtr:GetCurPetAttr(key)
  60. local actorData = ManagerContainer.DataMgr.PetDataMgr:GetPetActorData(self.data)
  61. return actorData:GetFinalAttr(key)
  62. end
  63. function UIPetLvUpCtr:SendPetLvUp()
  64. ManagerContainer.DataMgr.PetDataMgr:SendPetLvUp(self.data)
  65. end
  66. function UIPetLvUpCtr:AttrsChanged(tbArrtDeffrent)
  67. if tbArrtDeffrent ~= nil then
  68. for i=1,#tbArrtDeffrent do
  69. local Data = tbArrtDeffrent[i]
  70. local IsHero = Data.is_hero_pet
  71. local ActorId = Data.actor_id
  72. if self.data == ActorId and not IsHero then
  73. local actorData = ManagerContainer.DataMgr.PetDataMgr:GetPetActorData(self.data)
  74. lastAttrs = {}
  75. newAttrs = {}
  76. for k,v in pairs(Enum.HeroAttrType) do
  77. newAttrs[v] = math.floor(SDataUtil.InvConvert(actorData:GetFinalAttr(v)))
  78. local Dif = Data:GetAttribute(v)
  79. if Dif == nil then
  80. Dif = 0
  81. end
  82. lastAttrs[v] = newAttrs[v] - Dif
  83. end
  84. ManagerContainer.LuaUIMgr:AttrNoticeDisplay1( {lastAttrs, newAttrs})
  85. end
  86. end
  87. end
  88. end
  89. function UIPetLvUpCtr:RefreshLeftPet()
  90. self.data = ManagerContainer.DataMgr.PetDataMgr:GetNextSortId(self.data, false)
  91. end
  92. function UIPetLvUpCtr:RefreshRightPet()
  93. self.data = ManagerContainer.DataMgr.PetDataMgr:GetNextSortId(self.data, true)
  94. end
  95. function UIPetLvUpCtr:SetSkillUpMatId(id)
  96. self.skillUpMat = id
  97. end
  98. function UIPetLvUpCtr:GetSkillUpMat()
  99. return self.skillUpMat
  100. end
  101. function UIPetLvUpCtr:SendPetSkillUp()
  102. ManagerContainer.DataMgr.PetDataMgr:SendPetSkillUp(self.data, self.skillUpMat)
  103. end
  104. -- function UIPetLvUpCtr:GetScale()
  105. -- LogError(tostring(self.data))
  106. -- local PetActor = ManagerContainer.DataMgr.PetDataMgr:GetPetActorData(self.data)
  107. -- local Scale = PetActor:GetScale()
  108. -- return Scale
  109. -- end
  110. function UIPetLvUpCtr:GetScale()
  111. if not self.curPetData then
  112. return 1
  113. end
  114. -- LogError(Inspect(self.curPetData.skillList))
  115. local Nveragelevles = 0
  116. local nCount = 0
  117. for _,v in pairs(self.curPetData.skillList) do
  118. Nveragelevles = Nveragelevles + v.level
  119. nCount = nCount + 1
  120. end
  121. -- if nCount > 0 then
  122. -- Nveragelevles = math.ceil(Nveragelevles / nCount)
  123. -- end
  124. -- if Nveragelevles < 1 then
  125. -- Nveragelevles = 1
  126. -- end
  127. Nveragelevles = Nveragelevles - nCount
  128. if Nveragelevles <= 0 then
  129. Nveragelevles = 0
  130. end
  131. local Scale = 1
  132. local cfg = GlobalConfig.Instance:GetConfigStrValue(318)
  133. if cfg and cfg ~= '' then
  134. local itemCfgs = string.split(cfg, ';')
  135. if itemCfgs then
  136. for _,v in pairs(itemCfgs) do
  137. if v and v ~= '' then
  138. local itemCfg = string.split(v, ':')
  139. if itemCfg and #itemCfg >= 2 then
  140. local nLevel = tonumber(itemCfg[1])
  141. local fScale = tonumber(itemCfg[2])
  142. if nLevel <= Nveragelevles then
  143. Scale = fScale
  144. end
  145. end
  146. end
  147. end
  148. end
  149. end
  150. return Scale
  151. end
  152. function UIPetLvUpCtr:GetCurPetSkillData(id)
  153. if not self.curPetData then return end
  154. for _,v in pairs(self.curPetData.skillList) do
  155. if v.cfgId == id then
  156. return v
  157. end
  158. end
  159. return
  160. end
  161. function UIPetLvUpCtr:GetPetActorData()
  162. local id = self.data
  163. local actorData = ManagerContainer.DataMgr.PetDataMgr:GetPetActorData(id)
  164. if not actorData then
  165. return
  166. end
  167. return actorData
  168. end
  169. function UIPetLvUpCtr:IsSkillMax()
  170. if not self.curPetData then return false end
  171. local petCfgData = ManagerContainer.CfgMgr:GetPetDataById(self.curPetData.cfgId)
  172. local maxLimit = #petCfgData.Skill1Rate
  173. for _,v in pairs(self.curPetData.skillList) do
  174. if v.level < maxLimit then
  175. return false
  176. end
  177. end
  178. return true
  179. end
  180. function UIPetLvUpCtr:GetRelationAddAttrs()
  181. local function GetMaxActiveRelationIdx(relationPets, cfgData)
  182. local count = 3
  183. local maxIdx = 0
  184. for j = 3, 1, -1 do
  185. local condition = cfgData['Condition'..j]
  186. local state
  187. if condition then
  188. local curCount = 0
  189. if relationPets then
  190. for k,v1 in pairs(relationPets) do
  191. local cfgId = condition[k][1]
  192. local num = condition[k][2]
  193. if v1.cfgId == cfgId and v1.advanceLevel >= num and v1.petId > 0 then
  194. curCount = curCount + 1
  195. end
  196. end
  197. end
  198. state = curCount >= count
  199. if state then
  200. if maxIdx == 0 then
  201. maxIdx = j
  202. end
  203. end
  204. end
  205. end
  206. return maxIdx
  207. end
  208. local list = {}
  209. local petData = self:GetCurPetData()
  210. local relationDatas = ManagerContainer.DataMgr.PetDataMgr:GetAllPetRelationDatas()
  211. for _,v in pairs(relationDatas) do
  212. local cfgData = ManagerContainer.CfgMgr:GetPetPartnerDataById(v.cfgId)
  213. local maxIdx = GetMaxActiveRelationIdx(v.relationPets, cfgData)
  214. if maxIdx > 0 then
  215. for i = maxIdx, 1, -1 do
  216. for k, v1 in pairs(cfgData["attribute"..i]) do
  217. if not list[v1[1]] then
  218. list[v1[1]] = 0
  219. end
  220. list[v1[1]] = list[v1[1]] + v1[2]
  221. end
  222. end
  223. end
  224. end
  225. return list
  226. end
  227. function UIPetLvUpCtr:SendPetBattleDown()
  228. local petData = self:GetCurPetData()
  229. if petData.heroId > 0 then
  230. local data = {{key = petData.heroId, value = 0}}
  231. ManagerContainer.DataMgr.PetDataMgr:SendPetBattle(data)
  232. end
  233. end
  234. function UIPetLvUpCtr:SetSlotCount(count)
  235. self.slotCount = count
  236. end
  237. function UIPetLvUpCtr:RefreshSlotRPState()
  238. end
  239. function UIPetLvUpCtr:SendOneKeyUp()
  240. local petData = self:GetCurPetData()
  241. if not petData then return end
  242. local slots = petData.slots
  243. local kvList = {}
  244. for i = 1, self.slotCount do
  245. local slot = slots and slots[i] or nil
  246. local state = slot and (slot.stampId > 0) or false
  247. if not state then
  248. local list, qualityStamp = ManagerContainer.DataMgr.PetDataMgr.petStampData:GetAllPetStampDatasByTypeExcludeId(i)
  249. if qualityStamp and qualityStamp.petId == 0 then
  250. kvList[#kvList + 1] = {key = i, value = qualityStamp.id}
  251. end
  252. end
  253. end
  254. if #kvList > 0 then
  255. ManagerContainer.DataMgr.PetDataMgr:SendStampUpReq(self.data, kvList)
  256. end
  257. end
  258. function UIPetLvUpCtr:SendOneKeyDown()
  259. local petData = self:GetCurPetData()
  260. if not petData then return end
  261. local slots = petData.slots
  262. local canDown = false
  263. for i = 1, self.slotCount do
  264. local slot = slots and slots[i] or nil
  265. local state = slot and (slot.stampId > 0) or false
  266. if state then
  267. canDown = true
  268. break
  269. end
  270. end
  271. if canDown then
  272. ManagerContainer.DataMgr.PetDataMgr:SendStampDownReq(self.data, 0)
  273. end
  274. end
  275. function UIPetLvUpCtr:RefreshSkillMatsData()
  276. if not self.curPetData then return end
  277. if self.skillUpMat then return end
  278. self.skillUpMat = nil
  279. local selfId = self.curPetData.id
  280. local petDatasSource = ManagerContainer.DataMgr.PetDataMgr:GetPetDatas()
  281. local petDatas = petDatasSource
  282. local petData = self.curPetData
  283. local selfDatas = CommonUtil.ArrayFilterSelections(petDatas, Enum.FilterType.AND, {"cfgId", "qiyueHeroId"}, {petData.cfgId, 0})
  284. for j = #selfDatas, 1, -1 do
  285. if selfDatas[j].id == selfId then
  286. table.remove(selfDatas, j)
  287. break
  288. end
  289. end
  290. if #selfDatas > 0 then
  291. CommonUtil.ArraySortSelections(selfDatas, Enum.TableSortRule.Up, "isBattle", "quality", "isSupport", "isRelevant", "advanceLevel", "level", "cfgId")
  292. if #selfDatas > 0 then
  293. self.skillUpMat = selfDatas[1].id
  294. return
  295. end
  296. end
  297. local commonDatas = CommonUtil.ArrayFilterSelections(petDatas, Enum.FilterType.AND, {"cfgId", "qiyueHeroId"}, {commonSkillMatId, 0})
  298. for j = #commonDatas, 1, -1 do
  299. if commonDatas[j].id == selfId then
  300. table.remove(commonDatas, j)
  301. break
  302. end
  303. end
  304. if #commonDatas > 0 then
  305. CommonUtil.ArraySortSelections(commonDatas, Enum.TableSortRule.Up, "isBattle", "quality", "isSupport", "isRelevant", "advanceLevel", "level", "cfgId")
  306. if #commonDatas > 0 then
  307. self.skillUpMat = commonDatas[1].id
  308. return
  309. end
  310. end
  311. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("Petstudy_003")
  312. end
  313. function UIPetLvUpCtr:GetSkillMatPetData()
  314. if not self.skillUpMat then return end
  315. local petData = ManagerContainer.DataMgr.PetDataMgr:GetPetDataById(self.skillUpMat)
  316. return petData
  317. end
  318. function UIPetLvUpCtr:WasSkillUp(petData)
  319. if not petData.skillList then return false end
  320. for _,v in pairs(petData.skillList) do
  321. if v.level > 1 then
  322. return true
  323. end
  324. end
  325. return false
  326. end
  327. function UIPetLvUpCtr:QueryPetDetailInfo()
  328. ManagerContainer.DataMgr.PetDataMgr:QueryPetDetailInfos({self.data})
  329. end
  330. function UIPetLvUpCtr:GetAsyncIdx()
  331. self.asyncIdx = self.asyncIdx + 1
  332. return self.asyncIdx
  333. end
  334. function UIPetLvUpCtr:GetData()
  335. return self.data
  336. end
  337. function UIPetLvUpCtr:OnDispose()
  338. self.data = nil
  339. self.view = nil
  340. self.curSkillMat = nil
  341. end
  342. return UIPetLvUpCtr