-- 跑向某个entity,并与其进行index=1的交互 local Base = require("Battle/Logic/AI/Decision/Decision_Base") local Decision_RunToAndInteract = class("Decision_RunToAndInteract", Base) local ARRIVE_DIST_SQR = FP.newV1(1) --[[ 初始化 --]] function Decision_RunToAndInteract:initialize(entity) --类型 self.Type = LuaConst.DecisionType.RunToAndInteract --瞬时 self.IsOnce = false end --[[ 进入该Decision --]] function Decision_RunToAndInteract:DecisionIn(entity, decisionData) if entity.components.aiBase.runToAndInteractEntity then SystemManager.FindPath(entity, entity.components.aiBase.runToAndInteractEntity:GetLogicPos() , true) end end function Decision_RunToAndInteract:DecisionOut(entity, decisionData) entity.components.aiBase:SetRunToAndInteractEntity(nil) --退出这个Decision时就清空DynamicPos end function Decision_RunToAndInteract:CanEnter(entity) return entity.components.aiBase.runToAndInteractEntity ~= nil end --[[ 能否退出 退出条件:移动到固定目标点 --]] function Decision_RunToAndInteract:CanExit(entity, decisionData, command) if entity.components.aiBase.runToAndInteractEntity == nil then return true end return false end --[[ 输出指令 --]] function Decision_RunToAndInteract:SetCommand(entity, decisionData, command) local aiBaseComponent = entity.components.aiBase local decisionRecordDic = aiBaseComponent:GetDecisionRecordDic(decisionData) if self:ShouldBlockAI(decisionRecordDic) then return command end if self:HasPlayerInput(command) then --如果有玩家输入,就直接把目标位置设为nil,这个会引发该Decision退出 entity.components.aiBase:SetRunToAndInteractEntity(nil) return command end local runToAndInteractEntity = entity.components.aiBase.runToAndInteractEntity if not runToAndInteractEntity:IsValid() then entity.components.aiBase:SetRunToAndInteractEntity(nil) else if FP.V2.DistanceSqr(entity:GetLogicPos(), runToAndInteractEntity:GetLogicPos()) <= ARRIVE_DIST_SQR then -- 跑到了,则进行交互 if entity.components.aiBase.CurStateType ~= LuaConst.StateType.Interact then command.SpecialCommand = LuaConst.SpecialCommandType.Interact command.MoveType = LuaConst.CmdMoveTypeBaseEnum.InteractBase + 1 end else command = self:RunToPathPoint(entity, command, decisionData) -- 向其跑 end end return command end return Decision_RunToAndInteract