2022-05-13 00:59:03 -07:00
|
|
|
|
using Content.Shared.Chemistry.Reagent;
|
2021-11-03 16:48:03 -07:00
|
|
|
|
using Content.Shared.FixedPoint;
|
2023-06-04 16:45:02 -04:00
|
|
|
|
using Robust.Shared.Prototypes;
|
2021-07-31 04:50:32 -07:00
|
|
|
|
|
|
|
|
|
|
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.
|
2021-11-20 16:47:53 -07:00
|
|
|
|
///
|
|
|
|
|
|
/// This can also trigger on -other- reagents, not just the one metabolizing. By default, it uses the
|
|
|
|
|
|
/// one being metabolized.
|
2021-07-31 04:50:32 -07:00
|
|
|
|
/// </summary>
|
2022-02-16 00:23:23 -07:00
|
|
|
|
public sealed class ReagentThreshold : ReagentEffectCondition
|
2021-07-31 04:50:32 -07:00
|
|
|
|
{
|
|
|
|
|
|
[DataField("min")]
|
2021-11-03 16:48:03 -07:00
|
|
|
|
public FixedPoint2 Min = FixedPoint2.Zero;
|
2021-07-31 04:50:32 -07:00
|
|
|
|
|
|
|
|
|
|
[DataField("max")]
|
2021-11-03 16:48:03 -07:00
|
|
|
|
public FixedPoint2 Max = FixedPoint2.MaxValue;
|
2021-07-31 04:50:32 -07:00
|
|
|
|
|
2021-11-20 16:47:53 -07:00
|
|
|
|
[DataField("reagent")]
|
|
|
|
|
|
public string? Reagent;
|
|
|
|
|
|
|
2021-11-10 03:11:28 -07:00
|
|
|
|
public override bool Condition(ReagentEffectArgs args)
|
2021-07-31 04:50:32 -07:00
|
|
|
|
{
|
2023-05-13 15:10:32 +12:00
|
|
|
|
var reagent = Reagent ?? args.Reagent?.ID;
|
|
|
|
|
|
if (reagent == null)
|
|
|
|
|
|
return true; // No condition to apply.
|
2021-11-20 16:47:53 -07:00
|
|
|
|
|
|
|
|
|
|
var quant = FixedPoint2.Zero;
|
2023-05-13 15:10:32 +12:00
|
|
|
|
if (args.Source != null && args.Source.ContainsReagent(reagent))
|
2021-11-10 03:11:28 -07:00
|
|
|
|
{
|
2023-05-13 15:10:32 +12:00
|
|
|
|
quant = args.Source.GetReagentQuantity(reagent);
|
2021-11-10 03:11:28 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-11-20 16:47:53 -07:00
|
|
|
|
return quant >= Min && quant <= Max;
|
2021-07-31 04:50:32 -07:00
|
|
|
|
}
|
2023-06-04 16:45:02 -04:00
|
|
|
|
|
|
|
|
|
|
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()));
|
|
|
|
|
|
}
|
2021-07-31 04:50:32 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|