local Base = require("Battle/Logic/AI/Decision/Decision_Base") local Decision_AutoFightTest = class("Decision_AutoFightTest", Base) local PVPPos = FP.newV2(-121 ,311 ) local CirCleLmtSqr = FP.newV1(100) local CirCleLmtSqr2 = FP.newV1(900) local SearchTargetDis = FP.newV1(64) local internal = FP.newV1(0.35) --33 自动战斗测试(更随机,用于一致性测试) --[[ 初始化 --]] function Decision_AutoFightTest:initialize(entity) --类型 self.Type = LuaConst.DecisionType.AutoFightTest --瞬时 self.IsOnce = false end --[[ 进入该Decision --]] function Decision_AutoFightTest:DecisionIn(entity, decisionData) SystemManager.FindPath(entity, PVPPos, true) end --[[ 能否进入 --]] function Decision_AutoFightTest:CanEnter(entity, decisionData, command) return true end --[[ 能否退出 --]] function Decision_AutoFightTest:CanExit(entity, decisionData, command) return false end --[[ 输出指令 --]] function Decision_AutoFightTest:SetCommand(entity, decisionData, command) local skillBaseComp = entity.components.skillBase -- 先寻路到点-成功 local dis = FP.V2.DistanceSqr(entity.components.move.LogicPos, PVPPos) if dis > CirCleLmtSqr2 then SystemManager.FindPath(entity, PVPPos, true) end local pathComponent = entity.components.path local curPathPos = pathComponent.Path[pathComponent.CurPathPosIndex] if curPathPos then return self:RunToPathPoint(entity, command) end -- 离点太远了 ,返回点 local disSqr = FP.V2.SqrMagnitude(PVPPos - entity.components.move.LogicPos) if disSqr > CirCleLmtSqr then SystemManager.FindPath(entity, PVPPos, true) return self:RunToPathPoint(entity, command) end local holaEntityList = CampManager.GetEntityListOfCampId(LuaConst.ECampID.NEUTRAL_HOSTILE) -- 找光环吃 if holaEntityList and #holaEntityList > 0 then local midindex = math.random(1, #holaEntityList) local midEntity = holaEntityList[midindex] SystemManager.FindPath(entity, midEntity.components.move.LogicPos, true) return self:RunToPathPoint(entity, command) end --然后自由战斗 if skillBaseComp.CanSwitchAll then --先索敌 8米范围敌人 local skillTarget = nil for i, syncE in ipairs(LogicUpdateManager.EntityList_Sync) do if CampManager.IsEnemyEntity(syncE,entity) then if skillTarget then local dis = FP.V2.DistanceSqr(entity.components.move.LogicPos, syncE.components.move.LogicPos) local dis2 = FP.V2.DistanceSqr(entity.components.move.LogicPos, skillTarget.components.move.LogicPos) if dis <= dis2 then skillTarget = syncE end else skillTarget = syncE end end end if not skillTarget then -- 没有敌人继续向中心跑 local dis = PVPPos - entity.components.move.LogicPos if FP.Math.Abs(dis.x) < internal and FP.Math.Abs(dis.z) < internal then command.MoveDir = dis end return command end local curSkill = skillBaseComp.CurSkillData if curSkill and curSkill.Type == LuaConst.SkillType.Serial and curSkill.ParamInt1 >= 1 and curSkill.ParamInt1 <= #skillBaseComp.CurSkillSwitchList then command.SkillIndex = curSkill.ParamInt1 else if entity.components.attr:IsSAFilled() then command.SkillIndex = SystemManager.GetSkillIndexByKeyPosition(entity,LuaConst.MusouSkillKeyPos) else if math.random() > 0.1 then --10%的概率释放技能 local canList= {} for k,skillData in ipairs(skillBaseComp.AutoFightSkillDataList) do local ConditionTree = ConditionManager.GetConditionDataTree(skillData.AutoBattleCondition) if skillBaseComp:CanUseSkill(skillData) and ConditionManager.MeetCondition(entity, ConditionTree ) then table.insert(canList,skillData.KeyPosition) end end local index = math.random(1, #canList) command.SkillIndex = SystemManager.GetSkillIndexByKeyPosition(entity,canList[index]) if command.SkillIndex == nil then command.SkillIndex = 0 end end end end command.MoveDir = skillTarget.components.move.LogicPos - entity.components.move.LogicPos else command.MoveDir = PVPPos - entity.components.move.LogicPos end return command end function Decision_AutoFightTest:RunToPathPoint(entity, command) local pathComponent = entity.components.path local selfPos = entity.components.move.LogicPos local curPathPos = pathComponent.Path[pathComponent.CurPathPosIndex] if curPathPos then local dis = curPathPos - selfPos if FP.Math.Abs(dis.x) < internal and FP.Math.Abs(dis.z) < internal then pathComponent.CurPathPosIndex = pathComponent.CurPathPosIndex + 1 else command.MoveDir = curPathPos - selfPos command.RotateDir:Reset(command.MoveDir) end end return command end return Decision_AutoFightTest