UICollectTipsCtr.lua 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. local UICollectTipsCtr = class("UICollectTipsCtr", require("UICtrBase"))
  2. local UICollectCtr
  3. local keepSakeExchangeNums
  4. function UICollectTipsCtr:Init(view)
  5. self.view = view
  6. local val = GlobalConfig.Instance:GetConfigStrValue(275)
  7. if val ~= "" and val ~= nil then
  8. keepSakeExchangeNums = CommonUtil.DeserializeGlobalStrToTable(val)
  9. end
  10. self.isAuto = false
  11. self.canLvUp = false
  12. end
  13. function UICollectTipsCtr:SetData(data)
  14. UICollectCtr = ManagerContainer.LuaUIMgr:GetViewCtrById(Enum.UIPageName.UICollect)
  15. self.asyncIdx = 0
  16. if data == nil then return end
  17. self.data = data
  18. end
  19. function UICollectTipsCtr:GetAsyncIdx()
  20. self.asyncIdx = self.asyncIdx + 1
  21. return self.asyncIdx
  22. end
  23. function UICollectTipsCtr:GetData()
  24. return self.data
  25. end
  26. function UICollectTipsCtr:GetType()
  27. return self.data.type
  28. end
  29. function UICollectTipsCtr:GetCfgId()
  30. return self.data.cfgId
  31. end
  32. function UICollectTipsCtr:GetOffsetCfgId(offset)
  33. if UICollectCtr then
  34. local newCfgId = self.data.cfgId
  35. if self.data.type == Enum.CollectType.Card then
  36. newCfgId = UICollectCtr:GetCardBookOffsetCfgId(self:GetCfgId(), offset)
  37. elseif self.data.type == Enum.CollectType.Pet then
  38. newCfgId = UICollectCtr:GetPetBookOffsetCfgId(self:GetCfgId(), offset)
  39. elseif self.data.type == Enum.CollectType.KeepSake then
  40. newCfgId = UICollectCtr:GetKeepSakeBookOffsetCfgId(self:GetCfgId(), offset)
  41. end
  42. self.data.cfgId = newCfgId
  43. if self.view then
  44. self.view:Init()
  45. end
  46. end
  47. end
  48. function UICollectTipsCtr:ResetKeepSakeMaterialCount()
  49. self.isAuto = false
  50. self.canLvUp = false
  51. self.ownedExchangeCount = CommonUtil.GetOwnResCountByItemId(Enum.ItemIds.KeepSakeExchange)
  52. self.keepSakeOriMats = {}
  53. self.needMats = {}
  54. local keepSakeId = self:GetCfgId()
  55. local lv = ManagerContainer.DataMgr.KeepSakeBookData:GetKeepSakeBookDataById(keepSakeId)
  56. local cfgData = ManagerContainer.CfgMgr:GetKeepSakeCfgDataById(keepSakeId)
  57. if not cfgData then
  58. return
  59. end
  60. local curLv = lv or 0
  61. local nextLv = curLv + 1
  62. local materials = cfgData["MaterialLevel"..nextLv]
  63. if materials then
  64. for i = 1, #materials do
  65. local material = materials[i]
  66. self.keepSakeOriMats[material[1]] = ManagerContainer.DataMgr.KeepSakeBookData:GetMaterialById(material[1])
  67. self.needMats[material[1]] = material[2]
  68. end
  69. end
  70. self.displayMats = clone(self.keepSakeOriMats)
  71. end
  72. local function GetKeepSakeExchange(quality)
  73. for _,v in pairs(keepSakeExchangeNums) do
  74. if tonumber(v[1]) == quality then
  75. return tonumber(v[2])
  76. end
  77. end
  78. return 0
  79. end
  80. function UICollectTipsCtr:AutoAddKeepSakeMaterialCount()
  81. self.isAuto = true
  82. self.canLvUp = true
  83. for k, v in pairs(self.keepSakeOriMats) do
  84. local cfgData = ManagerContainer.CfgMgr:GetItemById(k)
  85. local exchangeCount = tonumber(GetKeepSakeExchange(cfgData.Quality))
  86. if exchangeCount then
  87. local delta = self.needMats[k] - v
  88. if self.ownedExchangeCount < delta*exchangeCount then
  89. local count = math.floor(self.ownedExchangeCount/exchangeCount)
  90. self.displayMats[k] = self.displayMats[k] + count
  91. self.ownedExchangeCount = self.ownedExchangeCount - count * exchangeCount
  92. elseif delta > 0 then
  93. self.displayMats[k] = self.displayMats[k] + delta
  94. self.ownedExchangeCount = self.ownedExchangeCount - delta * exchangeCount
  95. end
  96. end
  97. end
  98. for k,v in pairs(self.displayMats) do
  99. if v < self.needMats[k] then
  100. self.canLvUp = false
  101. break
  102. end
  103. end
  104. end
  105. function UICollectTipsCtr:GetDisplayMats(id)
  106. return self.displayMats[id]
  107. end
  108. function UICollectTipsCtr:GetOwnedKeepSakeExchange()
  109. return self.ownedExchangeCount
  110. end
  111. function UICollectTipsCtr:SendKeepSakeActivity()
  112. local id = self:GetCfgId()
  113. if not self.isAuto and not ManagerContainer.DataMgr.KeepSakeBookData:CanKeepSakeLvUp(id) then
  114. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("ItemNotEnoughDefault")
  115. return
  116. end
  117. if self.isAuto and not self.canLvUp then
  118. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("MaterialsNotEnoughDefault")
  119. return
  120. end
  121. ManagerContainer.DataMgr.KeepSakeBookData:SendKeepSakeLevelUpReq(id)
  122. end
  123. function UICollectTipsCtr:GetRightCfgId()
  124. end
  125. function UICollectTipsCtr:OnDispose()
  126. self.data = nil
  127. self.view = nil
  128. end
  129. return UICollectTipsCtr