ThirstyPrecondition.cs 867 B

1234567891011121314151617181920212223242526
  1. using Content.Shared.Hands.Components;
  2. using Content.Shared.Nutrition.Components;
  3. using Robust.Shared.Prototypes;
  4. namespace Content.Server.NPC.HTN.Preconditions;
  5. /// <summary>
  6. /// Returns true if the active hand entity has the specified components.
  7. /// </summary>
  8. public sealed partial class ThirstyPrecondition : HTNPrecondition
  9. {
  10. [Dependency] private readonly IEntityManager _entManager = default!;
  11. [DataField(required: true)]
  12. public ThirstThreshold MinThirstState = ThirstThreshold.Parched;
  13. public override bool IsMet(NPCBlackboard blackboard)
  14. {
  15. if (!blackboard.TryGetValue<EntityUid>(NPCBlackboard.Owner, out var owner, _entManager))
  16. {
  17. return false;
  18. }
  19. return _entManager.TryGetComponent<ThirstComponent>(owner, out var thirst) ? thirst.CurrentThirstThreshold <= MinThirstState : false;
  20. }
  21. }