-- 工具脚本: 使用同步玩法的玩家数据 ,进入非同步玩法 ,自动战斗。 local BattleSimulatorBattleProfiler ={} local LogicUpdateManager = require("Battle/Logic/LogicUpdateManager") local SystemManager = require("Battle/Logic/Entity/System/SystemManager") local EntityFactory = require("Battle/Logic/EntityFactory") local LevelFunction = require("Battle/Logic/Level/LevelFunction/LevelFunction") local SyncLevelFunction = require("Battle/Logic/Level/LevelFunction/SyncLevelFunction") local private = {} local battle_common_pb = require 'Proto/battle_common_pb' local CONST_LEVEL = 188 -- 关卡ID local ReplayDataFilePath = "ReplayData/replaydata" -- 获取玩家数据的文件 local AutoFightAI = 1007 -- 自动战斗的AIID 。 LuaConst.PveRobotAIID --region 开始战斗的唯一代码入口 function BattleSimulatorBattleProfiler.StartFight(levelID, playerID, playerCount) local dataBytes = LuaExt.FileReadBytes(ReplayDataFilePath) if not dataBytes then logging.error(LTAG.ERROR, "replay data file read failed:", ReplayDataFilePath) return end local msg = battle_common_pb.ForCheckBattleAllInfo() msg:ParseFromString(dataBytes) --fake data local fakeHeroName = "ZhuGeLiang" --要使用另一份回放数据就在这里赋值,一般打一场乱世争雄获得,把主将的数据拷贝40份。 local fakeData = LuaExt.FileReadBytes(ReplayDataFilePath .. fakeHeroName) --此时需要存一份相应命名的回放文件 local fakeInfoTemp if fakeData then local fakeMsg = battle_common_pb.ForCheckBattleAllInfo() fakeMsg:ParseFromString(fakeData) local fakePlayersInfo = fakeMsg.playerInfo for _, info in ipairs(fakePlayersInfo) do local roleInfo = info.roleInfo fakeInfoTemp = roleInfo break end end --fake data end local playersInfo = msg.playerInfo LevelPlayerManager.MyPlayerIDInRoom = playerID or 1 playerCount = playerCount or 0 local roleCount = #playersInfo if playerCount > 0 and playerCount < roleCount then roleCount = playerCount end local roleList = {} local common_pb = require 'Proto/common_pb' for idx, info in ipairs(playersInfo) do local roleInfo = info.roleInfo --模拟玩家属性 -- local attrIndexAtk = LuaConst.AttrTypeId['atk'] + 1 -- for _, v in ipairs(roleInfo.battleInfo.infoForUnFair) do -- v.attr.attrs[attrIndexAtk] = 1000 -- end if roleInfo.playerID <= roleCount then roleInfo.campID = roleInfo.playerID % 2 + 1 --重新分配阵营 if fakeHeroName and fakeInfoTemp then local originDataStr = fakeInfoTemp:SerializeToString() local fakeInfo = common_pb.BattleRoomRoleInfo() --注意是battle_common_pb的子结构 fakeInfo:ParseFromString(originDataStr) fakeInfo.campID = roleInfo.campID fakeInfo.playerID = roleInfo.playerID --修改属性 local attrIndexAtk = LuaConst.AttrTypeId['atk'] + 1 for _, v in ipairs(fakeInfo.battleInfo.infoForUnFair) do v.attr.attrs[attrIndexAtk] = 1000 end table.insert(roleList, fakeInfo) else table.insert(roleList, roleInfo) end end end LevelPlayerManager.SetSyncAllPlayersArmyTable(roleList, false) -- 设置有哪些玩家 LogicUpdateManager.ResetData() private.maxBorn = nil LevelManager.SwitchLevel(levelID or CONST_LEVEL, msg.randomSeed, false, false) -- 355021 势力战中战场 , 300207 - 世界boss, 220 - 普攻关卡 , 350102 -军团boss LevelManager.CurLevelFunc.isSyncLevel = false -- 当开始战斗后 ,让cmd不从kcp获取 private.OldIsFreeToEnterAndLeaveLevel = LevelManager.IsFreeToEnterAndLeaveLevel private.oldIsFreeEnter = LevelManager.IsFreeToEnterAndLeaveLevel() -- 重定向一些函数 private.OldCreatePlayers = LevelPlayerManager.CreatePlayers LevelPlayerManager.CreatePlayers = private.CreatePlayers LevelFunction.CreatePlayers = SyncLevelFunction.CreatePlayers LevelFunction.CreatePlayerEntity = SyncLevelFunction.CreatePlayerEntity LevelFunction.GetBornItem = SyncLevelFunction.GetBornItem LevelFunction.OnPlayerAllHeroDead = SyncLevelFunction.OnPlayerAllHeroDead LevelFunction.ReviveTimeIsUp = SyncLevelFunction.ReviveTimeIsUp LevelFunction.OnSetCurEntity = SyncLevelFunction.OnSetCurEntity LevelFunction.GetReviveTime = private.GetReviveTime LevelFunction.IsAutoUseMusou = private.IsAutoUseMusou LevelManager.IsShowHeroLifeBarLevel = private.IsShowHeroLifeBarLevel LevelManager.IsFreeToEnterAndLeaveLevel = function() return false end -- 全部为同时进入玩法 private.OldGetBornItem = LevelItemManager.GetBornItem LevelItemManager.GetBornItem = private.GetBornItem MDL.Unlock.IsUnlock = function() return true end CTL.ChannelChat.IsCanOpenGuildWarVoice = function() return false end private.OldUpdateLoading = LevelManager.OnUpdateLoading LevelManager.OnUpdateLoading = private.OnUpdateLoading end --endregion 开始战斗的唯一代码入口 --region 重定向的特殊代码 function private.CreatePlayers(pos,dir) LevelManager.CurLevelFunc.isFreeToEnterAndLeave = false --默认不是随进随出 LevelManager.CurLevelFunc:CreatePlayers(pos,dir) MultiplayManager.SetAllRolesActive() -- 显示 for i,entity in ipairs(LogicUpdateManager.EntityList_Sync) do -- 开启自动战斗 if entity and entity:GetPlayerID() ~= LevelPlayerManager.MyPlayerIDInRoom then SystemManager.StartAutoFight(entity) entity.components.autoFight:StartPveAutoFight() -- 加这句代码目的:syncLevel玩法开启的话,由于isSyncLevel 设置为了 false,导致不能自动战斗。 end end --恢复部分重定向 LevelPlayerManager.CreatePlayers = private.OldCreatePlayers LevelItemManager.GetBornItem = private.OldGetBornItem end function private.GetBornItem(index) if private.maxBorn == nil then private.maxBorn = LevelItemManager.GetItemCountByType(LuaConst.LevelItemType.BornPoint) end local item if private.oldIsFreeEnter then -- 随进随出的玩法出生规则 local playerInfo = LevelPlayerManager.GetPlayerInfoByPlayerIDInRoom(index) -- 一般认为index ==playerID local bornIndex = LevelManager.CurLevelFunc:GetBornIndex(playerInfo) if bornIndex == 0 then bornIndex = LevelManager.bornPointCount end item = private.OldGetBornItem(bornIndex) else -- 一起出生的规则 if index > private.maxBorn then index = math.random(1, private.maxBorn) end item = private.OldGetBornItem(index) end return item end function private.OnUpdateLoading() private.OldUpdateLoading() if LevelManager._levelLogicData.LogicLoadingStep == LuaConst.Enum_LoadingStep.EnterLevel then LevelManager.IsFreeToEnterAndLeaveLevel = private.OldIsFreeToEnterAndLeaveLevel LevelManager.OnUpdateLoading = private.OldUpdateLoading end end function private.IsAutoUseMusou() return true end function private.IsShowHeroLifeBarLevel() return true end function private.GetReviveTime() return 5000 end --endregion 重定向的特殊代码 function BattleSimulatorBattleProfiler.GuildWarResetPos() -- 势力战中战场设置位置的测试代码 local camp1Pos = FP.newV2(-150, 140) local camp2Pos = FP.newV2(-150, 170) for i,entity in ipairs(LogicUpdateManager.EntityList_Sync) do if entity:IsActive() then entity.components.move:SetLogicPos( entity:GetCampID() == 1 and camp1Pos or camp2Pos) end end end return BattleSimulatorBattleProfiler