2024-05-08 19:18:03 +10:00
|
|
|
|
using System.Threading;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Robust.Shared.Random;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.NPC.HTN.PrimitiveTasks.Operators.Math;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-06-02 03:46:35 +10:00
|
|
|
|
/// Set random float value between <see cref="SetRandomFloatOperator.MinAmount"/> and
|
|
|
|
|
|
/// <see cref="SetRandomFloatOperator.MaxAmount"/> specified <see cref="SetRandomFloatOperator.TargetKey"/>
|
|
|
|
|
|
/// in the <see cref="NPCBlackboard"/>.
|
2024-05-08 19:18:03 +10:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
public sealed partial class SetRandomFloatOperator : HTNOperator
|
|
|
|
|
|
{
|
|
|
|
|
|
[Dependency] private readonly IRobustRandom _random = default!;
|
|
|
|
|
|
|
2024-06-02 03:46:35 +10:00
|
|
|
|
[DataField(required: true), ViewVariables]
|
2024-05-08 19:18:03 +10:00
|
|
|
|
public string TargetKey = string.Empty;
|
|
|
|
|
|
|
|
|
|
|
|
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
|
|
|
|
|
public float MaxAmount = 1f;
|
|
|
|
|
|
|
|
|
|
|
|
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
2024-06-02 03:46:35 +10:00
|
|
|
|
public float MinAmount;
|
2024-05-08 19:18:03 +10:00
|
|
|
|
|
|
|
|
|
|
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) }
|
|
|
|
|
|
}
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|