local Base = require("Battle/Logic/Level/LevelFunction/SyncSoloLevelFunction") local SyncFairSoloTournamentLevelFunction = class("SyncFairSoloTournamentLevelFunction",Base) local EventSystem = require('Event/EventSystem') local tournament_pb = require 'Proto/fair_tournament_opt_pb' local ELevelWaitingPhase = LuaConst.ELevelWaitingPhase local Const_WaitOthersFrame = DataSheetManager.ConstData:GetDataByID("FairTournamenTVTWaitTime").IntValue * LuaConst.LogicFrameRate local CampID1 = 1 local CampID2 = 2 function SyncFairSoloTournamentLevelFunction:BeginLevel() self.forceWaitOtherPlayerPhase = true -- 需要等他人进入 Base.BeginLevel(self) self.dontStartAutoFightWhenPlayerOffline = false -- 首次进入时掉线 ,也开启自动战斗 if MultiplayManager.IsFromStartEnter then MultiplayManager.SetAllRolesActive() -- 这个只是作为父类的补充。 实际代码是:不应该有 IsFromStartEnter 判断 ,都要调用MultiplayManager.SetAllRolesActive() . 但是为了防止重复执行故加了判断。 end -- 修改战斗时长 local battleTime = DataSheetManager.FairMatchTime:GetDataByID(LevelManager.GetMatchStage()).BattleTime -- 单位秒 LevelItemManager.Global:DoAction(LuaConst.LevelActionType.Global_SetRemainTime, nil, battleTime) NetManager.OpenLog = false logging.crit(LTAG.NET, "CloseLog") end function SyncFairSoloTournamentLevelFunction:GetWaitingOtherPlayerMaxFrame() return Const_WaitOthersFrame end function SyncFairSoloTournamentLevelFunction:ChangeWaitingPhase(newPhase) -- 不要用base 。策划要求等人时,关卡时间继续倒计时 if self.curWaitingPhase ~= newPhase then if newPhase == ELevelWaitingPhase.WAITING_OTHER_PLAYER then --LevelItemManager.Global:Notify_WaitOtherPlayer_WaitStart() elseif newPhase == ELevelWaitingPhase.COUNT_DOWN then self:DispatchCountdown(self.syncWaitingCountDownFrame / 20) LevelItemManager.Global:Notify_WaitOtherPlayer_CountdownStart() elseif newPhase == ELevelWaitingPhase.WAIT_OVER then self:BeforeWaitFinish(self.curWaitingPhase) LevelItemManager.Global:Notify_WaitOtherPlayer_WaitFinished() end self.curWaitingPhaseFrameEla = 0 self.curWaitingPhase = newPhase else logging.error(LTAG.ERROR, "GWS : 试图重复改变waitingPhase!(无害提示,程序用)") end end function SyncFairSoloTournamentLevelFunction:OnOffLine(playerID) Base.OnOffLine(self,playerID) local entitys = LevelPlayerManager.GetPlayerEntitysByPlayerIDInRoom(playerID) if entitys then SystemManager.StartAutoFight(entitys[1], true) end end function SyncFairSoloTournamentLevelFunction:SendBattleResult(quitRoomEntity) local checkStr = self:GetBattleResultCheckStr() if LevelManager.IsInLevelWatchBattle() then -- 观战不发结算 self.watchCheckStr = checkStr return end local msg = tournament_pb.C2GUploadFairTournamentBattleResult() for _,playerID in ipairs(LevelPlayerManager.SyncPlayerIDList) do local campID = LevelPlayerManager.GetCampIDByPlayerIDInRoom(playerID) if campID == CampID1 then msg.camp1PlayerId = playerID end if campID == CampID2 then msg.camp2PlayerId = playerID end end self.playerID2DeadHeroDic = {} --key是playerID, value是一个list,记录了这个玩家死过的英雄id, 用来给外部查询 self:FillFighterRecords(msg.camp1, msg.camp1PlayerId) self:FillFighterRecords(msg.camp2, msg.camp2PlayerId) msg.checkInfo = checkStr msg.passTime = math.floor(LogicUpdateManager._clientHandleFrame * LuaConst.TimeSpan) -- 时间:秒(和结算界面显示的要一致) if quitRoomEntity then --如果有人中途就退出了,视为投降,直接判负 local quitCampID = LevelPlayerManager.GetCampIDByPlayerIDInRoom(quitRoomEntity:GetPlayerID()) msg.winnerCampId = quitCampID == 1 and 2 or 1 else if msg.camp2.leftTotalHp >= 3 and msg.camp1.leftTotalHp >= 3 then msg.winnerCampId = 1 --双方都满血,不能算作双方都失败( 随机一个胜利) else if msg.camp1.aliveHero == msg.camp2.aliveHero then --如果存活武将数量相等,判断血量 if msg.camp1.leftTotalHp == msg.camp2.leftTotalHp then --如果两个玩家最后血量相等,比较伤害量 local dmgDelta = 0 for i,dmg in ipairs(msg.camp1.damage) do dmgDelta = dmgDelta + dmg end for i,dmg in ipairs(msg.camp2.damage) do dmgDelta = dmgDelta - dmg end if dmgDelta ~= 0 then if dmgDelta > 0 then msg.winnerCampId = CampID1 elseif dmgDelta then msg.winnerCampId = CampID2 end else --如果两个玩家最后血量相等、伤害量相等,算camp1胜利(实际就是随机) msg.winnerCampId = 1 end else msg.winnerCampId = msg.camp1.leftTotalHp > msg.camp2.leftTotalHp and CampID1 or CampID2 end else --如果存活武将数量不相等,直接判断存活武将数量 msg.winnerCampId = msg.camp1.aliveHero > msg.camp2.aliveHero and CampID1 or CampID2 end end end self.winnerCampId = msg.winnerCampId --存起来方便其他地方查询 if USE_LUA_STANDALONE then -- 服务器校验时 ,需要的字符串要设置好 BattleSimulator.SetCheckResult(msg.checkInfo, msg:SerializeToString()) end if LogicUpdateManager.IsReplayOrServerCheck then -- 客户端重播或服务器校验的话,不要发送TCP logging.log(LTAG.LOG, "[GWS]SoloTournament BattleCheckStr = :",msg.checkInfo) BattleSimulator.EndPlay() if LevelManager.IsReplayBattle() then return end end EventSystem.Dispatch(EventID.SyncSoloTournament_BattleResult,msg) end return SyncFairSoloTournamentLevelFunction