Files
tbd-station-14/Content.Server/Chemistry/ReagentEffectConditions/ReagentThreshold.cs
Nemanja b9fb66f005 Chem guidebook (#17123)
* im good at atomizing. welcome to half-finished chem guides.

* wagh

* e

* save work

* aa

* woweee UI

* finishing the last of it

* don't actually update the engine :(

---------

Co-authored-by: moonheart08 <moonheart08@users.noreply.github.com>
2023-06-04 15:45:02 -05:00

53 lines
1.8 KiB
C#

using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
using Robust.Shared.Prototypes;
namespace Content.Server.Chemistry.ReagentEffectConditions
{
/// <summary>
/// Used for implementing reagent effects that require a certain amount of reagent before it should be applied.
/// For instance, overdoses.
///
/// This can also trigger on -other- reagents, not just the one metabolizing. By default, it uses the
/// one being metabolized.
/// </summary>
public sealed class ReagentThreshold : ReagentEffectCondition
{
[DataField("min")]
public FixedPoint2 Min = FixedPoint2.Zero;
[DataField("max")]
public FixedPoint2 Max = FixedPoint2.MaxValue;
[DataField("reagent")]
public string? Reagent;
public override bool Condition(ReagentEffectArgs args)
{
var reagent = Reagent ?? args.Reagent?.ID;
if (reagent == null)
return true; // No condition to apply.
var quant = FixedPoint2.Zero;
if (args.Source != null && args.Source.ContainsReagent(reagent))
{
quant = args.Source.GetReagentQuantity(reagent);
}
return quant >= Min && quant <= Max;
}
public override string GuidebookExplanation(IPrototypeManager prototype)
{
ReagentPrototype? reagentProto = null;
if (Reagent is not null)
prototype.TryIndex(Reagent, out reagentProto);
return Loc.GetString("reagent-effect-condition-guidebook-reagent-threshold",
("reagent", reagentProto?.LocalizedName ?? "this reagent"),
("max", Max == FixedPoint2.MaxValue ? (float) int.MaxValue : Max.Float()),
("min", Min.Float()));
}
}
}