KeyFloatEqualsPrecondition.cs 841 B

12345678910111213141516171819202122
  1. namespace Content.Server.NPC.HTN.Preconditions.Math;
  2. /// <summary>
  3. /// Checks if there is a float value for the specified <see cref="KeyFloatEqualsPrecondition.Key"/>
  4. /// in the <see cref="NPCBlackboard"/> and the specified value is equal to the <see cref="KeyFloatEqualsPrecondition.Value"/>.
  5. /// </summary>
  6. public sealed partial class KeyFloatEqualsPrecondition : HTNPrecondition
  7. {
  8. [Dependency] private readonly IEntityManager _entManager = default!;
  9. [DataField(required: true), ViewVariables]
  10. public string Key = string.Empty;
  11. [DataField(required: true), ViewVariables(VVAccess.ReadWrite)]
  12. public float Value;
  13. public override bool IsMet(NPCBlackboard blackboard)
  14. {
  15. return blackboard.TryGetValue<float>(Key, out var value, _entManager) &&
  16. MathHelper.CloseTo(value, value);
  17. }
  18. }