Files
tbd-station-14/Content.Shared/_Offbrand/EntityEffects/AdjustReagentGaussian.cs
Janet Blackquill 579ea90d49 thusd refactoring
2025-10-03 12:21:48 -04:00

55 lines
1.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Content.Shared.Chemistry.Reagent;
using Content.Shared.EntityEffects;
using Content.Shared.FixedPoint;
using Content.Shared.Random.Helpers;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Timing;
namespace Content.Shared._Offbrand.EntityEffects;
public sealed partial class AdjustReagentGaussian : EntityEffect
{
[DataField(required: true)]
public ProtoId<ReagentPrototype> Reagent;
[DataField(required: true)]
public double μ;
[DataField(required: true)]
public double σ;
public override void Effect(EntityEffectBaseArgs args)
{
if (args is not EntityEffectReagentArgs reagentArgs)
throw new NotImplementedException();
if (reagentArgs.Source == null)
return;
var timing = IoCManager.Resolve<IGameTiming>();
var seed = SharedRandomExtensions.HashCodeCombine(new() { (int)timing.CurTick.Value, args.EntityManager.GetNetEntity(args.TargetEntity).Id });
var rand = new System.Random(seed);
var amount = rand.NextGaussian(μ, σ);
amount *= reagentArgs.Scale.Double();
if (amount < 0 && reagentArgs.Source.ContainsPrototype(Reagent))
reagentArgs.Source.RemoveReagent(Reagent, -amount);
else if (amount > 0)
reagentArgs.Source.AddReagent(Reagent, amount);
}
protected override string? ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys)
{
var proto = prototype.Index(Reagent);
return Loc.GetString("reagent-effect-guidebook-adjust-reagent-gaussian",
("chance", Probability),
("deltasign", Math.Sign(μ)),
("reagent", proto.LocalizedName),
("mu", Math.Abs(μ)),
("sigma", Math.Abs(σ)));
}
}