using Content.Server.Chemistry.EntitySystems;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
using JetBrains.Annotations;
using Content.Server.Body.Components;
using Content.Shared.Disease;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Server.Disease.Effects
{
///
/// Adds or removes reagents from the
/// host's chemstream.
///
[UsedImplicitly]
public sealed class DiseaseAdjustReagent : DiseaseEffect
{
///
/// The reagent ID to add or remove.
///
[DataField("reagent", customTypeSerializer:typeof(PrototypeIdSerializer))]
public string? Reagent = null;
[DataField("amount", required: true)]
public FixedPoint2 Amount = default!;
public override void Effect(DiseaseEffectArgs args)
{
if (!args.EntityManager.TryGetComponent(args.DiseasedEntity, out var bloodstream))
return;
var stream = bloodstream.ChemicalSolution;
if (stream != null)
{
var solutionSys = args.EntityManager.EntitySysManager.GetEntitySystem();
if (Reagent != null)
{
if (Amount < 0 && stream.ContainsReagent(Reagent))
solutionSys.TryRemoveReagent(args.DiseasedEntity, stream, Reagent, -Amount);
if (Amount > 0)
solutionSys.TryAddReagent(args.DiseasedEntity, stream, Reagent, Amount, out _);
}
}
}
}
}