UIDailyDiamondRechargeInfo.lua 7.3 KB

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