local EventSystem = require('Event/EventSystem') local Base = require("Battle/Logic/Level/LevelFunction/SyncLevelFunction") local SyncTeamPVPLevelFunction = class("SyncTeamPVPLevelFunction",Base) local battle_match_pb = require 'Proto/battle_match_pb' local Const_Obstruct = {8001,8002,8003,8004,8005,8006}--6个阻挡墙 local Const_RandomBuff = {2002,2003}--两个随机怪元素 local BORN_ITEM_COUNT = 3 -- 一方有3个出生点 local BlueColor = ""; local RedColor = ""; --3v3同步玩法,等待开始时间 (人齐后,等待fight的时长) local SyncWaitingCountDownFrame = 100 local Const_RebornTimesMax = -1 -- 最大复活次数 local Const_RebornAutoTime = {10,15,30} -- 每次的复活时间 local TipsGrapFrame = {[3] =300 ,[4] = 300,[5] = 300,[6] = 400,[7] = 400} local IMMORTAL_DUTAION_ON_REVIVE = DataSheetManager.ConstData:GetDataByID("IMMORTAL_DUTAION_ON_REVIVE_3v3") IMMORTAL_DUTAION_ON_REVIVE = IMMORTAL_DUTAION_ON_REVIVE and IMMORTAL_DUTAION_ON_REVIVE.FloatValue local IMMORTAL_BUFF_ID = 500001 local FightStateType = { None = 0, --战斗没开始或者结束了 Waiting = 1 ,-- 30秒等待其他人 阶段 Waiting2 = 2 , -- 等待30结束或者人齐后 ,开始54321阶段 Fighting = 3 , -- 战斗中了 } local private = { _fightState = FightStateType.None, --战斗阶段(进入-等待-等待2-战斗-结束) _isCountingTime = false,--战斗开始倒计时 _passBattleTimeFrame = 0,--战斗经过时长 _totalBattleTimeFrame = 6000,--战斗总时长6000秒 _maxProgress = 2000,-- 总进度条长度 _maxHolding = 100, --hold 时长 _checkTick = 200,-- 加时赛检查时长 _crucialTimes = 0, -- 加时次数 _isOverByTime = false,--时间结束 _myCampID = -1,--临时记录我的阵容id,好做区分 _otherCampID = -1,--临时记录敌方的阵容id,好做区分 _myTeamEntitys = {},-- 红队的entity _enemyEntitys = {},-- 蓝队的entity _lastMyTeamNum = 0, _lastOtherTeamNum = 0, _inHoldMyTeamNum = 0,--在据点中的我方数 _inHoldOthersNum = 0,--在据点中的敌方数 _inCirCleEntityList = {}, --在据点中的人的列表 _popsTimeDic = {}, -- type = frame 那种类型tip弹出的时间 campDirCount = {}, -- 存贮创建camp对应的数量 [campid] = count _occupyEvents = {}, -- 存储占领据点所要派发的事件 } -- 关卡加载完毕-loading结束时 function private.Reset() private._isCountingTime = false--战斗开始倒计时 private._passBattleTimeFrame = 0--战斗经过时长 private._isOverByTime = false--时间结束 private._lastMyTeamNum = 0 private._lastOtherTeamNum = 0 private._inHoldMyTeamNum = 0--在据点中的我方数 private._inHoldOthersNum = 0--在据点中的敌方数 private._inCirCleEntityList = {} --在据点中的人的列表 private._popsTimeDic = {} -- type = frame 那种类型tip弹出的时间 private.campDirCount = {} private._occupyEvents = {} -- 存储占领据点所要派发的事件 private._fightState = FightStateType.Waiting private.ShowIDSPOP2Frame = nil end --储存战斗的状态信息 local BattleInfo = { curState = 0,-- 当前占领状态 myProgress = 0,--单位 :帧 我方进度 otherProgress = 0;--单位 :帧 敌方进度 holdProgress = 0;--单位 :帧 抢占方的抢占进度 holdCamp = -1;--正在抢占方 occupyCamp = -1;--已经占领方 } local TeamPvPHoldState = { None = 0,--占点从来没有被占领过 Holding = 1,--无占领抢夺 HoldingStop = 2, --抢夺中停止了 Occupy = 3,--已经占领 OccupyHolding = 4,--被占领中去抢夺(A占领B去抢夺) 类似于Holding OccupyHoldingStop = 5,--抢夺中被压制,暂停抢夺,类似于HoldingStop Crucial = 6,--在99.99%的时候出现敌人(加时) CrucialHolding = 7,--加时被抢回(A到99%触发加时,B将A赶下) CrucialHoldingStop = 8,--加时被抢有压制抢(A到99%触发加时,B将A赶下,B盘子没转满A进来,B盘子停止) Over = 9,--比赛结束 } function SyncTeamPVPLevelFunction:GetExpClass() return require "Battle/Expression/ExpLevel/ExpLevelFunction/ExpSyncTeamPVPLevelFunction" end function SyncTeamPVPLevelFunction:InitLevel() Base.InitLevel(self) if LevelManager.LevelType == LuaConst.LevelType.SyncTeamPVP then self.needRecordPlayerHangUp = LevelManager.GetSwitchInGMS(LuaConst.GMSSWitchType.PunishForAFK) -- 本关卡是否需要记录玩家挂机了 end self.damageDic = {} --key为playerID,value为伤害量 end function SyncTeamPVPLevelFunction:OnLoadFinished() local totalBattleTime = DataSheetManager.ConstData:GetDataByID("TVTBattleTime").IntValue private._totalBattleTimeFrame = totalBattleTime * LuaConst.LogicFrameRate local maxprogress = MultiplayManager.GetTVTPointSpeed() --print("TVTPointSpeed", tostring(maxprogress)) private._maxProgress = FP.tonumberV1(FP.Math.Floor(FP.Const.One/maxprogress / LuaConst.TimeSpan) ) local maxHolding = DataSheetManager.ConstData:GetDataByID("TVTBattleSpeed").FloatValue private._maxHolding = FP.tonumberV1(FP.Math.Floor(FP.Const.One/maxHolding / LuaConst.TimeSpan) ) private._crucialTimes = 0 local checkTick = DataSheetManager.ConstData:GetDataByID("TVTOverTime").IntListValue[1] private._checkTick = checkTick * LuaConst.LogicFrameRate private.waitingFrame = -1 BattleInfo.curState = TeamPvPHoldState.None BattleInfo.myProgress = 0 BattleInfo.otherProgress = 0 BattleInfo.holdProgress = 0 BattleInfo.holdCamp = -1 BattleInfo.occupyCamp = -1 private.Reset() --TODO:注册接听元素事件 EventSystem.Regist(EventID.Level_ItemTriggerOccupy, self.OnOccupyTrigger, self) for i, v in LevelItemManager.GetItemIterByType(LuaConst.LevelItemType.StrongHold) do if v.ItemData.OccupyRule == LuaConst.LevelOccupyRule.None then table.insert(private._occupyEvents, v.LevelItemID..EventID._OccupierChanged) end end Base.OnLoadFinished(self) end function SyncTeamPVPLevelFunction:BeginLevel() Base.BeginLevel(self) --如果是在重新进入的时,需要让玩家重新active if not MultiplayManager.IsFromStartEnter then MultiplayManager.SetAllRolesActive() end for i,ob in ipairs(Const_Obstruct) do local item = LevelItemManager.GetItemByID(ob) item:DoAction(LuaConst.LevelActionType.Obstruct_Active) end end function SyncTeamPVPLevelFunction:OnLevelSucceed(withShow) -- 不能删除,需要不走基类的这个函数 end function SyncTeamPVPLevelFunction:StopLevel() EventSystem.UnRegist(EventID.Level_ItemTriggerOccupy, self.OnOccupyTrigger, self) for i, v in ipairs(private._occupyEvents) do private._occupyEvents[i] = nil end for i,v in ipairs(LogicUpdateManager.EntityList_Normal) do if v:IsAlive() then SystemManager.SetNextState(LuaConst.StateType.Idle, v) end end for i,v in ipairs(LogicUpdateManager.EntityList_Sync) do if v:IsAlive() then SystemManager.SetNextState(LuaConst.StateType.Idle, v) end end Base.StopLevel(self) BattleInfo.curState = TeamPvPHoldState.None BattleInfo.myProgress = 0 BattleInfo.otherProgress = 0 BattleInfo.holdProgress = 0 BattleInfo.holdCamp = -1 BattleInfo.occupyCamp = -1 private._isOverByTime = false; private._fightState = FightStateType.None end function SyncTeamPVPLevelFunction:CreatePlayerEntity(playerInfo, heroArmyData,isPlayerSelf,index) -- index == playerID local count = private.campDirCount[playerInfo.campID] or 0 count = count + 1 private.campDirCount[playerInfo.campID] = count local bornItemIndex = count % BORN_ITEM_COUNT if bornItemIndex == 0 then bornItemIndex = BORN_ITEM_COUNT end local bornItemIndex = (2 * bornItemIndex) - (playerInfo.campID % 2 ) local entity = Base.CreatePlayerEntity(self,playerInfo, heroArmyData,isPlayerSelf,bornItemIndex) --区分敌我 if playerInfo.campID == LevelPlayerManager.MainEntityCampID then private._myCampID = playerInfo.campID table.insert(private._myTeamEntitys , entity) else private._otherCampID = playerInfo.campID table.insert(private._enemyEntitys ,entity) end return entity end function SyncTeamPVPLevelFunction:CreatePlayers() private._myTeamEntitys = {}-- 红队的entity private._enemyEntitys = {}-- 蓝队的entity Base.CreatePlayers(self) end function private.Waiting2Over(selfFunc) -- 返回是否 恰好等待倒计时结束 if private.waitingFrame > SyncWaitingCountDownFrame then return false end private.waitingFrame = private.waitingFrame +1 if private.waitingFrame == SyncWaitingCountDownFrame then if (not LogicUpdateManager.IsInReconnectFastPlay()) then selfFunc.exp:CloseCountDownFormalPanel() private.ShowIDSPOP2Frame = LogicUpdateManager._clientHandleFrame + 100 end private._isCountingTime = true --天下会武3V3需要从第一帧起算总时间,加快节奏 if LevelManager.CheckCurLevelType(LuaConst.LevelType.SyncTeamFairChampionship) then private._totalBattleTimeFrame = private._totalBattleTimeFrame - LogicUpdateManager._clientHandleFrame end EventSystem.Dispatch(EventID.UI_UIBattleTeamPVPBattlePanel_BeginBattle) for i,ob in ipairs(Const_Obstruct) do local item = LevelItemManager.GetItemByID(ob) item:DoAction(LuaConst.LevelActionType.Obstruct_Deactive) end for i,monsterID in ipairs(Const_RandomBuff) do local item = LevelItemManager.GetItemByID(monsterID) item:DoAction(LuaConst.LevelActionType.Monster_Active) end print("关闭空气墙:",LogicUpdateManager._clientHandleFrame) return true end if (LogicUpdateManager.IsInReconnectFastPlay()) then return false end if (SyncWaitingCountDownFrame - private.waitingFrame) % 20 == 0 then local second = (SyncWaitingCountDownFrame - private.waitingFrame) / 20 EventSystem.Dispatch(EventID.UI_SyncTeamPVP_OpenCountDownPanel) EventSystem.Dispatch(EventID.UI_UIBattleCountDownPanel_SetNumber , second) if second <= 0 then EventSystem.Dispatch(EventID.PlayGameSound,"UI_begin") end end return false end function SyncTeamPVPLevelFunction:PreUpdate() if private._fightState == FightStateType.Fighting or private._fightState == FightStateType.None then if private.ShowIDSPOP2Frame == LogicUpdateManager._clientHandleFrame then private.ShowTips(private.GetLocalizedTxt(Const_IDS.IDS_Announce_POP2), 2) private.ShowIDSPOP2Frame = nil end return end if private._fightState == FightStateType.Waiting then if LogicUpdateManager._clientHandleFrame == LuaConst.SyncWaitOtherLimitFreame then -- 等到了30秒 private._fightState = FightStateType.Waiting2 if not LogicUpdateManager.IsInReconnectFastPlay() then EventSystem.Dispatch(EventID.BI_LevelMiddle,BIManager.BIType.SyncBattle,"[3v3]WaitOtherTimeOver") end elseif LogicUpdateManager.OnlinePlayerCount == LevelPlayerManager.PvpPlayerCount then -- 30秒内 ,人都齐了 private._fightState = FightStateType.Waiting2 end if private._fightState == FightStateType.Waiting2 then ExpLevelManager.WaitingOtherEnter(true ,LogicUpdateManager._clientHandleFrame ,LogicUpdateManager.GetServerFrame()) else ExpLevelManager.WaitingOtherEnter(false ,LogicUpdateManager._clientHandleFrame ,LogicUpdateManager.GetServerFrame()) end end if private._fightState == FightStateType.Waiting2 then local waitOver = private.Waiting2Over(self) if waitOver then private._fightState = FightStateType.Fighting if not LogicUpdateManager.IsInReconnectFastPlay() then EventSystem.Dispatch(EventID.BI_LevelMiddle,BIManager.BIType.SyncBattle,"[3v3]GoFight") end for i,entity in ipairs(LogicUpdateManager.EntityList_Sync) do SystemManager.AddBuff(entity,LuaConst.SpecialBuffs.CanSkill,entity,nil,nil) --机器人或者掉线的人开启自动战斗 if entity._logicInitData.BattleMemberType == LuaConst.BattleMemberType.Robot_Hero or (not LevelPlayerManager.IsOnline(entity:GetPlayerID()) ) then entity.components.autoFight.IsSyncAuto = true --logging.error(LTAG.ERROR, " 迟到啦! IsSyncAuto - eid: ", entity._logicInitData.EntityID) SystemManager.SetAIByID(entity,LevelManager.GetRobotAI(entity)) if not LogicUpdateManager.IsInReconnectFastPlay() then EventSystem.Dispatch(EventID.BI_LevelMiddle,BIManager.BIType.SyncBattle,"[3v3]GoFightOffLine" , entity._logicInitData.EntityID) end elseif entity._logicInitData.BattleMemberType == LuaConst.BattleMemberType.AI_Hero then entity.components.autoFight.IsAIAutoTest = true SystemManager.SetAIByID(entity , LuaConst.PVPTestAIID) end end end end end function SyncTeamPVPLevelFunction:GetRobotAI(entity) return LuaConst.PVPRobotAIID end function SyncTeamPVPLevelFunction:ShouldAddCanUseSkillToHeroWhenBorn() --3v3玩法一开始不添加可以使用技能的Buff return false end function SyncTeamPVPLevelFunction:OnOccupyTrigger(levelItemID, entity, enter) if enter then table.insert(private._inCirCleEntityList,entity) if entity:GetCampID() == LevelPlayerManager.MainEntityCampID then private._inHoldMyTeamNum = private._inHoldMyTeamNum + 1 else private._inHoldOthersNum = private._inHoldOthersNum + 1 end else table.removebyvalue(private._inCirCleEntityList,entity) if entity:GetCampID() == LevelPlayerManager.MainEntityCampID then private._inHoldMyTeamNum = private._inHoldMyTeamNum - 1 else private._inHoldOthersNum = private._inHoldOthersNum - 1 end end --print("我方数:", private._inHoldMyTeamNum, ",敌方数:", private._inHoldOthersNum) end --增加攻防时间 function private.AddConfrontTime() --只有一种情况不加时间 : 占领人为A 且 圈内无敌人B local continue = false for _,entity in ipairs(private._inCirCleEntityList) do if BattleInfo.teamPvPOccupyCamp == entity:GetCampID() then if (BattleInfo.teamPvPOccupyCamp == LevelPlayerManager.MainEntityCampID and private._inHoldOthersNum == 0) or (BattleInfo.teamPvPOccupyCamp ~= LevelPlayerManager.MainEntityCampID and private._inHoldMyTeamNum == 0) then continue = true end end if not continue then entity.components.record.ConfrontTimeFrame = entity.components.record.ConfrontTimeFrame + 1 end end end --抢占进度 function private.AddHoldigProgress() BattleInfo.holdProgress = BattleInfo.holdProgress + 1 if BattleInfo.holdProgress >= private._maxHolding then BattleInfo.occupyCamp = BattleInfo.holdCamp if BattleInfo.curState == TeamPvPHoldState.CrucialHolding then --关闭加时进度条 private.ShowCheckTime(false) end BattleInfo.curState = TeamPvPHoldState.Occupy private.BeginHolding(false, BattleInfo.occupyCamp == LevelPlayerManager.MainEntityCampID, false,false ,true) -- 隐藏下方进度条 if BattleInfo.occupyCamp == LevelPlayerManager.MainEntityCampID then private.BeginMyProgess() for i, v in ipairs(private._occupyEvents) do EventSystem.Dispatch(v, BattleInfo.occupyCamp,true) end elseif BattleInfo.occupyCamp ~= LevelPlayerManager.MainEntityCampID then private.BeginOtherProgess() for i, v in ipairs(private._occupyEvents) do EventSystem.Dispatch(v, BattleInfo.occupyCamp,false) end end end end --增加占领的进度条 function private.AddOccupyProgress() if BattleInfo.occupyCamp == LevelPlayerManager.MainEntityCampID then if BattleInfo.myProgress < private._maxProgress then BattleInfo.myProgress = BattleInfo.myProgress + 1 end else if BattleInfo.otherProgress < private._maxProgress then BattleInfo.otherProgress = BattleInfo.otherProgress + 1 end end --判断是胜负还是加时 if BattleInfo.myProgress >= private._maxProgress and BattleInfo.occupyCamp == LevelPlayerManager.MainEntityCampID then if private._inHoldOthersNum == 0 then BattleInfo.curState = TeamPvPHoldState.Over else BattleInfo.curState = TeamPvPHoldState.Crucial if BattleInfo.otherProgress >= private._maxProgress then BattleInfo.otherProgress = private._maxProgress - 1 end --设置加时时长 private._crucialTimes = private._crucialTimes + 1 local timeList = DataSheetManager.ConstData:GetDataByID("TVTOverTime").IntListValue if private._crucialTimes > #timeList then private._crucialTimes = #timeList end local checkTick = timeList[private._crucialTimes] private._checkTick = checkTick * LuaConst.LogicFrameRate private.ShowCheckTime(true , private._crucialTimes) end end if BattleInfo.otherProgress >= private._maxProgress and BattleInfo.occupyCamp ~= LevelPlayerManager.MainEntityCampID then if private._inHoldMyTeamNum == 0 then BattleInfo.curState = TeamPvPHoldState.Over else BattleInfo.curState = TeamPvPHoldState.Crucial if BattleInfo.myProgress >= private._maxProgress then BattleInfo.myProgress = private._maxProgress - 1 end --设置加时时长 private._crucialTimes = private._crucialTimes + 1 local timeList = DataSheetManager.ConstData:GetDataByID("TVTOverTime").IntListValue if private._crucialTimes > #timeList then private._crucialTimes = #timeList end local checkTick = timeList[private._crucialTimes] private._checkTick = checkTick * LuaConst.LogicFrameRate private.ShowCheckTime(true , private._crucialTimes) end end end --检查是否结束 function private.CheckIsOver() if (BattleInfo.occupyCamp == LevelPlayerManager.MainEntityCampID and private._inHoldOthersNum == 0) or (BattleInfo.occupyCamp ~= LevelPlayerManager.MainEntityCampID and private._inHoldMyTeamNum == 0) then BattleInfo.curState = TeamPvPHoldState.Over return true end return false end function SyncTeamPVPLevelFunction:OnCreatePlayer(playerID, playerInfo, firstEntity) Base.OnCreatePlayer(self, playerID, playerInfo, firstEntity) self.damageDic[playerID] = FP.newV1(0) --给训练机器人改名字 if playerInfo.fighterType == LuaConst.BattleMemberType.Robot_Hero and playerInfo.isGuideRobot then self.exp:SetPracticeRobotName(playerID) end end function SyncTeamPVPLevelFunction:GetRobotAIElo(entity) local elo = entity._logicInitData.elo or 0 if entity._logicInitData.BattleMemberType == LuaConst.BattleMemberType.Robot_Hero then local playerInfo = LevelPlayerManager.GetPlayerInfoByPlayerIDInRoom(entity:GetPlayerID()) if not playerInfo.isGuideRobot then -- 训练机器人不需要取对手的elo elo = 0 local campID = entity:GetCampID() for i,_entity in ipairs(LogicUpdateManager.EntityList_Sync) do if _entity:GetCampID() ~= campID then elo = _entity._logicInitData.elo or 0 break end end end end return elo end function SyncTeamPVPLevelFunction:OnUpdate() Base.OnUpdate(self) if not private._isCountingTime then return end private._passBattleTimeFrame = private._passBattleTimeFrame + 1 if(private._passBattleTimeFrame >= private._totalBattleTimeFrame) then private._isOverByTime = true BattleInfo.curState = TeamPvPHoldState.Over; end --给圈内的人增加攻防时间 private.AddConfrontTime() local curState = BattleInfo.curState if curState == TeamPvPHoldState.None then if private._inHoldMyTeamNum ~= 0 and private._inHoldOthersNum == 0 then BattleInfo.holdCamp = LevelPlayerManager.MainEntityCampID BattleInfo.curState = TeamPvPHoldState.Holding private.BeginHolding(true, true, true, true) private.ShowTips(private.GetLocalizedTxt(Const_IDS.IDS_Announce_POP3), 3) elseif private._inHoldMyTeamNum == 0 and private._inHoldOthersNum ~= 0 then BattleInfo.holdCamp = private._otherCampID BattleInfo.curState = TeamPvPHoldState.Holding private.BeginHolding(true, false, true, true) private.ShowTips(private.GetLocalizedTxt(Const_IDS.IDS_Announce_POP4), 4) end elseif curState == TeamPvPHoldState.Holding then if BattleInfo.holdCamp == LevelPlayerManager.MainEntityCampID and ( private._inHoldOthersNum ~= 0 or private._inHoldMyTeamNum == 0 ) or ( BattleInfo.holdCamp ~= LevelPlayerManager.MainEntityCampID and ( private._inHoldOthersNum == 0 or private._inHoldMyTeamNum ~= 0 ) ) then BattleInfo.curState = TeamPvPHoldState.HoldingStop private.BeginHolding(false, BattleInfo.holdCamp == LevelPlayerManager.MainEntityCampID, false) else private.AddHoldigProgress() end elseif curState == TeamPvPHoldState.HoldingStop then if BattleInfo.holdCamp == LevelPlayerManager.MainEntityCampID then if private._inHoldOthersNum == 0 and private._inHoldMyTeamNum ~= 0 then BattleInfo.curState = TeamPvPHoldState.Holding private.BeginHolding(true, true, false) elseif private._inHoldMyTeamNum == 0 and private._inHoldOthersNum ~= 0 then BattleInfo.holdCamp = private._otherCampID BattleInfo.curState = TeamPvPHoldState.Holding private.BeginHolding(true, false, true, true) private.ShowTips(private.GetLocalizedTxt(Const_IDS.IDS_Announce_POP4), 4) end elseif BattleInfo.holdCamp ~= LevelPlayerManager.MainEntityCampID then if private._inHoldMyTeamNum == 0 and private._inHoldOthersNum ~= 0 then BattleInfo.curState = TeamPvPHoldState.Holding private.BeginHolding(true, false, false) elseif private._inHoldMyTeamNum ~= 0 and private._inHoldOthersNum == 0 then BattleInfo.holdCamp = LevelPlayerManager.MainEntityCampID BattleInfo.curState = TeamPvPHoldState.Holding private.BeginHolding(true, true, true, true) private.ShowTips(private.GetLocalizedTxt(Const_IDS.IDS_Announce_POP3), 3) end end elseif curState == TeamPvPHoldState.OccupyHolding then--A占领中被B抢夺 if BattleInfo.occupyCamp == LevelPlayerManager.MainEntityCampID and BattleInfo.holdCamp ~= LevelPlayerManager.MainEntityCampID then if private._inHoldOthersNum == 0 then --敌方抢夺失败 BattleInfo.holdProgress = private._maxHolding BattleInfo.holdCamp = LevelPlayerManager.MainEntityCampID BattleInfo.curState = TeamPvPHoldState.Occupy private.BeginHolding(false, true, false ,false ,true); private.BeginMyProgess() elseif private._inHoldMyTeamNum ~= 0 then --我方压制敌方抢夺 BattleInfo.curState = TeamPvPHoldState.OccupyHoldingStop private.BeginHolding(false, false, false) private.BeginMyProgess() else private.AddHoldigProgress() end elseif BattleInfo.occupyCamp ~= LevelPlayerManager.MainEntityCampID and BattleInfo.holdCamp == LevelPlayerManager.MainEntityCampID then if private._inHoldMyTeamNum == 0 then --我方抢夺失败 BattleInfo.holdProgress = private._maxHolding BattleInfo.holdCamp = private._otherCampID BattleInfo.curState = TeamPvPHoldState.Occupy private.BeginHolding(false, false, false,false ,true) private.BeginOtherProgess() elseif private._inHoldOthersNum ~= 0 then --敌方压制敌方抢夺 BattleInfo.curState = TeamPvPHoldState.OccupyHoldingStop private.BeginHolding(false, true, false) private.BeginOtherProgess() else private.AddHoldigProgress() end end --ui展示 if (BattleInfo.occupyCamp == LevelPlayerManager.MainEntityCampID and private._inHoldOthersNum ~= 0 and private._lastOtherTeamNum == 0) then private.ShowTips(private.GetLocalizedTxt(Const_IDS.IDS_Announce_POP5), 5) elseif BattleInfo.occupyCamp ~= LevelPlayerManager.MainEntityCampID and private._inHoldMyTeamNum ~= 0 and private._lastMyTeamNum == 0 then private.ShowTips(private.GetLocalizedTxt(Const_IDS.IDS_Announce_POP6), 6) end elseif curState == TeamPvPHoldState.OccupyHoldingStop then -- 抢夺被压制 if BattleInfo.holdCamp == LevelPlayerManager.MainEntityCampID then --我方抢夺被压制 if (private._inHoldOthersNum == 0 and private._inHoldMyTeamNum ~= 0) then--我方反压制成功,继续抢夺 BattleInfo.curState = TeamPvPHoldState.OccupyHolding private.BeginHolding(true, true, false) elseif private._inHoldMyTeamNum == 0 and private._inHoldOthersNum ~= 0 then --我方抢夺失败 BattleInfo.holdCamp = private._otherCampID BattleInfo.curState = TeamPvPHoldState.Occupy BattleInfo.holdProgress = private._maxHolding private.BeginHolding(false, false, false,false ,true) end elseif BattleInfo.holdCamp ~= LevelPlayerManager.MainEntityCampID then if (private._inHoldMyTeamNum == 0 and private._inHoldOthersNum ~= 0) then BattleInfo.curState = TeamPvPHoldState.OccupyHolding private.BeginHolding(true, false, false) elseif private._inHoldMyTeamNum ~= 0 and private._inHoldOthersNum == 0 then BattleInfo.holdCamp = LevelPlayerManager.MainEntityCampID BattleInfo.curState = TeamPvPHoldState.Occupy BattleInfo.holdProgress = private._maxHolding private.BeginHolding(false, true, false,false ,true) end end private.AddOccupyProgress() --ui展示 if (BattleInfo.occupyCamp == LevelPlayerManager.MainEntityCampID and private._inHoldOthersNum ~= 0 and private._lastOtherTeamNum == 0) then private.ShowTips(private.GetLocalizedTxt(Const_IDS.IDS_Announce_POP5), 5) elseif BattleInfo.occupyCamp ~= LevelPlayerManager.MainEntityCampID and private._inHoldMyTeamNum ~= 0 and private._lastMyTeamNum == 0 then private.ShowTips(private.GetLocalizedTxt(Const_IDS.IDS_Announce_POP6), 6) end elseif curState == TeamPvPHoldState.Occupy then -- 已经占领 if BattleInfo.occupyCamp == LevelPlayerManager.MainEntityCampID and private._inHoldMyTeamNum == 0 and private._inHoldOthersNum ~= 0 then BattleInfo.curState = TeamPvPHoldState.OccupyHolding private.BeginHolding(true, false, BattleInfo.holdCamp ~= private._otherCampID) BattleInfo.holdCamp = private._otherCampID private.BeginMyProgess(false) elseif BattleInfo.occupyCamp ~= LevelPlayerManager.MainEntityCampID and private._inHoldOthersNum == 0 and private._inHoldMyTeamNum ~= 0 then BattleInfo.curState = TeamPvPHoldState.OccupyHolding private.BeginHolding(true, true, BattleInfo.holdCamp ~= LevelPlayerManager.MainEntityCampID) BattleInfo.holdCamp = LevelPlayerManager.MainEntityCampID private.BeginOtherProgess(false) else private.AddOccupyProgress() end --ui tips显示 if (BattleInfo.occupyCamp == LevelPlayerManager.MainEntityCampID and private._inHoldOthersNum ~= 0 and private._lastOtherTeamNum == 0) then private.ShowTips(private.GetLocalizedTxt(Const_IDS.IDS_Announce_POP5), 5) elseif BattleInfo.occupyCamp ~= LevelPlayerManager.MainEntityCampID and private._inHoldMyTeamNum ~= 0 and private._lastMyTeamNum == 0 then private.ShowTips(private.GetLocalizedTxt(Const_IDS.IDS_Announce_POP6), 6) end elseif curState == TeamPvPHoldState.Crucial then -- 在99%的时候出现敌人 --加时是否结束 private._checkTick = private._checkTick -1 if private._checkTick == 0 then--倒计时结束 ,判断一下是否over BattleInfo.curState = TeamPvPHoldState.Over else if BattleInfo.occupyCamp == LevelPlayerManager.MainEntityCampID then if private._inHoldOthersNum == 0 then BattleInfo.curState = TeamPvPHoldState.Over --关闭加时进度条 private.ShowCheckTime(false) elseif private._inHoldMyTeamNum == 0 then BattleInfo.holdCamp = private._otherCampID BattleInfo.curState = TeamPvPHoldState.CrucialHolding private.BeginHolding(true, false, true) end elseif BattleInfo.occupyCamp ~= LevelPlayerManager.MainEntityCampID then if private._inHoldMyTeamNum == 0 then BattleInfo.curState = TeamPvPHoldState.Over --关闭加时进度条 private.ShowCheckTime(false) elseif private._inHoldOthersNum == 0 then BattleInfo.holdCamp = LevelPlayerManager.MainEntityCampID BattleInfo.curState = TeamPvPHoldState.CrucialHolding private.BeginHolding(true, true, true) end end end elseif curState == TeamPvPHoldState.CrucialHolding then --加时被抢下 --加时是否结束 private._checkTick = private._checkTick -1 if private._checkTick == 0 then--倒计时结束 ,判断一下是否over BattleInfo.curState = TeamPvPHoldState.Over else if BattleInfo.occupyCamp == LevelPlayerManager.MainEntityCampID and BattleInfo.holdCamp ~= LevelPlayerManager.MainEntityCampID then if private._inHoldOthersNum == 0 then --敌方抢夺失败 BattleInfo.holdProgress = private._maxHolding BattleInfo.holdCamp = LevelPlayerManager.MainEntityCampID BattleInfo.curState = TeamPvPHoldState.Crucial private.BeginHolding(false, true, false,false ,true); private.BeginMyProgess() elseif private._inHoldMyTeamNum ~= 0 then --我方压制敌方抢夺 BattleInfo.curState = TeamPvPHoldState.CrucialHoldingStop private.BeginHolding(false, false, false) private.BeginMyProgess() else private.AddHoldigProgress() end elseif BattleInfo.occupyCamp ~= LevelPlayerManager.MainEntityCampID and BattleInfo.holdCamp == LevelPlayerManager.MainEntityCampID then if private._inHoldMyTeamNum == 0 then --我方抢夺失败 BattleInfo.holdProgress = private._maxHolding BattleInfo.holdCamp = private._otherCampID BattleInfo.curState = TeamPvPHoldState.Crucial private.BeginHolding(false, false, false,false ,true) private.BeginOtherProgess() elseif private._inHoldOthersNum ~= 0 then --敌方压制敌方抢夺 BattleInfo.curState = TeamPvPHoldState.CrucialHoldingStop private.BeginHolding(false, true, false) private.BeginOtherProgess() else private.AddHoldigProgress() end end end elseif curState == TeamPvPHoldState.CrucialHoldingStop then --加时是否结束 private._checkTick = private._checkTick -1 if private._checkTick == 0 then--倒计时结束 ,判断一下是否over BattleInfo.curState = TeamPvPHoldState.Over else if BattleInfo.holdCamp == LevelPlayerManager.MainEntityCampID then --我方抢夺被压制 if (private._inHoldOthersNum == 0 and private._inHoldMyTeamNum ~= 0) then--我方反压制成功,继续抢夺 BattleInfo.curState = TeamPvPHoldState.CrucialHolding private.BeginHolding(true, true, false) elseif private._inHoldMyTeamNum == 0 and private._inHoldOthersNum ~= 0 then --我方抢夺失败 BattleInfo.holdCamp = private._otherCampID BattleInfo.curState = TeamPvPHoldState.Crucial BattleInfo.holdProgress = private._maxHolding private.BeginHolding(false, false, false,false ,true) end elseif BattleInfo.holdCamp ~= LevelPlayerManager.MainEntityCampID then if (private._inHoldMyTeamNum == 0 and private._inHoldOthersNum ~= 0) then BattleInfo.curState = TeamPvPHoldState.CrucialHolding private.BeginHolding(true, false, false) elseif private._inHoldMyTeamNum ~= 0 and private._inHoldOthersNum == 0 then BattleInfo.holdCamp = LevelPlayerManager.MainEntityCampID BattleInfo.curState = TeamPvPHoldState.Crucial BattleInfo.holdProgress = private._maxHolding private.BeginHolding(false, true, false,false ,true) end end end elseif curState == TeamPvPHoldState.Over then --if private._isOverByTime then 只要在最后,无论是否是时间结束,都要让占领方获胜 if BattleInfo.myProgress >= private._maxProgress and BattleInfo.occupyCamp ~= LevelPlayerManager.MainEntityCampID then BattleInfo.myProgress = private._maxProgress - 1 end if BattleInfo.otherProgress >= private._maxProgress and BattleInfo.occupyCamp == LevelPlayerManager.MainEntityCampID then BattleInfo.otherProgress = private._maxProgress - 1 end --end private.SetOverUI() private.BeginMyProgess(false); private.BeginOtherProgess(false); self:SendBattleResult() self:StopLevel() if LogicUpdateManager.IsReplayOrServerCheck then BattleSimulator.EndPlay() end end end function SyncTeamPVPLevelFunction:OnHpChange(entity, caster, delta, op) Base.OnHpChange(self, entity, caster, delta, op) if op == "sub" and delta < FP.Const.Zero then caster = caster:GetOriginEntity() if caster.isHero and caster.CampID ~= entity.CampID then self.damageDic[caster:GetPlayerID()]:Add(-delta) end end end function SyncTeamPVPLevelFunction:OnEntityDead(entity) Base.OnEntityDead(self,entity) if not entity._logicInitData.IsPlayer then return end --统计 local recordComp = entity.components.record local killerRecord = nil if(recordComp.KillerEntity ~= nil) and recordComp.KillerEntity ~= entity then killerRecord =recordComp.KillerEntity.components.record killerRecord.KillNum = killerRecord.KillNum + 1 killerRecord.TotalKillNum = killerRecord.TotalKillNum + 1 if killerRecord.MaxKillNum < killerRecord.KillNum then killerRecord.MaxKillNum = killerRecord.KillNum end end recordComp.DeadCount = recordComp.DeadCount + 1 --显示 if(killerRecord == nil) then return end if not LogicUpdateManager.IsInReconnectFastPlay() and (not USE_LUA_STANDALONE) then -- 校验程序不需要tips local bekilledColor = "" local killerColor = "" if(entity:GetCampID() == LevelPlayerManager.MainEntityCampID) then bekilledColor = BlueColor killerColor = RedColor else bekilledColor = RedColor killerColor = BlueColor end local beKilledName = bekilledColor .. entity._logicInitData.Name .. "" local killerName = killerColor .. recordComp.KillerEntity._logicInitData.Name .. "" if not LevelManager.IsInLevelWatchBattle() then if (entity._logicInitData.IsPlayerSelf) then if entity ~= recordComp.KillerEntity then EventSystem.Dispatch(EventID.UI_AddTipsMsg,Const_IDS["IDS_Announce_POP9"], killerName) end elseif recordComp.KillerEntity._logicInitData.IsPlayerSelf then EventSystem.Dispatch(EventID.UI_AddTipsMsg,Const_IDS["IDS_Announce_POP8"], beKilledName) EventSystem.Dispatch(EventID.Level_UpdateKillNum,killerRecord.TotalKillNum) end end if recordComp.KillNum >= 3 then local stopTip = string.FormatByIdsId(Const_IDS.IDS_Announce_POP13, killerName, beKilledName, recordComp.KillNum); private.ShowTips(stopTip) end local killtip = "" if killerRecord.KillNum > 5 then killtip = string.FormatByIdsId(Const_IDS.IDS_Announce_POP12, killerName, killerRecord.KillNum) private.ShowTips(killtip) elseif killerRecord.KillNum >= 3 then killtip = string.FormatByIdsId(Const_IDS.IDS_Announce_POP11, killerName, killerRecord.KillNum) private.ShowTips(killtip) elseif killerRecord.KillNum == 2 then killtip = string.FormatByIdsId(Const_IDS.IDS_Announce_POP10, killerName, killerRecord.KillNum) private.ShowTips(killtip) end local leftAwaken = BattleDataGetter.GetHeroIsAwaken(recordComp.KillerEntity:GetPlayerID(), recordComp.KillerEntity._logicInitData.CharacterID) local rightAwaken = BattleDataGetter.GetHeroIsAwaken(entity:GetPlayerID(), entity._logicInitData.CharacterID) --expEntity.Entity._logicInitData.CharacterID if entity ~= recordComp.KillerEntity then EventSystem.Dispatch(EventID.UI_SyncTeamPVP_ShowKillTitleInfo ,recordComp.KillerEntity._logicInitData.Name, recordComp.KillerEntity._logicInitData.CharacterID , entity._logicInitData.Name, entity._logicInitData.CharacterID,entity:GetCampID() == LevelPlayerManager.MainEntityCampID,leftAwaken,rightAwaken) -- 左边的人是否是敌人 end end --重置数据 recordComp.KillNum = 0 end function SyncTeamPVPLevelFunction:OnPlayerAllHeroDead(entity) --不调用Base local reviveCount = entity.components.revive.ReviveCount if Const_RebornTimesMax == -1 or reviveCount < Const_RebornTimesMax then --复活次数是否达到上限 if reviveCount >= #Const_RebornAutoTime then entity.components.revive.ReviveTimer = Const_RebornAutoTime[#Const_RebornAutoTime] * 1000 else entity.components.revive.ReviveTimer = Const_RebornAutoTime[reviveCount + 1] * 1000 end end -- entity.components.patrol:ResetPathIndex()-- 路径(现在用随机点的方式效果跟路径差不多,所以注掉路径的方式) EventSystem.Dispatch(EventID.UI_BattleTeamPVPBattlePanel_OnEntityRevive, entity) end function SyncTeamPVPLevelFunction:OnRevive(entity,isInBornPoint) -- 不使用Base if entity.components.revive.ReviveTimer > 0 or entity:IsAlive() then EventSystem.Dispatch(EventID.BI_LevelMiddle,BIManager.BIType.SyncBattle, "[3v3]ReviveError", entity.components.revive.ReviveTimer) -- 毫秒 return false end SystemManager.OnRevive(entity,isInBornPoint) if IMMORTAL_DUTAION_ON_REVIVE then local buffctrl = RuntimeDataManager.New_BuffCtrl() buffctrl.ForceDuration:Reset(IMMORTAL_DUTAION_ON_REVIVE) SystemManager.AddBuff(entity, IMMORTAL_BUFF_ID, entity, nil, buffctrl) end return true end function SyncTeamPVPLevelFunction:GetBattleInfo() return BattleInfo end function SyncTeamPVPLevelFunction:SendBattleResult() local checkinfo = self:GetBattleResultCheckStr() -- new 使用基类提供的方法 if LevelManager.IsInLevelWatchBattle() then -- 观战不发结算 self.watchCheckStr = checkStr return end local msg = battle_match_pb.C2GUploadBattleResult() msg.ourCaptureProgress = BattleInfo.myProgress msg.enemyCaptureProgress = BattleInfo.otherProgress msg.checkInfo = checkinfo for i,entity in ipairs(private._myTeamEntitys) do local battleResult = battle_match_pb.FighterResult() battleResult.playerId = entity:GetPlayerID() battleResult.killNum = entity.components.record.TotalKillNum battleResult.deadNum = entity.components.record.DeadCount battleResult.fightingTime = entity.components.record.ConfrontTimeFrame local playerInfo = LevelPlayerManager.GetPlayerInfoByPlayerIDInRoom(battleResult.playerId) battleResult.serId = playerInfo.serId battleResult.totalDamage = self.damageDic[battleResult.playerId] and FP.tonumberV1(self.damageDic[battleResult.playerId]) or 0 local heroArmyData = LevelPlayerManager.GetPlayerArmyData(entity:GetPlayerID(),entity) table.insert(battleResult.heroIds,heroArmyData.HeroID) table.insert(battleResult.heroIds,heroArmyData.AdjutantID) table.insert(msg.ourFighterRecords, battleResult) battleResult.isNegativeFight = self.playerHangUpStateDic[battleResult.playerId] == LuaConst.PlayerHangUpState.Punish or self.playerHangUpStateDic[battleResult.playerId] == LuaConst.PlayerHangUpState.PunishManualFight table.insert(battleResult.isHeroAwakens, heroArmyData.mainHeroAwaken) table.insert(battleResult.isHeroAwakens, heroArmyData.viceHeroAwaken) end for i,entity in ipairs(private._enemyEntitys) do local battleResult = battle_match_pb.FighterResult() battleResult.playerId = entity:GetPlayerID() battleResult.killNum = entity.components.record.TotalKillNum battleResult.deadNum = entity.components.record.DeadCount battleResult.fightingTime = entity.components.record.ConfrontTimeFrame local playerInfo = LevelPlayerManager.GetPlayerInfoByPlayerIDInRoom(battleResult.playerId) battleResult.serId = playerInfo.serId battleResult.totalDamage = self.damageDic[battleResult.playerId] and FP.tonumberV1(self.damageDic[battleResult.playerId]) or 0 local heroArmyData = LevelPlayerManager.GetPlayerArmyData(entity:GetPlayerID(),entity) table.insert(battleResult.heroIds,heroArmyData.HeroID) table.insert(battleResult.heroIds,heroArmyData.AdjutantID) table.insert(msg.enemyFighterRecords, battleResult) battleResult.isNegativeFight = self.playerHangUpStateDic[battleResult.playerId] == LuaConst.PlayerHangUpState.Punish or self.playerHangUpStateDic[battleResult.playerId] == LuaConst.PlayerHangUpState.PunishManualFight table.insert(battleResult.isHeroAwakens, heroArmyData.mainHeroAwaken) table.insert(battleResult.isHeroAwakens, heroArmyData.viceHeroAwaken) end if not LogicUpdateManager.IsReplayOrServerCheck then logging.log(LTAG.LOG, LogicUpdateManager._clientHandleFrame, ":发送战斗结算协议") EventSystem.Dispatch(EventID.BI_LevelMiddle,BIManager.BIType.SyncBattle, "[3v3]SendBattleResult", LogicUpdateManager._clientHandleFrame) EventSystem.Dispatch(EventID.SyncTeam_PVPSendBattleResult,msg) else logging.log(LTAG.LOG, "[GWS]SyncTeamPVP BattleCheckStr = ", checkinfo) end if USE_LUA_STANDALONE then BattleSimulator.SetCheckResult(checkinfo, msg:SerializeToString()) end end function SyncTeamPVPLevelFunction:GetLeftBattleTimeFrame() return private._totalBattleTimeFrame - private._passBattleTimeFrame end function SyncTeamPVPLevelFunction:OnPlayerFirstOnline(playerID) Base.OnPlayerFirstOnline(self, playerID) local entities = LevelPlayerManager.GetPlayerEntitysByPlayerIDInRoom(playerID) if entities then if entities[1] and entities[1].components.autoFight:IsAuto() then -- 首次进入房间发现其已经自动战斗了 for i,_entity in ipairs(entities) do self:StopAutoFight(_entity) end end end end function SyncTeamPVPLevelFunction:OnOffLine(playerID) local entitys = LevelPlayerManager.GetPlayerEntitysByPlayerIDInRoom(playerID) entitys[1].components.autoFight.IsSyncAuto = true SystemManager.SetAIByID(entitys[1],LuaConst.PVPRobotAIID) end -- old↓ 方法提到基类了 -- function private.GetBattleResultCheckInfo() -- local result = "" -- for i,entity in ipairs(LogicUpdateManager.EntityList_Sync) do -- local moveComp = entity.components.move -- local str = string.format("%d,f:%d, px:%d,pz:%d,fx:%d,fz:%d,Anim:%s,hp:%d|" -- , entity._logicInitData.EntityID,BattleDataGetter.GetCurFrameIndex() ,moveComp.LogicPos.x[1], moveComp.LogicPos.z[1],moveComp.LogicRotateDir.x[1], moveComp.LogicRotateDir.z[1],tostring(entity.components.anim.CurAnimID),entity.components.attr.hp[1]) -- result = result .. str -- end -- return result -- end -- old↑ function private.GetMyTeamTotalKillNum() local num = 0; for i,entity in ipairs(private._myTeamEntitys) do num = entity.components.record.TotalKillNum + num end return num end function private.GetOtherTeamTotalKillNum() local num = 0; for i,entity in ipairs(private._enemyEntitys) do num = entity.components.record.TotalKillNum + num end return num end function private.GetMyTeamConfrontTime() local time = 0; for i,entity in ipairs(private._myTeamEntitys) do time = time + entity.components.record.ConfrontTimeFrame end return time end function private.GetOtherTeamConfrontTime() local time = 0; for i,entity in ipairs(private._enemyEntitys) do time = time + entity.components.record.ConfrontTimeFrame end return time end function SyncTeamPVPLevelFunction:GetProgressOfCamp(campID) local myCampID = private._myTeamEntitys[1] and private._myTeamEntitys[1].CampID if campID == myCampID then return BattleInfo.myProgress else return BattleInfo.otherProgress end end ------------------表现部分代码------------- function private.SetOverUI() EventSystem.Dispatch(EventID.UI_BattleTeamPVPBattlePanel_Over) --设置界面需要的数据 local my = math.floor(BattleInfo.myProgress / private._maxProgress * 100) local other = math.floor(BattleInfo.otherProgress / private._maxProgress * 100) local maxKillNum = LogicUpdateManager._curEntity.components.record.MaxKillNum local totalKillNum = LogicUpdateManager._curEntity.components.record.TotalKillNum EventSystem.Dispatch(EventID.UI_SyncTeamPVP_SetReslut,my, other, maxKillNum,totalKillNum) end function private.BeginHolding(isgo ,isMyCamp , isSetHoldingZero ,isFirst ,stopUI2) if isSetHoldingZero == nil then isSetHoldingZero = true end if isFirst == nil then isFirst = false end if isSetHoldingZero then BattleInfo.holdProgress = 0 end EventSystem.Dispatch(EventID.UI_BattleTeamPVPBattlePanel_SetHoldingProgress , isgo ,isMyCamp,isSetHoldingZero,isFirst ,stopUI2) end function private.BeginMyProgess(isgo) if isgo == nil then isgo = true end EventSystem.Dispatch(EventID.UI_BattleTeamPVPBattlePanel_SetMyProgress , isgo) end function private.BeginOtherProgess(isgo) if isgo == nil then isgo = true end EventSystem.Dispatch(EventID.UI_BattleTeamPVPBattlePanel_SetOtherProgress , isgo) end function private.ShowCheckTime(show ,crucialTimes) --EventSystem.Dispatch(EventID.UI_BattleTeamPVPBattlePanel_ShowCheckTime , show ,crucialTimes) --if show then -- private.ShowTips(private.GetLocalizedTxt(Const_IDS.IDS_Announce_POP7),7) --end end function private.GetLocalizedTxt(ids) local str = UIUtils.GetLocalizedTxt(ids) if not str then return "" end return str end function private.ShowTips(str,type) if LogicUpdateManager.IsInReconnectFastPlay() then return end local canShow = false if TipsGrapFrame[type] == nil then canShow = true else local lastTimeFrame = private._popsTimeDic[type] if lastTimeFrame == nil then lastTimeFrame = 0 end if LogicUpdateManager._clientHandleFrame - lastTimeFrame >= TipsGrapFrame[type] then canShow = true private._popsTimeDic[type] = LogicUpdateManager._clientHandleFrame end end if canShow then EventSystem.Dispatch(EventID.UI_MainShowTips,str) end end return SyncTeamPVPLevelFunction