diff --git a/Classes/Bot/Mover/SAINMoverClass.cs b/Classes/Bot/Mover/SAINMoverClass.cs index 139dff14..d8f3a78d 100644 --- a/Classes/Bot/Mover/SAINMoverClass.cs +++ b/Classes/Bot/Mover/SAINMoverClass.cs @@ -196,6 +196,7 @@ public bool WalkToPoint(Vector3 point, bool mustHaveCompletePath = true, float r { TriggerNewMove(path.corners, point, false, ESprintUrgency.None, path); _activePath.SetDestinationReachDistance(reachDist); + _activePath.PathStatus = path.status; return true; } return false; diff --git a/Layers/Extract/ExtractAction.cs b/Layers/Extract/ExtractAction.cs index eaf5ce6b..d0a97309 100644 --- a/Layers/Extract/ExtractAction.cs +++ b/Layers/Extract/ExtractAction.cs @@ -121,6 +121,51 @@ private void MoveToExtract(float distance, Vector3 point) Bot.Mover.ActivePath.RequestStartSprint(SAINComponent.Classes.Mover.ESprintUrgency.High, "extract"); } + if (shouldStartExtract(distance)) + { + return; + } + + if (ReCalcPathTimer > Time.time) + { + return; + } + + ExtractTimer = -1f; + ReCalcPathTimer = Time.time + 4f; + + if (!canMoveToExtract(point)) + { + Bot.Memory.Extract.ExtractStatus = EExtractStatus.None; + return; + } + + Bot.Memory.Extract.ExtractStatus = EExtractStatus.MovingTo; + + var pathController = Bot.Mover; + if (pathController.ActivePath.PathStatus == NavMeshPathStatus.PathComplete) + { + return; + } + + // If the path to the extract is invalid or the path is incomplete and the bot reached the end of it, select a new extract + float distanceToEndOfPath = Vector3.Distance(BotOwner.Position, pathController.ActivePath.GetLastCorner().Position); + if (distanceToEndOfPath < BotExtractManager.MinDistanceToExtract) + { + // Need to reset the search timer to prevent the bot from immediately selecting (possibly) the same extract + BotManagerComponent.Instance.BotExtractManager.ResetExfilSearchTime(Bot); + + Bot.Memory.Extract.ExfilPoint = null; + Bot.Memory.Extract.ExfilPosition = null; + + Bot.Memory.Extract.ExtractStatus = EExtractStatus.None; + + Logger.LogWarning($"{BotOwner.name} reached the end of an incomplete path when trying to find its extract. Searching for a new extract..."); + } + } + + private bool shouldStartExtract(float distance) + { if (distance > MinDistanceToStartExtract * 2) { ExtractStarted = false; @@ -132,35 +177,37 @@ private void MoveToExtract(float distance, Vector3 point) if (ExtractStarted) { - return; + return true; + } + + return false; + } + + private bool canMoveToExtract(Vector3 point) + { + if (!Bot.Mover.WalkToPoint(point, false, 0.5f)) + { + return false; } - if (ReCalcPathTimer < Time.time) + var pathController = Bot.Mover; + if (pathController?.ActivePath == null) { - ExtractTimer = -1f; - ReCalcPathTimer = Time.time + 4f; + Logger.LogError($"{BotOwner.name} has a null path to its extract"); - if (Bot.Mover.WalkToPoint(point, false, 0.5f)) - { - Bot.Memory.Extract.ExtractStatus = EExtractStatus.MovingTo; - var pathController = Bot.Mover; - if (pathController?.ActivePath != null) - { - float distanceToEndOfPath = Vector3.Distance(BotOwner.Position, pathController.ActivePath.GetLastCorner().Position); - bool reachedEndOfIncompletePath = (pathController.ActivePath.PathStatus == NavMeshPathStatus.PathPartial) && (distanceToEndOfPath < BotExtractManager.MinDistanceToExtract); - - // If the path to the extract is invalid or the path is incomplete and the bot reached the end of it, select a new extract - if ((pathController.ActivePath.PathStatus == NavMeshPathStatus.PathInvalid) || reachedEndOfIncompletePath) - { - // Need to reset the search timer to prevent the bot from immediately selecting (possibly) the same extract - BotManagerComponent.Instance.BotExtractManager.ResetExfilSearchTime(Bot); + return false; + } - Bot.Memory.Extract.ExfilPoint = null; - Bot.Memory.Extract.ExfilPosition = null; - } - } - } + // Need to first check if the bot has started moving to extract because there is currently a race condition that sometimes resets PathStatus + // to PathInvalid. If the path is invalid and the bot has not already started moving, it might actually be unable to travel there. + if ((Bot.Memory.Extract.ExtractStatus == EExtractStatus.None) && (pathController.ActivePath.PathStatus == NavMeshPathStatus.PathInvalid)) + { + Logger.LogWarning($"{BotOwner.name} has an invalid path to its extract"); + + return false; } + + return true; } public void StartExtract(Vector3 point)