AddFloatOperator.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. using System.Threading;
  2. using System.Threading.Tasks;
  3. namespace Content.Server.NPC.HTN.PrimitiveTasks.Operators.Math;
  4. /// <summary>
  5. /// Added <see cref="AddFloatOperator.Amount"/> to float value for the
  6. /// specified <see cref="AddFloatOperator.TargetKey"/> in the <see cref="NPCBlackboard"/>.
  7. /// </summary>
  8. public sealed partial class AddFloatOperator : HTNOperator
  9. {
  10. [Dependency] private readonly IEntityManager _entManager = default!;
  11. [DataField(required: true), ViewVariables]
  12. public string TargetKey = string.Empty;
  13. [DataField, ViewVariables(VVAccess.ReadWrite)]
  14. public float Amount;
  15. public override async Task<(bool Valid, Dictionary<string, object>? Effects)> Plan(NPCBlackboard blackboard,
  16. CancellationToken cancelToken)
  17. {
  18. if (!blackboard.TryGetValue<float>(TargetKey, out var value, _entManager))
  19. return (false, null);
  20. return (
  21. true,
  22. new Dictionary<string, object>
  23. {
  24. { TargetKey, value + Amount }
  25. }
  26. );
  27. }
  28. }