AI/ActionSystem/BehaviorTree/Nodes/MoveToNode.cs
namespace HC3;

/// <summary>
/// A node that moves an agent to a specified target position.
/// </summary>
public class MoveToNode : Node
{
	private readonly Agent Agent;
	private readonly Vector3 Target;
	private readonly string Reason;

	public MoveToNode( Agent agent, Vector3 target, string reason = "Moving to target" )
	{
		Agent = agent;
		Target = target;
		Reason = reason;
	}

	public override Status Tick()
	{
		if ( !Agent.IsValid() )
			return Status.Failure;

		if ( Agent.Controller.Navigate( Target ) )
		{
			return Status.Success;
		}

		// Still couldn't make a path, so we failed
		if ( Agent.Controller.GetCurrentPath() == null )
		{
			return Status.Failure;
		}

		return Status.Running;
	}

	public override ActionDisplayInfo? GetDisplay()
	{
		float progress = Agent.Controller.GetPathProgress();
		return new ActionDisplayInfo(
			"directions_walk",
			Reason,
			progress
		);
	}
}