Files
tbd-station-14/Content.Server/Chemistry/ReagentEffectConditions/ReagentThreshold.cs
KrasnoshchekovPavel 3fcbbc0732 Added localization of groups and types: damage, metabolism (#27368)
* Added localization of groups and types: damage, metabolism (displayed in the guide book). The text for the health analyzer, weapon damage inspection is now taken from damage prototypes

* fix damage tests

* fix damage test yml

* fix damage test prototypes

* Update Content.Shared/Damage/Prototypes/DamageGroupPrototype.cs

* Update Content.Shared/Damage/Prototypes/DamageTypePrototype.cs

---------

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
2024-04-28 14:48:19 +10:00

52 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 partial class ReagentThreshold : ReagentEffectCondition
{
[DataField]
public FixedPoint2 Min = FixedPoint2.Zero;
[DataField]
public FixedPoint2 Max = FixedPoint2.MaxValue;
// TODO use ReagentId
[DataField]
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)
quant = args.Source.GetTotalPrototypeQuantity(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 ?? Loc.GetString("reagent-effect-condition-guidebook-this-reagent")),
("max", Max == FixedPoint2.MaxValue ? (float) int.MaxValue : Max.Float()),
("min", Min.Float()));
}
}
}