local BattleSimulatorAutoFight ={} 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 AttrComponent = require "Battle/Logic/Entity/Component/AttrComponent" local LuaUpdater = require "Main/LuaUpdater" local private = { timeLines = {} } local NilFunc = function() end ------------------------↓通跑关卡的代码 ↓--------------------- --要跑的所有关卡 local levels = { -- 第一章 1001,1011,1041, 101011,101041, 201011,201041, -- 第二章202031,102031, 2011,2012,2031,2041,2051,2061,2062, 102011,102012,102031,102041,102051,102061,102062, 202011,202012,202031,202041,202051,202061,202062, -- 第三章 3011,3021,3041,3051,3061,3071,3081, 103011,103021,103041,103051,103061,103071,103081, 203011,203021,203041,203051,203061,203071,203081, -- 第四章 4011,4021,4031,4041,4051,4061,4071,4081,4091,4101, 104011,104021,104031,104041,104051,104061,104071,104081,104091,104101, 204011,204021,204031,204041,204051,204061,204071,204081,204091,204101, -- 第五章 5011,5021,5031,5041,5051,5061,5071,5081,5091,5101, 105011,105021,105031,105041,105051,105061,105071,105081,105091,105101, 205011,205021,205031,205041,205051,205061,205071,205081,205091,5101, -- 第六章 6011,6021,6031,6041,6051,6061,6071,6081,6091,6101, 106011,106021,106031,106041,106051,106061,106071,106081,106091,106101, 206011,206021,206031,206041,206051,206061,206071,206081,206091,206101, -- 第七章 7011,7021,7031,7041,7051,7061,7071,7081,7091,7101, 107011,107021,107031,107041,107051,107061,107071,107081,107091,107101, 207011,207021,207031,207041,207051,207061,207071,207081,207091,207101, -- 第八章 8011,8021,8031,8041,8051,8061,8071,8081,8091,8101, 108011,108021,108031,108041,108051,108061,108071,108081,108091,108101, 208011,208021,208031,208041,208051,208061,208071,208081,208091,208101, -- 第九章 9011,9021,9031,9041,9051,9061,9071,9081,9091,9101, 109011,109021,109031,109041,109051,109061,109071,109081,109091,109101, 209011,209021,209031,209041,209051,209061,209071,209081,209091,209101, } --跑关卡用到的布阵 local heros = { 1,2,3,4,5,6 } local Level_HeroAttr = 125 -- 玩家属性 local Level_BossAttrID = 1000008 -- boss的属性 local Level_MonsterAttrID = 1000001 --小兵的属性 local Level_MaxRunTime = 8400 -- 最长跑关卡时间 function BattleSimulatorAutoFight.SetAutoRunLevelConfig(levelList,heroList,heroAttr,bossAttrID,monsterAttrID,maxRunTime) levels = levelList heros = heroList Level_HeroAttr = heroAttr Level_BossAttrID = bossAttrID Level_MonsterAttrID = monsterAttrID Level_MaxRunTime = maxRunTime * 1200 end --装入Redirect中,目的是防止随意require这个脚本导致一些错误 function BattleSimulatorAutoFight.Redirect() private.DoCreateEntity = EntityFactory.DoCreateEntity --记录下原始的方法 -- 怪物的创建,武将是不会使用这个的 EntityFactory.DoCreateEntity = function() local entity = private.DoCreateEntity() -- 可再此修改属性 if entity:IsBoss() then entity.components.attr = AttrComponent:new(entity, nil, Level_BossAttrID) else entity.components.attr = AttrComponent:new(entity, nil, Level_MonsterAttrID) end return entity end -- 关卡开始,则自动战斗 private.LevelFuncBeginLevel = LevelFunction.BeginLevel --记录原始的方法 LevelFunction.BeginLevel = function(self) private.LevelFuncBeginLevel(self) NotSyncBattleSetter.SwitchPveAutoFightState() end -- 关卡结束,则自动下一关战斗 private.OnLevelSucceed = LevelFunction.OnLevelSucceed LevelFunction.OnLevelSucceed = function(self) self.exp.OnLevelSucceed = NilFunc private.OnLevelSucceed(self) BattleSimulatorAutoFight.CanGotoNext = true end if USE_LUA_STANDALONE then -- 在校验程序中需要特殊的处理 SystemManager.PlayTimeline = function(path, pauseLevel, autoPassTime, callback, sourceFlag, duration) local overFrame = LogicUpdateManager._clientHandleFrame + duration * LuaConst.LogicFrameRate table.insert(private.timeLines,{overFrame,callback,path} ) end -- 重写播放TL private.OnLogicUpdate = LogicUpdateManager.OnLogicUpdate LogicUpdateManager.OnLogicUpdate = function(deltaTime, timeSinceUpdate) private.OnLogicUpdate(deltaTime, timeSinceUpdate) local tlCount = #private.timeLines for i = tlCount,1,-1 do local tl = private.timeLines[i] if LogicUpdateManager._clientHandleFrame >= tl[1] then tl[2](tl[3], 0, false) -- callback(path, 0, false) table.remove(private.timeLines,i) end end BattleSimulatorAutoFight.OnLogicUpdate() end end end --更新 function BattleSimulatorAutoFight.OnLogicUpdate() if BattleSimulatorAutoFight.CanGotoNext then BattleSimulatorAutoFight.CanGotoNext = nil private.EndOneLevelFight() end if LogicUpdateManager._clientHandleFrame >= Level_MaxRunTime then logging.log(LTAG.LOG, "--------[gws] 自动跑关卡超时! :",levels[BattleSimulatorAutoFight.curLevelIndex],"---------------") BattleSimulatorAutoFight.curLevelIndex = #levels BattleSimulatorAutoFight.finish = true end end --开始的接口 function BattleSimulatorAutoFight.RunLevels() BattleSimulatorAutoFight.Redirect() LuaUpdater.StartFixedUpdate(BattleSimulatorAutoFight.OnLogicUpdate) BattleSimulatorAutoFight.curLevelIndex = 1 private.StartOneLevelFight() if USE_LUA_STANDALONE then LogicUpdateManager.IsAutoCheckLevel = true while not BattleSimulatorAutoFight.finish do --逻辑模拟循环 LogicUpdateManager.OnLogicUpdate(0.05) end end return 0 end function private.StartOneLevelFight() private.timeLines = {} logging.log(LTAG.LOG, "--------[gws] 开始自动跑关卡 :",levels[BattleSimulatorAutoFight.curLevelIndex],"---------------") private.SetHeroTable(heros, Level_HeroAttr, 1) LevelManager.SwitchLevel(levels[BattleSimulatorAutoFight.curLevelIndex]) end function private.EndOneLevelFight() BattleSimulatorAutoFight.curLevelIndex = BattleSimulatorAutoFight.curLevelIndex + 1 if BattleSimulatorAutoFight.curLevelIndex > #levels then logging.log(LTAG.LOG, "[gws]自动跑任务完成! ") LuaUpdater.StopFixedUpdate(BattleSimulatorAutoFight.OnLogicUpdate) BattleSimulatorAutoFight.finish = true else private.StartOneLevelFight() end end ------------------------↑通跑关卡的代码 ↑--------------------- ------------------------↓武将机制测试↓------------------------ local PVPConfig = { levelID = 201, --测试武将之间的战斗用的关卡 heroNumber = 30, --能上场的武将数量 heroAttr = {Group = 2,Difficulty = 1}, --玩家的属性 bossEvent = {bornFrame = 100, monsterID = 992, posX = 224, posZ = 240, Group = 2}, -- 第多少帧出生一个怪物 ;Group 就是属性表的值,难度一定是1 enemy = --敌人信息 { {}, {}, }, } function BattleSimulatorAutoFight.RunHeroFight() private.lastPVPCount = 0 BattleSimulatorAutoFight.StartPVPFight() end function BattleSimulatorAutoFight.StartPVPFight() private.SetHeroTable(private.Get6Hero(), PVPConfig.heroAttr.Group, PVPConfig.heroAttr.Difficulty) LevelManager.SwitchLevel(PVPConfig.levelID) end function BattleSimulatorAutoFight.EndPVPFight() end ------------------------↑ 武将机制测试 ↑------------------------ ------------------------ 以下为通用代码 ------------------ function private.SetHeroTable(heros, groupID, difficulty) LevelPlayerManager.BeforeStorePlayerInfo() local army = {} for i = 1, 3 do local heroArmyData = {} heroArmyData.HeroID = heros[i*2-1] heroArmyData.AdjutantID = heros[i*2] heroArmyData.mainHeroMusouSkillId = 1 heroArmyData.viceHeroMusouSkillId = 1 heroArmyData.horseID = 1 heroArmyData.Attr = {} local monsterValue = DataSheetManager.MonsterValueData:GetDataByGroupID_Difficulty(groupID,difficulty) if monsterValue then local value = nil for i,attrName in ipairs(LuaConst.AttrIntType) do value = monsterValue[attrName] if value then table.insert(heroArmyData.Attr , value ) else table.insert(heroArmyData.Attr, 0) end end end local pos = (i -1) * 2 -- 左中右 军 LevelPlayerManager.SetPlayerArmyPosInfo(LevelPlayerManager.MyPlayerIDInRoom ,heroArmyData.HeroID,pos) LevelPlayerManager.SetPlayerArmyPosInfo(LevelPlayerManager.MyPlayerIDInRoom ,heroArmyData.AdjutantID,pos + 1) table.insert(army,heroArmyData) end LevelPlayerManager.MainEntityCampID = LuaConst.STANDALONE_PLAYER_CAMP LevelPlayerManager.MyPlayerIDInRoom = LuaConst.STANDALONE_PLAYER_PlayID LevelPlayerManager.PlayersArmyTable[LuaConst.STANDALONE_PLAYER_PlayID] = { playerInfo = {name = "test" ,setting = {[1] = true ,}} ,army = army } end function private.Get6Hero() local h1,h2,h3,h4,h5,h6 local count = 0 for i1 = 1,PVPConfig.heroNumber do h1 = i1 for i2 = 1,PVPConfig.heroNumber do if h1 ~= i2 then h2 = i2 for i3 = 1,PVPConfig.heroNumber do if h1 ~= i3 and h2 ~= i3 then h3 = i3 for i4 = 1,PVPConfig.heroNumber do if h3 ~= i4 and h2 ~= i4 and h1 ~= i4 then h4 = i4 for i5 = 1,PVPConfig.heroNumber do if h4 ~= i5 and h3 ~= i5 and h2 ~= i5 and h2 ~= i5 and h1 ~= i5 then h5 = i5 for i6 = 1,PVPConfig.heroNumber do if h5 ~= i6 and h4 ~= i6 and h3 ~= i6 and h2 ~= i6 and h2 ~= i6 and h1 ~= i6 then h6 = i6 count = count + 1 if count > private.lastPVPCount then private.lastPVPCount = count return {h1,h2,h3,h4,h5,h6} end end end end end end end end end end end end return h1,h2,h3,h4,h5,h6 end -- 加怪 function BattleSimulatorAutoFight.OnUpdate() if LogicUpdateManager._clientHandleFrame == PVPConfig.bossEvent.bornFrame then SystemManager.CreateMonster(PVPConfig.bossEvent.monsterID, PVPConfig.bossEvent.posX, PVPConfig.bossEvent.posZ, nil, nil, PVPConfig.bossEvent.Group) end end return BattleSimulatorAutoFight