SetRandomFloatOperator.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using System.Threading;
  2. using System.Threading.Tasks;
  3. using Robust.Shared.Random;
  4. namespace Content.Server.NPC.HTN.PrimitiveTasks.Operators.Math;
  5. /// <summary>
  6. /// Set random float value between <see cref="SetRandomFloatOperator.MinAmount"/> and
  7. /// <see cref="SetRandomFloatOperator.MaxAmount"/> specified <see cref="SetRandomFloatOperator.TargetKey"/>
  8. /// in the <see cref="NPCBlackboard"/>.
  9. /// </summary>
  10. public sealed partial class SetRandomFloatOperator : HTNOperator
  11. {
  12. [Dependency] private readonly IRobustRandom _random = default!;
  13. [DataField(required: true), ViewVariables]
  14. public string TargetKey = string.Empty;
  15. [DataField, ViewVariables(VVAccess.ReadWrite)]
  16. public float MaxAmount = 1f;
  17. [DataField, ViewVariables(VVAccess.ReadWrite)]
  18. public float MinAmount;
  19. public override async Task<(bool Valid, Dictionary<string, object>? Effects)> Plan(NPCBlackboard blackboard,
  20. CancellationToken cancelToken)
  21. {
  22. return (
  23. true,
  24. new Dictionary<string, object>
  25. {
  26. { TargetKey, _random.NextFloat(MinAmount, MaxAmount) }
  27. }
  28. );
  29. }
  30. }