local Team_Controller = {} local private = {} local EventSystem = require 'Event/EventSystem' local MaxTeamMemberNum = 3 local TeamApplyWaitMaxTime = DataSheetManager.ConstData:GetDataByID("TeamApplyWaitMaxTime").IntValue local TeamInviteWaitMaxTime = DataSheetManager.ConstData:GetDataByID("TeamInviteWaitMaxTime").IntValue local TeamListClientRefreshTime = DataSheetManager.ConstData:GetDataByID("TeamListClientRefreshTime").IntValue local TeamShoutCDTime = DataSheetManager.ConstData:GetDataByID("TeamNoticeCD").IntValue Team_Controller.TeamInvitedAutoPopUPKey = "Team_Invited_AutoPopUP" Team_Controller.TeamApplyAutoPopUPKey = "Team_Apply_AutoPopUP" function Team_Controller.OnStartup() EventSystem.Regist(EventID.UI_Team_ApplyInfoHandle, private.RefreshApplyTeamList) EventSystem.Regist(EventID.UI_Team_InviteInfoHandle, private.RefreshInviteTeamList) EventSystem.Regist(EventID.New_Day_Refresh, private.RefreshAutoPopUPValue) EventSystem.Regist(EventID.UI_Team_MemberInfoChange, private.OnTeamCountChange) EventSystem.Regist(EventID.UI_Team_TeamTargetChange, private.OnTeamTargetChange) Team_Controller.WaitForInviteId = nil private.applyTimerHandle = nil private.inviteTimerHandle = nil private.lastShoutTimeStamp = 0 private.warnedContinuousLineTarget = nil end function Team_Controller.IsSpecifiedTarget(target) return target == 0 or target == MDL.Team.ContinuousLineType end function Team_Controller.GetSpecifiedTargetTitle(target) if target == 0 then return Const_IDS["IDS_TeamUI_Myteam_TargetEmpty"] elseif target == MDL.Team.ContinuousLineType then return Const_IDS["IDS_ContinuousLineOrder_Title"] end end --region -- **************** 轮询方法 ******************* -- function private.RefreshApplyTeamList() local applyTeamList = MDL.Team.GetApplyTeamList() if #applyTeamList > 0 then if not private.applyTimerHandle then private.applyTimerHandle = TimerUtil.Interval(function() private.CheckApplyTeamListValidate() end, TeamListClientRefreshTime, 0) end else if private.applyTimerHandle then TimerUtil.Remove(private.applyTimerHandle) private.applyTimerHandle = nil end end end function private.CheckApplyTeamListValidate() local applyTeamList = MDL.Team.GetApplyTeamList() local currentTime = UTL.Time.GetServerTimestamp() + 1 for i, v in ipairs(applyTeamList) do if currentTime - v.applyTime >= TeamApplyWaitMaxTime then Team_Controller.TeamEchoManager(Team_Controller.EchoType.ApplyInfoHandle, false, v.applyPlayerId) table.remove(applyTeamList, i) end end end function private.RefreshInviteTeamList() local inviteTeamList = MDL.Team.GetInviteList() if #inviteTeamList > 0 then if not private.inviteTimerHandle then private.inviteTimerHandle = TimerUtil.Interval(function() private.CheckInviteTeamListValidate() end, TeamListClientRefreshTime, 0) end else if private.inviteTimerHandle then TimerUtil.Remove(private.inviteTimerHandle) private.inviteTimerHandle = nil end end end function private.CheckInviteTeamListValidate() local inviteTeamList = MDL.Team.GetInviteList() local currentTime = UTL.Time.GetServerTimestamp() + 1 local ExTimeStamp, RemovedInfo = 0, nil for i, v in ipairs(inviteTeamList) do if v.type == MDL.Team.InvitedType.Room then RemovedInfo = {type = v.type, ActivityID = v.info.BriefInfo.ActivityID, RoomID = v.info.BriefInfo.RoomID} ExTimeStamp = v.info.HouseOwner.InviteTime elseif v.type == MDL.Team.InvitedType.Team then RemovedInfo = {type = v.type, teamId = v.info.teamInfo.teamId} ExTimeStamp = v.info.inviteTime end if currentTime - ExTimeStamp >= TeamInviteWaitMaxTime then Team_Controller.TeamEchoManager(Team_Controller.EchoType.InviteInfoHandle, false, RemovedInfo) table.remove(inviteTeamList, i) end end end function private.RefreshAutoPopUPValue() PersistentData.DeviceData:Set(Team_Controller.TeamInvitedAutoPopUPKey, 0, true) PersistentData.DeviceData:Set(Team_Controller.TeamApplyAutoPopUPKey, 0, true) end --endregion --region -- **************** 逻辑方法 ******************* -- function Team_Controller.EnterTeamPlayByTarget(mainTarget, subTarget) local activityId = mainTarget if activityId == LuaConst.ActivityType.TVT then UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UISyncTeamPVPMainPanel) elseif activityId == LuaConst.ActivityType.TeamDungeon1 or activityId == LuaConst.ActivityType.TeamDungeon2 or activityId == LuaConst.ActivityType.TeamDungeon3 then CTL.TeamDungeon.FindTeamPVENPC(activityId) UIManager.RecoverTopView() CTL.HomeMain.CloseOpenView() elseif activityId == LuaConst.ActivityType.WorldBoss then CTL.WorldBoss.OpenMainPanel() elseif activityId == LuaConst.ActivityType.CountryWorldBoss then CTL.CountryWorldBoss.OpenCountryWorldBossPanel() elseif activityId == LuaConst.ActivityType.RebelStrike then CTL.RebelStrike.OpenMain() elseif table.containValue(MDL.MultiplayerDungeon.SubActivityId, activityId) then local rotationTime = MDL.MultiplayerDungeon.GetRotationOrder(activityId) if rotationTime and rotationTime <= UTL.Time.GetServerTimestamp() then -- 只有已经在轮换池中 & 当前正在开放,才可以进入,否则提示未开启 MDL.MultiplayerDungeon.MultiplayerDungeonInfoRequest(mainTarget, subTarget) else CTL.Tips.AddTipsMsg(Const_IDS.IDS_TeamIn_OutOfTime) end elseif activityId == LuaConst.ActivityType.SyncSolo then UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UISyncSoloMainPanel) elseif activityId == LuaConst.ActivityType.TreasureDungeon then CTL.Task.FindTreasureDoor() UIManager.CloseView(Const_UI_Lua.UIEnum.UITeamBasePanel) UIManager.RecoverView() elseif activityId == LuaConst.ActivityType.GuildEscort then CTL.GuildEscort.OpenMainPanel() elseif activityId == LuaConst.ActivityType.SyncFourCountryWar then CTL.SyncFourCountryWar.OpenMainPanel() end end function Team_Controller.OpenTeamInteractive(memberId, callBack, posX, posY) if not Team_Controller.IsSelfMemberById(memberId) then UIManager.OpenView(Const_UI_Lua.UIEnum.UITeamInteractive, {memberId = memberId, callBack = callBack, x = posX, y = posY}) end end function private.SendTeamApplyReqByLimit(teamId, teamTarget, teamLimit) if Team_Controller.IsPlayerReachTeamLimit(teamLimit) then if Team_Controller.IsPlayerLevelLowerActivityLimit(teamTarget.mainTarget) then UTL.MessageBox.ShowOKCancelBox(UIUtils.GetLocalizedTxt(Const_IDS["IDS_TeamUI_Apply"]), UIUtils.GetLocalizedTxt(Const_IDS["IDS_Team_LevelBelowTarget"]), function() private.SendTeamApplyReqByIfInTeam(teamId) end) else private.SendTeamApplyReqByIfInTeam(teamId) end end end function private.SendTeamApplyReqByIfInTeam(teamId) if Team_Controller.IsInTeam() then private.LeaveTeamAndSendApply(teamId) else MDL.Team.TeamApplyReq(teamId) end end function private.LeaveTeamAndSendApply(teamId) CTL.GuildEscort.GuildEscortQuit(function() UTL.MessageBox.ShowOKCancelBox(UIUtils.GetLocalizedTxt(Const_IDS["IDS_TeamUI_Apply"]), UIUtils.GetLocalizedTxt(Const_IDS["IDS_Team_ExitAndApplyTeam"]), function() MDL.Team.TeamLeaveReq() private.LeaveApplyReqTeamId = teamId end) end) end function Team_Controller.OnLeaveApplyReq() if private.LeaveApplyReqTeamId then MDL.Team.TeamApplyReq(private.LeaveApplyReqTeamId) private.LeaveApplyReqTeamId = nil end end function Team_Controller.SendTeamApplyRequest(teamId, teamTarget, teamLimit) if Team_Controller.IsInTeam() then if MDL.Team.GetMyTeamId() == teamId then CTL.Tips.AddTipsMsg(Const_IDS["IDS_Team_AlreadyInThisTeam"]) return end end private.SendTeamApplyReqByLimit(teamId, teamTarget, teamLimit) end function Team_Controller.OpenTeamPanel(mainTarget, subTarget) UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UITeamBasePanel, {mainTarget = mainTarget, subTarget = subTarget}) end function private.GetTeamRecruitMsg() local teamInfo = MDL.Team.GetTeamInfo() if not teamInfo then logging.error(LTAG.ERROR, "没有找到自己队伍信息!!!") return end local leaderName = MDL.Team.GetMemberNameById(Team_Controller.GetTeamLeaderId()) local teamTarget = teamInfo.target local teamLimit = teamInfo.limit local teamInfo = { teamId = teamInfo.teamId, teamTarget = teamTarget, teamLimit = teamLimit, curCount = MDL.Team.GetTeamMemberNumbers(), name = leaderName, cartRarity = MDL.GuildEscort.GetCurLevelEscort(), } return teamInfo end function Team_Controller.ShutTeamRecruitMsg(isInit, isGuild) if isInit then private.lastShoutTimeStamp = 0 else local currentTime = UTL.Time.GetServerTimestamp() if private.lastShoutTimeStamp ~= 0 then if currentTime - private.lastShoutTimeStamp < TeamShoutCDTime then return end end private.lastShoutTimeStamp = currentTime end local teamInfo = private.GetTeamRecruitMsg() local targetActivityId = teamInfo.teamTarget.mainTarget local recruitChannelID -- 如果是军团押镖则组队信息发送到 势力频道 否则发送到招募频道 if isGuild or targetActivityId == LuaConst.ActivityType.GuildEscort then recruitChannelID = MDL.ChannelChat.GetChannelIdByCfgID(MDL.ChannelChat.ChannelCfgId.Legion) else recruitChannelID = MDL.ChannelChat.GetChannelIdByCfgID(MDL.ChannelChat.ChannelCfgId.ZhaoMu) end MDL.ChannelChat.SendChatTeamRecruitMsg(recruitChannelID, nil , teamInfo) CTL.Tips.AddTipsMsg(Const_IDS["IDS_Team_CallInfoSendToChannel"]) end function Team_Controller.GetShutTimeCD() local shoutCdTime = 0 if private.lastShoutTimeStamp ~= 0 then shoutCdTime = TeamShoutCDTime - (UTL.Time.GetServerTimestamp() - private.lastShoutTimeStamp) end return shoutCdTime < 0 and 0 or shoutCdTime end --endregion --region -- **************** 判断方法 ******************* -- function Team_Controller.IsInTeam() return IsServerDataNotNil(MDL.Team.GetTeamInfo()) end function Team_Controller.IsTeamFunctionUnlock() return MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.Team) end function Team_Controller.IsTeamLeader(memberId) local memberInfo = MDL.Team.GetMemberInfoById(memberId) or {} return memberInfo.type == MDL.Team.MemberType.Leader end function Team_Controller.GetTeamLeaderId() for i, v in ipairs(MDL.Team.GetAllMembersInfo()) do if v.type == MDL.Team.MemberType.Leader then return v.memberId end end return private.selfAcId end function Team_Controller.GetTeamLeader() for i, v in ipairs(MDL.Team.GetAllMembersInfo()) do if v.type == MDL.Team.MemberType.Leader then return v end end return nil end function Team_Controller.IsSelfLeader() local selfInfo = MDL.Team.GetSelfMemberInfo() or {} return selfInfo.type == MDL.Team.MemberType.Leader end function Team_Controller.IsSelfMemberById(memberId) if not private.selfAcId then private.selfAcId = BattleDataGetter.GetAcID() end return private.selfAcId == memberId end function Team_Controller.IsMemberInTeam(memberId) for i, v in ipairs(MDL.Team.GetAllMembersInfo()) do if v.memberId == memberId then return true end end return false end function Team_Controller.IsTeamFull() return MDL.Team.GetTeamMemberNumbers() == MaxTeamMemberNum end function Team_Controller.IsAllMemberFollowing() if not private.selfAcId then private.selfAcId = BattleDataGetter.GetAcID() end for i, v in ipairs(MDL.Team.GetAllMembersInfo()) do if v.memberId ~= private.selfAcId then if v.state ~= MDL.Team.MemberState.Following then return false end end end return true end function Team_Controller.SomeMemberNotFollowing() if not private.selfAcId then private.selfAcId = BattleDataGetter.GetAcID() end for i, v in ipairs(MDL.Team.GetAllMembersInfo()) do if v.memberId ~= private.selfAcId then local entity = SyncMoveManager.GetEntityByAcid(v.memberId) if v.state ~= MDL.Team.MemberState.Following or entity == nil then local name = MDL.Team.GetMemberNameById(v.memberId) return true, name end end end return false end function Team_Controller.SomeMemberNotInSameScene() if not private.selfAcId then private.selfAcId = BattleDataGetter.GetAcID() end for i, v in ipairs(MDL.Team.GetAllMembersInfo()) do if v.memberId ~= private.selfAcId then local entity = SyncMoveManager.GetEntityByAcid(v.memberId) if entity == nil then local name = MDL.Team.GetMemberNameById(v.memberId) return true, name end end end return false end --acid :队员的acid function Team_Controller.LeaderIsFollowingNPC(acid) local leaderID = MDL.Team.GetFollowTeamLeaderId(acid) if leaderID then return SyncMoveManager.IsChasingAndFollowingNPC(leaderID) end end function Team_Controller.IfCanCreateTeam() local mapFeature = DataSheetManager.LevelFeatureData:GetDataByLevelFeatureID(BattleDataGetter.GetCurLevelType()) return mapFeature.IsCreateTeam end function Team_Controller.IfCanSendApply() local mapFeature = DataSheetManager.LevelFeatureData:GetDataByLevelFeatureID(BattleDataGetter.GetCurLevelType()) return mapFeature.ScatterCanApplyTeam end function Team_Controller.IfCanInvite() local mapFeature = DataSheetManager.LevelFeatureData:GetDataByLevelFeatureID(BattleDataGetter.GetCurLevelType()) return mapFeature.IsInviteOthers end function Team_Controller.IfCanFollow() local levelType = BattleDataGetter.GetCurLevelType() local mapFeature = DataSheetManager.LevelFeatureData:GetDataByLevelFeatureID(levelType) return mapFeature.MembersCanFollowCaptain end function Team_Controller.IfCanCallMembers() local mapFeature = DataSheetManager.LevelFeatureData:GetDataByLevelFeatureID(BattleDataGetter.GetCurLevelType()) return mapFeature.CaptainCanCall end function Team_Controller.IfCanOperateTeam() end function Team_Controller.IsPlayerLevelLowerActivityLimit(activityId) if Team_Controller.IsSpecifiedTarget(activityId) then return false end local activityData = DataSheetManager.ActivityData:GetDataByID(activityId) return not MDL.Unlock.IsUnlock(activityData.FuctionUnlockID) end function Team_Controller.IsPlayerReachTeamLimit(teamLimit) if MDL.HeroSelect.GetTeamLevel() < teamLimit.level then CTL.Tips.AddTipsMsg(Const_IDS["IDS_Team_LevelNotEnough"]) return false end if MDL.Player.GetLineUpGs() < teamLimit.power then CTL.Tips.AddTipsMsg(Const_IDS["IDS_Team_CombatNotEnough"]) return false end return true end function Team_Controller.OperateTeamInvitedPanel(isAdd, invitedInfo) if isAdd then if UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UITeamInvitedPanel) then Team_Controller.TeamEchoManager(Team_Controller.EchoType.InviteInfoHandle, true, invitedInfo) else Team_Controller.TeamEchoManager(Team_Controller.EchoType.InviteInfoHandle, true) end else Team_Controller.TeamEchoManager(Team_Controller.EchoType.InviteInfoHandle, false, invitedInfo) end end -- 是否自动弹出队伍申请弹窗 function Team_Controller.IsAutoPopUpApplyview() local lastTime = PersistentData.DeviceData:Get(Team_Controller.TeamApplyAutoPopUPKey) or 0 if lastTime == 0 then return true elseif lastTime > 0 and UTL.Time.IsTimestampCrossDay(lastTime) then PersistentData.DeviceData:Set(Team_Controller.TeamApplyAutoPopUPKey, 0, true) return true end return false end -- 是否自动弹出队伍邀请弹窗 function Team_Controller.IsAutoPopUpInvitedview() local lastTime = PersistentData.DeviceData:Get(Team_Controller.TeamInvitedAutoPopUPKey) or 0 if lastTime == 0 then return true elseif lastTime > 0 and UTL.Time.IsTimestampCrossDay(lastTime) then PersistentData.DeviceData:Set(Team_Controller.TeamInvitedAutoPopUPKey, 0, true) return true end return false end --endregion Team_Controller.EchoType = { CreateTeam = "CreateTeam", LeaveTeam = "LeaveTeam", MemberInfoChange = "MemberInfoChange", TeamInfoChange = "TeamInfoChange", ApplyInfoHandle = "ApplyInfoHandle", InviteInfoHandle = "InviteInfoHandle", RecommendTeamListChange = "RecommendTeamListChange", StrangerListRefresh = "StrangerListRefresh", TeamTargetChange = "TeamTargetChange", } --region -- **************** 协议响应方法 ******************* -- ---针对协议Response和Push过来的消息的一个统一管理。 ---传入type(随用随加)和相应参数,在此函数中进行管理,调用相应的函数。 ---函数中包括一些界面弹出的处理和相应事件的派发。 function Team_Controller.TeamEchoManager(echoType, ...) logging.log(LTAG.LOG, "TeamEchoManager派发事件:", echoType) EventSystem.Dispatch(EventID["UI_Team_"..echoType], ...) -- 被动变更跟随状态 if echoType == Team_Controller.EchoType.MemberInfoChange or echoType == Team_Controller.EchoType.LeaveTeam then EventSystem.Dispatch(EventID.UI_Auto_Tips, LuaConst.AutoType.AutoFollow) end end --endregion function Team_Controller.EnterSingleTreasure(doorId) MDL.Task.DigTreasureEnterReq(doorId) end function Team_Controller.EnterTeamTreasure(doorId) local taskList = MDL.Task.GetTaskList(MDL.Task.Enum_TaskType.TreasureCave) if taskList == nil or next(taskList) == nil then CTL.Tips.AddTipsMsg(Const_IDS.IDS_DigTreasure_CaveTimeOut) return end if Team_Controller.IsTeamLeader(BattleDataGetter.GetAcID()) then local teamMemberNum = MDL.Team.GetTeamMemberNumbers() teamMemberNum = teamMemberNum == 0 and 1 or teamMemberNum if teamMemberNum == 1 then UTL.MessageBox.ShowOKCancelBox(nil,Const_IDS.IDS_DigTreasure_ConfirmTeam,function () Team_Controller.OpenTeamPanel(LuaConst.ActivityType.TreasureDungeon) end,function() MDL.Task.DigTreasureEnterReq(doorId) end,Const_IDS.IDS_DigTreasure_GoToTeam,Const_IDS.IDS_DigTreasure_StillIn ) else if not Team_Controller.IsAllMemberFollowing() then UTL.MessageBox.ShowOKCancelBox(UIUtils.GetLocalizedTxt(Const_IDS["IDS_TeamIn_NeedAllFollow_Title"]), UIUtils.GetLocalizedTxt(Const_IDS["IDS_TeamIn_NeedAllFollow"]), function() MDL.Team.TeamCallMemberReq() end) return end MDL.Task.DigTreasureEnterReq(doorId) end else CTL.Tips.AddTipsMsg(Const_IDS.IDS_DigTreasure_BeCaptain) end end --保存页面索引 function Team_Controller.SaveTeamBaseUIPageIndex(index) --UITeamBasePanel 页面的打开的索引 private.TeamBaseIndex = index end function Team_Controller.SaveTeamBaseUIPageChildIndex(childIndex) --UITeamBasePanel 页面的打开的索引 private.TeamBaseChildIndex = childIndex end --获取页面索引 function Team_Controller.GetTeamBaseUIPageIndex() local index = private.TeamBaseIndex private.TeamBaseIndex = nil return index end --获取页面索引 function Team_Controller.GetTeamBaseUIPageChildIndex() local childIndex = private.TeamBaseChildIndex private.TeamBaseChildIndex = nil return childIndex end --region 带国家的匹配成员信息接口 目前仅用于国战PVP --攻击方国家 function Team_Controller.GetAttackerCountry() local matchMembersInfo = MDL.TeamMatch.GetMatchMemberInfo() for i, v in ipairs(matchMembersInfo) do if v.isAttacker then return v.countryId end end end --受击方国家 function Team_Controller.GetBeAttackerCountry() local matchMembersInfo = MDL.TeamMatch.GetMatchMemberInfo() for i, v in ipairs(matchMembersInfo) do if not v.isAttacker then return v.countryId end end end --获取攻击方成员和受击方成员信息 function Team_Controller.GetAttackMembersAndBeAttackMembers() local attackers,beAttackers ={},{} local matchMembersInfo = MDL.TeamMatch.GetMatchMemberInfo() for i, v in ipairs(matchMembersInfo) do if v.isAttacker then table.insert(attackers,v) else table.insert(beAttackers,v) end end return attackers,beAttackers end --endregion function private.OnTeamCountChange() private.WarnToContinuousLine() end function private.OnTeamTargetChange() private.WarnToContinuousLine() end --提示队长做一条龙 function private.WarnToContinuousLine() if BattleDataGetter.IsTownLevel() == false then return end if Team_Controller.IsSelfLeader() and Team_Controller.IsTeamFull() and MDL.Team.GetTeamTarget() == MDL.Team.ContinuousLineType then if private.warnedContinuousLineTarget then return end local target = MDL.Activities.GetContinuousLineTarget(true) if target then private.warnedContinuousLineTarget = target local activityData = DataSheetManager.ActivityData:GetDataByID(target) UTL.MessageBox.ShowOKCancelNoCloseBox(Const_IDS.IDS_ContinuousLineOrder_Title, string.FormatByIdsId(Const_IDS.IDS_ContinuousLineOrder_Tips, UIUtils.GetLocalizedTxt(Const_IDS[activityData.Activity])), private.OnEnterContinuousLine) end else private.warnedContinuousLineTarget = nil end end function private.OnEnterContinuousLine() if private.warnedContinuousLineTarget then MDL.Team.TeamCallMemberReq() CTL.Activities.OpenActivityWindowByID(private.warnedContinuousLineTarget) end end --匹配弹窗是否自动确认 function Team_Controller.IsActivityAutoReady(activityId) if MDL.Team.IsFollowing() then return activityId == LuaConst.ActivityType.TreasureDungeon or activityId == LuaConst.ActivityType.TeamDungeon1 or activityId == LuaConst.ActivityType.TeamDungeon2 or activityId == LuaConst.ActivityType.WantedTask or activityId == LuaConst.ActivityType.TeamDungeon3 end end return Team_Controller