TotalHunger.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. using Content.Shared.EntityEffects;
  2. using Content.Shared.Nutrition.Components;
  3. using Content.Shared.Nutrition.EntitySystems;
  4. using Robust.Shared.Prototypes;
  5. namespace Content.Server.EntityEffects.EffectConditions;
  6. public sealed partial class Hunger : EntityEffectCondition
  7. {
  8. [DataField]
  9. public float Max = float.PositiveInfinity;
  10. [DataField]
  11. public float Min = 0;
  12. public override bool Condition(EntityEffectBaseArgs args)
  13. {
  14. if (args.EntityManager.TryGetComponent(args.TargetEntity, out HungerComponent? hunger))
  15. {
  16. var total = args.EntityManager.System<HungerSystem>().GetHunger(hunger);
  17. if (total > Min && total < Max)
  18. return true;
  19. }
  20. return false;
  21. }
  22. public override string GuidebookExplanation(IPrototypeManager prototype)
  23. {
  24. return Loc.GetString("reagent-effect-condition-guidebook-total-hunger",
  25. ("max", float.IsPositiveInfinity(Max) ? (float) int.MaxValue : Max),
  26. ("min", Min));
  27. }
  28. }