UIEveryDayGiftRechargeInfo.lua 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. ---
  2. --- Generated by EmmyLua(https://github.com/EmmyLua)
  3. --- Created by admin.
  4. --- DateTime: 2024/11/12 13:41
  5. ---@class UIEveryDayGiftRechargeInfo
  6. UIEveryDayGiftRechargeInfo = class()
  7. local this = UIEveryDayGiftRechargeInfo
  8. function this:ctor()
  9. end
  10. function this:Reset()
  11. end
  12. function this:Init()
  13. self:InitData()
  14. self:RegistMessages()
  15. self.EveryDayGiftAllData = SL:GetConfigTable("cfg_everydayGift_recharge")
  16. self.EveryDayGiftData = {}
  17. self.EverDayGiftFreeDataId = {}
  18. end
  19. function this:InitData()
  20. end
  21. function this:RegistMessages()
  22. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_RECHARGE_ACTION, self.RES_RECHARGE_ACTION, self)
  23. end
  24. --服务器发送礼包组消息后刷新礼包组的数据
  25. function this:RES_RECHARGE_ACTION(_, message)
  26. if tonumber(message.type)~= 13 then --类型9
  27. return
  28. end
  29. if message.data then
  30. self.EveryDayGiftData ={}
  31. self.EveryDayGiftData.buyDay = message.data.buyDay
  32. self.EveryDayGiftData.dayFreeGift = message.data.dayFreeGift
  33. self.EveryDayGiftData.group = message.data.group
  34. self.EveryDayGiftData.todayBuy = message.data.todayBuy
  35. self.EveryDayGiftData.needCost = 6
  36. local rewardShowItem = {}
  37. local taskInfo = {}
  38. local taskAllDayInfo={}
  39. local taskInfoReward = {}
  40. local havereward = false
  41. local carreerId = SL:GetMetaValue(EMetaVarGetKey.JOB)
  42. for k , v in ipairs(self.EveryDayGiftAllData) do
  43. if v.round == tonumber(message.data.group) then
  44. if v.sort == 0 then
  45. for key,value in ipairs(v.showItem) do
  46. if value[1] == carreerId or value[1] == 0 then
  47. taskInfoReward = {
  48. itemId = value[2],
  49. count = value[3]
  50. }
  51. table.insert(rewardShowItem,taskInfoReward)
  52. end
  53. end
  54. self.EverDayGiftFreeDataId = v.id
  55. self.EveryDayGiftData.rewardShowItem = rewardShowItem
  56. else
  57. taskInfo = {}
  58. taskInfo.id = v.id
  59. taskInfo.day = v.sort
  60. taskInfo.task = v.task
  61. taskInfo.canGain = false
  62. taskInfo.haveGain = false
  63. taskInfo.showItem={}
  64. taskInfo.gift={}
  65. if v.sort == 1 then
  66. self.EveryDayGiftData.needCost = v.needCost
  67. end
  68. if message.data.buyDay >=v.sort then
  69. taskInfo.canGain = true
  70. end
  71. if not table.isNullOrEmpty(message.data.rewards) then
  72. for key,value in pairs(message.data.rewards) do
  73. if value == v.id then
  74. taskInfo.haveGain = true
  75. break
  76. end
  77. end
  78. end
  79. for key,value in ipairs(v.showItem) do
  80. if value[1] == carreerId or value[1] == 0 then
  81. taskInfoReward = {
  82. itemId = value[2],
  83. count = value[3]
  84. }
  85. table.insert(taskInfo.showItem,taskInfoReward)
  86. end
  87. end
  88. for key,value in ipairs(v.gift) do
  89. if value[1] == carreerId or value[1] == 0 then
  90. taskInfoReward = {
  91. itemId = value[2],
  92. count = value[3]
  93. }
  94. table.insert(taskInfo.gift,taskInfoReward)
  95. end
  96. end
  97. if taskInfo.canGain and (not taskInfo.haveGain) then --可领取
  98. taskInfo.sort = 1
  99. havereward = true
  100. elseif taskInfo.canGain then --已领取
  101. taskInfo.sort = 3
  102. elseif (not taskInfo.haveGain) then --未完成
  103. taskInfo.sort = 2
  104. else
  105. taskInfo.sort = 0
  106. end
  107. if taskInfo.sort~=0 then
  108. table.insert(taskAllDayInfo,taskInfo)
  109. end
  110. end
  111. end
  112. end
  113. table.sort(taskAllDayInfo,function (a,b)
  114. if a.sort == b.sort then
  115. return a.day<b.day
  116. else
  117. return a.sort<b.sort
  118. end
  119. end)
  120. self.EveryDayGiftData.task = taskAllDayInfo
  121. InfoManager.mainRechargeInfo:RefreshMainRechargeRedPoint("tog_EveryDayGift",(not self.EveryDayGiftData.dayFreeGift)or havereward)
  122. SL:onLUAEvent(LUA_EVENT_EVERYDAYGIFT_RECHARGE_CHANGE)
  123. end
  124. end