local DirectGift_Controller = {} local private = {} local EventSystem = require('Event/EventSystem') local Infrast = require("Infrast/Infrast") local DirectGiftDailyRedPoint = "DirectGiftDailyRedPoint" function DirectGift_Controller.OnStartup() EventSystem.Regist(EventID.UI_DirectGift_GiftInfoUpdate, private.CheckNewDirectGift) private.giftExpireTimerList = {} private.giftStartTimerList = {} private.giftNewInfo = {} private.isWelfareShowNew = {} private.isActivityShowNew = {} end --region -- **************** 轮询开启礼包 ******************* -- function DirectGift_Controller.AddGiftStartTimer(activityId, giftId, time) if not private.giftStartTimerList[activityId] then private.giftStartTimerList[activityId] = {} end if private.giftStartTimerList[activityId][giftId] then TimerUtil.Remove(private.giftStartTimerList[activityId][giftId]) end private.giftStartTimerList[activityId][giftId] = TimerUtil.Interval(function() EventSystem.Dispatch(EventID.DirectGift_UpdateDirectGiftList) end, time, 1) end function DirectGift_Controller.RemoveGiftStartTimer(activityId, giftId) if private.giftStartTimerList[activityId] then if private.giftStartTimerList[activityId][giftId] then TimerUtil.Remove(private.giftStartTimerList[activityId][giftId]) private.giftStartTimerList[activityId][giftId] = nil end end end function DirectGift_Controller.ClearGiftStartTimer() for i, v in pairs(private.giftStartTimerList) do for index, value in ipairs(v) do TimerUtil.Remove(value) end end private.giftStartTimerList = {} end --endregion --region -- **************** 轮询过期 ******************* -- function DirectGift_Controller.AddGiftExpireTimer(activityId, giftId, time) if not private.giftExpireTimerList[activityId] then private.giftExpireTimerList[activityId] = {} end if private.giftExpireTimerList[activityId][giftId] then TimerUtil.Remove(private.giftExpireTimerList[activityId][giftId]) end private.giftExpireTimerList[activityId][giftId] = TimerUtil.Interval(function() MDL.DirectGift.RemoveGiftInfo(activityId, giftId) end, time, 1) end function DirectGift_Controller.RemoveGiftExpireTimer(activityId, giftId) if private.giftExpireTimerList[activityId] then if private.giftExpireTimerList[activityId][giftId] then TimerUtil.Remove(private.giftExpireTimerList[activityId][giftId]) private.giftExpireTimerList[activityId][giftId] = nil end end end function DirectGift_Controller.ClearGiftExpireTimer() for i, v in pairs(private.giftExpireTimerList) do for index, value in ipairs(v) do TimerUtil.Remove(value) end end private.giftExpireTimerList = {} end --endregion function DirectGift_Controller.IsHasFreeGift(giftType, activityId) for i, v in MDL.DirectGift.GetDirectGiftEnumerator(giftType, activityId) do if v.data.IsFree then return true end end return false end DirectGift_Controller.GiftSoldOutType = { Hide = 1, --隐藏 SoldOut = 2, --显示“已售罄” } private.TabSoldOutType = { Hide = 1, --隐藏 Empty = 2, --显示没有礼包 SoldOut = 3, --保持原样 } function DirectGift_Controller.IsShowNormalDirectGiftTab(welfareId) local isSuccess, welfareData = DataSheetManager.DirectGiftOrder:TryGetDataByID(welfareId) if isSuccess then local soldOutType = welfareData.TabSellOutType if soldOutType == private.TabSoldOutType.Hide then for i, v in MDL.DirectGift.GetNormalDirectGiftEnumerator(welfareId) do return true end return false end end return true end function DirectGift_Controller.IsGiftUnlockToSee(giftData) if MDL.Currency.GetTotalRechargeMoney() >= giftData.ViewPayNum then local teamLevel = MDL.HeroSelect.GetTeamLevel() if teamLevel >= giftData.LevelLimitMin and teamLevel <= giftData.LevelLimitMax then if giftData.PreGiftID and giftData.PreGiftID > 0 then --阶梯礼包解锁逻辑 if MDL.DirectGift.GetGiftBuyingCount(giftData.ActivityID, giftData.PreGiftID) < giftData.PreGiftNum then return false end end return true end end return false end function DirectGift_Controller.IsWelfareShowNew(welfareId) if welfareId then return private.isWelfareShowNew[welfareId] else for i, v in pairs(private.isWelfareShowNew) do if v then return true end end return false end end function DirectGift_Controller.IsActivityShowNew(activityId) return private.isActivityShowNew[activityId] or false end function DirectGift_Controller.IsDirectGiftShowNew(activityId, giftId) if not next(private.giftNewInfo) then private.LoadNewDirectGiftInfo() end local acId = BattleDataGetter.GetAcID() if not private.giftNewInfo[acId] then return true end if not private.giftNewInfo[acId][activityId] then return true end return not private.giftNewInfo[acId][activityId][giftId] end function private.CheckNewDirectGift() if not next(private.giftNewInfo) then private.LoadNewDirectGiftInfo() end local acId = BattleDataGetter.GetAcID() if not private.giftNewInfo[acId] then private.giftNewInfo[acId] = {} end local selfData = private.giftNewInfo[acId] for index, v in MDL.DirectGift.GetNormalDirectGiftEnumerator() do local welfareId = v.data.HotPackageTab if not private.isWelfareShowNew[welfareId] then local activityId = v.activityId if not selfData[activityId] then private.isWelfareShowNew[welfareId] = true else if not selfData[activityId][v.giftId] then private.isWelfareShowNew[welfareId] = true end -- 如果是日、周、月刷新礼包,保存的数据与当前不一致要刷新红点 local limitType = v.data.LimitType if not selfData[activityId][limitType] then private.isWelfareShowNew[welfareId] = true else if limitType == LuaConst.LimitBuyType.Daily and tonumber(UTL.Time.OsDateOriginal("%d", UTL.Time.GetServerTimestamp())) ~= selfData[activityId][limitType] then private.isWelfareShowNew[welfareId] = true elseif limitType == LuaConst.LimitBuyType.Weekly and tonumber(UTL.Time.OsDateOriginal("%W", UTL.Time.GetServerTimestamp())) ~= selfData[activityId][limitType] then private.isWelfareShowNew[welfareId] = true elseif limitType == LuaConst.LimitBuyType.Monthly and tonumber(UTL.Time.OsDateOriginal("%m", UTL.Time.GetServerTimestamp())) ~= selfData[activityId][limitType] then private.isWelfareShowNew[welfareId] = true end end end end end for index, v in MDL.DirectGift.GetDirectGiftEnumerator(MDL.DirectGift.DirectGiftType.Base) do local activityId = v.activityId if not private.isActivityShowNew[activityId] then if not selfData[activityId] then private.isActivityShowNew[activityId] = true else if not selfData[activityId][v.giftId] then private.isActivityShowNew[activityId] = true end end end end end local LocalDataDir = "LocalData" local DirectGiftNewInfoFilePath = "LocalData/DirectGiftNewInfo" function DirectGift_Controller.SaveNewDirectGiftInfo(welfareId, activityId) if not next(private.giftNewInfo) then private.LoadNewDirectGiftInfo() end local acId = BattleDataGetter.GetAcID() if not private.giftNewInfo[acId] then private.giftNewInfo[acId] = {} end local saveData = private.giftNewInfo[acId] if welfareId then for index, v in MDL.DirectGift.GetNormalDirectGiftEnumerator(welfareId) do local activityId = v.activityId if not saveData[activityId] then saveData[activityId] = {} end saveData[activityId][v.giftId] = true -- 如果是日、周、月礼包,保存对应的日月周做为下次刷新的标识 local limitType = v.data.LimitType if not saveData[activityId][limitType] then saveData[activityId][limitType] = {} end if limitType == LuaConst.LimitBuyType.Daily then saveData[activityId][limitType] = tonumber(UTL.Time.OsDateOriginal("%d", UTL.Time.GetServerTimestamp())) elseif limitType == LuaConst.LimitBuyType.Weekly then saveData[activityId][limitType] = tonumber(UTL.Time.OsDateOriginal("%W", UTL.Time.GetServerTimestamp())) elseif limitType == LuaConst.LimitBuyType.Monthly then saveData[activityId][limitType] = tonumber(UTL.Time.OsDateOriginal("%m", UTL.Time.GetServerTimestamp())) end end private.isWelfareShowNew[welfareId] = false end if activityId then for index, v in MDL.DirectGift.GetDirectGiftEnumerator(MDL.DirectGift.DirectGiftType.Base, activityId) do if not saveData[activityId] then saveData[activityId] = {} end saveData[activityId][v.giftId] = true end private.isActivityShowNew[activityId] = false end LuaExt.DirectoryCreate(LocalDataDir) LuaExt.FileWriteBytes(DirectGiftNewInfoFilePath, false, Infrast.EncodeToBytes(private.giftNewInfo)) EventSystem.Dispatch(EventID.UI_DirectGift_NewGiftInfoChange) end function private.LoadNewDirectGiftInfo() local bytes = LuaExt.FileReadBytes(DirectGiftNewInfoFilePath) if not string.isNilOrEmpty(bytes) then local localData = Infrast.DecodeFromBytes(bytes) if localData then private.giftNewInfo = localData return end end private.giftNewInfo = {} end function DirectGift_Controller.DeleteNewGiftInfo() LuaExt.FileDelete(DirectGiftNewInfoFilePath) end return DirectGift_Controller