local TeamMatch_Model = {} local private = {} local EventSystem = require('Event/EventSystem') local confirm_panel_pb = require 'Proto.confirm_panel_pb' local battle_match_pb = require 'Proto.battle_match_pb' TeamMatch_Model.MatchConfirmState = { WaitChoose = 0, WaitMember = 1, WaitEnter = 2, } function TeamMatch_Model.OnStartup() --EventSystem.Regist(EventID.UI_TeamMatch_MemberStateChanged, private.DealWithMatchInfoByState) NetManager.RegisterMsgCB(MessageEnums.MessageChangeConfirmState, private.MatchStateConfirmResp) NetManager.RegisterMsgCB(MessageEnums.MessagePlayerMatchOperate, private.PlayerMatchOperateResp) NetManager.RegisterMsgCB(MessageEnums.MessageG2CPushConfirmPanelInfo, private.MatchConfirmPanelInfoPush) NetManager.RegisterMsgCB(MessageEnums.MessageG2CPushPlayerStateChange, private.PlayerReadyStateChangePush) NetManager.RegisterMsgCB(MessageEnums.MessageG2CNotifyPlayerMatchCancel, private.PlayerMatchCancelPush) NetManager.RegisterMsgCB(MessageEnums.MessageG2CBattleMatchResult, private.BattleMatchResultPush) private.confirmId = nil private.matchMemberInfo = {} private.StartMatchingTime = 0 private.MatchingTimerID = nil end function TeamMatch_Model.GetMatchingTimerID() return private.MatchingTimerID end function TeamMatch_Model.SetMatchingTimerID(id) private.MatchingTimerID = id end function TeamMatch_Model.ClearMatchingTimerID() private.MatchingTimerID = nil end function TeamMatch_Model.GetStartMatchingTime() return private.StartMatchingTime end function TeamMatch_Model.SetStartMatchingTime(time) private.StartMatchingTime = time end function TeamMatch_Model.ClearStartMatchingTime() private.StartMatchingTime = 0 end function TeamMatch_Model.GetMatchMemberIndexByName(name) for i, v in ipairs(private.matchMemberInfo) do if v.PlayerName == name then return i end end logging.error(LTAG.ERROR, "没有找到该名字的玩家的Index", name) end function TeamMatch_Model.GetMatchMemberStateByName(name) for i, v in ipairs(private.matchMemberInfo) do if v.PlayerName == name then return v.state end end logging.error(LTAG.ERROR, "没有找到该名字的玩家的state", name) end function TeamMatch_Model.GetMatchMemberInfo() return private.matchMemberInfo end function TeamMatch_Model.ClearMatchInfo() private.confirmId = nil private.matchMemberInfo = {} end function TeamMatch_Model.IsMatchSuccessful() for i, v in ipairs(private.matchMemberInfo) do if not v.state then return false end end return true end function TeamMatch_Model.GetMatchConfirmState() if TeamMatch_Model.IsMatchSuccessful() then return TeamMatch_Model.MatchConfirmState.WaitEnter else if TeamMatch_Model.GetMatchMemberStateByName(BattleDataGetter.GetPlayerName()) then return TeamMatch_Model.MatchConfirmState.WaitMember end end return TeamMatch_Model.MatchConfirmState.WaitChoose end ---协议相关 function TeamMatch_Model.MatchStateConfirmReq(isConfirm) local msg = confirm_panel_pb.ChangeConfirmStateReq() msg.ConfirmID = private.confirmId msg.Ready = isConfirm private.isConfirm = isConfirm NetManager.SendMessage(MessageEnums.MessageChangeConfirmState, msg) end function private.MatchStateConfirmResp(msgResp) logging.log(LTAG.LOG, "MatchStateConfirmResp", msgResp) --国战PVP需要特殊处理 if private.currentActivityId == LuaConst.ActivityType.CountryPVP and private.isConfirm then local time = private.countDownTick - UTL.Time.GetServerTimestamp() if not UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UICountryMatchPanel) then UIManager.OpenView(Const_UI_Lua.UIEnum.UICountryMatchPanel, {time = time}) end end end function TeamMatch_Model.PlayerMatchOperateReq(activityId, ifMatch, subParam, heroIds) local msg = battle_match_pb.PlayerMatchOperateReq() msg.activityID = activityId msg.add = ifMatch msg.subID = subParam or 0 if heroIds then for i, v in ipairs(heroIds) do local heroInfo = battle_match_pb.MatchHeroInfo() local id, res = CTL.HeroAwaken.DecodeHeroId(v) if res then heroInfo.isAwaken = true heroInfo.heroId = id else heroInfo.isAwaken = false heroInfo.heroId = v end table.insert(msg.heroInfo, heroInfo) end end NetManager.SendMessage(MessageEnums.MessagePlayerMatchOperate, msg) end function private.PlayerMatchOperateResp(msgResp) if msgResp.Resp.Code == 0 then if IsServerDataNotNil(msgResp.failMembers) then CTL.TeamMatch.DealWithMatchErrorReason(msgResp.failMembers) end if not msgResp.inTeam then local feedback = msgResp.feedBack if feedback.SwitchMatching then if feedback.StopOldMatching then CTL.TeamMatch.CancelAllMatch() end if feedback.StartNewMatching then CTL.Tips.AddTipsMsg(Const_IDS["IDS_TeamMatchCancel_SingleChange"], UIUtils.GetLocalizedTxt(Const_IDS[DataSheetManager.ActivityData:GetDataByID(msgResp.activityID).Activity])) CTL.TeamMatch.SetMatchStateByActivityId(msgResp.add, msgResp.activityID, false) end else CTL.TeamMatch.SetMatchStateByActivityId(msgResp.add, msgResp.activityID) end end end end function private.MatchConfirmPanelInfoPush(msg) MDL.TeamMatch.ClearMatchInfo() private.confirmId = msg.ConfirmID if msg.ActivityID ~= LuaConst.ActivityType.GuildEscort then --玩家此时可能资源没下好,拒绝邀请 if CTL.HotFix.HasActivityDownload(msg.ActivityID) == false then --取消匹配 TeamMatch_Model.MatchStateConfirmReq(false) return end end if msg.ReasonEnum ~= 0 then CTL.TeamMatch.ShowMatchErrorTipsByReason(msg.ReasonEnum, msg.ReasonName, msg.ActivityID) UIManager.CloseView(Const_UI_Lua.UIEnum.UITeamMatchPanel) return end local needOpenCountryPVPMatch = false local isMyAttacker = false local attacker --缓存攻击方数据 local time = msg.CountDownTick - UTL.Time.GetServerTimestamp() for i, v in ipairs(msg.playerInfos) do table.insert(private.matchMemberInfo, { HeadIcon = v.HeadIcon, PlayerName = v.PlayerName, PlayerLevel = v.PlayerLevel, state = false, sex = v.Sex, PortraitId = v.PortraitId, FrameId = v.FrameId, --增加了公会相关信息 guildId = IsServerDataNotNil(v.guildInfo) and v.guildInfo.guildId or nil, guildName = IsServerDataNotNil(v.guildInfo) and v.guildInfo.guildName or nil, emblemFrame = IsServerDataNotNil(v.guildInfo) and v.guildInfo.emblemFrame or nil, emblemContent = IsServerDataNotNil(v.guildInfo) and v.guildInfo.emblemContent or nil, --增加国家相关信息 isAttacker = v.isAttacker, --是否是攻击方 countryId = v.countryId, --国家id isAutoSendConfirm = v.isAutoSendConfirm, --是否主动推送确认面板请求 gs = v.gs --战力 }) --国战PVP 如果需要推送面板请求,就直接发请求,用PVP的匹配界面 if v.isAutoSendConfirm and BattleDataGetter.GetPlayerName() == v.PlayerName and msg.ActivityID == LuaConst.ActivityType.CountryPVP then needOpenCountryPVPMatch = true isMyAttacker = v.isAttacker end --缓存攻击方数据 if v.isAttacker and v.isAutoSendConfirm then attacker = v; end end if msg.ActivityID == LuaConst.ActivityType.GuildEscort then MDL.GuildEscort.SyncEscortPrepareInfo(msg.escortInfo) UIManager.OpenView(Const_UI_Lua.UIEnum.UIGuildEscortMatchPanel, {activityId = msg.ActivityID, time = time}) else --国战PVP 如果需要推送面板请求,就直接发请求,用PVP的匹配界面 if needOpenCountryPVPMatch then --显示被攻击的提示 if not isMyAttacker and attacker then local countryName = "" local countryData = DataSheetManager.CountryBase:GetDataByID(attacker.countryId) if countryData then countryName = countryData.CountryName end local content = string.FormatByIdsId(Const_IDS.IDS_CountryPVP_FightStart_Info_2,UIUtils.GetLocalizedTxt(Const_IDS[countryName]),attacker.PlayerName) CTL.Tips.AddTipsMsg(content) end TeamMatch_Model.MatchStateConfirmReq(true) UIManager.OpenView(Const_UI_Lua.UIEnum.UICountryMatchPanel, {time = time}) else --其他情况,国战PVP走单独的弹窗 if msg.ActivityID == LuaConst.ActivityType.CountryPVP then --目前修改为队员无需确认直接跟随队长进入战斗 --UIManager.OpenView(Const_UI_Lua.UIEnum.UICountryTeamEnter,{activityId = msg.ActivityID,time = time}) MDL.TeamMatch.MatchStateConfirmReq(true) else UIManager.OpenView(Const_UI_Lua.UIEnum.UITeamMatchPanel, {activityId = msg.ActivityID, time = time}) end end end CTL.TeamMatch.CancelAllMatch() --缓存活动ID\倒计时 private.currentActivityId = msg.ActivityID private.countDownTick = msg.CountDownTick end function private.PlayerReadyStateChangePush(msg) --local index = TeamMatch_Model.GetMatchMemberIndexByName(msg.PlayerName) logging.log(LTAG.LOG,"PlayerReadyStateChangePush",msg.PlayerName,msg.Ready) local name = msg.PlayerName for i, v in ipairs(private.matchMemberInfo) do if v.PlayerName == name then v.state = msg.Ready EventSystem.Dispatch(EventID.UI_TeamMatch_MemberStateChanged, msg.Ready, msg.PlayerName) return end end logging.warn(LTAG.WARN, "本地数据中没有找到该名字的玩家的名字", name, private.matchMemberInfo) end --仅在个人时,服务器用这个推送中断匹配 function private.PlayerMatchCancelPush(msg) logging.log(LTAG.ERROR, "MessageG2CNotifyPlayerMatchCancel", msg) if not msg.OnlyNotify then if msg.showIDS and not string.isNilOrEmpty(msg.showIDS) then CTL.Tips.AddTipsMsg(Const_IDS[msg.showIDS]) else CTL.Tips.AddTipsMsg(Const_IDS.IDS_TeamDungeon1_Match_Cancel) end end if CTL.TeamMatch.IsActivityMatchingById(msg.ActivityID) then CTL.TeamMatch.CancelAllMatch() end end function private.BattleMatchResultPush(msg) -- 公平竞技匹配成功后停止任务行为 ---[[ -- 停止寻路 CTL.Level.TryBreakConveyProgress() NotSyncBattleSetter.StopAutoFightPathInTown() -- 停止采集 NotSyncBattleSetter.SetMainPlayerNextState(LuaConst.StateType.Idle,-1, "idle_loop", nil ,-1) EventSystem.Dispatch(EventID.UI_Scene_BreakCollectItem , BattleDataGetter.GetCurSkillUIEntity()) ---]] if msg.activityId == LuaConst.ActivityType.TVT then MDL.SyncTeamPVP.SyncTeamBattleMatchResultReceive(msg) elseif msg.activityId == LuaConst.ActivityType.SyncSolo then MDL.SyncSolo.SyncSoloBattleMatchResultReceive(msg) elseif msg.activityId == LuaConst.ActivityType.SyncFourCountryWar then MDL.SyncFourCountryWar.SyncFourCountryWarBattleMatchResultReceive(msg) end end return TeamMatch_Model