--1v1异步竞技场,是单机关卡 local EventSystem = require('Event/EventSystem') local Base = require("Battle/Logic/Level/LevelFunction/LevelFunction") local SoloFightLevelFunction = class("SoloFightLevelFunction",Base) local private = {} local SA_SPEED_UP_BUFF = 500088 --无双值获取加速buff local round = 0 -- 回合数 local battleTime = 0 local enemyGS = {} local myGS = {} --用服务器发过来的数据构造一组hero单位,army是LevelPlayerManager的private.CreatArmy的返回值 function SoloFightLevelFunction:CreateEnemyPlayersByServerArmy(army,pos,dir,bornItemID,playerID) enemyGS = {} local heroEntityTable = {} --计算战力 for i,v in ipairs(army) do enemyGS[v.HeroID] = v.heroGs or 0 end local playerInfo = LevelPlayerManager.GetPlayerInfoByPlayerIDInRoom(LuaConst.STANDALONE_ENEMYPLAYER1_PLAYID) for i,v in ipairs(army) do EntityFactory.SetParams("BornItemID", bornItemID, "InitHP", v.HP, "Name", playerInfo.name) EntityFactory.SetParams("CampID", LuaConst.STANDALONE_ENEMY_CAMP) EntityFactory.SetParams("StratagemSkill", playerInfo.stratagemSkill) EntityFactory.SetType_ID(LuaConst.CharacterType.Hero, v.HeroID) EntityFactory.SetAttrTable_ID(v.Attr) EntityFactory.SetPos_Dir(pos, dir) EntityFactory.SetSelf_Sync(false, false) EntityFactory.SetEffectBreak_Weapon(v.mainHeroBreakNums,v.isMagicWeaponActive,v.mainHeroWeaponLevels) EntityFactory.SetHorse_ID(v.horseID, v.horseAppearanceId) EntityFactory.SetPet_Info(v.petInfo.petId, v.petInfo.stage, v.petInfo.petName, v.petInfo.petSkill) EntityFactory.SetHeroAppearance_ID(v.heroAppearanceId) EntityFactory.SetWeaponAppearance_ID(v.weaponAppearanceId) EntityFactory.SetDyeAppearanceList(v.mainDyeCurPartList) EntityFactory.SetLightEffect_ID(v.lightEffectIds) EntityFactory.SetWeaponSoulInfo(v.weaponSoulInfo) EntityFactory.SetParams("PlayerID", playerID) local entity = EntityFactory.DoCreatePlayerEntity() --entity._logicInitData.PlayerIDInRoom = playerID entity._logicInitData.OfficialPosition = playerInfo.officialPosition entity:SetGs(self:GetGsByArmyData(v.heroGs, v)) table.insert(heroEntityTable,entity) local adjutantID = v.AdjutantID if adjutantID and adjutantID > 0 then EntityFactory.SetType_ID(LuaConst.CharacterType.Adjutant, adjutantID) EntityFactory.SetAttrTable_ID(v.Attr) EntityFactory.SetEffectBreak_Weapon(v.viceHeroBreakNums,v.isViceMagicWeaponActive,v.viceHeroWeaponLevels) EntityFactory.SetHeroAppearance_ID(v.viceHeroAppearanceId) EntityFactory.SetWeaponAppearance_ID(v.viceWeaponAppearanceId) EntityFactory.SetDyeAppearanceList(v.viceDyeCurPartList) EntityFactory.DoCreateAdjutantEntity(entity) end end self:TryAddPlayerBuff(LuaConst.STANDALONE_ENEMYPLAYER1_PLAYID) LevelPlayerManager.SetPlayerEntityTable(heroEntityTable ,playerID) local entities = LevelPlayerManager.GetPlayerEntitysByPlayerIDInRoom(playerID) SystemManager.SetCameraTarget(entities[1]) end function SoloFightLevelFunction:InitLevel() Base.InitLevel(self) self.myPoint = 0 self.enemyPoint = 0 self.isSwitching = false self.newlyDeadHero = nil self.deadFlagDic = {} --key是entityID,value是bool值用来标记是否死亡过,这个数据仅用作log end --armyData是LevelPlayerManager.GetPlayerArmyByPlayerIDInRoom返回的list里的元素 function SoloFightLevelFunction:GetGsByArmyData(wholeArmyGs, armyData) return armyData.heroGs end function SoloFightLevelFunction:GetLevelAutoFightInitRule() --不调用base return LuaConst.ELevelAutoFightInitRule.OPEN end function SoloFightLevelFunction:CreatePlayers(pos,dir) Base.CreatePlayers(self,dir) self:CreateEnemyHeroes() local myArmy = LevelPlayerManager.GetPlayerArmyByPlayerIDInRoom(LuaConst.STANDALONE_PLAYER_PlayID) myGS = {} for i,v in ipairs(myArmy) do myGS[v.HeroID] = v.heroGs or 0 end --给所有单位添加无双值加速获取buff local entities = LevelPlayerManager.GetPlayerEntitysByPlayerIDInRoom(LuaConst.STANDALONE_ENEMYPLAYER1_PLAYID) if entities then for i,entity in ipairs(entities) do SystemManager.AddBuff(entity,SA_SPEED_UP_BUFF,entity) end else logging.error(LTAG.ERROR, "HYW : 致命错误!敌人entities为空! @SoloFightLevelFunction:CreatePlayers") end entities = LevelPlayerManager.GetPlayerEntitysByPlayerIDInRoom(LuaConst.STANDALONE_PLAYER_PlayID) for i,entity in ipairs(entities) do SystemManager.AddBuff(entity,SA_SPEED_UP_BUFF,entity) end EventSystem.Dispatch(EventID.Battle_Solofight_CreateHeroFinished) end function SoloFightLevelFunction:GetRobotAI(entity) return LuaConst.SoloFightAIID end --创建敌方玩家的英雄 function SoloFightLevelFunction:CreateEnemyHeroes(pos,dir) repeat local enemyArmy = LevelPlayerManager.GetPlayerArmyByPlayerIDInRoom(LuaConst.STANDALONE_ENEMYPLAYER1_PLAYID) if not enemyArmy then logging.error(LTAG.ERROR, "HYW : enemyArmy nil Error @SoloFightLevelFunction:CreateEnemyHeroes!!") break end local bornItem = self:GetBornItemByIndex(2) if not bornItem then logging.error(LTAG.ERROR, "HYW : bornItem nil Error @SoloFightLevelFunction:CreateEnemyHeroes!!") break end -- new↓ 支持 固定/范围随机 位置出生 if not pos then pos = LogicRandom.GetRandomPointInLevelItem(nil, bornItem.ItemData, 8238236) end -- new↑ -- old↓-- 固定位置出生 --pos = pos or bornItem.ItemData.ItemPos -- old↑ dir = dir or bornItem.ItemData.ItemDir self.enemeyBornPos = pos self.enemyBornDir = dir self:CreateEnemyPlayersByServerArmy(enemyArmy,self.enemeyBornPos,self.enemyBornDir,bornItem.LevelItemID,LuaConst.STANDALONE_ENEMYPLAYER1_PLAYID) local firstEntity = BattleDataGetter.GetHeroInHeroEntityTableByIndex(LuaConst.STANDALONE_ENEMYPLAYER1_PLAYID,1) SystemManager.Active(firstEntity) until true end function SoloFightLevelFunction:BeginLevel() Base.BeginLevel(self) --设置AI local entityTable = LevelPlayerManager.GetPlayerEntitysByPlayerIDInRoom(LuaConst.STANDALONE_ENEMYPLAYER1_PLAYID) if entityTable then for i,entity in ipairs(entityTable) do entity.components.autoFight:StartPveAutoFight() SystemManager.SetAIByID(entity,LevelManager.GetRobotAI(entity)) end else logging.error(LTAG.ERROR, "HYW : 致命错误!敌人entityTable为空! @SoloFightLevelFunction:BeginLevel") end --BIlog round = 0 battleTime = 0 private.SendBILog(true) end function SoloFightLevelFunction:OnEntityDead(entity) Base.OnEntityDead(self, entity) if not self.isSwitching then if entity:GetCharacterType() == LuaConst.CharacterType.Hero then --仅处理Hero的 if self.deadFlagDic[entity.EntityID] then logging.error(LTAG.ERROR, "HYW : 已经死过了,又死一次 @SoloFightLevelFunction:OnEntityDead") else self.deadFlagDic[entity.EntityID] = true end private.SendBILog(false , entity) self.newlyDeadHero = entity --刷新积分 self:RefreshPoint(entity) if self:ShouldFinish() then self:_LevelFinish() else local alldead,firstAliveIndex = LevelPlayerManager.IsAllDead(entity) if alldead then self:_LevelFinish() else for i,_entity in LogicUpdateManager.ValidMonsterEntityIter() do --清理所有怪 SystemManager.DeadQuit(_entity) end EventSystem.Dispatch(EventID.Battle_Solofight_HeroDead,entity) --self:SwitchStart(firstAliveIndex) --现在由UI调了 end end end end end function SoloFightLevelFunction:OnPlayerOneHeroDead(entity) -- 不用base ,需要特殊的处理 end function SoloFightLevelFunction:RefreshPoint(deadEntity) if deadEntity._logicInitData.PlayerIDInRoom == LuaConst.STANDALONE_PLAYER_PlayID then self.enemyPoint = self.enemyPoint + 1 else self.myPoint = self.myPoint + 1 end end function SoloFightLevelFunction:ShouldFinish() return self.myPoint >= 2 or self.enemyPoint >= 2 end function SoloFightLevelFunction:SwitchHeroStart() self.isSwitching = true local alldead,firstAliveIndex = LevelPlayerManager.IsAllDead(self.newlyDeadHero) self:DelaySwitchHero(firstAliveIndex,1) end function SoloFightLevelFunction:DelaySwitchHero(index,delayFrame) LevelManager.AddTimer(function() --干掉所有active的hero LevelPlayerManager.KillAllActiveHero() LevelPlayerManager.SwitchHero(LuaConst.STANDALONE_PLAYER_PlayID,index,true) LevelPlayerManager.SwitchHero(LuaConst.STANDALONE_ENEMYPLAYER1_PLAYID,index,true) self:SwitchFinish() end,delayFrame) end function SoloFightLevelFunction:SwitchFinish() local entities = LevelPlayerManager.GetPlayerEntitysByPlayerIDInRoom(LuaConst.STANDALONE_PLAYER_PlayID) for i,entity in ipairs(entities) do if entity:IsActive() then SystemManager.OnConvey(entity,self.bornPos,self.bornDir) SystemManager.ClearStratagemCD(entity) break end end entities = LevelPlayerManager.GetPlayerEntitysByPlayerIDInRoom(LuaConst.STANDALONE_ENEMYPLAYER1_PLAYID) if entities then for i,entity in ipairs(entities) do if entity:IsActive() then SystemManager.OnConvey(entity,self.enemeyBornPos,self.enemyBornDir) SystemManager.SetCameraTarget(entity) SystemManager.ClearStratagemCD(entity) break end end else logging.error(LTAG.ERROR, "GWS : SoloFight 没有发现敌人的entity,太奇怪啦!") end EventSystem.Dispatch(EventID.Battle_Solofight_HeroSwitched) self.isSwitching = false --BIlog private.SendBILog(true ) end function SoloFightLevelFunction:ShouldShowVictoryPose() return false end --该方法并非标准生命周期函数,是本关卡模式特有的业务逻辑 function SoloFightLevelFunction:_LevelFinish() LevelManager.AddSummaryTime(LevelItemManager.Global:GetPassTime()) --这个玩法得自己设置一下,不然拿不到SummeryTime if self.myPoint > self.enemyPoint then LevelItemManager.Global:DoAction(LuaConst.LevelActionType.Global_LevelSucceed) EventSystem.Dispatch(EventID.Battle_Solofight_Win) --elseif self.myPoint == self.enemyPoint then else self.isNoTimeOut = true LevelItemManager.Global:DoAction(LuaConst.LevelActionType.Global_LevelFail) end end function SoloFightLevelFunction:OnLevelFail() Base.OnLevelFail(self) EventSystem.Dispatch(EventID.Battle_Solofight_Fail, self.isNoTimeOut) end function private.SendBILog(isStart ,overEntity) local myentity = LogicUpdateManager._curEntity if myentity.components.adjutant.AdjutantEntity then local lineHeroID = {tostring(myentity:GetOriginCharacterData().ID) , tostring(myentity.components.adjutant.AdjutantEntity:GetOriginCharacterData().ID)} local myHeroGS = myGS[myentity:GetOriginCharacterData().ID] local enemyEntityTable = LevelPlayerManager.GetPlayerEntitysByPlayerIDInRoom(LuaConst.STANDALONE_ENEMYPLAYER1_PLAYID) if enemyEntityTable then local enemyEntity = enemyEntityTable[1] local enemyHeroID = {tostring(enemyEntity:GetOriginCharacterData().ID) , tostring(enemyEntity.components.adjutant.AdjutantEntity:GetOriginCharacterData().ID)} local enemyHeroGS = enemyGS[enemyEntity:GetOriginCharacterData().ID] local isWin = 0 local winHerosHP = 0 local btime = 0 if isStart then round = round + 1 else btime = math.floor( (LogicUpdateManager._clientHandleFrame - battleTime) * LuaConst.TimeSpan ) battleTime = LogicUpdateManager._clientHandleFrame --死亡的是我自己 if overEntity == LogicUpdateManager._curEntity then isWin = 0 winHerosHP = FP.tonumberV1(enemyEntity.components.attr:HitPointPercents()) else isWin = 1 winHerosHP = FP.tonumberV1(LogicUpdateManager._curEntity.components.attr:HitPointPercents()) end end EventSystem.Dispatch(EventID.BI_LevelHigh,BIManager.BIType.OffLine1v1,round , 0, lineHeroID,myHeroGS,enemyHeroID ,enemyHeroGS,isStart,winHerosHP,btime ,isWin) else logging.error(LTAG.ERROR, "HYW : 致命错误!敌人enemyEntityTable为空! @SoloFightLevelFunction:SendBILog") end else logging.error(LTAG.ERROR, "HYW : 副将为空 估计是出Bug了@SoloFightLevelFunction的private.SendBILog。 当前LevelType : ", LevelManager.GetCurLevelType()) end end return SoloFightLevelFunction