local Base = require("Battle/Logic/AI/Decision/Decision_Base") local Decision_FleeGroupLeader = class("Decision_FleeGroupLeader", Base) local private = {} --[[ 初始化 --]] function Decision_FleeGroupLeader:initialize(entity) --类型 self.Type = LuaConst.DecisionType.FleeGroupLeader --瞬时 self.IsOnce = false end --[[ 能否进入 进入条件:存在最近的友方 --]] function Decision_FleeGroupLeader:CanEnter(entity, decisionData, command) private:SetNearestGroupLeader(entity, FP.newV1(decisionData.IntParam1 * decisionData.IntParam1)) if entity.components.target.NearestFriendEntity then return true else return false end end --[[ 能否退出 退出条件:最近的友方不存在 或 与最近的友方的距离过远 --]] function Decision_FleeGroupLeader:CanExit(entity, decisionData, command) local nearestFriendEntity = entity.components.target.NearestFriendEntity if nearestFriendEntity then if not FP.V2.IsDistanceGreater(entity.components.move.LogicPos, nearestFriendEntity.components.move.LogicPos, decisionData.IntParam1) then return false end nearestFriendEntity = nil end return true end --[[ 输出指令 --]] function Decision_FleeGroupLeader:SetCommand(entity, decisionData, command) local nearestFriendEntity = entity.components.target.NearestFriendEntity if nearestFriendEntity then command.MoveDir = entity.components.move.LogicPos - nearestFriendEntity.components.move.LogicPos command.RotateDir:Reset(command.MoveDir) end return command end function private:SetNearestGroupLeader(entity, disSqrLimit) local nearestFriendEntity = nil local min = nil for key,tempEntity in pairs(LogicUpdateManager.GroupAIEntityDir) do local disSqr = FP.V2.DistanceSqr(entity.components.move.LogicPos, tempEntity.components.move.LogicPos) if entity._logicInitData.EntityID ~= tempEntity._logicInitData.EntityID and disSqr <= disSqrLimit then if not min or min > disSqr then min = disSqr nearestFriendEntity = tempEntity end end end entity.components.target:SetNearestFriendEntity(nearestFriendEntity) end return Decision_FleeGroupLeader