local Base = require("Battle/Logic/AI/Decision/Decision_Base") local Decision_Return = class("Decision_Return", Base) --[[ 初始化 --]] function Decision_Return:initialize(entity) --类型 self.Type = LuaConst.DecisionType.Return --瞬时 self.IsOnce = false end --[[ 进入该Decision --]] function Decision_Return:DecisionIn(entity, decisionData) --清除目标 SystemManager.SetTarget(entity,nil) --寻路 SystemManager.FindPath(entity, entity.components.patrol.ExitPatrolPoint, true) end function Decision_Return:DecisionOut(entity, decisionData) Base.DecisionOut(self, entity, decisionData) BattleEventSystem.OnEntityDecisionReturnOut(entity) end --[[ 进入条件: 有群组时:Leader脱战 无群组时, 目标为空 或 与退出巡逻的位置的距离大于脱战距离 --]] function Decision_Return:CanEnter(entity, decisionData, command) if entity.components.patrol.IsForceReturn then return true else local leader = entity.components.group.LeaderEntity if leader then local leaderDecisionNode = leader.components.aiBase.CurDecisionNode return leaderDecisionNode and leaderDecisionNode.Type == LuaConst.DecisionType.Return else if not entity.components.target.Target then --目标为空 --重新索敌 local warnRange = entity.components.base.CurCharacterData.WarnRange SystemManager.OnSearchTarget(entity, 1, warnRange, 1, 0) return not entity.components.target.Target --目标依旧为空 else --与退出巡逻的位置的距离是否大于脱战距离 return FP.V2.IsDistanceSqrGreater(entity.components.patrol.ExitPatrolPoint, entity.components.move.LogicPos, entity.components.base.CurCharacterData.ReturnRange) end end end end --[[ 能否退出 退出条件:已返回出生点 --]] function Decision_Return:CanExit(entity, decisionData, command) local pathComponent = entity.components.path local curPathPos = pathComponent.Path[pathComponent.CurPathPosIndex] return not curPathPos end --[[ 输出指令 --]] function Decision_Return:SetCommand(entity, decisionData, command) return self:RunToPathPoint(entity, command,decisionData) end return Decision_Return