AI/ActionSystem/BehaviorTree/Nodes/TimedTagNode.cs
namespace HC3;
/// <summary>
/// A node that sets a tag on an agent for a specified duration.
/// </summary>
public class TimedTagNode : Node
{
private readonly Agent Agent;
private readonly string Tag;
private readonly float Duration;
private readonly string Reason;
private TimeUntil _timer;
public TimedTagNode( Agent agent, string tag, float duration, string reason = null )
{
Agent = agent;
Tag = tag;
Duration = duration;
Reason = reason;
}
protected override void OnStart()
{
Agent.Tags.Set( Tag, true );
_timer = Duration;
}
public override Status Tick()
{
if ( _timer )
{
Agent.Tags.Set( Tag, false );
return Status.Success;
}
return Status.Running;
}
public override ActionDisplayInfo? GetDisplay()
{
if ( Reason != null )
{
return new ActionDisplayInfo( "schedule", Reason, 1 - (_timer / Duration) );
}
return base.GetDisplay();
}
}