local TeamMatch_Controller = {} local private = {} local EventSystem = require 'Event/EventSystem' local battle_common_pb = require ("Proto/battle_common_pb") local MaxMatchTime = DataSheetManager.ConstData:GetDataByID("TeamDungeonMaxMatchTime").IntValue private.CannotJoinMatchReason = { Success = battle_common_pb.Success, NotMeetOpenConditions = battle_common_pb.ReasonNotMeetOpenConditions, -- 不满足活动开启条件。 InsufficientNums = battle_common_pb.ReasonInsufficientNums, -- 玩法的活动次数不足。 PlayerOffline = battle_common_pb.ReasonPlayerOffline, -- 玩家处于已离线状态。 --玩家如何处于这一状态:玩家首先发起入队申请,然后匹配进入战斗,然后对应队伍同意,此时有队员在战斗中。 InGame = battle_common_pb.ReasonInGame, -- 玩家处于副本的状态(包括离线副本和同步副本)。 NotFollow = battle_common_pb.ReasonNotFollow, -- 玩家没有处于跟随状态。 NotMeetMatchConditions = battle_common_pb.ReasonNotMeetMatchConditions, -- 不满足进入匹配条件。 TeamLeaderCancelMatch = battle_common_pb.ReasonTeamLeaderCancelMatch, -- 队伍的队长取消匹配。(停A成功开B失败也提示这个)。 TeamLeaderChangeMatch = battle_common_pb.ReasonTeamLeaderChangeMatch, -- 队伍队长已切换匹配。 TeamMeetMaxDirectAccess = battle_common_pb.ReasonTeamMeetMaxDirectAccess, -- 队伍成员已满,直接进入。 CreateTeam = battle_common_pb.ReasonCreateTeam, -- 创建队伍取消原有匹配。 JoinTeam = battle_common_pb.ReasonJoinTeam, -- 加入队伍取消原有匹配。 TeamMemberChange = battle_common_pb.ReasonTeamMemberChange, -- 队伍成员数量发生变化。 } function TeamMatch_Controller.OnStartup() private.MatchingActivity = nil end --先弹确认面板的,要等到确认之后的Matching再开始 --后弹确认面板的,要从MatchUpload开始 function private.IsTeamMatchingState(teamState, activityId) if teamState == MDL.Team.TeamState.Matching then return true end --if teamState == MDL.Team.TeamState.Matching and activityId == LuaConst.ActivityType.TVT then -- return true --end --if teamState == MDL.Team.TeamState.MatchUpload and (activityId == LuaConst.ActivityType.TeamDungeon1 or activityId == LuaConst.ActivityType.TeamDungeon2) then -- return true --end return false end --因为在后弹面板的匹配,到Matching状态的时候需要忽略不操作。以upload状态为准。 --为了防错PVP也相应处理一下。 function private.IsTeamIgnoreState(teamState, activityId) if teamState == MDL.Team.TeamState.MatchUpload then return true end --if teamState == MDL.Team.TeamState.MatchUpload and activityId == LuaConst.ActivityType.TVT then -- return true --end --if teamState == MDL.Team.TeamState.Matching and (activityId == LuaConst.ActivityType.TeamDungeon1 or activityId == LuaConst.ActivityType.TeamDungeon2) then -- return true --end return false end function TeamMatch_Controller.DealWithTeamStatePush(teamState, activityId, errorReason, errorName) if errorReason then TeamMatch_Controller.ShowMatchErrorTipsByReason(errorReason, errorName, activityId) end if not private.IsTeamIgnoreState(teamState, activityId) then local isHideTips = teamState == MDL.Team.TeamState.Confirm if private.IsTeamMatchingState(teamState, activityId) then TeamMatch_Controller.SetMatchStateByActivityId(true, activityId, isHideTips) else TeamMatch_Controller.CancelAllMatch(isHideTips) end end end function TeamMatch_Controller.DealWithMatchTime(state, activityId) local matchingTimerID = MDL.TeamMatch.GetMatchingTimerID() if matchingTimerID and matchingTimerID ~= 0 then TimerUtil.Remove(MDL.TeamMatch.GetMatchingTimerID()) MDL.TeamMatch.ClearMatchingTimerID() end if state then TeamMatch_Controller.StartMatchTime(activityId) else TeamMatch_Controller.ClearMatchTime() end EventSystem.Dispatch(EventID.UI_TeamMatch_MatchTime, state) end function TeamMatch_Controller.StartMatchTime(activityId) if MDL.TeamMatch.GetStartMatchingTime() == 0 then MDL.TeamMatch.SetStartMatchingTime(UTL.Time.GetServerTimestamp()) end MDL.TeamMatch.SetMatchingTimerID(TimerUtil.Interval(TeamMatch_Controller.CancelAllMatch, MaxMatchTime, 1)) CTL.HomeMain.AddTownHomeDelayFuncNoUI(TeamMatch_Controller.OpenMatchTipPanel, activityId) end function TeamMatch_Controller.ClearMatchTime() MDL.TeamMatch.ClearStartMatchingTime() UIManager.CloseView(Const_UI_Lua.UIEnum.UIMatchTip) end function TeamMatch_Controller.OpenMatchTipPanel(activityId) if TeamMatch_Controller.IsActivityMatchingById(activityId) and (not UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UIMatchTip)) then UIManager.OpenView(Const_UI_Lua.UIEnum.UIMatchTip, {activityId = activityId}) --else -- if CTL.HomeMain.GetFocusTarget() == Const_UI_Lua.UIEnum.UITownHome then -- EventSystem.Dispatch(EventID.UI_Delay_FocusOnTownHome) -- end end end function TeamMatch_Controller.SetMatchStateByActivityId(state, activityId, isHideTips) if activityId == LuaConst.ActivityType.TVT then MDL.SyncTeamPVP.OnSyncTeamPVPMatch(state) elseif activityId == LuaConst.ActivityType.TeamDungeon1 or activityId == LuaConst.ActivityType.TeamDungeon2 or activityId == LuaConst.ActivityType.TeamDungeon3 then local dungeonData = CTL.TeamDungeon.GetDungeonDataByActivityID(activityId) CTL.TeamDungeon.OnTeamDungeonMatch(state, dungeonData.ID) elseif activityId == LuaConst.ActivityType.SyncSolo then end if state then private.MatchingActivity = activityId else private.MatchingActivity = nil end TeamMatch_Controller.DealWithMatchTime(state, activityId) if state and not isHideTips then if not CTL.Team.IsTeamFull() then CTL.Tips.AddTipsMsg(Const_IDS.IDS_Team_3v3_StartMatch) end else CTL.Tips.AddTipsMsg(Const_IDS.IDS_Team_CancelMatch) end end function TeamMatch_Controller.CancelAllMatch(isHideTips) CTL.TeamDungeon.OnTeamDungeonMatch(false, nil) MDL.SyncTeamPVP.OnSyncTeamPVPMatch(false) private.MatchingActivity = nil TeamMatch_Controller.DealWithMatchTime(false) if not isHideTips then --CTL.Tips.AddTipsMsg(Const_IDS.IDS_TeamDungeon1_Match_Cancel) end end function TeamMatch_Controller.CancelCurMatch() local matchId = TeamMatch_Controller.IsInMatching() if matchId then local func = TeamMatch_Controller.GetFuncById(matchId) if func then CTL.TeamMatch.OnPressMatchButton(matchId, func)--告知服务器取消匹配 end end end function TeamMatch_Controller.DealWithMatchErrorReason(failInfos) for i, v in ipairs(failInfos) do local reason = v.Reason local playerId = v.ACID local name if playerId == BattleDataGetter.GetAcID() then name = BattleDataGetter.GetPlayerName() else name = MDL.Team.GetMemberNameById(playerId) end TeamMatch_Controller.ShowMatchErrorTipsByReason(reason, name) end end function TeamMatch_Controller.ShowMatchErrorTipsByReason(reason, name, activityId) if reason == private.CannotJoinMatchReason.Success or reason == private.CannotJoinMatchReason.TeamLeaderChangeMatch then return end local ids if reason == private.CannotJoinMatchReason.NotMeetOpenConditions then ids = private.FormatErrorIDS(UIUtils.GetLocalizedTxt(Const_IDS.IDS_TeamMatch_Prefix_NotOpen)) elseif reason == private.CannotJoinMatchReason.InsufficientNums then ids = private.FormatErrorIDS(UIUtils.GetLocalizedTxt(Const_IDS.IDS_TeamMatch_Prefix_NoRewardTimes)) elseif reason == private.CannotJoinMatchReason.PlayerOffline then ids = private.FormatErrorIDS(UIUtils.GetLocalizedTxt(Const_IDS.IDS_TeamMatch_Prefix_Offline)) elseif reason == private.CannotJoinMatchReason.InGame then ids = private.FormatErrorIDS(UIUtils.GetLocalizedTxt(Const_IDS.IDS_TeamMatch_Prefix_InCopymap)) elseif reason == private.CannotJoinMatchReason.NotFollow then ids = private.FormatErrorIDS(UIUtils.GetLocalizedTxt(Const_IDS.IDS_TeamMatch_Prefix_NeedFollow)) elseif reason == private.CannotJoinMatchReason.NotMeetMatchConditions then ids = UIUtils.GetLocalizedTxt(Const_IDS.IDS_TeamMatchCancel_NewComer) elseif reason == private.CannotJoinMatchReason.TeamLeaderCancelMatch then if CTL.Team.IsSelfLeader() then ids = UIUtils.GetLocalizedTxt(Const_IDS.IDS_Team_CancelMatch) else ids = UIUtils.GetLocalizedTxt(Const_IDS.IDS_TeamMatchCancel_CaptainCancel) end --elseif reason == private.CannotJoinMatchReason.TeamLeaderChangeMatch then --ids = UIUtils.GetLocalizedTxt(Const_IDS.IDS_TeamMatchCancel_CaptainChange) --name = UIUtils.GetLocalizedTxt(Const_IDS[DataSheetManager.ActivityData:GetDataByID(activityId).Activity]) elseif reason == private.CannotJoinMatchReason.TeamMeetMaxDirectAccess then ids = UIUtils.GetLocalizedTxt(Const_IDS.IDS_TeamMatch_TeamFull) elseif reason == private.CannotJoinMatchReason.CreateTeam then ids = UIUtils.GetLocalizedTxt(Const_IDS.IDS_TeamMatchCancel_CreateTeam) elseif reason == private.CannotJoinMatchReason.JoinTeam then ids = UIUtils.GetLocalizedTxt(Const_IDS.IDS_TeamMatchCancel_JoinTeam) elseif reason == private.CannotJoinMatchReason.TeamMemberChange then ids = UIUtils.GetLocalizedTxt(Const_IDS.IDS_TeamMatchCancel_PlayerNumChange) end CTL.Tips.AddTipsMsg(ids, name) end function private.FormatErrorIDS(ids) local str if CTL.Team.IsTeamFull() then str = UIUtils.GetLocalizedTxt(Const_IDS.IDS_TeamMatch_Suffix_CantIn) else if TeamMatch_Controller.IsInMatching() then str = UIUtils.GetLocalizedTxt(Const_IDS.IDS_TeamMatch_Suffix_CancelMatch) else str = UIUtils.GetLocalizedTxt(Const_IDS.IDS_TeamMatch_Suffix_CantMatch) end end return string.FormatByIdsId(Const_IDS.IDS_TeamMatch_Format, ids, str) end function TeamMatch_Controller.IsActivityEnterNumEnough(activityId) if activityId == LuaConst.ActivityType.WorldBoss then return MDL.WorldBoss.IsTimesLeft() elseif activityId == LuaConst.ActivityType.TeamDungeon1 or activityId == LuaConst.ActivityType.TeamDungeon2 or activityId == LuaConst.ActivityType.TeamDungeon3 then return MDL.TeamDungeon.IsTimesLeft(activityId) elseif activityId == LuaConst.ActivityType.CountryWorldBoss then return MDL.CountryWorldBoss.IsTimesLeft() else return true end end --用来判断资源是否下载完成 --levelFeatureID:对应LuaConst中的levelType --levelId:地图id,LevelInfo表的ID function TeamMatch_Controller.IsCanGoOtherScene(levelFeatureID, levelId) --判断资源是否已下载好 if CTL.HotFix.HasLevelPackageDownload(levelFeatureID, levelId) == false then return false end if private.MatchingActivity then CTL.Tips.AddTipsMsg(Const_IDS["IDS_TeamDungeon1_Matching"]) return false end --打开匹配界面(通用匹配)不让切场景 if UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UITeamMatchPanel) == true then return false end --打开押镖匹配界面不让切场景 if UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UIGuildEscortMatchPanel) == true then return false end return true end function TeamMatch_Controller.IsInMatching() return private.MatchingActivity end function TeamMatch_Controller.IsActivityMatchingById(activityId) return private.MatchingActivity and activityId == private.MatchingActivity end function TeamMatch_Controller.IsMapAllowMatch() local mapFeature = DataSheetManager.LevelFeatureData:GetDataByLevelFeatureID(BattleDataGetter.GetCurLevelType()) return mapFeature.IsMatchTeam end --是否正在进行匹配的判断,由于有切换的需求,放在每个地方自己先行判断 function TeamMatch_Controller.IsCanStartMatch(activityId) if CTL.HotFix.HasActivityDownload(activityId) == false then return false end local activityData = DataSheetManager.ActivityData:GetDataByID(activityId) if (not activityData.TypeTips or activityData.TypeTips == 0) and CTL.Team.IsInTeam() then CTL.Tips.AddTipsMsg(Const_IDS["IDS_1v1Sync_TeamFail"]) --队伍中不能进行单人活动匹配 return false end if CTL.Team.IsInTeam() and not CTL.Team.IsSelfLeader() then CTL.Tips.AddTipsMsg(Const_IDS["IDS_Team_NeedCaptain"]) --需队长进行该操作 return false end local isOpen, content = CTL.Activities.IsOpen(activityId) if not isOpen then CTL.Tips.AddTipsMsg(content) return false end --目前进入副本没有次数限制,只有奖励限制 --local isNumEnough = TeamMatch_Controller.IsActivityEnterNumEnough(activityId) --if not isNumEnough then -- local content = string.format(UIUtils.GetLocalizedTxt(Const_IDS["IDS_TeamMatch_NoRewardTimes"]), UIUtils.GetLocalizedTxt(Const_IDS[activityData.Activity])) -- CTL.Tips.AddTipsMsg(content) -- return false --end local isMapAllowMatch = TeamMatch_Controller.IsMapAllowMatch() if not isMapAllowMatch then CTL.Tips.AddTipsMsg(Const_IDS.IDS_TeamMatch_InvalidScene) return false end --local isMatching = TeamMatch_Controller.IsInMatching() --if isMatching then -- return false --end return true end function TeamMatch_Controller.ChangeMatchActivityConfirm(func) UTL.MessageBox.ShowOKCancelBox(UIUtils.GetLocalizedTxt(Const_IDS.IDS_TeamMatch_Change_Title), UIUtils.GetLocalizedTxt(Const_IDS.IDS_TeamMatch_Change), func, nil) end TeamMatch_Controller.MatchOperationState = { StartMatch = 1, CancelMatch = 2, SwitchMatch = 3, } function TeamMatch_Controller.GetMatchOperationStateByActivityId(activityId) if TeamMatch_Controller.IsCanStartMatch(activityId) then if not TeamMatch_Controller.IsInMatching() then return TeamMatch_Controller.MatchOperationState.StartMatch else if TeamMatch_Controller.IsActivityMatchingById(activityId) then return TeamMatch_Controller.MatchOperationState.CancelMatch else return TeamMatch_Controller.MatchOperationState.SwitchMatch end end end return false end function TeamMatch_Controller.OnPressMatchButton(activityId, func) local state = TeamMatch_Controller.GetMatchOperationStateByActivityId(activityId) if state == TeamMatch_Controller.MatchOperationState.StartMatch then func(activityId, true) elseif state == TeamMatch_Controller.MatchOperationState.SwitchMatch then CTL.TeamMatch.ChangeMatchActivityConfirm(function() func(activityId, true) end) elseif state == TeamMatch_Controller.MatchOperationState.CancelMatch then func(activityId, false) end return state end function TeamMatch_Controller.GetFuncById(activityId) local func if activityId == LuaConst.ActivityType.SyncSolo then func = MDL.SyncSolo.DealWithSyncSoloMatch --谁与争锋 elseif activityId == LuaConst.ActivityType.TVT or activityId == LuaConst.ActivityType.SyncFourCountryWar then func = MDL.TeamMatch.PlayerMatchOperateReq --三军争霸 elseif activityId == LuaConst.ActivityType.TeamDungeon1 or activityId == LuaConst.ActivityType.TeamDungeon2 or activityId == LuaConst.ActivityType.TeamDungeon3 then func = CTL.TeamDungeon.DealWithTeamPVEMatch -- 经典战役PVE end return func end function TeamMatch_Controller.IgnoreCheckMatchForLoading() return private.ignoreCheckMatchForLoading end function TeamMatch_Controller.SetIgnoreCheckMatchForLoading(v) private.ignoreCheckMatchForLoading = v end function TeamMatch_Controller.GetMatchDesc(activityId) if activityId == LuaConst.ActivityType.TeamDungeon1 or activityId == LuaConst.ActivityType.TeamDungeon2 or activityId == LuaConst.ActivityType.TeamDungeon3 then local countData = MDL.Activities.GetCountInfo(activityId) return string.FormatByIdsId(Const_IDS.IDS_TeamDungeon1_RewardNum_1, countData.curCount, countData.sumCount) elseif activityId == LuaConst.ActivityType.TreasureDungeon then if CTL.Team.IsSelfLeader() then return UIUtils.GetLocalizedTxt(Const_IDS.IDS_DigTreasure_Team_OwnerTips) else local info = MDL.Task.GetTreasureRewardInfo() local sumCount = DataSheetManager.ConstData:GetDataByID("DigTreasureDailyHelpTimes").IntValue local curCount = info and info.rewardCountLeft or 0 local name = UIUtils.GetLocalizedTxt(Const_IDS.IDS_DigTreasure_TreasureCave_Title) return string.FormatByIdsId(Const_IDS.IDS_DigTreasure_Team_RewardTimes, name, curCount, sumCount) end elseif activityId == LuaConst.ActivityType.GuildEscort then local residueNum, num = MDL.GuildEscort.GetEscortNumLimit() return string.FormatByIdsId(Const_IDS.IDS_Escort_LeftAwardNum, residueNum, num) else return "" end end function TeamMatch_Controller.IsShowNoRewardTip(activityId) if CTL.Team.IsSelfLeader() then return false end if activityId == LuaConst.ActivityType.TreasureDungeon then local info = MDL.Task.GetTreasureRewardInfo() local curCount = info and info.rewardCountLeft or 0 if curCount == 0 then return true end end return false end --判断这次匹配弹窗是在匹配 还是进入副本 function TeamMatch_Controller.IsShowRefuseIn(activityId) return activityId ~= LuaConst.ActivityType.TVT end return TeamMatch_Controller