ActivityChipRewardItem.lua 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. local ActivityChipRewardItem = class("ActivityChipRewardItem",require("Activities/ActivityTypeItem"))
  2. function ActivityChipRewardItem:ctor(actId)
  3. self.redPointType = Enum.RPNotifyType.ActivityCollect
  4. self.data = {}
  5. self.map = {}
  6. self.globalMap = {}
  7. self:InitData(actId)
  8. end
  9. function ActivityChipRewardItem:InitData(actId)
  10. self.data = {}
  11. self.map = {}
  12. local cfgList = ManagerContainer.CfgMgr:GetActivitiesCollectionCfg(actId)
  13. if cfgList ~= nil then
  14. for i = 1,#cfgList do
  15. local cfg = cfgList[i]
  16. if cfg ~= nil then
  17. local data = {cfgId = cfg.Id, rewardNum = 0, order = cfg.Order,isNotice = false}
  18. self.data[#self.data + 1] = data
  19. self.map[data.cfgId] = data
  20. end
  21. end
  22. end
  23. CommonUtil.ArraySortSelections(self.data, Enum.TableSortRule.Up, "order")
  24. end
  25. function ActivityChipRewardItem:SyncSrvData(serverData)
  26. local collectionRewardData = serverData[3]
  27. for i = 1, #collectionRewardData do
  28. local data = self.map[collectionRewardData[i].id]
  29. if data then
  30. data.rewardNum = collectionRewardData[i].reward_num
  31. data.isNotice = collectionRewardData[i].no_notice
  32. end
  33. end
  34. end
  35. function ActivityChipRewardItem:SetWordNotice(collect_id,no_notice)
  36. local data = self.map[collect_id]
  37. if data then
  38. data.isNotice = no_notice
  39. end
  40. end
  41. function ActivityChipRewardItem:GetShowDataByCfgId(cfgId)
  42. local data = self.data
  43. for i = 1, #data do
  44. if data[i].cfgId == cfgId then
  45. return data[i],i
  46. end
  47. end
  48. return nil,nil
  49. end
  50. function ActivityChipRewardItem:RefreshCollectionGlobalData(list)
  51. for _,v in pairs(list) do
  52. local key = v.key
  53. local num = v.value
  54. self.globalMap[key] = num
  55. end
  56. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.ACTIVITY_GLOBAL_REFRESH)
  57. end
  58. function ActivityChipRewardItem:GetGlobalCount(id)
  59. return self.globalMap[id] or 0
  60. end
  61. function ActivityChipRewardItem:GetAllDatas()
  62. return self.data
  63. end
  64. function ActivityChipRewardItem:HasRedPoint()
  65. if self:IsOutofDate() then
  66. return false
  67. end
  68. if next(self.data) == nil then
  69. return false
  70. end
  71. for i = 1, #self.data do
  72. local data = self.data[i]
  73. local cfgData = ManagerContainer.CfgMgr:GetActivitiesCollectionCfgById(data.cfgId)
  74. if cfgData then
  75. local enough = true
  76. local showData = self.map[data.cfgId]
  77. local globalCount = self:GetGlobalCount(data.cfgId)
  78. if showData.rewardNum >= cfgData.Number or (globalCount >= cfgData.ServersReward and cfgData.ServersReward > 0) then
  79. enough = false
  80. end
  81. if enough then
  82. for i = 1, #cfgData.ExchangeCondition do
  83. local reward = cfgData.ExchangeCondition[i]
  84. local curNum = CommonUtil.GetOwnResCountByItemId(reward[1])
  85. if curNum < reward[2] then
  86. enough = false
  87. end
  88. end
  89. end
  90. if enough and not showData.isNotice then
  91. return true
  92. end
  93. end
  94. end
  95. return false
  96. end
  97. function ActivityChipRewardItem:SendRewardReq(day)
  98. ManagerContainer.DataMgr.ActsDataMgr:SendGetActivityRewardReq(self.actId,day)
  99. end
  100. function ActivityChipRewardItem:GetLeftTime()
  101. local leftTime = self.curDayEndTime - ManagerContainer.LuaTimerMgr:GetTimeSecond()
  102. if leftTime < 0 then
  103. leftTime = 0
  104. end
  105. return leftTime
  106. end
  107. return ActivityChipRewardItem