local FairSoloTournament_Controller = {} local private = {} local EventSystem = require('Event/EventSystem') local MATCH_LOBBY_MAP_ID = 620001 --跨服准备地图id local SINGLE_MATCH_LOBBY_MAP_ID = 620002 --单服准备地图id local CONST_TIME_RESULT = 40655 local FairSoloTournamentTaskClick = "FairSoloTournamentTaskClick" function FairSoloTournament_Controller.OnStartup() EventSystem.Regist(EventID.TimerWheelStartTimeOver, private.OnActivityStart) EventSystem.Regist(EventID.TimerWheelEndTimeOver, private.OnActivityEnd) EventSystem.Regist(EventID.UI_DelayToTownPlay, private.OnEnterLevel) EventSystem.Regist(EventID.UI_FairSoloTournament_RefreshModuleInfo, private.OnRefreshModuleInfo) private.hasOpenTask = false end function FairSoloTournament_Controller.RefreshActivityRed() EventSystem.Dispatch(EventID.UI_Activity_Refresh_Single_RedPoint, LuaConst.ActivityType.FairSoloTournament, false) if MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.FairSoloTournament) then local curMatchTimeID = MDL.FairSoloTournament.GetCurMatchTimeID() if curMatchTimeID > MDL.FairSoloTournament.Enum_BigStage.FairAdvance then private.hasOpenTask = false FairSoloTournament_Controller.AddTaskClickRedPoint() end if curMatchTimeID > MDL.FairSoloTournament.Enum_BigStage.FairAdvance and curMatchTimeID < MDL.FairSoloTournament.Enum_BigStage.FairDisplay then if MDL.FairSoloTournament.CheckIsBattleStage() then EventSystem.Dispatch(EventID.UI_Activity_Refresh_Single_RedPoint, LuaConst.ActivityType.FairSoloTournament, true) end end end end function private.OnEnterLevel() private.isQuitFromLobby = false if BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.CrossFairSoloTournamentTown) or BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SingleFairSoloTournamentTown) then --如果参赛者在bp开始之后进的场景,需要恢复bp进度 if UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UIFairSoloTournamentBanSelect) == false then local stageInfo = MDL.FairSoloTournament.GetStageInfo(MDL.FairSoloTournament.GetCurStageID()) if stageInfo then if stageInfo.state == MDL.FairSoloTournament.Enum_State.BanPick then local myAcid = BattleDataGetter.GetAcID() local myGroupInfo for i, v in ipairs(stageInfo.groupInfos) do local acid_1 = v.playerInfos[1].acid local acid_2 = v.playerInfos[2].acid if string.isNilOrEmpty(acid_1) == false and string.isNilOrEmpty(acid_2) == false and (acid_1 == myAcid or acid_2 == myAcid) then myGroupInfo = v break end end if myGroupInfo and FairSoloTournament_Controller.CheckBattleGroupEnd(myGroupInfo) == false then local groupState = MDL.FairSoloTournament.GetBattleGroupState(myGroupInfo) if groupState ~= MDL.FairSoloTournament.Enum_State.Finish then FairSoloTournament_Controller.OpenBanPick(myGroupInfo.groupId, myGroupInfo.turn, stageInfo.stateEndTime, false) end end end end end --如果进来时机不对,要给踢走 local isQuit = private.CheckQuitMatchLobby() if isQuit == false then if private.watchingBattleStage then --从观战返回,需要打开上一次观战的地方 FairSoloTournament_Controller.OpenMain(private.watchingBattleStage) end end end end --活动时间开始 function private.OnActivityStart(timeId, activityId, timeIndex) if activityId == LuaConst.ActivityType.FairSoloTournament then if MDL.FairSoloTournament.CheckIsBattleStage() then --活动界面红点前提需要活动开启 EventSystem.Dispatch(EventID.UI_Activity_Refresh_Single_RedPoint, LuaConst.ActivityType.FairSoloTournament, true) if BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.CrossFairSoloTournamentTown) == false and BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SingleFairSoloTournamentTown) == false then if not UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UIFairSoloTournamentBase) then if CTL.Activities.IsInActivitySpecificLevel() then UIManager.OpenView(Const_UI_Lua.UIEnum.UIActivitiesRemind, { LuaConst.ActivityType.FairSoloTournament }) else CTL.HomeMain.AddTownHomeDelayView(Const_UI_Lua.UIEnum.UIActivitiesRemind, { LuaConst.ActivityType.FairSoloTournament }) end end end end end end function private.OnActivityEnd(timeId, activityId, timeIndex) if activityId == LuaConst.ActivityType.FairSoloTournament then EventSystem.Dispatch(EventID.UI_Activity_Refresh_Single_RedPoint, LuaConst.ActivityType.FairSoloTournament, false) end end function FairSoloTournament_Controller.OpenTask() if private.hasOpenTask == false then private.hasOpenTask = true FairSoloTournament_Controller.RemoveTaskClickRedPoint() end UIManager.OpenView(Const_UI_Lua.UIEnum.UIFairSoloTournamentTask) end function FairSoloTournament_Controller.GetLastGroupSelectIndex() return private.lastGroupSelectIndex or 0 end function FairSoloTournament_Controller.SetLastGroupSelectIndex(index) private.lastGroupSelectIndex = index end function FairSoloTournament_Controller.TryOpenGroupRecommend() if MDL.FairSoloTournament.IsGroupCompetitionFinish() then --小组赛结束,跳转到最新阶段 EventSystem.Dispatch(EventID.UI_CloseAndRecoverView, Const_UI_Lua.UIEnum.UIFairSoloTournamentBase) FairSoloTournament_Controller.OpenMain() else --未结束,切到赛事页签 if not UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UIFairSoloTournamentBase) then FairSoloTournament_Controller.OpenMain() end EventSystem.Dispatch(EventID.UI_FairSoloTournament_ChangeGroupTab, 0) end end function FairSoloTournament_Controller.TryOpenGroupRank() if MDL.FairSoloTournament.IsGroupCompetitionFinish() then --小组赛结束,跳转到最新阶段 EventSystem.Dispatch(EventID.UI_CloseAndRecoverView, Const_UI_Lua.UIEnum.UIFairSoloTournamentBase) FairSoloTournament_Controller.OpenMain() else --未结束,切到排名页签 if not UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UIFairSoloTournamentBase) then FairSoloTournament_Controller.OpenMain() end EventSystem.Dispatch(EventID.UI_FairSoloTournament_ChangeGroupTab, 1) end end function FairSoloTournament_Controller.TryOpenMain() if BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.CrossFairSoloTournamentTown) or BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SingleFairSoloTournamentTown) then FairSoloTournament_Controller.OpenMain() end end --打开主界面 function FairSoloTournament_Controller.OpenMain(selectStage) local curMatchTimeID = MDL.FairSoloTournament.GetCurMatchTimeID() if curMatchTimeID >= MDL.FairSoloTournament.Enum_BigStage.FairScreening and curMatchTimeID <= MDL.FairSoloTournament.Enum_BigStage.FairFinals then local MatchTime = DataSheetManager.FairMatchTime:GetDataByID(curMatchTimeID) if UTL.Time.IsServerInOpeningTime(MatchTime.StartTime, MatchTime.EndTime) then MDL.FairSoloTournament.IsOpenMainPanel = true else MDL.FairSoloTournament.IsOpenMainPanel = false end end if MDL.FairSoloTournament.IsShowEntry() and MDL.FairSoloTournament.GetCurStageID() > MDL.FairSoloTournament.ConfigStage.Prepare then if not UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UIFairSoloTournamentBase) then local context if selectStage then context = { selectStage = selectStage } end UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIFairSoloTournamentBase, context) end else CTL.Tips.AddTipsMsg(Const_IDS.IDS_Formation_RelationShip_Closed) end end function FairSoloTournament_Controller.AddTaskClickRedPoint() if MDL.FairSoloTournament.IsNo1GeneratedNextDay() then return end local timeValue = PersistentData.PlayerData:Get(FairSoloTournamentTaskClick, 0) if timeValue > 0 and UTL.Time.IsTimestampCrossDay(timeValue) then PersistentData.PlayerData:Remove(FairSoloTournamentTaskClick) timeValue = 0 end if timeValue <= 0 then CTL.RedPoint.AddRedPoint(CTL.RedPoint.RedPointKey.FairSoloTournament_Task_Click) end end function FairSoloTournament_Controller.RemoveTaskClickRedPoint() PersistentData.PlayerData:Set(FairSoloTournamentTaskClick, UTL.Time.GetServerTimestamp(), true) CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.FairSoloTournament_Task_Click) end --按照武将品质排(大往前),品质一样按照武将资质排序(大往前),资质一样按武将表ID排(小往前) function private.SortHeroRule(heroId_1, heroId_2) local heroData_1 = DataSheetManager.HeroNum:GetDataByID(heroId_1) local heroData_2 = DataSheetManager.HeroNum:GetDataByID(heroId_2) if heroData_1.HeroQuality == heroData_2.HeroQuality then if heroData_1.HeroIntelligence == heroData_2.HeroIntelligence then return heroId_1 < heroId_2 end return heroData_1.HeroIntelligence > heroData_2.HeroIntelligence end return heroData_1.HeroQuality > heroData_2.HeroQuality end --获取bp全武将列表 function FairSoloTournament_Controller.GetAllSortedHeroList() local sortedHeroList = {} for i, v in DataSheetManager.HeroNum:GetEnumerator() do if v.isOpen then table.insert(sortedHeroList, v.ID) end end table.sort(sortedHeroList, private.SortHeroRule) CTL.HeroAwaken.TryFillAwakenHero(sortedHeroList, true) return sortedHeroList end function FairSoloTournament_Controller.EnterLobby() local isUnlock, content = MDL.Unlock.IsClientUnlockWithText(MDL.Unlock.FunctionType.FairSoloTournament, "IDS_Activity_Condition_01") if isUnlock == false then CTL.Tips.AddTipsMsg(content) return end if BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.CrossFairSoloTournamentTown) or BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SingleFairSoloTournamentTown) then CTL.Tips.AddTipsMsg(Const_IDS.IDS_HeroMatch1v1_BeInScene) else EventSystem.Dispatch(EventID.UI_CloseAndRecoverView, Const_UI_Lua.UIEnum.UIFairSoloTournamentBase) if CTL.WarZone.IsWarZoneOpen() then CTL.MiniMap.GoToMap(MATCH_LOBBY_MAP_ID) else CTL.MiniMap.GoToMap(SINGLE_MATCH_LOBBY_MAP_ID) end end end --观战 function FairSoloTournament_Controller.WatchBattle(groupInfo, gRoomId, playerId, acid, stage) if MDL.FairSoloTournament.GetCurStageID() ~= stage then CTL.Tips.AddTipsMsg(Const_IDS["IDS_FairTournament_WatchOver"]) return end local stageInfo = MDL.FairSoloTournament.GetStageInfo(stage) if stageInfo == nil then logging.error(LTAG.ERROR, "[天下会武]当前无阶段数据居然可以观战?", stage) return end if (stageInfo.state == MDL.FairSoloTournament.Enum_State.Battle and groupInfo.isBattleEnd) or stageInfo.state == MDL.FairSoloTournament.Enum_State.Finish or FairSoloTournament_Controller.CheckBattleGroupEnd(groupInfo) then CTL.Tips.AddTipsMsg(Const_IDS["IDS_FairTournament_WatchDone"]) return end if stageInfo.state ~= MDL.FairSoloTournament.Enum_State.BanPick and stageInfo.state ~= MDL.FairSoloTournament.Enum_State.Battle then CTL.Tips.AddTipsMsg(Const_IDS["IDS_FairTournament_OutWatchTime"]) return end if BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.CrossFairSoloTournamentTown) == false and BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SingleFairSoloTournamentTown) == false then CTL.Tips.AddTipsMsg(Const_IDS["IDS_FairTournament_WatchScene"]) return end --记录当前正在观战的对战组 private.watchingBattleAcid = acid private.watchingBattleStage = stage if stageInfo.state == MDL.FairSoloTournament.Enum_State.BanPick then MDL.FairSoloTournament.FairTournamentBPWatchReq(MDL.FairSoloTournament.WATCHTYPE_WATCH, groupInfo.groupId, groupInfo.turn, acid) else MDL.WatchBattle.WatchBattleRequest(gRoomId, MDL.WatchBattle.WatchBattleType.FairSoloTournament, playerId, stage) end end function FairSoloTournament_Controller.GetWatchingBattleAcid() return private.watchingBattleAcid end function FairSoloTournament_Controller.ClearWatchingBattleParam() private.watchingBattleAcid = nil private.watchingBattleStage = nil end function FairSoloTournament_Controller.GetMyRankDesc() local bestStage = MDL.FairSoloTournament.GetMyHighestStage() if bestStage == 0 then --未参赛 return nil end local rankDes if bestStage >= MDL.FairSoloTournament.ConfigStage.Display then -- 排名赛 - 冠军赛极端ID 递增 if bestStage >= MDL.FairSoloTournament.ConfigStage.Finals_128T64 then rankDes = string.FormatByIdsId(Const_IDS["IDS_HeroMatch1v1_NowResult2"], 128) elseif bestStage >= MDL.FairSoloTournament.ConfigStage.Finals_64T32 then rankDes = string.FormatByIdsId(Const_IDS["IDS_HeroMatch1v1_NowResult2"], 64) elseif bestStage >= MDL.FairSoloTournament.ConfigStage.Finals_32T16 then rankDes = string.FormatByIdsId(Const_IDS["IDS_HeroMatch1v1_NowResult2"], 32) elseif bestStage >= MDL.FairSoloTournament.ConfigStage.Finals_16T8 then rankDes = string.FormatByIdsId(Const_IDS["IDS_HeroMatch1v1_NowResult2"], 16) elseif bestStage >= MDL.FairSoloTournament.ConfigStage.Finals_8T4 then rankDes = string.FormatByIdsId(Const_IDS["IDS_HeroMatch1v1_NowResult2"], 8) elseif bestStage >= MDL.FairSoloTournament.ConfigStage.Finals_4T2 then rankDes = string.FormatByIdsId(Const_IDS["IDS_HeroMatch1v1_NowResult2"], 4) elseif bestStage >= MDL.FairSoloTournament.ConfigStage.Finals_2T1 then -- 亚军 rankDes = UIUtils.GetLocalizedTxt(Const_IDS["IDS_HeroMatch1v1_NowResult3"]) else -- 冠军 rankDes = UIUtils.GetLocalizedTxt(Const_IDS["IDS_HeroMatch1v1_NowResult4"]) end elseif bestStage == MDL.FairSoloTournament.ConfigStage.Group_2 then --止步小组赛 local rank = MDL.FairSoloTournament.GetMyGroupRank() if rank and rank > 0 then rankDes = string.FormatByIdsId(Const_IDS.IDS_FairTournament_RaceOneRank1, rank) end else rankDes = UIUtils.GetLocalizedTxt(Const_IDS["IDS_HeroMatch1v1_NoRaceRank"]) end return rankDes, bestStage end function private.CheckQuitMatchLobby() local curTitle = MDL.FairSoloTournament.GetCurMatchTimeID() local isQuit = false if curTitle < MDL.FairSoloTournament.Enum_BigStage.FairScreening then isQuit = true elseif curTitle > MDL.FairSoloTournament.Enum_BigStage.FairFinals then --当前可能是刚从决赛结束切换到展示期 local cfg = DataSheetManager.FairMatchTime:GetDataByID(MDL.FairSoloTournament.Enum_BigStage.FairFinals) local closeTime = UTL.Time.GetServerIntervalTimeByTimeId(cfg.EndTime) if closeTime <= 0 then isQuit = true end end if isQuit then FairSoloTournament_Controller.QuitFromLobby() end return isQuit end --从等待区返回主城统一用这个接口,防止调用多次 function FairSoloTournament_Controller.QuitFromLobby() if BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.CrossFairSoloTournamentTown) or BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SingleFairSoloTournamentTown) then if private.isQuitFromLobby then return end private.isQuitFromLobby = true --直接返回洛阳 CTL.Level.ConveyLevelByLevelID(CTL.Level.GetMainCityId()) end end function FairSoloTournament_Controller.SetBattleGroupPlayerInfo(array, lineArray, stageInfo, groupInfo, curRound, isLeft) lineArray:SetState(0) for k, v in ipairs(array) do v.cdTimer:EndTimer() v.state_BtnLeft:SetState(2) v.state_BtnRight:SetState(2) v.state_NumLeft:SetState(3) v.state_NumRight:SetState(3) if k <= 2 then UIUtils.SetActive(v.state_Match, false) local havePlayerInfo = groupInfo.playerInfos[k].acid ~= "" FairSoloTournament_Controller.SetBattleCellInfo(v.group_Player, MDL.FairSoloTournament.GetPlayerShowInfo(groupInfo.playerInfos[k].acid)) -- 已竞猜 local isGuess = MDL.FairSoloTournament.CheckIsGuessByGroupID_ACID(groupInfo.groupId, groupInfo.playerInfos[k].acid, false) UIUtils.SetActive(v.group_Player.img_Bet, havePlayerInfo and isGuess or false) local state_Btn = isLeft and v.state_BtnLeft or v.state_BtnRight UIUtils.SetActive(v.state_BtnLeft, isLeft) UIUtils.SetActive(v.state_BtnRight, not isLeft) local lab_WinNum = isLeft and v.txt_WinLeftNum or v.txt_WinRightNum local state_WinNum = isLeft and v.state_NumLeft or v.state_NumRight local multiplier = string.FormatByIdsId(Const_IDS.IDS_FairTournament_PickRate, CTL.FairSoloTournament.ParseBetRate(groupInfo.playerInfos[k].multiplier)) v.txt_LeftMoreRate.text = multiplier v.txt_LeftRate.text = multiplier v.txt_RightMoreRate.text = multiplier v.txt_RightRate.text = multiplier if curRound > 1 then private.SetWinNum(state_WinNum, lab_WinNum, groupInfo.playerInfos, curRound, k == 1, stageInfo.stageId) end local isNotBye = groupInfo.playerInfos[1].acid ~= "" and groupInfo.playerInfos[2].acid ~= "" --无轮空 --出现轮空隐藏观战和竞猜 if isNotBye then --竞猜状态 if isGuess then state_Btn:SetState(1) else state_Btn:SetState(0) end UIUtils.SetActive(v.btn_LeftWatch, true) UIUtils.SetActive(v.btn_RightWatch, true) else state_Btn:SetState(2) UIUtils.SetActive(v.btn_LeftWatch, false) UIUtils.SetActive(v.btn_RightWatch, false) end if stageInfo.state == MDL.FairSoloTournament.Enum_State.Battle then -- 战斗中 if groupInfo.isBattleEnd == false then private.SetWinNum(state_WinNum, lab_WinNum, groupInfo.playerInfos, curRound, k == 1, stageInfo.stageId) end end else UIUtils.SetActive(v.btn_LeftWatch, false) UIUtils.SetActive(v.btn_RightWatch, false) v.group_Player.state_Info:SetState(2) UIUtils.SetActive(v.state_Match, true) if stageInfo.state == MDL.FairSoloTournament.Enum_State.Ready or stageInfo.state == MDL.FairSoloTournament.Enum_State.Matching then -- 准备中 private.SetReadyState(v, stageInfo.stateEndTime - UTL.Time.GetServerTimestamp(), curRound) elseif stageInfo.state == MDL.FairSoloTournament.Enum_State.Battle then -- 战斗中 if groupInfo.isBattleEnd == false then v.state_Match:SetState(2) else --这里需要判断是否整个阶段已经提前结束,即某一方的胜场数达到2 if FairSoloTournament_Controller.CheckBattleGroupEnd(groupInfo) then private.SetFinishState(v, lineArray, groupInfo, curRound) else v.state_Match:SetState(2) end end elseif stageInfo.state == MDL.FairSoloTournament.Enum_State.Roll then v.state_Match:SetState(1) elseif stageInfo.state == MDL.FairSoloTournament.Enum_State.BanPick then v.state_Match:SetState(2) elseif stageInfo.state == MDL.FairSoloTournament.Enum_State.Finish then private.SetFinishState(v, lineArray, groupInfo, curRound) end UIUtils.SetActive(v.group_Player.img_Bet, false) end end end function private.SetReadyState(player_Cell, time, round) player_Cell.state_Match:SetState(0) player_Cell.txt_NotStartedInfo.text = string.FormatByIdsId(Const_IDS.IDS_FairTournament_RoundStart, round) player_Cell.cdTimer:ResetAndBeginCustomTimer(false, time, 0, "{0}:{1}:{2}") end function private.SetWinNum(state_WinNum, lab_WinNum, playerInfos, curRound, isLeft, stageId) state_WinNum:SetState(3) local headInfo_1 = playerInfos[1].acid ~= "" and playerInfos[1] or nil local headInfo_2 = playerInfos[2].acid ~= "" and playerInfos[2] or nil if isLeft then if headInfo_1 then local leftWin = headInfo_1.winNum or 0 if headInfo_2 then if stageId == MDL.FairSoloTournament.ConfigStage.Finals_4T2 then state_WinNum:SetState(2) else state_WinNum:SetState(0) end local rightWin = headInfo_2.winNum or 0 local isDone = leftWin >= 2 or rightWin >= 2 if leftWin > rightWin and isDone then UIUtils.SetLabel(lab_WinNum, UTL.Color.FormatTextByColor(MDL.HeroMatch1v1.WinColor, leftWin)) else UIUtils.SetLabel(lab_WinNum, UTL.Color.FormatWhiteColor(leftWin)) end else UIUtils.SetLabel(lab_WinNum, UTL.Color.FormatTextByColor(MDL.HeroMatch1v1.WinColor, leftWin)) end else UIUtils.SetLabel(lab_WinNum, UTL.Color.FormatWhiteColor(0)) end else if headInfo_2 then local rightWin = headInfo_2.winNum or 0 if headInfo_1 then if stageId == MDL.FairSoloTournament.ConfigStage.Finals_4T2 then state_WinNum:SetState(2) else state_WinNum:SetState(1) end local leftWin = headInfo_1.winNum or 0 local isDone = leftWin >= 2 or rightWin >= 2 if leftWin < rightWin and isDone then UIUtils.SetLabel(lab_WinNum, UTL.Color.FormatTextByColor(MDL.HeroMatch1v1.WinColor, rightWin)) else UIUtils.SetLabel(lab_WinNum, UTL.Color.FormatWhiteColor(rightWin)) end else UIUtils.SetLabel(lab_WinNum, UTL.Color.FormatTextByColor(MDL.HeroMatch1v1.WinColor, rightWin)) end else UIUtils.SetLabel(lab_WinNum, UTL.Color.FormatWhiteColor(0)) end end end function private.SetFinishState(player_Cell, lineArray, groupInfos, curRound) lineArray:SetState(0) UIUtils.SetActive(player_Cell.state_Match, false) player_Cell.group_Player.state_Info:SetState(0) local headInfo_1 = groupInfos.playerInfos[1].acid ~= "" and groupInfos.playerInfos[1] or nil local headInfo_2 = groupInfos.playerInfos[2].acid ~= "" and groupInfos.playerInfos[2] or nil if headInfo_1 and headInfo_2 then local leftWin = headInfo_1.winNum or 0 local rightWin = headInfo_2.winNum or 0 local isLeft = leftWin > rightWin local acid = isLeft and groupInfos.playerInfos[1].acid or groupInfos.playerInfos[2].acid local winHeadInfo = isLeft and MDL.FairSoloTournament.GetPlayerShowInfo(headInfo_1.acid) or MDL.FairSoloTournament.GetPlayerShowInfo(headInfo_2.acid) FairSoloTournament_Controller.SetBattleCellInfo(player_Cell.group_Player, winHeadInfo) -- 已竞猜 UIUtils.SetActive(player_Cell.group_Player.img_Bet, MDL.FairSoloTournament.CheckIsGuessByGroupID_ACID(groupInfos.groupId, acid, false)) lineArray:SetState(leftWin > rightWin and 1 or 2) elseif headInfo_1 and not headInfo_2 then FairSoloTournament_Controller.SetBattleCellInfo(player_Cell.group_Player, MDL.FairSoloTournament.GetPlayerShowInfo(headInfo_1.acid)) -- 已竞猜 UIUtils.SetActive(player_Cell.group_Player.img_Bet, MDL.FairSoloTournament.CheckIsGuessByGroupID_ACID(groupInfos.groupId, headInfo_1.acid, false)) lineArray:SetState(1) elseif headInfo_2 and not headInfo_1 then FairSoloTournament_Controller.SetBattleCellInfo(player_Cell.group_Player, MDL.FairSoloTournament.GetPlayerShowInfo(headInfo_2.acid)) -- 已竞猜 UIUtils.SetActive(player_Cell.group_Player.img_Bet, MDL.FairSoloTournament.CheckIsGuessByGroupID_ACID(groupInfos.groupId, headInfo_2.acid, false)) lineArray:SetState(2) else player_Cell.group_Player.state_Info:SetState(1) end end function FairSoloTournament_Controller.SetBattleCellInfo(comp, showInfo) if showInfo == nil then comp.state_Info:SetState(1) else comp.state_Info:SetState(0) if showInfo.acid == BattleDataGetter.GetAcID() then UIUtils.SetActive(comp.img_Self, true) comp.txt_Name.text = UTL.Color.FormatTextByColor("fff08b", showInfo.name) else UIUtils.SetActive(comp.img_Self, false) comp.txt_Name.text = showInfo.name end UIUtils.SetLabel(comp.txt_Server, CTL.CrossServer.GetServerShowStr(showInfo.ShowServerId)) UIUtils.SetLabel(comp.txt_GuildName, showInfo.guildName) CTL.Character.SetPortraitAndFrame(comp.UIHeroHead, showInfo.PortraitId, showInfo.FrameId) FairSoloTournament_Controller.SetContractFlag(comp.img_Type, comp.lab_Type, comp.state_Type, showInfo) UIUtils.SetCanvasSortingOrderByMainCanvas(comp.UIHeroHead.effectUpCanvas, comp.canvas_Type, CTL.Character.UpOrder.Common) end end --优先显示同势力,再同服,再同战区 function FairSoloTournament_Controller.SetContractFlag(imgType, lab_Type, state_Type, showInfo) if showInfo.acid == BattleDataGetter.GetAcID() then UIUtils.SetActive(imgType, false) return end --小组赛竞猜标识,只在小组赛显示 if MDL.FairSoloTournament.IsGroupCompetitionFinish() == false and MDL.FairSoloTournament.GetGuessingInfoByGroupID_ACID(nil, showInfo.acid, true) then UIUtils.SetActive(imgType, true) state_Type:SetState(4) UIUtils.SetLabelText(lab_Type, Const_IDS.IDS_FairTournament_Pick) return end --排名赛竞猜标识 if MDL.FairSoloTournament.IsGroupCompetitionFinish() and MDL.FairSoloTournament.CheckIfGuessingByAcid(showInfo.acid) then UIUtils.SetActive(imgType, true) state_Type:SetState(4) UIUtils.SetLabelText(lab_Type, Const_IDS.IDS_FairTournament_Attention) return end --同势力 if MDL.Guild.IsSameGuild(showInfo.guildId) then UIUtils.SetActive(imgType, true) state_Type:SetState(0) UIUtils.SetLabelText(lab_Type, Const_IDS.IDS_FairTournament_SameGuild) return end --同服 if showInfo.ShowServerId == MDL.Login.GetServerShowId() then UIUtils.SetActive(imgType, true) state_Type:SetState(1) UIUtils.SetLabelText(lab_Type, Const_IDS.IDS_FairTournament_SameServer) return end --同战区 if showInfo.IsSameWarZone then UIUtils.SetActive(imgType, true) state_Type:SetState(2) UIUtils.SetLabelText(lab_Type, Const_IDS.IDS_FairTournament_SameZone) return end --热门 if MDL.FairSoloTournament.GetIfHotAdvance(showInfo.acid) then UIUtils.SetActive(imgType, true) state_Type:SetState(3) UIUtils.SetLabelText(lab_Type, Const_IDS.IDS_FairTournament_HotHot) return end UIUtils.SetActive(imgType, false) end --leftAcid一定是我自己 function FairSoloTournament_Controller.OpenRoll(leftAcid, rightAcid, groupId, rollTime) if UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UIFairSoloTournamentRoll) == false then UIManager.OpenView(Const_UI_Lua.UIEnum.UIFairSoloTournamentRoll, { groupId = groupId, leftAcid = leftAcid, rightAcid = rightAcid, rollTime = rollTime }) end end function FairSoloTournament_Controller.OpenBanPick(groupId, round, endTime, isWatch, watchAcid) UIManager.CloseView(Const_UI_Lua.UIEnum.UIFairSoloTournamentRoll) if UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UIFairSoloTournamentBanSelect) == false then UIManager.OpenView(Const_UI_Lua.UIEnum.UIFairSoloTournamentBanSelect, { groupId = groupId, round = round, endTime = endTime, isWatch = isWatch, watchAcid = watchAcid }) end end function FairSoloTournament_Controller.TryWatchBattle(groupInfo) local watchParam = MDL.FairSoloTournament.GetWatchParam() if watchParam then local gRoomId, playerId if groupInfo.playerInfos[1].acid == watchParam.acid then gRoomId = groupInfo.playerInfos[1].gRoomId playerId = groupInfo.playerInfos[1].playerId else gRoomId = groupInfo.playerInfos[2].gRoomId playerId = groupInfo.playerInfos[2].playerId end MDL.WatchBattle.WatchBattleRequest(gRoomId, MDL.WatchBattle.WatchBattleType.FairSoloTournament, playerId, MDL.FairSoloTournament.GetCurStageID()) MDL.FairSoloTournament.ClearWatchParam() end end --处理对战轮空的情况 function FairSoloTournament_Controller.OnBattleGroupBye(groupId) local watchParam = MDL.FairSoloTournament.GetWatchParam() if watchParam and watchParam.groupId == groupId then --观战者 UIManager.CloseView(Const_UI_Lua.UIEnum.UIFairSoloTournamentBanSelect) MDL.FairSoloTournament.ClearWatchParam() else --参赛者 CTL.Tips.AddTipsMsg(Const_IDS["IDS_FairTournament_NoOpponent"]) UIManager.CloseView(Const_UI_Lua.UIEnum.UIFairSoloTournamentBanSelect) end end function FairSoloTournament_Controller.RefreshTaskRed() local taskInfoArray = MDL.FairSoloTournament.GetTaskInfo() local hasRed = false if taskInfoArray then for i, v in ipairs(taskInfoArray) do if v.state == 1 then hasRed = true break end end end if hasRed then CTL.RedPoint.AddRedPoint(CTL.RedPoint.RedPointKey.FairSoloTournament_Task_CanGet) else CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.FairSoloTournament_Task_CanGet) end end --赛季结束关闭一切相关界面 function FairSoloTournament_Controller.CloseAllOnSeasonEnd() --移除所有红点 CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.FairSoloTournament_Task_Click) CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.FairSoloTournament_Task_CanGet) EventSystem.Dispatch(EventID.UI_Activity_Refresh_Single_RedPoint, LuaConst.ActivityType.FairSoloTournament, false) UIManager.CloseView(Const_UI_Lua.UIEnum.UIWarzoneList) UIManager.CloseView(Const_UI_Lua.UIEnum.UICommonNoteView) EventSystem.Dispatch(EventID.UI_FairSoloTournament_OnSeasonEnd) end --话题竞猜可获得数量 function FairSoloTournament_Controller.GetPreGuessingNum(info, myBetOption, targetBetNum) local hasBetNum = info.betNum --chosenTotalNum 选中选项总金额 local chosenTotalNum = targetBetNum --unChosenTotalNum 未选中选项总金额 local unChosenTotalNum = 0 for i, v in ipairs(info.totalBet) do if i == myBetOption then chosenTotalNum = chosenTotalNum + v else unChosenTotalNum = unChosenTotalNum + v end end if info.betOption == myBetOption then --前后押注相同,只是修改金额,需要减掉上一次的押注 chosenTotalNum = chosenTotalNum - hasBetNum else --前后押注不相同,会返还前一次的押注,因此未选中的总金额需要扣掉 unChosenTotalNum = unChosenTotalNum - hasBetNum end local configRate = DataSheetManager.ConstData:GetDataByID("FairTournamentTopicGuessOddsUpLmt").IntValue local rate = math.min(unChosenTotalNum / chosenTotalNum, configRate) local rewardNum = DataSheetManager.ConstData:GetDataByID("FairTournamentTopicGuessLowLmt").IntValue return targetBetNum + rewardNum + math.ceil(targetBetNum * rate) end function FairSoloTournament_Controller.OpenBetKeyBoard(groupId, acid, betRate, stageId, round) local curStageId = MDL.FairSoloTournament.GetCurStageID() if stageId ~= curStageId then CTL.Tips.AddTipsMsg(Const_IDS["IDS_FairTournament_PickDone"]) return end local isGroup = stageId == MDL.FairSoloTournament.ConfigStage.Group_1 or stageId == MDL.FairSoloTournament.ConfigStage.Group_2 --是否小组赛 --小组赛第二天开始之后不允许竞猜 if isGroup and CTL.FairSoloTournament.GetGroupFinalDayStartTime() <= 0 then CTL.Tips.AddTipsMsg(Const_IDS["IDS_FairTournament_RaceOneOverPick"]) return end --比赛状态判断 local stageInfo = MDL.FairSoloTournament.GetStageInfo(stageId) if (isGroup == false and (stageInfo.state >= MDL.FairSoloTournament.Enum_State.Roll or round > 1)) then CTL.Tips.AddTipsMsg(Const_IDS["IDS_FairTournament_OutPickTime"]) return end --非小组赛是否改投了同组的另外一个 if isGroup == false then local guessInfo = MDL.FairSoloTournament.GetGuessingInfoByGroupID(groupId, false) if guessInfo and guessInfo.betAcid ~= acid then CTL.Tips.AddTipsMsg(Const_IDS["IDS_FairTournament_NotPickOther"]) return end end --竞猜次数判断 local guessInfo = MDL.FairSoloTournament.GetGuessingInfoByGroupID_ACID(groupId, acid, isGroup) if guessInfo and guessInfo.betAcid == acid then --已竞猜可以追投,不用判断次数 else local maxTimes = MDL.FairSoloTournament.GetTodayGuessingMaxTimes() if MDL.FairSoloTournament.GetMyInfo().battleBetNum >= maxTimes then CTL.Tips.AddTipsMsg(Const_IDS["IDS_FairTournament_NoPickNum"]) return end end local hasBetNum = guessInfo and guessInfo.betNum or 0 local showInfo = MDL.FairSoloTournament.GetPlayerShowInfo(acid) UIManager.OpenView(Const_UI_Lua.UIEnum.UIFairSoloTournamentKeyBoard, { betRate = betRate, hasBetNum = hasBetNum, playerName = showInfo and showInfo.name or "", stageId = stageId, groupId = groupId, acid = acid }) end function FairSoloTournament_Controller.ParseBetRate(multiplier) return tonumber(string.format("%.2f", multiplier)) end --前x名能进小组赛,小组前x名晋级 function FairSoloTournament_Controller.GetGroupPlayerCount() local count = DataSheetManager.ConstData:GetDataByID("FairTournamentPlayerNum_QuDao").IntListValue if GameAppInfo.IsChinesePackage() then if SDKUtil.ChannelID == LuaConst.SDKChannelId.Hero_Android or SDKUtil.ChannelID == LuaConst.SDKChannelId.Hero_iOS then count = DataSheetManager.ConstData:GetDataByID("FairTournamentPlayerNum_GuanWang").IntListValue end elseif GameAppInfo.IsJapanesePackage() then count = DataSheetManager.ConstData:GetDataByID("FairTournamentPlayerNum_RiFu").IntListValue elseif GameAppInfo.IsVietnamPackage() then count = DataSheetManager.ConstData:GetDataByID("FairTournamentPlayerNum_YueNanFu").IntListValue else if GameAppInfo.IsOverseaHMT() then count = DataSheetManager.ConstData:GetDataByID("FairTournamentPlayerNum_YaFu").IntListValue elseif GameAppInfo.IsOverseaAmerica() then count = DataSheetManager.ConstData:GetDataByID("FairTournamentPlayerNum_MeiFu").IntListValue elseif GameAppInfo.IsOverseaEurope() then count = DataSheetManager.ConstData:GetDataByID("FairTournamentPlayerNum_OuFu").IntListValue end end return count[1], count[2] end --groupId = stageID * 1000000 + group * 10000 + num * 100 + turn function FairSoloTournament_Controller.ParseGroupID(groupId) local temp = groupId / 10000 local result = math.modf(temp % 100) return result end --距离小组赛最后一天的开始时间还差多长时间,过了时间返回-1 function FairSoloTournament_Controller.GetGroupFinalDayStartTime() local curMatchTimeID = MDL.FairSoloTournament.Enum_BigStage.FairScreening if curMatchTimeID == MDL.FairSoloTournament.Enum_BigStage.FairScreening then local startTm = MDL.FairSoloTournament.GetModuleInfo().startTm local startZeroTm = UTL.Time.GetServerZeroTimestampByTimestamp(startTm) local advanceTimeCfg = DataSheetManager.FairMatchTime:GetDataByID(MDL.FairSoloTournament.Enum_BigStage.FairAdvance) local groupTimeCfg = DataSheetManager.FairMatchTime:GetDataByID(MDL.FairSoloTournament.Enum_BigStage.FairScreening) local targetTime = startZeroTm + advanceTimeCfg.Day * UTL.Time.TotalSecondsOneDay + (groupTimeCfg.Day - 1) * UTL.Time.TotalSecondsOneDay + DataSheetManager.TimeRefresh:GetDataByID(groupTimeCfg.StartTime).HMS return targetTime - UTL.Time.GetServerTimestamp() end return -1 end function FairSoloTournament_Controller.GetJoinedTimeDesc() local _, timeStr = UTL.Time.GetDateDescAndTime({ CONST_TIME_RESULT }) return timeStr end --距离上榜时间还剩余的时间 function FairSoloTournament_Controller.GetLeftTimeFromResult() local timeCfg = DataSheetManager.FairMatchTime:GetDataByID(MDL.FairSoloTournament.Enum_BigStage.FairAdvance) --这里在 UTL.Time.GetZeroTimestamp 内的 os.time 返回的是系统本地时间,可能会因为时区不同导致跨天,直接补时差即可,无论正负时区都可以处理。 --第二次加时间偏移则是正常的时间偏移计算 local target = UTL.Time.GetServerZeroTimestampByTimestamp(MDL.FairSoloTournament.GetModuleInfo().startTm) + timeCfg.Day * UTL.Time.TotalSecondsOneDay + DataSheetManager.TimeRefresh:GetDataByID(CONST_TIME_RESULT).HMS return target - UTL.Time.GetServerTimestamp() end function FairSoloTournament_Controller.OpenNote() local moduleInfo = MDL.FairSoloTournament.GetModuleInfo() local seasonStartTime = moduleInfo.startTm local startDay, endDay, startTime local day = 0 for k, v in DataSheetManager.FairMatchTime:GetEnumerator() do day = day + v.Day if v.ID + 1 == MDL.FairSoloTournament.Enum_BigStage.FairScreening then startDay = os.date(UTL.Time.FormatDateEnum.MD, seasonStartTime + day * UTL.Time.TotalSecondsOneDay) elseif v.ID == MDL.FairSoloTournament.Enum_BigStage.FairScreening then startTime = v.StartTime elseif v.ID + 1 == MDL.FairSoloTournament.Enum_BigStage.FairDisplay then endDay = os.date(UTL.Time.FormatDateEnum.MD, seasonStartTime + (day - 1) * UTL.Time.TotalSecondsOneDay) break end end --小组赛第一天5点 local timeStr = FairSoloTournament_Controller.GetJoinedTimeDesc() local dateStr = string.format("%s-%s", startDay, timeStr) if GameAppInfo.IsVietnamPackage() then dateStr = string.format("%s %s", timeStr, startDay) end local count, group = CTL.FairSoloTournament.GetGroupPlayerCount() UIManager.OpenView(Const_UI_Lua.UIEnum.UICommonNoteView, { id = LuaConst.NoteID.FairSoloTournament, params = { dateStr, count, count / 16, group, group } }) end --小组赛之后的比赛进度描述 function FairSoloTournament_Controller.GetOverGroupProgressDesc() local progressDesc, roundDesc = "", "" local curStageID = MDL.FairSoloTournament.GetCurStageID() local curStageInfo = MDL.FairSoloTournament.GetStageInfo(curStageID) if curStageInfo and #curStageInfo.groupInfos > 0 then --这里加个判空,最后一轮结束时这里数据为空 local config = DataSheetManager.FairMatchStage:GetDataByID(curStageID) local curTurn = curStageInfo.groupInfos[1].turn progressDesc = string.FormatByIdsId(Const_IDS[config.SceneDes], curTurn) if curTurn < 3 then roundDesc = string.FormatByIdsId(Const_IDS[config.SceneDes], curTurn + 1) else if curStageID == MDL.FairSoloTournament.ConfigStage.Finals_2T1 then roundDesc = UIUtils.GetLocalizedTxt(Const_IDS[config.SceneNextDes]) else roundDesc = string.FormatByIdsId(Const_IDS[config.SceneNextDes], 1) end end end return progressDesc, roundDesc end function FairSoloTournament_Controller.CheckBattleGroupEnd(groupInfo) --胜场大于2即结束 return groupInfo.playerInfos[1].winNum >= 2 or groupInfo.playerInfos[2].winNum >= 2 end function FairSoloTournament_Controller.SetCurStage2PanelStage(stageId) private.curStage2PanelStage = stageId end function FairSoloTournament_Controller.GetCurStage2PanelStage() return private.curStage2PanelStage end --胜场数>击败数>1v1排名 function FairSoloTournament_Controller.SortByWinNum(playerInfo_1, playerInfo_2) local acid_1 = playerInfo_1.acid local acid_2 = playerInfo_2.acid local num_1 = MDL.FairSoloTournament.GetPlayerGroupWinNum(acid_1) local num_2 = MDL.FairSoloTournament.GetPlayerGroupWinNum(acid_2) if num_1 == num_2 then local defeatNum_1 = MDL.FairSoloTournament.GetPlayerGroupDefeatNum(acid_1) local defeatNum_2 = MDL.FairSoloTournament.GetPlayerGroupDefeatNum(acid_2) if defeatNum_1 == defeatNum_2 then local rank_1 = MDL.FairSoloTournament.GetPlayerSyncSoloRank(acid_1) local rank_2 = MDL.FairSoloTournament.GetPlayerSyncSoloRank(acid_2) return rank_1 < rank_2 end return defeatNum_1 > defeatNum_2 end return num_1 > num_2 end --region 结算 function FairSoloTournament_Controller.OnBattleResultPush(msg) if LevelManager._levelLogicData.LogicLoadingStep ~= LuaConst.Enum_LoadingStep.None and LevelManager._levelLogicData.LogicLoadingStep ~= LuaConst.Enum_LoadingStep.FastPlay then EventSystem.Dispatch(EventID.BI_LevelMiddle, BIManager.BIType.SyncBattle, "[sync]tournamentResultAtBeforeBegin") NotSyncBattleSetter.StopCurLevel() LevelManager.SetLoadingLevelEnd() end private.cacheBattleSummary = msg if msg.winnerCampId < 0 then -- 当前比赛轮空 private.ShowFilterRewardsPanel(msg.Rewards) else CameraController.Instance:SetGray(false) CTL.HomeMain.CloseOpenView() if #msg.Rewards > 0 then EventSystem.Regist(EventID.UI_HeroMatch1v1_OnShowBattleSummary, private.ShowBattleResult) -- 事件就不改名字了 private.ShowFilterRewardsPanel(msg.Rewards) else private.ShowBattleResult() end end end function private.ShowFilterRewardsPanel(rewardList) if #rewardList > 0 then UIManager.OpenView( Const_UI_Lua.UIEnum.UIRewardGainPanel, { tipsIDS = "IDS_HeroMatch1v1_RewardTips", -- 策划说不需要换IDS topContentIDS = "IDS_HeroMatch1v1_JoinReward", duration = 3, itemList = rewardList } ) end end function private.ShowBattleResult() EventSystem.UnRegist(EventID.UI_HeroMatch1v1_OnShowBattleSummary, private.ShowBattleResult) local msg = private.cacheBattleSummary local info = { passTime = msg.passTime, Icons = msg.Icons, isWin = msg.winnerCampId == BattleDataGetter.GetMyCampID(), enemyFighterRecords = BattleDataGetter.GetMyCampID() == 1 and msg.camp2 or msg.camp1, -- 右侧显示camp2 ourFighterRecords = BattleDataGetter.GetMyCampID() == 1 and msg.camp1 or msg.camp2, -- 左侧显示camp1 diffValue = 0, IsCustomRoom = true, costProtectCard = false, } UIManager.OpenView(Const_UI_Lua.UIEnum.UISyncSoloBattleOverPanel, info) -- 使用1v1的界面 end --endregion function private.OnRefreshModuleInfo() --冠军产生第二天,去掉任务红点 if MDL.FairSoloTournament.IsNo1GeneratedNextDay() then FairSoloTournament_Controller.RemoveTaskClickRedPoint() end end return FairSoloTournament_Controller