Revert 'Revert 'Solution Entities'' (#23168)
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using Content.Shared.Body.Prototypes;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using JetBrains.Annotations;
|
||||
@@ -14,7 +13,7 @@ namespace Content.Server.Chemistry.ReagentEffects
|
||||
/// <summary>
|
||||
/// The reagent ID to remove. Only one of this and <see cref="Group"/> should be active.
|
||||
/// </summary>
|
||||
[DataField("reagent", customTypeSerializer:typeof(PrototypeIdSerializer<ReagentPrototype>))]
|
||||
[DataField(customTypeSerializer: typeof(PrototypeIdSerializer<ReagentPrototype>))]
|
||||
public string? Reagent = null;
|
||||
// TODO use ReagentId
|
||||
|
||||
@@ -22,41 +21,39 @@ namespace Content.Server.Chemistry.ReagentEffects
|
||||
/// The metabolism group to remove, if the reagent satisfies any.
|
||||
/// Only one of this and <see cref="Reagent"/> should be active.
|
||||
/// </summary>
|
||||
[DataField("group", customTypeSerializer:typeof(PrototypeIdSerializer<MetabolismGroupPrototype>))]
|
||||
[DataField(customTypeSerializer: typeof(PrototypeIdSerializer<MetabolismGroupPrototype>))]
|
||||
public string? Group = null;
|
||||
|
||||
[DataField("amount", required: true)]
|
||||
[DataField(required: true)]
|
||||
public FixedPoint2 Amount = default!;
|
||||
|
||||
public override void Effect(ReagentEffectArgs args)
|
||||
{
|
||||
if (args.Source != null)
|
||||
if (args.Source == null)
|
||||
return;
|
||||
|
||||
var amount = Amount;
|
||||
amount *= args.Scale;
|
||||
|
||||
if (Reagent != null)
|
||||
{
|
||||
var solutionSys = args.EntityManager.EntitySysManager.GetEntitySystem<SolutionContainerSystem>();
|
||||
var amount = Amount;
|
||||
|
||||
amount *= args.Scale;
|
||||
|
||||
if (Reagent != null)
|
||||
if (amount < 0 && args.Source.ContainsPrototype(Reagent))
|
||||
args.Source.RemoveReagent(Reagent, -amount);
|
||||
if (amount > 0)
|
||||
args.Source.AddReagent(Reagent, amount);
|
||||
}
|
||||
else if (Group != null)
|
||||
{
|
||||
var prototypeMan = IoCManager.Resolve<IPrototypeManager>();
|
||||
foreach (var quant in args.Source.Contents.ToArray())
|
||||
{
|
||||
if (amount < 0 && args.Source.ContainsPrototype(Reagent))
|
||||
solutionSys.RemoveReagent(args.SolutionEntity, args.Source, Reagent, -amount);
|
||||
if (amount > 0)
|
||||
solutionSys.TryAddReagent(args.SolutionEntity, args.Source, Reagent, amount, out _);
|
||||
}
|
||||
else if (Group != null)
|
||||
{
|
||||
var prototypeMan = IoCManager.Resolve<IPrototypeManager>();
|
||||
foreach (var quant in args.Source.Contents.ToArray())
|
||||
var proto = prototypeMan.Index<ReagentPrototype>(quant.Reagent.Prototype);
|
||||
if (proto.Metabolisms != null && proto.Metabolisms.ContainsKey(Group))
|
||||
{
|
||||
var proto = prototypeMan.Index<ReagentPrototype>(quant.Reagent.Prototype);
|
||||
if (proto.Metabolisms != null && proto.Metabolisms.ContainsKey(Group))
|
||||
{
|
||||
if (amount < 0)
|
||||
solutionSys.RemoveReagent(args.SolutionEntity, args.Source, quant.Reagent, amount);
|
||||
if (amount > 0)
|
||||
solutionSys.TryAddReagent(args.SolutionEntity, args.Source, quant.Reagent, amount, out _);
|
||||
}
|
||||
if (amount < 0)
|
||||
args.Source.RemoveReagent(quant.Reagent, amount);
|
||||
if (amount > 0)
|
||||
args.Source.AddReagent(quant.Reagent, amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user