--[[ 推送Controller ]] local Notification_Controller = {} local private = {} local EventSystem = require('Event/EventSystem') local LuaFuncEntry = require("Main/LuaFuncEntry") local isTotalNotificationEnabled = false; local SendServerNotificationEnabled = "SendServerNotificationEnabled" function Notification_Controller.OnStartup() private.SetupEntryFunc(true) EventSystem.Regist(EventID.ApplicationPause, private.OnApplicationPause) EventSystem.Regist(EventID.ApplicationQuit, private.OnApplicationQuit) NotificationProxy.Init(UIUtils.GetLocalizedTxt(Const_IDS["IDS_APPPUSH_NAME"]), UIUtils.GetLocalizedTxt(Const_IDS["IDS_APPPUSH_NOTICE_PushDescription"])) end function private.SetupEntryFunc(isRegist) LuaFuncEntry.SetupMainEntryFunc(isRegist, LuaFuncEntry.FuncType.OnNofiticationState, private.RespNotificationState) end function Notification_Controller.OnShutdown() private.SetupEntryFunc(false) end function private.OnApplicationQuit() private.OnApplicationPause(true) end function private.OnApplicationPause(isPause, pauseTime) if NetManager.IsLaunch() then return end if isPause then Notification_Controller.RegisterAllNotification() else Notification_Controller.UnregisteAllNotification() Notification_Controller.ReqNotificationState() end end function private.GetRegisterId(pushCfgId, firstIndex, secondIndex) return tonumber(GameAppInfo.Global_ProductId)*10000+pushCfgId*1000+firstIndex*100+secondIndex end function Notification_Controller.RegistePushByPushCfgId(pushCfgId) if not MDL.Notification.GetNotificationEnabled(pushCfgId) then return end local pushCfgData = DataSheetManager.AppPush:GetDataByID(pushCfgId) local pushTitle = UIUtils.GetLocalizedTxt(Const_IDS[pushCfgData.ShowTitle]) local pushContent = UIUtils.GetLocalizedTxt(Const_IDS[pushCfgData.ShowMessage]) if pushCfgData.Class == MDL.Notification.PushType.TiLi then if MDL.Unlock.IsUnlock(pushCfgData.Fuction) then private.RegisterTiLiNotification() end elseif pushCfgData.Class == MDL.Notification.PushType.GuaJi then if MDL.Unlock.IsUnlock(pushCfgData.Fuction) then private.RegisterGuaJiNotification() end elseif pushCfgData.Class == MDL.Notification.PushType.Activity then if CTL.Activities.IsOpen(pushCfgData.Fuction) then local activityCfgData = DataSheetManager.ActivityData:GetDataByID(pushCfgData.Fuction) for index, timeData in ipairs(activityCfgData.Time_Table) do private.RegistePushByTimeId(timeData.StartTime, pushCfgId, index, pushTitle, pushContent) end end elseif pushCfgData.Class == MDL.Notification.PushType.Custom_Time then private.RegistePushByTimeId(pushCfgData.TimeStart, pushCfgId, 1, pushTitle, pushContent) elseif pushCfgData.Class == MDL.Notification.PushType.HeroMatch1v1 then local curMatchTimeID = MDL.HeroMatch1v1.GetCurMatchTimeID() if MDL.HeroMatch1v1.IsShowHeroMatch1v1Entry() and curMatchTimeID >= MDL.HeroMatch1v1.Enum_BigStage.Advance and curMatchTimeID < MDL.HeroMatch1v1.Enum_BigStage.Display then private.RegistePushHeroMatch1v1(pushCfgId, 1, pushTitle, pushContent) end elseif pushCfgData.Class == MDL.Notification.PushType.HeroMatch3v3 then local curMatchTimeID = MDL.HeroMatch3v3.GetCurMatchTimeID() if MDL.HeroMatch3v3.IsShowHeroMatch3v3Entry() and curMatchTimeID >= MDL.HeroMatch3v3.Enum_BigStage.Advance and curMatchTimeID < MDL.HeroMatch3v3.Enum_BigStage.Display then private.RegistePushHeroMatch3v3(pushCfgId, 1, pushTitle, pushContent) end elseif pushCfgData.Class == MDL.Notification.PushType.FairSoloTournament then local curMatchTimeID = MDL.FairSoloTournament.GetCurMatchTimeID() if MDL.FairSoloTournament.IsShowEntry() and curMatchTimeID >= MDL.FairSoloTournament.Enum_BigStage.FairAdvance and curMatchTimeID < MDL.FairSoloTournament.Enum_BigStage.FairDisplay then private.RegistePushFairSoloTournament(pushCfgId, 1, pushTitle, pushContent) end elseif pushCfgData.Class == MDL.Notification.PushType.TeamFairChampionship then local curMatchTimeID = MDL.TeamFairChampionship.GetCurBigStageID() if CTL.TeamFairChampionship.IsShowEntry() and curMatchTimeID >= MDL.TeamFairChampionship.Enum_BigStage.Screening and curMatchTimeID < MDL.TeamFairChampionship.Enum_BigStage.Display then private.RegistePushTeamFairChampionship(pushCfgId, 1, pushTitle, pushContent) end elseif pushCfgData.Class == MDL.Notification.PushType.Mine then private.RegistePushMine(pushCfgData) end end function private.RegistePushMine(pushCfgData) if MDL.Unlock.IsUnlock(pushCfgData.Fuction) then local myMine = MDL.GuildMine.GetMyMineInfo().mineBaseShowInfo if myMine and myMine.mineLevel > 0 then local mineData = DataSheetManager.MineQuality:GetDataByID(myMine.mineLevel) local MyMineTimer = (myMine.mineBeginTime + mineData.CollectTime * UTL.Time.TotalSecondsOneMinute) - UTL.Time.GetServerTimestamp() if MyMineTimer > 0 then local notificationTime = UTL.Time.GetLocalTimestamp() + MyMineTimer local year, month, day, hour, min = private.GetYMDHM(notificationTime) local pushTitle = UIUtils.GetLocalizedTxt(Const_IDS[pushCfgData.ShowTitle]) local pushContent = UIUtils.GetLocalizedTxt(Const_IDS[pushCfgData.ShowMessage]) logging.log(LTAG.LOG, pushTitle, pushContent, year, month, day, hour, min) Notification_Controller.RegisteNotification(private.GetRegisterId(MDL.Notification.ConstPushID.Mine, 1, 1), pushTitle, pushContent, year, month, day, hour, min, 0) end end end end function private.RegistePushByTimeId(timeRefreshCfgId, pushCfgId, timeIndex, title, content) local timeRefreshCfg = DataSheetManager.TimeRefresh:GetDataByID(timeRefreshCfgId) if timeRefreshCfg.Timer == UTL.Time.TimeType.DAILY then local serverStartTime = UTL.Time.GetServerTimestampByTimeId(timeRefreshCfgId) --转换成本地时间 local localStartTime = serverStartTime local curLocalTime = UTL.Time.GetLocalTimestamp() --时间是否已经过了,没有则注册当前的时间,过了,则加一天注册 if curLocalTime > localStartTime then localStartTime = localStartTime + UTL.Time.TotalSecondsOneDay end local year, month, day, hour, min = private.GetYMDHM(localStartTime) Notification_Controller.RegisteNotification(private.GetRegisterId(pushCfgId, timeIndex, 1), title, content, year, month, day, hour, min, 0) for i=1, 7 do localStartTime = localStartTime + UTL.Time.TotalSecondsOneDay year, month, day, hour, min = private.GetYMDHM(localStartTime) Notification_Controller.RegisteNotification(private.GetRegisterId(pushCfgId, timeIndex, i+1), title, content, year, month, day, hour, min, 0) end elseif timeRefreshCfg.Timer == UTL.Time.TimeType.WEEKLY then local serverTimeInterval = UTL.Time.GetServerIntervalTimeByTimeId(timeRefreshCfgId) --转换成本地时间 local curLocalTime = UTL.Time.GetLocalTimestamp() local localStartTime = curLocalTime + serverTimeInterval --时间是否已经过了,没有则注册当前的时间,过了,则加7天注册 if curLocalTime > localStartTime then localStartTime = localStartTime + UTL.Time.TotalSecondsOneWeek end --目前看在ios没有周触发的接口,因此在当前基础上往后就算3-4次的时间 local year, month, day, hour, min = private.GetYMDHM(localStartTime) Notification_Controller.RegisteNotification(private.GetRegisterId(pushCfgId, timeIndex, 1), title, content, year, month, day, hour, min, 0) for i=1, 3 do localStartTime = localStartTime + UTL.Time.TotalSecondsOneWeek year, month, day, hour, min = private.GetYMDHM(localStartTime) Notification_Controller.RegisteNotification(private.GetRegisterId(pushCfgId, timeIndex, i+1), title, content, year, month, day, hour, min, 0) end end end function private.RegistePushHeroMatch1v1(pushCfgId, timeIndex, title, content) -- 天地群雄活动开始推送 local matchStartTime = MDL.HeroMatch1v1.GetHeroMatch1v1AllInfo().startTm local refreshTimeCfg = DataSheetManager.TimeRefresh:GetDataByID(1).HMS local day = 0 local secondIndex = 0 for k,v in DataSheetManager.MatchTime:GetEnumerator() do day = day + v.Day if v.ID + 1 == MDL.HeroMatch1v1.Enum_BigStage.Screening then local MatchTime = DataSheetManager.MatchTime:GetDataByID(v.ID + 1) for i = 1, 2 do local timeRefreshCfg = matchStartTime + (i - 1 + day) * UTL.Time.TotalSecondsOneDay + DataSheetManager.TimeRefresh:GetDataByID(MatchTime.StartTime).HMS - refreshTimeCfg if timeRefreshCfg > UTL.Time.GetLocalTimestamp() then local year, month, day, hour, min = private.GetYMDHM(timeRefreshCfg) secondIndex = secondIndex + 1 Notification_Controller.RegisteNotification(private.GetRegisterId(pushCfgId, timeIndex, secondIndex), title, content, year, month, day, hour, min, 0) end end elseif v.ID + 1 < MDL.HeroMatch1v1.Enum_BigStage.Display then local timeRefreshCfg = matchStartTime + day * UTL.Time.TotalSecondsOneDay + DataSheetManager.TimeRefresh:GetDataByID(v.StartTime).HMS - refreshTimeCfg if timeRefreshCfg > UTL.Time.GetLocalTimestamp() then local year, month, day, hour, min = private.GetYMDHM(timeRefreshCfg) secondIndex = secondIndex + 1 Notification_Controller.RegisteNotification(private.GetRegisterId(pushCfgId, timeIndex, secondIndex), title, content, year, month, day, hour, min, 0) end end end end function private.RegistePushHeroMatch3v3(pushCfgId, timeIndex, title, content) -- 天地群雄活动开始推送 local matchStartTime = MDL.HeroMatch3v3.GetHeroMatch3v3AllInfo().startTm local refreshTimeCfg = DataSheetManager.TimeRefresh:GetDataByID(1).HMS local day = 0 local secondIndex = 0 for k,v in DataSheetManager.TeamMatchTime:GetEnumerator() do day = day + v.Day if v.ID + 1 == MDL.HeroMatch3v3.Enum_BigStage.Screening then local MatchTime = DataSheetManager.TeamMatchTime:GetDataByID(v.ID + 1) for i = 1, 2 do local timeRefreshCfg = matchStartTime + (i - 1 + day) * UTL.Time.TotalSecondsOneDay + DataSheetManager.TimeRefresh:GetDataByID(MatchTime.StartTime).HMS - refreshTimeCfg if timeRefreshCfg > UTL.Time.GetLocalTimestamp() then local year, month, day, hour, min = private.GetYMDHM(timeRefreshCfg) secondIndex = secondIndex + 1 Notification_Controller.RegisteNotification(private.GetRegisterId(pushCfgId, timeIndex, secondIndex), title, content, year, month, day, hour, min, 0) end end elseif v.ID + 1 < MDL.HeroMatch3v3.Enum_BigStage.Display then local timeRefreshCfg = matchStartTime + day * UTL.Time.TotalSecondsOneDay + DataSheetManager.TimeRefresh:GetDataByID(v.StartTime).HMS - refreshTimeCfg if timeRefreshCfg > UTL.Time.GetLocalTimestamp() then local year, month, day, hour, min = private.GetYMDHM(timeRefreshCfg) secondIndex = secondIndex + 1 Notification_Controller.RegisteNotification(private.GetRegisterId(pushCfgId, timeIndex, secondIndex), title, content, year, month, day, hour, min, 0) end end end end function private.RegistePushFairSoloTournament(pushCfgId, timeIndex, title, content) -- 天下会武活动开始推送 local matchStartTime = MDL.FairSoloTournament.GetModuleInfo().startTm local refreshTimeCfg = DataSheetManager.TimeRefresh:GetDataByID(1).HMS local day = 0 local secondIndex = 0 for k,v in DataSheetManager.FairMatchTime:GetEnumerator() do if v.ID > MDL.FairSoloTournament.Enum_BigStage.FairAdvance and v.ID < MDL.FairSoloTournament.Enum_BigStage.FairDisplay then for i = 1, v.Day do local targetTimestamp = matchStartTime + (i - 1 + day) * UTL.Time.TotalSecondsOneDay + DataSheetManager.TimeRefresh:GetDataByID(v.StartTime).HMS - refreshTimeCfg if targetTimestamp > UTL.Time.GetLocalTimestamp() then local year, month, day, hour, min = private.GetYMDHM(targetTimestamp) secondIndex = secondIndex + 1 Notification_Controller.RegisteNotification(private.GetRegisterId(pushCfgId, timeIndex, secondIndex), title, content, year, month, day, hour, min, 0) end end end day = day + v.Day end end function private.RegistePushTeamFairChampionship(pushCfgId, timeIndex, title, content) -- 天下会武活动开始推送 local matchStartTime = MDL.TeamFairChampionship.GetMatchStartTime() local refreshTimeCfg = DataSheetManager.TimeRefresh:GetDataByID(1).HMS local day = 0 local secondIndex = 0 for k,v in DataSheetManager.TeamMatchTime:GetEnumerator() do if v.ID > MDL.TeamFairChampionship.Enum_BigStage.Advance and v.ID < MDL.TeamFairChampionship.Enum_BigStage.Display then for i = 1, v.Day do local targetTimestamp = matchStartTime + (i + day) * UTL.Time.TotalSecondsOneDay + DataSheetManager.TimeRefresh:GetDataByID(v.StartTime).HMS - refreshTimeCfg if targetTimestamp > UTL.Time.GetLocalTimestamp() then local year, month, day, hour, min = private.GetYMDHM(targetTimestamp) secondIndex = secondIndex + 1 Notification_Controller.RegisteNotification(private.GetRegisterId(pushCfgId, timeIndex, secondIndex), title, content, year, month, day, hour, min, 0) end end end day = day + v.Day end end function private.GetYMDHM(timeStamp) local date = UTL.Time.OsDateOriginal("*t", timeStamp) return date.year, date.month, date.day, date.hour, date.min end function Notification_Controller.RegisteNotification(registerId, title, content, fireYear, fireMonth, fireDay, fireHour, fireMin, notificationRepeat) NotificationProxy.RegisteNotification(registerId, title, content, fireYear, fireMonth, fireDay, fireHour, fireMin, notificationRepeat) end function Notification_Controller.RegisterAllNotification() for __, pushCfgData in DataSheetManager.AppPush:GetEnumerator() do Notification_Controller.RegistePushByPushCfgId(pushCfgData.ID) end end function Notification_Controller.UnregisteAllNotification() NotificationProxy.UnregisteAllNotification() end function Notification_Controller.UnregisteNotificationById(id) NotificationProxy.UnregisteNotificationById(id) end --是否显示打开通知提醒界面 function Notification_Controller.IsShowNoticeSettingOpen() if MDL.Notification.GetHasGetNotificationReward() then return false end if Notification_Controller.IsTotalNoticeOpen() then return false end return true end --总统制开关开启 function Notification_Controller.IsTotalNoticeOpen() return isTotalNotificationEnabled end function Notification_Controller.ReqNotificationState() NotificationProxy.ReqNotificationState() end --ios请求系统的推送开启是异步的,Android也改成伪异步 function private.RespNotificationState(isEnabled) isTotalNotificationEnabled = isEnabled --判断领奖 if not MDL.Notification.GetHasGetNotificationReward() and Notification_Controller.IsTotalNoticeOpen() then MDL.Notification.ReqNotificationReward() end private.RefreshNotificationRedpoint() private.SaveNotificationState() private.SendServerNotificationState() end --前往手机设置界面 function Notification_Controller.GoToSysSetting() NotificationProxy.GoToSysSetting() end function private.RegisterTiLiNotification() local pushCfgData = DataSheetManager.AppPush:GetDataByID(MDL.Notification.ConstPushID.TiLi) local pushTitle = UIUtils.GetLocalizedTxt(Const_IDS[pushCfgData.ShowTitle]) local pushContent = UIUtils.GetLocalizedTxt(Const_IDS[pushCfgData.ShowMessage]) local MaxEnergy = DataSheetManager.ConstData:GetDataByID("MaxEnergy").IntValue local curEnergy = MDL.Player.GetEnergyValue() if curEnergy < MaxEnergy then local needTime = (MaxEnergy-curEnergy)*DataSheetManager.ConstData:GetDataByID("RestoreEnergyTime").IntValue local notificationTime = UTL.Time.GetLocalTimestamp()+needTime local year, month, day, hour, min = private.GetYMDHM(notificationTime) Notification_Controller.RegisteNotification(private.GetRegisterId(MDL.Notification.ConstPushID.TiLi, 1, 1), pushTitle, pushContent, year, month, day, hour, min, 0) end end function private.RegisterGuaJiNotification() local pushCfgData = DataSheetManager.AppPush:GetDataByID(MDL.Notification.ConstPushID.GuaJi) local pushTitle = UIUtils.GetLocalizedTxt(Const_IDS[pushCfgData.ShowTitle]) local pushContent = UIUtils.GetLocalizedTxt(Const_IDS[pushCfgData.ShowMessage]) local totalTime = MDL.ClimbTower.GetTotalDuration() local duration = MDL.ClimbTower.GetHangUpDuration() if duration < totalTime then local notificationTime = UTL.Time.GetLocalTimestamp()+totalTime-duration local year, month, day, hour, min = private.GetYMDHM(notificationTime) Notification_Controller.RegisteNotification(private.GetRegisterId(MDL.Notification.ConstPushID.GuaJi, 1, 1), pushTitle, pushContent, year, month, day, hour, min, 0) end end --第一次领取挂机奖励以及参加上林宴结束,如果没有打开通知则提示去打开通知 function Notification_Controller.TryOpenNotificationTipPanel() --没有弹出过提醒界面,没有打开通知权限并且服务器没有记录奖励 if not MDL.Notification.GetHasGetNotificationReward() and not Notification_Controller.IsTotalNoticeOpen() then if not PersistentData.PlayerData:Get(LuaConst.SettingKeyEnum.HasOpenedNotificationRemind) then PersistentData.PlayerData:Set(LuaConst.SettingKeyEnum.HasOpenedNotificationRemind, true, true) UIManager.OpenView(Const_UI_Lua.UIEnum.UICommonRemind, {remindType=Const_UI_Lua.CommonRemind.Notification}) end end end function Notification_Controller.InitNotification(isHasGetReward) logging.log(LTAG.YL, "InitNotification", isHasGetReward) MDL.Notification.SetHasGetNotificationReward(isHasGetReward) Notification_Controller.UnregisteAllNotification() Notification_Controller.ReqNotificationState() end function private.RefreshNotificationRedpoint() --如果已经过了任务强制引导,并且没有领取奖励,显示红点 if Notification_Controller.IsShowNoticeSettingOpen() and not PersistentData.PlayerData:Get(LuaConst.SettingKeyEnum.HasOpenNotification) then CTL.RedPoint.AddRedPoint(CTL.RedPoint.RedPointKey.Setting_Notification); else CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.Setting_Notification); end end function Notification_Controller.SetHasOpenNotificationPanel() PersistentData.PlayerData:Set(LuaConst.SettingKeyEnum.HasOpenNotification, true, true) private.RefreshNotificationRedpoint() end function private.SaveNotificationState() local curState = Notification_Controller.IsTotalNoticeOpen() local saveState = PersistentData.PlayerData:Get(LuaConst.SettingKeyEnum.LocalSaveNotificationState) if curState ~= saveState then PersistentData.PlayerData:Set(LuaConst.SettingKeyEnum.LocalSaveNotificationState, curState, true) EventSystem.Dispatch(EventID.BI_LevelLow, BIManager.BIType.AppPush, curState and 1 or 0) logging.log(LTAG.YL, "发送系统通知设置:", curState) end end function private.SendServerNotificationState() local state = PersistentData.PlayerData:Get(SendServerNotificationEnabled) if state == nil then local curState = Notification_Controller.IsTotalNoticeOpen() --99枚举是总开关 MDL.Notification.UpdateAppPushSwitchReq(99, curState) logging.crit(LTAG.CRIT,"发送系统通知设置:", curState) PersistentData.PlayerData:Set(SendServerNotificationEnabled, true, true) end end return Notification_Controller