local base = require("Battle/Logic/AI/Decision/Decision_Base") local Decision_AutoFightPath = class("Decision_AutoFightPath", base) local tonumberV2=FP.tonumberV2 local SqrMagnitude=FP.V2.SqrMagnitude local Const_Vector2_Zero=FP.Const.Vector2_Zero local newV2=FP.newV2 --TODO 逻辑需要整理 --[[ 初始化 --]] function Decision_AutoFightPath:initialize(entity) --类型 self.Type = LuaConst.DecisionType.AutoFightPath --瞬时 self.IsOnce = false end --[[ 进入该Decision --]] function Decision_AutoFightPath:DecisionIn(entity, decisionData) local decisionRecordDic = entity.components.aiBase:GetDecisionRecordDic(decisionData) if decisionRecordDic then decisionRecordDic.onFootFrameCount = 0 decisionRecordDic.dontAutoRide = false end self:FindPathIfNeed(entity, decisionData) end --[[ 退出该Decision --]] function Decision_AutoFightPath:DecisionOut(entity, decisionData) local comp_Path = entity.components.path local comp_AutoFight = entity.components.autoFight local arrive = false local curPathPos = comp_Path.Path[comp_Path.CurPathPosIndex] if not curPathPos then --到达目的地 arrive = true else if comp_AutoFight.RadiusSqr and comp_Path.TargetPos then local disSqr = SqrMagnitude(comp_Path.TargetPos - entity.components.move.LogicPos) if disSqr < comp_AutoFight.RadiusSqr then arrive = true end end end if arrive then if comp_AutoFight.CallBack then comp_AutoFight.CallBack(entity) comp_AutoFight.CallBack = nil end end --停止自动寻路 comp_AutoFight:StopAutoFindPath() NotSyncBattleSetter.SetIsChangeSceneFinding(false) end --[[ 能否进入 --]] function Decision_AutoFightPath:CanEnter(entity, decisionData, command) local comp_AutoFight = entity.components.autoFight return comp_AutoFight.IsAutoFindPath and comp_AutoFight.TargetPos end --[[ 能否退出 退出条件:关闭自动寻路 或 玩家移动摇杆/释放技能 或 运动到最后一个点 或 与目标点距离小于指定值 --]] function Decision_AutoFightPath:CanExit(entity, decisionData, command) if command.MoveDir ~= Const_Vector2_Zero or command.SkillIndex > 0 then return true end local comp_AutoFight = entity.components.autoFight if not comp_AutoFight.IsAutoFindPath then return true; end if not NotSyncBattleSetter.IsChangeSceneFinding() then local comp_Path = entity.components.path local curPathPos = comp_Path.Path[comp_Path.CurPathPosIndex] if not curPathPos then return true elseif comp_AutoFight.RadiusSqr and comp_Path.TargetPos then local disSqr = SqrMagnitude(comp_Path.TargetPos - entity.components.move.LogicPos) if disSqr < comp_AutoFight.RadiusSqr then return true end end end return false end function Decision_AutoFightPath:FindPathIfNeed(entity,decisionData) local comp_AutoFight = entity.components.autoFight local decisionRecordDic = entity.components.aiBase:GetDecisionRecordDic(decisionData) if comp_AutoFight.TargetPos then SystemManager.FindPath(entity, comp_AutoFight.TargetPos, true) decisionRecordDic.tagetPos = comp_AutoFight.TargetPos comp_AutoFight.TargetPos = nil else --200毫秒刷新一次路径,因为这个Decision只有主角会运行,而且只有主城会运行。所以可以频繁寻路 self:IntervalFindPath(entity, decisionData, nil, 200, nil, decisionRecordDic.tagetPos, decisionRecordDic) end end --[[ 输出指令 --]] function Decision_AutoFightPath:SetCommand(entity, decisionData, command) self:FindPathIfNeed(entity, decisionData) return self:RunToPathPoint(entity, command,decisionData) end return Decision_AutoFightPath