diff --git a/Content.Server/GameObjects/Components/Chemistry/InjectorComponent.cs b/Content.Server/GameObjects/Components/Chemistry/InjectorComponent.cs index 9d7878f79d..d4bcfdffc6 100644 --- a/Content.Server/GameObjects/Components/Chemistry/InjectorComponent.cs +++ b/Content.Server/GameObjects/Components/Chemistry/InjectorComponent.cs @@ -201,19 +201,11 @@ namespace Content.Server.GameObjects.Components.Chemistry // TODO: Account for partial transfer. - foreach (var (reagentId, quantity) in removedSolution.Contents) - { - if(!_prototypeManager.TryIndex(reagentId, out ReagentPrototype reagent)) continue; - removedSolution.RemoveReagent(reagentId, reagent.ReactionEntity(solution.Owner, ReactionMethod.Injection, quantity)); - } + removedSolution.DoEntityReaction(solution.Owner, ReactionMethod.Injection); solution.TryAddSolution(removedSolution); - foreach (var (reagentId, quantity) in removedSolution.Contents) - { - if(!_prototypeManager.TryIndex(reagentId, out ReagentPrototype reagent)) continue; - reagent.ReactionEntity(targetBloodstream.Owner, ReactionMethod.Injection, quantity); - } + removedSolution.DoEntityReaction(targetBloodstream.Owner, ReactionMethod.Injection); Owner.PopupMessage(user, Loc.GetString("You inject {0}u into {1:theName}!", removedSolution.TotalVolume, targetBloodstream.Owner)); Dirty(); @@ -243,11 +235,7 @@ namespace Content.Server.GameObjects.Components.Chemistry return; } - foreach (var (reagentId, quantity) in removedSolution.Contents) - { - if(!_prototypeManager.TryIndex(reagentId, out ReagentPrototype reagent)) continue; - removedSolution.RemoveReagent(reagentId, reagent.ReactionEntity(targetSolution.Owner, ReactionMethod.Injection, quantity)); - } + removedSolution.DoEntityReaction(targetSolution.Owner, ReactionMethod.Injection); targetSolution.TryAddSolution(removedSolution); diff --git a/Content.Server/GameObjects/Components/Chemistry/PillComponent.cs b/Content.Server/GameObjects/Components/Chemistry/PillComponent.cs index 9c1bd88881..d96e27cc60 100644 --- a/Content.Server/GameObjects/Components/Chemistry/PillComponent.cs +++ b/Content.Server/GameObjects/Components/Chemistry/PillComponent.cs @@ -103,11 +103,7 @@ namespace Content.Server.GameObjects.Components.Chemistry // TODO: Account for partial transfer. - foreach (var (reagentId, quantity) in split.Contents) - { - if (!_prototypeManager.TryIndex(reagentId, out ReagentPrototype reagent)) continue; - split.RemoveReagent(reagentId, reagent.ReactionEntity(trueTarget, ReactionMethod.Ingestion, quantity)); - } + split.DoEntityReaction(trueTarget, ReactionMethod.Ingestion); firstStomach.TryTransferSolution(split); diff --git a/Content.Server/GameObjects/Components/Chemistry/VaporComponent.cs b/Content.Server/GameObjects/Components/Chemistry/VaporComponent.cs index 44461c3b94..208cfd658f 100644 --- a/Content.Server/GameObjects/Components/Chemistry/VaporComponent.cs +++ b/Content.Server/GameObjects/Components/Chemistry/VaporComponent.cs @@ -135,12 +135,7 @@ namespace Content.Server.GameObjects.Components.Chemistry if (!Owner.TryGetComponent(out SolutionContainerComponent contents)) return; - foreach (var reagentQuantity in contents.ReagentList.ToArray()) - { - if (reagentQuantity.Quantity == ReagentUnit.Zero) continue; - var reagent = _prototypeManager.Index(reagentQuantity.ReagentId); - contents.TryRemoveReagent(reagentQuantity.ReagentId, reagent.ReactionEntity(collidedWith, ReactionMethod.Touch, reagentQuantity.Quantity * 0.125f)); - } + contents.Solution.DoEntityReaction(collidedWith, ReactionMethod.Touch); // Check for collision with a impassable object (e.g. wall) and stop if (collidedWith.TryGetComponent(out IPhysicsComponent physics)) diff --git a/Content.Server/GameObjects/Components/Nutrition/DrinkComponent.cs b/Content.Server/GameObjects/Components/Nutrition/DrinkComponent.cs index 6ea6074a46..4990ac6075 100644 --- a/Content.Server/GameObjects/Components/Nutrition/DrinkComponent.cs +++ b/Content.Server/GameObjects/Components/Nutrition/DrinkComponent.cs @@ -181,11 +181,7 @@ namespace Content.Server.GameObjects.Components.Nutrition // TODO: Account for partial transfer. - foreach (var (reagentId, quantity) in split.Contents) - { - if (!_prototypeManager.TryIndex(reagentId, out ReagentPrototype reagent)) continue; - split.RemoveReagent(reagentId, reagent.ReactionEntity(target, ReactionMethod.Ingestion, quantity)); - } + split.DoEntityReaction(target, ReactionMethod.Ingestion); firstStomach.TryTransferSolution(split); diff --git a/Content.Server/GameObjects/Components/Nutrition/FoodComponent.cs b/Content.Server/GameObjects/Components/Nutrition/FoodComponent.cs index 94fef359b0..b7318fdce1 100644 --- a/Content.Server/GameObjects/Components/Nutrition/FoodComponent.cs +++ b/Content.Server/GameObjects/Components/Nutrition/FoodComponent.cs @@ -183,11 +183,7 @@ namespace Content.Server.GameObjects.Components.Nutrition // TODO: Account for partial transfer. - foreach (var (reagentId, quantity) in split.Contents) - { - if (!_prototypeManager.TryIndex(reagentId, out ReagentPrototype reagent)) continue; - split.RemoveReagent(reagentId, reagent.ReactionEntity(trueTarget, ReactionMethod.Ingestion, quantity)); - } + split.DoEntityReaction(trueTarget, ReactionMethod.Ingestion); firstStomach.TryTransferSolution(split); diff --git a/Content.Shared/Chemistry/Solution.cs b/Content.Shared/Chemistry/Solution.cs index ea334527b3..96b802696b 100644 --- a/Content.Shared/Chemistry/Solution.cs +++ b/Content.Shared/Chemistry/Solution.cs @@ -3,6 +3,8 @@ using System.Collections; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; +using Content.Shared.Interfaces.GameObjects.Components; +using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.Serialization; using Robust.Shared.IoC; using Robust.Shared.Maths; @@ -315,6 +317,20 @@ namespace Content.Shared.Chemistry return newSolution; } + public void DoEntityReaction(IEntity entity, ReactionMethod method) + { + var proto = IoCManager.Resolve(); + + foreach (var (reagentId, quantity) in _contents) + { + if (!proto.TryIndex(reagentId, out ReagentPrototype reagent)) + continue; + + var removedAmount = reagent.ReactionEntity(entity, method, quantity); + RemoveReagent(reagentId, removedAmount); + } + } + [Serializable, NetSerializable] public readonly struct ReagentQuantity: IComparable {