AI/ActionSystem/BehaviorTree/Nodes/RestoreNeedNode.cs
namespace HC3;
/// <summary>
/// A node that restores a specific need by a given amount (or sets it to a specific level)
/// </summary>
public sealed class RestoreNeedNode : Node
{
private readonly Agent Agent;
private readonly string NeedName;
private readonly float Value;
private readonly bool IsRelative;
private bool _complete;
/// <summary>
/// Creates a node that restores a specific need
/// </summary>
/// <param name="agent">The agent whose need will be restored</param>
/// <param name="needName">The name of the need to restore</param>
/// <param name="value">Value to set or add</param>
/// <param name="isRelative">If true, adds value to current level; if false, sets level to value</param>
public RestoreNeedNode( Agent agent, string needName, float value, bool isRelative = false )
{
Agent = agent;
NeedName = needName;
Value = value;
IsRelative = isRelative;
}
public override Status Tick()
{
if ( _complete ) return Status.Success;
var needSystem = Agent.GetComponent<NeedSystem>();
if ( needSystem != null )
{
var need = needSystem.GetNeed( NeedName );
if ( need.IsValid() )
{
if ( IsRelative )
need.Level += Value;
else
need.Level = Value;
}
}
_complete = true;
return Status.Success;
}
public override ActionDisplayInfo? GetDisplay()
{
return new ActionDisplayInfo( "autorenew", $"Restoring {NeedName}...", 1.0f );
}
}