ActivityChipRewardItem.lua 3.7 KB

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