Files
tbd-station-14/Content.Server/NPC/HTN/PrimitiveTasks/Operators/Math/SetRandomFloatOperator.cs
Tornado Tech a29b6a6894 Clean up new HTNs tasks (#28469)
* Clean up new HTNs tasks

* Added docs to math operations
2024-06-01 13:46:35 -04:00

37 lines
1.1 KiB
C#

using System.Threading;
using System.Threading.Tasks;
using Robust.Shared.Random;
namespace Content.Server.NPC.HTN.PrimitiveTasks.Operators.Math;
/// <summary>
/// Set random float value between <see cref="SetRandomFloatOperator.MinAmount"/> and
/// <see cref="SetRandomFloatOperator.MaxAmount"/> specified <see cref="SetRandomFloatOperator.TargetKey"/>
/// in the <see cref="NPCBlackboard"/>.
/// </summary>
public sealed partial class SetRandomFloatOperator : HTNOperator
{
[Dependency] private readonly IRobustRandom _random = default!;
[DataField(required: true), ViewVariables]
public string TargetKey = string.Empty;
[DataField, ViewVariables(VVAccess.ReadWrite)]
public float MaxAmount = 1f;
[DataField, ViewVariables(VVAccess.ReadWrite)]
public float MinAmount;
public override async Task<(bool Valid, Dictionary<string, object>? Effects)> Plan(NPCBlackboard blackboard,
CancellationToken cancelToken)
{
return (
true,
new Dictionary<string, object>
{
{ TargetKey, _random.NextFloat(MinAmount, MaxAmount) }
}
);
}
}