local CommandTheWorld_Controller = {} local private = {} local EventSystem = require('Event/EventSystem') local GiftAheadEndTime = 10* 60 --礼包需要的提前时间(单位秒) --服务器推送的号令天下阶段/状态 private.CommandWorldPushStage = { NoneStage = 0, -- 服务器出错了,需要保护,隐藏入口,关闭界面 LocalRankStage = 1, -- 本地榜单。 OffSeasonStage = 2, -- 休赛期。 CrossRankStage = 3, -- 跨服榜单。 BalanceWait = 4, -- 结算等待。 HonorRankStage = 5, -- 荣誉榜。 } --道具索引,抽象两种道具A和B private.ItemIndex = { A = 1, B = 2 } CommandTheWorld_Controller.PopWindowType ={ Store = Const_UI_Lua.UIEnum.UICommandTheWorldStore, --兑换商城 Reward = Const_UI_Lua.UIEnum.UICommandTheWorldReward, --势力宝箱 Rank = Const_UI_Lua.UIEnum.UICommandTheWorldRank,--排行奖励界面 } function CommandTheWorld_Controller.OnStartup() private.activityEndTimerHandle = nil --活动结束定时器 EventSystem.Regist(EventID.UI_RefreshCurrency, private.RefreshRedPoint) EventSystem.Regist(EventID.UI_CommandTheWorld_RefreshRedPoint,private.RefreshRedPoint) EventSystem.Regist(EventID.UI_OACommon_RedPointChanged, private.RefreshRedPoint) EventSystem.Regist(EventID.UI_DirectGift_GiftInfoUpdate, private.RefreshRedPoint) EventSystem.Regist(EventID.FunctionUnlockUpdate, private.RefreshInfoByFunction) end function private.RefreshInfoByFunction(funcId, isUnlock) if funcId == MDL.Unlock.FunctionType.CommandTheWorld then if not isUnlock then private.EndAndCloseActivity() end end end --活动结束的定时器,活动结束时关闭界面 function CommandTheWorld_Controller.SetEndTimer() if private.activityEndTimerHandle then TimerUtil.Remove(private.activityEndTimerHandle) private.activityEndTimerHandle = nil end local activityInfo = MDL.OperationActivity.GetOperationActivityInfo(MDL.OperationActivity.ActivityType.BattlefieldMuster, MDL.CommandTheWorld.GetActivityId()) local nowTime = UTL.Time.GetServerTimestamp() local endTime = activityInfo.endTime if endTime > nowTime then local deltaTime = endTime - nowTime if deltaTime <= UTL.Time.TotalSecondsOneDay then private.activityEndTimerHandle = TimerUtil.Interval(private.EndAndCloseActivity, deltaTime, 1) end else private.EndAndCloseActivity() end end function private.EndAndCloseActivity() if private.activityEndTimerHandle then TimerUtil.Remove(private.activityEndTimerHandle) private.activityEndTimerHandle = nil end UIManager.CloseView(Const_UI_Lua.UIEnum.UIPreviewItemTips) UIManager.CloseView(Const_UI_Lua.UIEnum.UICommonNoteView) UIManager.CloseView(Const_UI_Lua.UIEnum.OperationActivity.UIGetActivityItemPanel) UIManager.CloseView(Const_UI_Lua.UIEnum.UICommandTheWorldActiveTask) UIManager.CloseView(Const_UI_Lua.UIEnum.UICommandTheWorldRank) UIManager.CloseView(Const_UI_Lua.UIEnum.UICommandTheWorldRecharge) UIManager.CloseView(Const_UI_Lua.UIEnum.UICommandTheWorldReward) UIManager.CloseView(Const_UI_Lua.UIEnum.UICommandTheWorldWindow) EventSystem.Dispatch(EventID.UI_CommandTheWorld_EndAndCloseActivity) EventSystem.Dispatch(EventID.UI_OperationActivity_InfoChanged) end -- 本服排行时间段内 function CommandTheWorld_Controller.IsLocalServerOpen() return MDL.CommandTheWorld.GetStage() == private.CommandWorldPushStage.LocalRankStage end --本服排行结束 function CommandTheWorld_Controller.IsLocalServerEnd() return MDL.CommandTheWorld.GetStage() ~= private.CommandWorldPushStage.LocalRankStage end --是否为结算等待阶段 function CommandTheWorld_Controller.IsBalanceWait() return MDL.CommandTheWorld.GetStage() == private.CommandWorldPushStage.BalanceWait end --战区排行还没开启 function CommandTheWorld_Controller.IsBeforeBattleAreaOpen() return CommandTheWorld_Controller.IsLocalServerOpen() or MDL.CommandTheWorld.GetStage() == private.CommandWorldPushStage.OffSeasonStage; end --荣誉榜开启之前 function CommandTheWorld_Controller.IsBeforeHonourOpen() return MDL.CommandTheWorld.GetStage() ~= private.CommandWorldPushStage.HonorRankStage and not CommandTheWorld_Controller.IsStageError(); end --荣誉榜阶段 function CommandTheWorld_Controller.IsHonorRankStage() return MDL.CommandTheWorld.GetStage() == private.CommandWorldPushStage.HonorRankStage end --本服排行结算阶段 function CommandTheWorld_Controller.IsLocalRankSummary() return MDL.CommandTheWorld.GetStage() == private.CommandWorldPushStage.OffSeasonStage end --如果发现号令天下阶段不对,关闭界面 function CommandTheWorld_Controller.CheckNeedCloseAllUI() if CommandTheWorld_Controller.IsStageError() then private.EndAndCloseActivity() end end --错误的阶段,需要加保护 function CommandTheWorld_Controller.IsStageError() local state = MDL.CommandTheWorld.GetStage() return state == private.CommandWorldPushStage.NoneStage or state == nil end --战区排行榜是否开启 function CommandTheWorld_Controller.IsBattleAreaOpen() return MDL.CommandTheWorld.GetStage() == private.CommandWorldPushStage.CrossRankStage end --战区排行榜已经结束 function CommandTheWorld_Controller.IsBattleAreaEnd() return MDL.CommandTheWorld.GetStage() == private.CommandWorldPushStage.HonorRankStage or MDL.CommandTheWorld.GetStage() == private.CommandWorldPushStage.BalanceWait end --活动是否结束了 function CommandTheWorld_Controller.IsActivityEnd() local currentTime = UTL.Time.GetServerTimestamp() local endTime = MDL.CommandTheWorld.GetActivityEndTime() return currentTime >= endTime end --获取本服排行剩余时间 function CommandTheWorld_Controller.GetRemainTimeOfLocalServer() if CommandTheWorld_Controller.IsLocalServerOpen() then local timAxisData = MDL.CommandTheWorld.GetCommandWorldTimAxis() --时间轴数据 local currentTime = UTL.Time.GetServerTimestamp() local startTime= MDL.CommandTheWorld.GetActivityBeginTime() local remainTime = startTime + timAxisData.Time1 * UTL.Time.TotalSecondsOneHour - currentTime return remainTime else return -1 end end --获取本服排行活动结束时间 function CommandTheWorld_Controller.GetLocalServerRankEndTime() local timAxisData = MDL.CommandTheWorld.GetCommandWorldTimAxis() --时间轴数据 local startTime= MDL.CommandTheWorld.GetActivityBeginTime() return startTime + timAxisData.Time1 * UTL.Time.TotalSecondsOneHour end --获取战区排行剩余时间 function CommandTheWorld_Controller.GetRemainTimeOfBattleServer() if CommandTheWorld_Controller.IsBattleAreaOpen() then local timAxisData = MDL.CommandTheWorld.GetCommandWorldTimAxis() --时间轴数据 local currentTime = UTL.Time.GetServerTimestamp() local startTime= MDL.CommandTheWorld.GetActivityBeginTime() local remainTime = startTime + timAxisData.Time3 * UTL.Time.TotalSecondsOneHour - currentTime return remainTime else return -1 end end --获取开启战区排行的剩余时间 function CommandTheWorld_Controller.GetRemainOpenTimeOfBattleServer() if CommandTheWorld_Controller.IsLocalRankSummary() then local timAxisData = MDL.CommandTheWorld.GetCommandWorldTimAxis() --时间轴数据 local currentTime = UTL.Time.GetServerTimestamp() local startTime= MDL.CommandTheWorld.GetActivityBeginTime() local remainTime = startTime + timAxisData.Time2 * UTL.Time.TotalSecondsOneHour - currentTime return remainTime else return -1 end end --获取战区排行活动时间 function CommandTheWorld_Controller.GetBattleAreaOpenTime() local timAxisData = MDL.CommandTheWorld.GetCommandWorldTimAxis() --时间轴数据 local startTime= MDL.CommandTheWorld.GetActivityBeginTime() return startTime + timAxisData.Time2 * UTL.Time.TotalSecondsOneHour end --获取战区排行活动结束时间 function CommandTheWorld_Controller.GetBattleAreaEndTime() local timAxisData = MDL.CommandTheWorld.GetCommandWorldTimAxis() --时间轴数据 local startTime= MDL.CommandTheWorld.GetActivityBeginTime() return startTime + timAxisData.Time3 * UTL.Time.TotalSecondsOneHour end --是否可以显示礼包 function CommandTheWorld_Controller.IsCanShowGift() local nowTime = UTL.Time.GetServerTimestamp() if nowTime < CommandTheWorld_Controller.GetShowGiftEndTime() then return true end return false end --显示礼包的截至时间(排行结算时间往前推GiftAheadEndTime秒) --跨服:战区排行榜结算;单服:本服排行榜结算 function CommandTheWorld_Controller.GetShowGiftEndTime() local battleEndTime if MDL.CommandTheWorld.IsSingleSerActivity() then battleEndTime = CommandTheWorld_Controller.GetLocalServerRankEndTime() else battleEndTime = CommandTheWorld_Controller.GetBattleAreaEndTime() end local showTime = battleEndTime - GiftAheadEndTime --时间往前推GiftAheadEndTime 秒数 return showTime end --势力宝箱中是否有可领取的奖励 function CommandTheWorld_Controller.HasCanGetRewardInBox() local rewardArray = MDL.CommandTheWorld.GetCommandWorldLevelReward() for i,v in ipairs(rewardArray) do local isCanGet = MDL.CommandTheWorld.IsCanGetLevelRewardByLevel(v.Level) if isCanGet then return true end end return false end --充值有礼 有奖励可领取 function CommandTheWorld_Controller.HasCanGetRewardInGift() local activityId = MDL.CommandTheWorld.GetActivityId() return CTL.OACommon.IsHasGiftRedPoint(activityId) end --活跃任务有奖励可领取 function CommandTheWorld_Controller.HasCanGetRewardInTask() local activityId = MDL.CommandTheWorld.GetActivityId() return CTL.OACommon.IsHasTaskRedPoint(activityId) end --获取活动道具A数量 function CommandTheWorld_Controller.GetItemACount() return private.GetItemCountByIndex(private.ItemIndex.A) end function private.GetItemCountByIndex(index) local items= MDL.CommandTheWorld.GetItemsInfo() if items and items[index] then return UTL.Item.GetItemStockCount(items[index].ItemID) end return 0 end --获取活动道具B数量 function CommandTheWorld_Controller.GetItemBCount() return private.GetItemCountByIndex(private.ItemIndex.B) end function private.GetItemIDByIndex(index) local items= MDL.CommandTheWorld.GetItemsInfo() if items and items[index] then return items[index].ItemID end return -1 end --获取活动道具A的Id function CommandTheWorld_Controller.GetItemAID() return private.GetItemIDByIndex(private.ItemIndex.A) end --获取活动道具B的ID function CommandTheWorld_Controller.GetItemBID() return private.GetItemIDByIndex(private.ItemIndex.B) end --获取活动道具的积分 function CommandTheWorld_Controller.GetItemIntegral(itemId,itemCount) local items= MDL.CommandTheWorld.GetItemsInfo() for i,v in ipairs(items) do if v.ItemID == itemId then return v.Integral * itemCount end end return 0 end --获取活动道具信息 function CommandTheWorld_Controller.GetItemsInfoByItemId(itemId) local items= MDL.CommandTheWorld.GetItemsInfo() for i,v in ipairs(items) do if v.ItemID == itemId then return v end end return nil end --显示红点逻辑 function private.RefreshRedPoint() --排行时间段内,道具数量>0 有红点 if (CTL.CommandTheWorld.IsLocalServerOpen() or CTL.CommandTheWorld.IsBattleAreaOpen()) and (CommandTheWorld_Controller.GetItemACount() > 0 or CommandTheWorld_Controller.GetItemBCount() > 0) then CTL.RedPoint.AddRedPoint(CTL.RedPoint.RedPointKey.CommandTheWorld_HasItem) else CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.CommandTheWorld_HasItem) end --有各种奖励可以领取,有红点 if MDL.CommandTheWorld.HasCanGetRewardInHonour() then CTL.RedPoint.AddRedPoint(CTL.RedPoint.RedPointKey.CommandTheWorld_RewardInHonour) else CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.CommandTheWorld_RewardInHonour) end if CommandTheWorld_Controller.IsBeforeHonourOpen() and CommandTheWorld_Controller.HasCanGetRewardInTask() then CTL.RedPoint.AddRedPoint(CTL.RedPoint.RedPointKey.CommandTheWorld_RewardInTask) else CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.CommandTheWorld_RewardInTask) end if CommandTheWorld_Controller.IsBeforeHonourOpen() and CommandTheWorld_Controller.HasCanGetRewardInGift() and CTL.CommandTheWorld.IsCanShowGift() then CTL.RedPoint.AddRedPoint(CTL.RedPoint.RedPointKey.CommandTheWorld_RewardInGift) else CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.CommandTheWorld_RewardInGift) end --势力宝箱红点 if CommandTheWorld_Controller.IsBeforeHonourOpen() and MDL.CommandTheWorld.IsShowGuildBoxRedPoint() and not CommandTheWorld_Controller.IsSingleSerActivityRankEnd() then CTL.RedPoint.AddRedPoint(CTL.RedPoint.RedPointKey.CommandTheWorld_GetRewardInBox) else CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.CommandTheWorld_GetRewardInBox) end end --打开主界面 function CommandTheWorld_Controller.OpenMainPanel() --请求本服排行 MDL.CommandTheWorld.GetCommandWorldRankAndDevoteReq(MDL.CommandTheWorld.CommandWorldType.LocalRank) --请求跨服排行 MDL.CommandTheWorld.GetCommandWorldRankAndDevoteReq(MDL.CommandTheWorld.CommandWorldType.CrossRank) --请求宝箱数据 MDL.CommandTheWorld.GetCommandWorldGuildTreasureBoxReq() --先关闭玩法内其他界面,防止玩法内重复打开 UIManager.CloseView(Const_UI_Lua.UIEnum.UICommandTheWorldRecharge) UIManager.CloseView(Const_UI_Lua.UIEnum.UICommandTheWorldActiveTask) UIManager.CloseView(Const_UI_Lua.UIEnum.UICommandTheWorldWindow) --检查是否需要打开战区荣誉榜界面 if CTL.CommandTheWorld.IsBattleAreaEnd() then CTL.CommandTheWorld.ShowHonourShowPanel() return end --防止重复打开 if not UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UICommandTheWorldMain) then UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UICommandTheWorldMain) end end --显示荣耀排行榜界面 function CommandTheWorld_Controller.ShowHonourShowPanel() UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UICommandTheWorldHonorRollPanel) end function CommandTheWorld_Controller.OpenSubView(uiName,view,tabParam) local activityType = MDL.OperationActivity.ActivityType.BattlefieldMuster if uiName == CTL.CommandTheWorld.PopWindowType.Store then local subView = view:OpenView(GetViewClass(uiName), {activityId = MDL.CommandTheWorld.GetActivityId(), activityType = activityType, tabParam = tabParam}, "CommandTheWorld/UICommandTheWorldStore") return subView else local subView = view:OpenView(GetViewClass(uiName), {activityId = MDL.CommandTheWorld.GetActivityId(), activityType = activityType, tabParam = tabParam}) return subView end end --是否有礼包 function CommandTheWorld_Controller.IsHasDirectGift() local count = 0 local activityId = MDL.CommandTheWorld.GetActivityId() for i, v in MDL.DirectGift.GetDirectGiftEnumerator(MDL.DirectGift.DirectGiftType.Base, activityId) do count = count +1 end return count > 0 end --是否显示号令天下活动 function CommandTheWorld_Controller.IsShowActivity() local activityType = MDL.OperationActivity.ActivityType.BattlefieldMuster local isShowEntry = false --单服活动开启入口; 非单服活动,要判断战区开启 if MDL.CommandTheWorld.IsSingleSerActivity() then isShowEntry = true else isShowEntry = CTL.WarZone.IsWarZoneOpen() end return CTL.OperationActivity.IsOperationActivityTypeEntryOpen(activityType) and CTL.OperationActivity.IsOperationActivityTypeUnlock(activityType) and MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.CommandTheWorld) and not CTL.CommandTheWorld.IsStageError() and isShowEntry end --是否是单服沙场点兵活动并且排行结束了 function CommandTheWorld_Controller.IsSingleSerActivityRankEnd() return MDL.CommandTheWorld.IsSingleSerActivity() and CTL.CommandTheWorld.IsLocalServerEnd() end return CommandTheWorld_Controller