local FightThrone_Controller = {} local private = {} local EventSystem = require('Event/EventSystem') local WedStartTimeId = 1617 --周三开启id local WedEndTimeId = 1618 --周三开启id local SatStartTimeId = 1619 --周六开启id local SatEndTimeId = 1620 --周六结束id local FakeThroneOpenTimeTb = {[1] = {StartTime = WedStartTimeId, EndTime = WedEndTimeId}, [2] = {StartTime = SatStartTimeId, EndTime = SatEndTimeId}} --活动入口状态枚举 FightThrone_Controller.EntryState = { Close = 0, --关闭 Timeout = 1, --入口开启中,但是已超时 Opening = 2, --入口开放中 } function FightThrone_Controller.OnStartup() EventSystem.Regist(EventID.FightThrone_SendResult, private.OnFightThroneResult) EventSystem.Regist(EventID.AfterTownLevelBegin, private.UpdateEntry) EventSystem.Regist(EventID.TimerWheelStartTimeOver, private.SetActivityRedPoint) EventSystem.Regist(EventID.TimerWheelEndTimeOver, private.SetActivityRedPoint) end function private.UpdateEntry() if private.entryTimer then TimerUtil.Remove(private.entryTimer) private.entryTimer = nil end local isUnlock, _ = CTL.Activities.IsOpen(LuaConst.ActivityType.FightThrone) if isUnlock == false then --加上解锁条件的判断 return end local state = CTL.FightThrone.GetEntryState() if state == FightThrone_Controller.EntryState.Opening then CTL.HomeMain.AddTownHomeDelayView(Const_UI_Lua.UIEnum.UIFightThroneRemind) else local activityState = CTL.Activities.GetState(LuaConst.ActivityType.FightThrone) local _, fakeOpenTime = FightThrone_Controller.GetFightThroneFakeOpenState() local openTime = activityState == CTL.Activities.ActivityState.NotOpen and CTL.Activities.GetTimeToOpen(LuaConst.ActivityType.FightThrone) or CTL.Activities.GetNextTimeToOpen(LuaConst.ActivityType.FightThrone) if fakeOpenTime then openTime = math.min(fakeOpenTime, openTime) end private.entryTimer = TimerUtil.Interval(private.UpdateEntry, openTime + 1, 1) end end function private.OnFightThroneResult() local levelType = BattleDataGetter.GetCurLevelType() if levelType == LuaConst.LevelType.FightThroneFirstFloor or levelType == LuaConst.LevelType.FightThroneSecondFloor then local context = { num1 = BattleDataGetter.GetCollectAmountOfPlayerByCollectKey(LuaConst.EFightThroneCollectType.SILVER) or 0, num2 = BattleDataGetter.GetCollectAmountOfPlayerByCollectKey(LuaConst.EFightThroneCollectType.GOLD) or 0, num3 = BattleDataGetter.GetCollectAmountOfPlayerByCollectKey(LuaConst.EFightThroneCollectType.JADE) or 0, canEnterNext = BattleDataGetter.GetMyFlagAmount() > 0, --策划新需求,将地上未捡的旗子随机分配给没有旗子的玩家 isRandom = BattleDataGetter.GetMyFlagIsRandom(), isDropOut = false, } UIManager.OpenView(Const_UI_Lua.UIEnum.UIFightThroneCollectionReward, context) end end function private.SetActivityRedPoint(timeId, activityId, timeIndex) if activityId == LuaConst.ActivityType.FightThrone then local time = MDL.RedPoint.GetRedPointTimeByType(MDL.RedPoint.RedPointType.FightThrone) if MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.FightThrone) and FightThrone_Controller.GetEntryState() == FightThrone_Controller.EntryState.Opening then if time and time > 0 and UTL.Time.IsTimestampSameDay(time) then EventSystem.Dispatch(EventID.UI_Activity_Refresh_Single_RedPoint, LuaConst.ActivityType.FightThrone, false) else EventSystem.Dispatch(EventID.UI_Activity_Refresh_Single_RedPoint, LuaConst.ActivityType.FightThrone, true) end else EventSystem.Dispatch(EventID.UI_Activity_Refresh_Single_RedPoint, LuaConst.ActivityType.FightThrone, false) end end end function FightThrone_Controller.OnLeaveBattle() UTL.MessageBox.ShowOKCancelBox(Const_IDS.IDS_ExitBarrier, Const_IDS.IDS_FightThrone_IfExit, private.OnDropOutBattle, nil) end function private.OnDropOutBattle() MDL.FightThrone.SetCollectRewardFromDropOut() CTL.HomeMain.AddTownHomeDelayFunc(private.ShowDropOutResult) LuaInputManager.SetSpecialCommand(LuaConst.SpecialCommandType.QuitRoom) end --返回主城,弹出中途退出结算 function private.ShowDropOutResult() local count1, count2, count3 = MDL.FightThrone.GetCollectRewardFromDropOut() local context = { num1 = count1, num2 = count2, num3 = count3, canEnterNext = false, isDropOut = true, } UIManager.OpenView(Const_UI_Lua.UIEnum.UIFightThroneCollectionReward, context) MDL.FightThrone.SetCollectRewardFromDropOut() end function FightThrone_Controller.IsWedOrSatDay() if MDL.GuildWar.GuildWarIsFirstSign() then local wedTimeRefreshData = DataSheetManager.TimeRefresh:GetDataByID(WedStartTimeId) local satTimeRefreshData = DataSheetManager.TimeRefresh:GetDataByID(SatStartTimeId) local serverWeekday = UTL.Time.GetServerWeekday() if serverWeekday == wedTimeRefreshData.Day or serverWeekday == satTimeRefreshData.Day then return true end end return false end function FightThrone_Controller.GetFightThroneFakeOpenState() if MDL.GuildWar.GuildWarIsFirstSign() then local wedTimeRefreshData = DataSheetManager.TimeRefresh:GetDataByID(WedStartTimeId) local satTimeRefreshData = DataSheetManager.TimeRefresh:GetDataByID(SatStartTimeId) local serverWeekday = UTL.Time.GetServerWeekday() local offsetStartTime = 0 local offsetEndTime = 0 if serverWeekday == wedTimeRefreshData.Day then offsetStartTime = UTL.Time.GetServerIntervalTimeByTimeId(WedStartTimeId) offsetEndTime = UTL.Time.GetServerIntervalTimeByTimeId(WedEndTimeId) elseif serverWeekday == satTimeRefreshData.Day then offsetStartTime = UTL.Time.GetServerIntervalTimeByTimeId(SatStartTimeId) offsetEndTime = UTL.Time.GetServerIntervalTimeByTimeId(SatEndTimeId) end if offsetStartTime > 0 then return CTL.Activities.ActivityState.NotOpen, offsetStartTime elseif offsetStartTime <= 0 and offsetEndTime > 0 then return CTL.Activities.ActivityState.Opening, offsetEndTime elseif offsetEndTime < 0 then return CTL.Activities.ActivityState.End, 0 end end return CTL.Activities.ActivityState.NotOpen, 0 end function FightThrone_Controller.GetFakeThroneEntryPassedTime() local wedTimeTb = FakeThroneOpenTimeTb[1] local satTimeTb = FakeThroneOpenTimeTb[2] local startTime if UTL.Time.IsServerInOpeningTime(wedTimeTb.StartTime, wedTimeTb.EndTime) then startTime = WedStartTimeId elseif UTL.Time.IsServerInOpeningTime(satTimeTb.StartTime, satTimeTb.EndTime) then startTime = SatStartTimeId end if startTime then local offset = UTL.Time.GetServerIntervalTimeByTimeId(startTime) if offset < 0 then return -offset end end return nil end function FightThrone_Controller.GetFakeThroneNextOpenTime(isNotOpen) local fakeTimeTb = {[1]= FakeThroneOpenTimeTb[1], [2] = FakeThroneOpenTimeTb[2]} local data = DataSheetManager.ActivityData:GetDataByID(LuaConst.ActivityType.FightThrone) for i, v in ipairs(data.Time_Table) do table.insert(fakeTimeTb, v) end return CTL.Activities.GetTimeOrNextToOpen(fakeTimeTb, isNotOpen) end --获取入口开放经过的时间 function private.GetEntryPassedTime() local activityCfg = DataSheetManager.ActivityData:GetDataByID(LuaConst.ActivityType.FightThrone) local startTime for _, timeData in ipairs(activityCfg.Time_Table) do if UTL.Time.IsServerInOpeningTime(timeData.StartTime, timeData.EndTime) then startTime = timeData.StartTime break end end if startTime then --配置时间-当前时间 local offset = UTL.Time.GetServerIntervalTimeByTimeId(startTime) if offset < 0 then return -offset end end if MDL.GuildWar.GuildWarIsFirstSign() then return FightThrone_Controller.GetFakeThroneEntryPassedTime() end return nil end --获取备战区结束时间 function FightThrone_Controller.GetTownCloseTime() local passedTime = private.GetEntryPassedTime() if passedTime then local closeTime = DataSheetManager.ConstData:GetDataByID("FightThronePreparationTime").IntValue local offset = closeTime - passedTime if offset > 0 then return offset end end return nil end --活动入口是否关闭:当在活动时间内当过了常量时间FightThroneAllowEntryTime后,不准再进入 function FightThrone_Controller.GetEntryState() local allowTime = DataSheetManager.ConstData:GetDataByID("FightThroneAllowEntryTime").IntValue local passedTime = private.GetEntryPassedTime() if passedTime then if passedTime < allowTime then return FightThrone_Controller.EntryState.Opening, allowTime - passedTime else return FightThrone_Controller.EntryState.Timeout end end return FightThrone_Controller.EntryState.Close end return FightThrone_Controller