Files
tbd-station-14/Content.Shared/EntityEffects/EffectConditions/ReagentThreshold.cs
pathetic meowmeow bf41de18aa Move entity effects definitions to shared (#35614)
* Move entity effects to shared

* relocate spawning to server

* Generic version of EntityEffect for just raising event.

* genericise everything

* oops forgot to push you

* some condensation

* finish rebas

* unwhite the space

* oops forgot nuke

* bad rebase fix

* useless annotations begone

---------

Co-authored-by: EmoGarbage404 <retron404@gmail.com>
2025-05-23 12:32:22 -04:00

57 lines
1.9 KiB
C#

using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
using Robust.Shared.Prototypes;
namespace Content.Shared.EntityEffects.EffectConditions;
/// <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 partial class ReagentThreshold : EntityEffectCondition
{
[DataField]
public FixedPoint2 Min = FixedPoint2.Zero;
[DataField]
public FixedPoint2 Max = FixedPoint2.MaxValue;
// TODO use ReagentId
[DataField]
public string? Reagent;
public override bool Condition(EntityEffectBaseArgs args)
{
if (args is EntityEffectReagentArgs reagentArgs)
{
var reagent = Reagent ?? reagentArgs.Reagent?.ID;
if (reagent == null)
return true; // No condition to apply.
var quant = FixedPoint2.Zero;
if (reagentArgs.Source != null)
quant = reagentArgs.Source.GetTotalPrototypeQuantity(reagent);
return quant >= Min && quant <= Max;
}
// TODO: Someone needs to figure out how to do this for non-reagent effects.
throw new NotImplementedException();
}
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 ?? Loc.GetString("reagent-effect-condition-guidebook-this-reagent")),
("max", Max == FixedPoint2.MaxValue ? (float) int.MaxValue : Max.Float()),
("min", Min.Float()));
}
}