using Content.Shared.Nutrition.Components;
using Content.Shared.Nutrition.EntitySystems;
using Content.Shared.Nutrition.Prototypes;
using Robust.Shared.Prototypes;
namespace Content.Shared.EntityConditions.Conditions.Body;
///
/// A condition which passes if the specified is between the specified
/// and . If the entity does not have the
/// specified satiation, the condition evaluates to false.
///
public sealed partial class SatiationEntityConditionSystem : EntityConditionSystem
{
[Dependency] private SatiationSystem _satiation = default!;
///
protected override void Condition(Entity entity,
ref EntityConditionEvent args)
{
if (_satiation.GetValueOrNull(entity, args.Condition.SatiationType) is not { } satiation)
return;
args.Result =
(args.Condition.MinInclusive && satiation >= args.Condition.Min || satiation > args.Condition.Min) &&
(args.Condition.MaxInclusive && satiation <= args.Condition.Max || satiation < args.Condition.Max);
}
}
///
public sealed partial class SatiationCondition : EntityConditionBase
{
///
/// The value above which this condition will fail. If is false, the condition will fail
/// if at that value as well.
///
[DataField]
public float Max = float.PositiveInfinity;
///
/// The value below which this condition will fail. If is false, the condition will fail
/// if at that value as well.
///
[DataField]
public float Min = 0;
///
/// If true, values exactly equal to will NOT fail.
///
[DataField]
public bool MaxInclusive = false;
///
/// If true, values exactly equal to will NOT fail.
///
[DataField]
public bool MinInclusive = false;
///
/// The type of satiation whose value will be considered.
///
[DataField(required: true)]
public ProtoId SatiationType;
///
public override string EntityConditionGuidebookText(IPrototypeManager prototype)
{
return Loc.GetString("entity-condition-guidebook-total-satiation",
("max", float.IsPositiveInfinity(Max) ? int.MaxValue : Max),
("min", Min),
("type", prototype.Index(SatiationType).Name));
}
}