* Commit * ploop * borger --------- Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com>
45 lines
1.6 KiB
C#
45 lines
1.6 KiB
C#
using Content.Shared.Chemistry.Components;
|
|
using Content.Shared.Chemistry.Reagent;
|
|
using Content.Shared.FixedPoint;
|
|
using Robust.Shared.Prototypes;
|
|
|
|
namespace Content.Shared.EntityConditions.Conditions;
|
|
|
|
/// <summary>
|
|
/// Returns true if this solution entity has an amount of reagent in it within a specified minimum and maximum.
|
|
/// </summary>
|
|
/// <inheritdoc cref="EntityConditionSystem{T, TCondition}"/>
|
|
public sealed partial class ReagentThresholdEntityConditionSystem : EntityConditionSystem<SolutionComponent, ReagentCondition>
|
|
{
|
|
protected override void Condition(Entity<SolutionComponent> entity, ref EntityConditionEvent<ReagentCondition> args)
|
|
{
|
|
var quant = entity.Comp.Solution.GetTotalPrototypeQuantity(args.Condition.Reagent);
|
|
|
|
args.Result = quant >= args.Condition.Min && quant <= args.Condition.Max;
|
|
}
|
|
}
|
|
|
|
/// <inheritdoc cref="EntityCondition"/>
|
|
public sealed partial class ReagentCondition : EntityConditionBase<ReagentCondition>
|
|
{
|
|
[DataField]
|
|
public FixedPoint2 Min = FixedPoint2.Zero;
|
|
|
|
[DataField]
|
|
public FixedPoint2 Max = FixedPoint2.MaxValue;
|
|
|
|
[DataField(required: true)]
|
|
public ProtoId<ReagentPrototype> Reagent;
|
|
|
|
public override string EntityConditionGuidebookText(IPrototypeManager prototype)
|
|
{
|
|
if (!prototype.Resolve(Reagent, out var reagentProto))
|
|
return String.Empty;
|
|
|
|
return Loc.GetString("entity-condition-guidebook-reagent-threshold",
|
|
("reagent", reagentProto.LocalizedName),
|
|
("max", Max == FixedPoint2.MaxValue ? int.MaxValue : Max.Float()),
|
|
("min", Min.Float()));
|
|
}
|
|
}
|