local WorldBossAutoTest = { Enable = false , } local private = {} local markCount = 0 local lasttime = 0 --一致性测试的自动化工具的部分代码 function WorldBossAutoTest.TryAutoEnterWorldBoss() -- 在主城的时候,每40秒检测一次能进入的世界boss,并且进入 if LevelManager.IsTown and LogicUpdateManager._clientHandleFrame > 0 and LogicUpdateManager._clientHandleFrame % 800 == 0 then if Time.time - lasttime > 10 then CTL.WorldBoss.ForceNextBoss() markCount = markCount + 1 print("自动进入到世界boss ,次数:" ,markCount) lasttime = Time.time end end end function WorldBossAutoTest.GetCommand() if not WorldBossAutoTest.Enable then return end if LogicUpdateManager._curEntity then --pvp 自动战斗脚本,客户端本地脚本,一致性测试 LuaInputManager.FixVirtualMoveDir:Reset() local entity = LogicUpdateManager._curEntity if entity.components.autoFight.IsSyncAuto then if LogicUpdateManager._clientHandleFrame % 700 == 0 then --LuaInputManager.SpecialCommand = LuaConst.SpecialCommandType.AutoFight LuaInputManager.SetSpecialCommand(LuaConst.SpecialCommandType.AutoFight) print("取消自动战斗") end return end -- 随机换人一分钟 if LogicUpdateManager._clientHandleFrame % 1300 == 0 then local ran = math.random(2,3) local entityList = BattleDataGetter.GetMyHeroEntityTable() if ran == 2 and entityList[2] and entityList[2]:IsAlive() then --LuaInputManager.SpecialCommand = LuaConst.SpecialCommandType.SwitchHeroToIndex2 LuaInputManager.SetSpecialCommand(LuaConst.SpecialCommandType.SwitchHeroToIndex2) elseif entityList[3] and entityList[3]:IsAlive() then --LuaInputManager.SpecialCommand = LuaConst.SpecialCommandType.SwitchHeroToIndex3 LuaInputManager.SetSpecialCommand(LuaConst.SpecialCommandType.SwitchHeroToIndex3) end print("换人") return end --设置攻击模式 if LogicUpdateManager._clientHandleFrame % 800 == 0 then --LuaInputManager.SpecialCommand = LuaConst.SpecialCommandType.SwitchFightMode LuaInputManager.SetSpecialCommand(LuaConst.SpecialCommandType.SwitchFightMode) print("设置攻击模式") return end --设置攻击的人 if LogicUpdateManager._clientHandleFrame % 1100 == 0 then local selectList = {} local infoList = BattleDataGetter.GetDamageList() for i,info in ipairs(infoList) do if info.playerID ~= LevelPlayerManager.MyPlayerIDInRoom then table.insert(selectList,i) end end if #selectList > 0 then local ran = math.random(1,#selectList) --LuaInputManager.SpecialCommand = LuaConst.SpecialCommandType.SetForceTargetOfIndexStart + selectList[ran] -1 LuaInputManager.SetSpecialCommand(LuaConst.SpecialCommandType.SetForceTargetOfIndexStart + selectList[ran] -1) print("设置攻击的人--:" ,LuaInputManager.SpecialCommand) end return end --设置自动战斗 if LogicUpdateManager._clientHandleFrame % 1400 == 0 then --LuaInputManager.SpecialCommand = LuaConst.SpecialCommandType.AutoFight LuaInputManager.SetSpecialCommand(LuaConst.SpecialCommandType.AutoFight) print("设置自动战斗") return end -- 追击目标 local forceTarget = nil local targetComponent = entity.components.target local entities = LevelPlayerManager.GetPlayerEntitysByPlayerIDInRoom(targetComponent.forcePlayerID) if entities and entities[1] and entities[1]:IsAlive() and entities[1]:IsActive() then forceTarget = entities[1] end if forceTarget == nil then --查找boss for _,tEntity in ipairs(LogicUpdateManager.EntityList_Normal) do if tEntity:GetCampID() > 20 then forceTarget = tEntity break end end end if forceTarget then return private.CommandChaseUseSkill(entity,forceTarget) end end return end local canuseSkillList = {} function private.CommandChaseUseSkill(entity,forceTarget) if not private.waitingSkillData then --确定要使用哪个技能 local skillBaseComp = entity.components.skillBase local curSkill = skillBaseComp.CurSkillData if curSkill and curSkill.Type == LuaConst.SkillType.Serial and curSkill.ParamInt1 >= 1 and curSkill.ParamInt1 <= #skillBaseComp.CurSkillSwitchList then local skillSwitch = skillBaseComp.CurSkillSwitchList[curSkill.ParamInt1] if skillSwitch then private.waitingSkillData = nil LuaInputManager.KeyPosition = skillSwitch.SwitchPutIn LuaInputManager.KeyRelease = true --连续技不管技能范围 end else table.clearArray(canuseSkillList) for k,skillData in ipairs(skillBaseComp.AutoFightSkillDataList) do local ConditionTree = ConditionManager.GetConditionDataTree(skillData.AutoBattleCondition) if private.CanAiUseSkill(entity,skillBaseComp,skillData,ConditionTree) then table.insert(canuseSkillList, skillData) end end if #canuseSkillList > 0 then local random = math.random(1,#canuseSkillList) private.waitingSkillData = canuseSkillList[random] end end end if private.waitingSkillData then local castRadiusNum = FP.tonumberV1(private.waitingSkillData.CastRadius) if castRadiusNum <= 0 or FP.LessEquals( FP.V2.DistanceSqr(entity:GetLogicPos(), forceTarget:GetLogicPos()) ,castRadiusNum * castRadiusNum) then LuaInputManager.KeyPosition = private.waitingSkillData.KeyPosition LuaInputManager.KeyRelease = true private.waitingSkillData = nil else LuaInputManager.FixVirtualMoveDir:Reset(forceTarget:GetLogicPos()):Sub(entity:GetLogicPos()):Normalize() end end end function private.CanAiUseSkill(entity,skillBaseComp,skillData,ConditionTree) local canUse if skillBaseComp:IsAdjutantSkill(skillData) then canUse = false --副将技肯定不能用 else canUse = skillBaseComp:CanUseSkill(skillData) and ConditionManager.MeetCondition(entity,ConditionTree) if skillBaseComp:IsMusouSkill(skillData) then canUse = canUse and LevelPlayerManager.IsEntityMagicWeaponActive(entity) end end return canUse end return WorldBossAutoTest