Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Classes/Bot/Mover/SAINMoverClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
93 changes: 70 additions & 23 deletions Layers/Extract/ExtractAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down