local Base = require("Battle/Logic/AI/Decision/Decision_Base") local Decision_RunToFollowTarget = class("Decision_RunToFollowTarget", Base) local RetinueSystem = require"Battle/Logic/Entity/System/RetinueSystem" --[[ 初始化 --]] function Decision_RunToFollowTarget:initialize(entity) --类型 self.Type = LuaConst.DecisionType.RunToFollowTarget --瞬时 self.IsOnce = false end function Decision_RunToFollowTarget:CanEnter(entity, decisionData, command) return entity.components.target.FollowTarget end --[[ 能否退出 完成条件:移动到距目标的 IntParam1米 内 --]] function Decision_RunToFollowTarget:CanExit(entity, decisionData, command) local targetPos = entity.components.aiBase:GetDecisionRecord(decisionData,"findPathTargetPos") if targetPos then return not FP.V2.IsDistanceSqrGreater(entity:GetLogicPos(), targetPos, decisionData.IntParam1 * decisionData.IntParam1) else local comp_Target = entity.components.target local target = comp_Target.FollowTarget if target then return FP.LessEquals(self:GetToFollowPosDistSqr(entity, decisionData, command, target), decisionData.IntParam1 * decisionData.IntParam1) else return true end end end function Decision_RunToFollowTarget:GetFollowPos(entity, decisionData, command, target) if decisionData.StringParam1 ~= "2" then return target.components.move.LogicPos else return RetinueSystem.GetRetinueFollowPos(entity) or target.components.move.LogicPos end end function Decision_RunToFollowTarget:GetToFollowPosDistSqr(entity, decisionData, command, target) if decisionData.StringParam1 ~= "2" then return entity.components.target.ToFollowTargetDisSqr else local retinueFollowPos = RetinueSystem.GetRetinueFollowPos(entity) if retinueFollowPos then return (retinueFollowPos - entity:GetLogicPos()):SqrMagnitude() else return entity.components.target.ToFollowTargetDisSqr end end end --[[ 输出指令 --]] function Decision_RunToFollowTarget:SetCommand(entity, decisionData, command) local aiBaseComponent = entity.components.aiBase if self:HasPlayerInput(command) then --如果有玩家输入,记录这个输入的时间,并跳出AI运行 return command end --old↓ -- local lastFindPathFrame = aiBaseComponent:GetDecisionRecord(decisionData,"lastFindPathFrame") or -99999 -- --每隔2s重新寻一次路 -- local passFrame = LogicUpdateManager._clientHandleFrame - lastFindPathFrame -- local passTime = passFrame * LuaConst.TimeSpanMs -- local target = entity.components.target.FollowTarget -- if passTime >= 2000 then -- aiBaseComponent:SetDecisionRecord(decisionData,"lastFindPathFrame",LogicUpdateManager._clientHandleFrame) -- if target then -- SystemManager.FindPath(entity, target.components.move.LogicPos, true) -- end -- end --old ↑ --new↓ --每隔decisionData.IntParam4重新寻一次路 local target = entity.components.target.FollowTarget local followPos = self:GetFollowPos(entity, decisionData, command, target) self:IntervalFindPath(entity, decisionData, command,decisionData.IntParam4, decisionData.StringParam1 ~= "2" and target, decisionData.StringParam1 == "2" and followPos) --new↑ local isConveyed = false --超时瞬移功能 if decisionData.IntParam2 > 0 and decisionData.IntParam3 > 0 then if self:GetToFollowPosDistSqr(entity, decisionData, command, target) < FP.newV1(decisionData.IntParam3 * decisionData.IntParam3) then aiBaseComponent:SetDecisionRecord(decisionData,"lastNearFrame",LogicUpdateManager._clientHandleFrame) end if LogicUpdateManager._clientHandleFrame - (aiBaseComponent:GetDecisionRecord(decisionData,"lastNearFrame") or aiBaseComponent.CurDecisionStartFrame) > decisionData.IntParam2 * 20 then local dir = followPos - entity.components.move.LogicPos SystemManager.OnConvey(entity, followPos, dir) FP.releaseV2(dir) isConveyed = true end end if not isConveyed then local forceTargetPos = nil if #entity.components.path.Path <= 1 then forceTargetPos = followPos if decisionData.StringParam1 == "1" then if entity.ExpEntity and target.ExpEntity then ExpSystemManager.SetOverrideTargetDirToTarget(entity.ExpEntity, target.ExpEntity) end end end command = self:RunToPathPoint(entity, command, decisionData, forceTargetPos) end return command end return Decision_RunToFollowTarget