UIEfficiencyInfo.lua 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. ---@class UIEfficiencyInfo
  2. ---@param expPotionResData EfficiencyProtos.ExperiencePotionRes
  3. UIEfficiencyInfo = class()
  4. local this = UIEfficiencyInfo
  5. function this:ctor()
  6. end
  7. function this:Reset()
  8. self.isFirst=false
  9. self.purchasedIds={}
  10. self.reveivedRewardTab={}
  11. end
  12. function this:Init()
  13. self.multiplierInfo={} --经验倍率信息
  14. self.efficiencyInfo={} --cfg_efficiency
  15. self.efficiencyPomoteCfg=nil
  16. self.reveivedRewardTab={} --已领取的奖励
  17. self.rewardCfg=nil --领取奖励cfg
  18. self.vipCfg = nil
  19. self.curAllExpMultiplier=0
  20. self.expPotionEndTime=1
  21. self.purchasedIds={}
  22. self.expPotionResData=nil
  23. self.isFirst=false
  24. self.vipInfo={}
  25. self:InitData()
  26. self:RegistMessages()
  27. self:InitPomoteConfig()
  28. end
  29. function this:InitData()
  30. end
  31. function this:RegistMessages()
  32. --[[ self.messageContainer:Regist(MessageDef.ResEfficiencyMagnificationMessage, self.ResEfficiencyMagnificationMessage, self)
  33. self.messageContainer:Regist(MessageDef.ResEfficiencyRewardInfoMessage, self.ResEfficiencyRewardInfoMessage, self)
  34. self.messageContainer:Regist(MessageDef.ResExperiencePotionMessage, self.ResExperiencePotionMessage, self)
  35. self.messageContainer:Regist(MessageDef.ResEfficiencyBuyInfoMessage,self.ResEfficiencyBuyInfoMessage,self)
  36. self.messageContainer:Regist(MessageDef.ResFirstRechargeViewMessage,self.ResFirstRechargeViewMessage,self)]]
  37. --self.messageContainer:Regist(MessageDef.ResEfficiencyBuyRateMessage,self.ResEfficiencyBuyRateMessage,self)
  38. SL:RegisterLuaNetMsg(MessageDef.ResEfficiencyMagnificationMessage, self.ResEfficiencyMagnificationMessage, self)
  39. SL:RegisterLuaNetMsg(MessageDef.ResEfficiencyRewardInfoMessage, self.ResEfficiencyRewardInfoMessage, self)
  40. SL:RegisterLuaNetMsg(MessageDef.ResExperiencePotionMessage, self.ResExperiencePotionMessage, self)
  41. SL:RegisterLuaNetMsg(MessageDef.ResEfficiencyBuyInfoMessage,self.ResEfficiencyBuyInfoMessage,self)
  42. SL:RegisterLuaNetMsg(MessageDef.ResFirstRechargeViewMessage,self.ResFirstRechargeViewMessage,self)
  43. end
  44. ---@param message EfficiencyProtos.EfficiencyMagnificationRes
  45. function this:ResEfficiencyMagnificationMessage(_,message)
  46. for k,v in pairs(message.efficiencyMagnificationInfos) do
  47. local cfg = SL:GetConfig("cfg_efficiency",v.id)
  48. if cfg then
  49. if cfg.type==2 then
  50. self:UpdateMultiplierData(v)
  51. end
  52. end
  53. end
  54. SL:ReqFirstRechargeViewMessage()
  55. end
  56. ---@param message EfficiencyProtos.EfficiencyRewardInfoRes
  57. function this:ResEfficiencyRewardInfoMessage(_,message)
  58. for k,v in pairs(message.id) do
  59. if not table.contains(self.reveivedRewardTab,v) then
  60. table.insert(self.reveivedRewardTab,v)
  61. end
  62. end
  63. end
  64. ---@param message EfficiencyProtos.ExperiencePotionRes
  65. function this:ResExperiencePotionMessage(_,message)
  66. self.isFirst=message.isFirst
  67. self.expPotionEndTime=message.endTime
  68. self.expPotionResData=message
  69. end
  70. ---@param message EfficiencyProtos.EfficiencyBuyInfoRes
  71. function this:ResEfficiencyBuyInfoMessage(_,message)
  72. for k,v in pairs(message.id) do
  73. if not table.contains(self.purchasedIds,v) then
  74. table.insert(self.purchasedIds,v)
  75. end
  76. end
  77. end
  78. ---@param message RoleProtos.FirstRechargeViewRes
  79. function this:ResFirstRechargeViewMessage(_,message)
  80. self.vipInfo = {message.id,message.receiveAmount}
  81. end
  82. ---@param message EfficiencyProtos.EfficiencyBuyRateRes
  83. function this:ResEfficiencyBuyRateMessage(_,message)
  84. for k,v in pairs(message.id) do
  85. if not table.contains(self.purchasedIds,v) then
  86. table.insert(self.purchasedIds,v)
  87. end
  88. end
  89. end
  90. --获取当前可以显示的奖励ui
  91. function this:GetCanShowReward()
  92. if self.rewardCfg==nil then
  93. self:InitRewardConfig()
  94. end
  95. for k,v in pairs(self.rewardCfg) do
  96. if not table.contains(self.reveivedRewardTab,v.id) then
  97. return v
  98. end
  99. end
  100. return nil
  101. end
  102. function this:GetCanShowVipInfo(id)
  103. if self.vipCfg == nil then
  104. self.vipCfg = {}
  105. end
  106. if id == #self.vipCfg then
  107. return true, self.vipCfg[id] or {}
  108. else
  109. return false, self.vipCfg[id] or {}
  110. end
  111. end
  112. function this:GetIsPurchasedById(id)
  113. return table.contains(self.purchasedIds,id)
  114. end
  115. --更新经验倍率信息v
  116. function this:UpdateMultiplierData(info)
  117. if self.multiplierInfo[info.id]==nil then
  118. self.multiplierInfo[info.id]={}
  119. end
  120. if self.multiplierInfo[info.id].curLevel~=info.level then
  121. self.multiplierInfo[info.id].expMultiplier=self:GetExpMultiplierByIdAndLevel(info.id,info.level)
  122. end
  123. self.multiplierInfo[info.id].curLevel=info.level
  124. if self.multiplierInfo[info.id].group==nil then
  125. self.multiplierInfo[info.id].group=self:GetGroupById(info.id)
  126. end
  127. if self.multiplierInfo[info.id].maxLevel==nil then
  128. self.multiplierInfo[info.id].maxLevel=self:GetEfficiencyMaxLevel(info.id)
  129. end
  130. self.curAllExpMultiplier= self.curAllExpMultiplier+self.multiplierInfo[info.id].expMultiplier
  131. end
  132. --获取效率信息通过cfgId
  133. function this:GetEfficiencyInfoById(id)
  134. if self.efficiencyInfo[id] then
  135. return self.efficiencyInfo[id]
  136. end
  137. return nil
  138. end
  139. --设置当前数据同组最大的等级
  140. function this:GetEfficiencyMaxLevel(id)
  141. local info = SL:GetConfig("cfg_efficiency",id)
  142. if info then
  143. return self:GetPomoteSameGroupMaxLevel(info.conditionGroup)
  144. end
  145. return 0
  146. end
  147. --设置当前数据同组最大的等级
  148. function this:GetExpMultiplierByIdAndLevel(id,level)
  149. return 0
  150. end
  151. --设置当前数据同组最大的等
  152. function this:GetExplosionRateByIdAndLevel(id,level)
  153. return 0
  154. end
  155. --设置当前数据组
  156. function this:GetGroupById(id)
  157. local efficiencyInfo = SL:GetConfig("cfg_efficiency",id)
  158. if efficiencyInfo then
  159. return efficiencyInfo.conditionGroup
  160. end
  161. return 0
  162. end
  163. --获取同组别列表里最大等级
  164. function this:GetPomoteSameGroupMaxLevel(group)
  165. self:InitPomoteConfig()
  166. if self.efficiencyPomoteCfg[group]==nil then
  167. return 0
  168. end
  169. if self.efficiencyPomoteCfg[group].maxLevel==nil then
  170. local level=0
  171. for k,v in pairs(self.efficiencyPomoteCfg[group]) do
  172. if level<=v.level then
  173. level=v.level
  174. end
  175. end
  176. self.efficiencyPomoteCfg[group].maxLevel=level
  177. end
  178. return self.efficiencyPomoteCfg[group].maxLevel
  179. end
  180. --初始化所有奖励数据
  181. function this:InitRewardConfig()
  182. self.rewardCfg=SL:FindConfigs("cfg_efficiency","type",1)
  183. end
  184. --初始化config数据
  185. function this:InitPomoteConfig()
  186. if self.efficiencyPomoteCfg==nil then
  187. self.efficiencyPomoteCfg={}
  188. if false then
  189. for k,v in pairs(cfg) do
  190. if self.efficiencyPomoteCfg[v.group]==nil then
  191. self.efficiencyPomoteCfg[v.group]={}
  192. end
  193. self.efficiencyPomoteCfg[v.group][v.level]=v
  194. end
  195. end
  196. end
  197. end
  198. --获取经验倍率数据
  199. function this:GetMultiplierInfoById(cfgId)
  200. return self.multiplierInfo[cfgId]
  201. end
  202. function this:GetAllExpMultiplier()
  203. return self.curAllExpMultiplier
  204. end
  205. function this:CheckFirstRecharge(id)
  206. if self.vipInfo[1] == id then
  207. return #self.vipInfo[2]
  208. end
  209. end
  210. function this:CheckBuyGift(str)
  211. local tab = string.split(str, '#')
  212. ---@type cfg_first_recharge_column
  213. local cfg = SL:GetConfig("cfg_first_recharge",tonumber(str))
  214. if next(self.vipInfo) then
  215. if #tab == 1 then
  216. if #cfg.amount == #self.vipInfo[2] then
  217. return 1
  218. else
  219. return 0
  220. end
  221. else
  222. for i, v in pairs(self.vipInfo[2]) do
  223. if v == tonumber(tab[2]) then
  224. return 1
  225. end
  226. end
  227. return 0
  228. end
  229. end
  230. return 0
  231. end