KeyFloatLessPrecondition.cs 804 B

123456789101112131415161718192021
  1. namespace Content.Server.NPC.HTN.Preconditions.Math;
  2. /// <summary>
  3. /// Checks if there is a float value for the specified <see cref="KeyFloatGreaterPrecondition.Key"/>
  4. /// in the <see cref="NPCBlackboard"/> and the specified value is less then <see cref="KeyFloatGreaterPrecondition.Value"/>.
  5. /// </summary>
  6. public sealed partial class KeyFloatLessPrecondition : 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) && value < Value;
  16. }
  17. }