UIDailyPackRechargeInfo.lua 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. --- Generated by EmmyLua(https://github.com/EmmyLua)
  2. --- Created by admin.
  3. --- DateTime: 2024/11/5 13:41
  4. ---@class UIDailyPackRechargeInfo
  5. UIDailyPackRechargeInfo = class()
  6. local this = UIDailyPackRechargeInfo
  7. function this:ctor()
  8. end
  9. function this:Reset()
  10. end
  11. function this:Init()
  12. self:InitData()
  13. self:RegistMessages()
  14. self.DailyPackAllData = SL:GetConfigTable("cfg_DailyGiftPack")
  15. self.DailyPackData = {}
  16. self.DailyPackAllGiftData={}
  17. end
  18. function this:InitData()
  19. end
  20. function this:RegistMessages()
  21. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_RECHARGE_ACTION, self.RES_RECHARGE_ACTION, self)
  22. SL:RegisterLUAEvent(LUA_EVENT_DAILYPACK_RECHARGE_COUNT_CHANGE, this.LUA_EVENT_DAILYPACK_RECHARGE_COUNT_CHANGE, self)
  23. end
  24. --服务器发送礼包组消息后刷新礼包组的数据
  25. function this:RES_RECHARGE_ACTION(_, message)
  26. if tonumber(message.type)~=4 then --类型4
  27. return
  28. end
  29. self.DailyPackData = {}
  30. self.DailyPackAllGiftData = {}
  31. if message then
  32. local itemInfo = {}
  33. local itemCountInfo = {}
  34. local keynum = 0
  35. local buycount = 0 --剩余次数
  36. local totalcount = 0
  37. for k , v in ipairs(self.DailyPackAllData) do
  38. if v.Packagetype == tonumber(message.data.group) and this:IsOpenJudge(v.conditionid) then
  39. itemInfo = {}
  40. itemInfo.id = v.id
  41. itemInfo.Price = v.Price
  42. itemInfo.Packagetype = v.Packagetype
  43. itemInfo.conditionid = v.conditionid
  44. itemInfo.Limited =tonumber(v.Limited)
  45. itemInfo.Rewards = v.Rewards
  46. itemInfo.Optionalreward = v.Optionalreward
  47. itemInfo.rebate = v.rebate
  48. itemInfo.purchase = v.purchase
  49. itemInfo.buyIndex = 0
  50. itemInfo.canBuy = true
  51. itemInfo.RechargeId = 0
  52. itemInfo.Countkey = 0
  53. buycount = 0
  54. totalcount = 0
  55. for key,value in pairs(message.data.countInfo) do
  56. keynum = tonumber(key)
  57. itemCountInfo = SL:GetConfig('cfg_recharge',keynum)
  58. if itemCountInfo.parameter == v.id then
  59. itemInfo.RechargeId = keynum
  60. itemInfo.Countkey = itemCountInfo.Countkey
  61. itemInfo.buyIndex = value
  62. buycount,totalcount = InfoManager.countInfo:GetLimitAndTotalCountByKey(itemCountInfo.Countkey)
  63. if buycount < 1 then
  64. itemInfo.canBuy = false
  65. end
  66. break
  67. end
  68. end
  69. if v.purchase ~= 0 then
  70. table.insert(self.DailyPackData,itemInfo)
  71. else
  72. table.insert(self.DailyPackAllGiftData,itemInfo)
  73. end
  74. end
  75. end
  76. end
  77. local isDailyPackRedPoint = false
  78. for k,v in pairs(self.DailyPackData) do
  79. if v.Price== 0 and v.canBuy then
  80. isDailyPackRedPoint = true
  81. end
  82. end
  83. InfoManager.mainRechargeInfo:RefreshMainRechargeRedPoint("tog_DailyPack",isDailyPackRedPoint)
  84. SL:onLUAEvent(LUA_EVENT_DAILYPACK_RECHARGE_CHANGE)
  85. end
  86. --Count刷新
  87. function this:LUA_EVENT_DAILYPACK_RECHARGE_COUNT_CHANGE()
  88. local isDailyPackRedPoint = false
  89. local buycount = 0 --剩余次数
  90. local totalcount = 0
  91. for k,v in pairs(self.DailyPackData) do
  92. buycount = 0
  93. totalcount = 0
  94. v.canBuy = true
  95. buycount,totalcount = InfoManager.countInfo:GetLimitAndTotalCountByKey(v.Countkey)
  96. if buycount < 1 then
  97. v.canBuy = false
  98. end
  99. if v.Price== 0 and v.canBuy then
  100. isDailyPackRedPoint = true
  101. end
  102. end
  103. InfoManager.mainRechargeInfo:RefreshMainRechargeRedPoint("tog_DailyPack",isDailyPackRedPoint)
  104. SL:onLUAEvent(LUA_EVENT_DAILYPACK_RECHARGE_CHANGE)
  105. end
  106. function this:IsOpenJudge(condition)
  107. local isShow = condition == "" or ConditionManager.Check4D(condition)
  108. ---if else 可特殊处理页签显示隐藏
  109. return isShow
  110. end
  111. --是否能够一键购买
  112. function this:IsCanBuyAllGift()
  113. if table.isNullOrEmpty(self.DailyPackData) then
  114. return false
  115. end
  116. local buycount = 0 --剩余次数
  117. local totalcount = 0
  118. for k,v in ipairs(self.DailyPackData) do
  119. buycount,totalcount = InfoManager.countInfo:GetLimitAndTotalCountByKey(v.Countkey)
  120. if v.Price~= 0 and ((not v.canBuy) or buycount ~=totalcount) then
  121. return false
  122. end
  123. end
  124. return true
  125. end
  126. --获取一键购买原价
  127. function this:GetAllBuyOriginPrice()
  128. local price = 0
  129. local buycount = 0 --剩余次数
  130. local totalcount = 0
  131. for k,v in ipairs(self.DailyPackData) do
  132. totalcount = 0
  133. buycount,totalcount = InfoManager.countInfo:GetLimitAndTotalCountByKey(v.Countkey)
  134. price = price +(v.Price * totalcount)
  135. end
  136. return price
  137. end
  138. --获取giftid自选道具
  139. function this:GetSelectRewardInfo(giftid)
  140. local itemInfo = {}
  141. local tab = {}
  142. local index = 0
  143. for k,v in ipairs(self.DailyPackData) do
  144. if v.id == giftid and (not table.isNullOrEmpty(v.Optionalreward))then
  145. for key,value in ipairs(v.Optionalreward) do
  146. index = index +1
  147. tab={
  148. rewardId = value[1],
  149. rewarcount = value[2],
  150. rewardIndex = index
  151. }
  152. table.insert(itemInfo,tab)
  153. end
  154. end
  155. end
  156. return itemInfo
  157. end
  158. --获取giftid上index自选道具
  159. function this:GetSelectRewardItem(giftid,Index)
  160. local itemInfo = {}
  161. local tab = {}
  162. local index = 0
  163. for k,v in ipairs(self.DailyPackData) do
  164. if v.id == giftid and (not table.isNullOrEmpty(v.Optionalreward))then
  165. for key,value in ipairs(v.Optionalreward) do
  166. index = index +1
  167. if index == Index then
  168. tab={
  169. rewardId = value[1],
  170. rewarcount = value[2],
  171. rewardIndex = index
  172. }
  173. table.insert(itemInfo,tab)
  174. break
  175. end
  176. end
  177. end
  178. end
  179. return itemInfo
  180. end
  181. --获取0元礼包是否已经买过--红点
  182. function this:GetSelectRewardInfo(giftid)
  183. local itemInfo = {}
  184. local tab = {}
  185. local index = 0
  186. for k,v in ipairs(self.DailyPackData) do
  187. if v.id == giftid and (not table.isNullOrEmpty(v.Optionalreward))then
  188. for key,value in ipairs(v.Optionalreward) do
  189. index = index +1
  190. tab={
  191. rewardId = value[1],
  192. rewarcount = value[2],
  193. rewardIndex = index
  194. }
  195. table.insert(itemInfo,tab)
  196. end
  197. end
  198. end
  199. return itemInfo
  200. end