Clean up terrible solution entity reaction copy pasta.
This commit is contained in:
@@ -201,19 +201,11 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
|||||||
|
|
||||||
// TODO: Account for partial transfer.
|
// TODO: Account for partial transfer.
|
||||||
|
|
||||||
foreach (var (reagentId, quantity) in removedSolution.Contents)
|
removedSolution.DoEntityReaction(solution.Owner, ReactionMethod.Injection);
|
||||||
{
|
|
||||||
if(!_prototypeManager.TryIndex(reagentId, out ReagentPrototype reagent)) continue;
|
|
||||||
removedSolution.RemoveReagent(reagentId, reagent.ReactionEntity(solution.Owner, ReactionMethod.Injection, quantity));
|
|
||||||
}
|
|
||||||
|
|
||||||
solution.TryAddSolution(removedSolution);
|
solution.TryAddSolution(removedSolution);
|
||||||
|
|
||||||
foreach (var (reagentId, quantity) in removedSolution.Contents)
|
removedSolution.DoEntityReaction(targetBloodstream.Owner, ReactionMethod.Injection);
|
||||||
{
|
|
||||||
if(!_prototypeManager.TryIndex(reagentId, out ReagentPrototype reagent)) continue;
|
|
||||||
reagent.ReactionEntity(targetBloodstream.Owner, ReactionMethod.Injection, quantity);
|
|
||||||
}
|
|
||||||
|
|
||||||
Owner.PopupMessage(user, Loc.GetString("You inject {0}u into {1:theName}!", removedSolution.TotalVolume, targetBloodstream.Owner));
|
Owner.PopupMessage(user, Loc.GetString("You inject {0}u into {1:theName}!", removedSolution.TotalVolume, targetBloodstream.Owner));
|
||||||
Dirty();
|
Dirty();
|
||||||
@@ -243,11 +235,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var (reagentId, quantity) in removedSolution.Contents)
|
removedSolution.DoEntityReaction(targetSolution.Owner, ReactionMethod.Injection);
|
||||||
{
|
|
||||||
if(!_prototypeManager.TryIndex(reagentId, out ReagentPrototype reagent)) continue;
|
|
||||||
removedSolution.RemoveReagent(reagentId, reagent.ReactionEntity(targetSolution.Owner, ReactionMethod.Injection, quantity));
|
|
||||||
}
|
|
||||||
|
|
||||||
targetSolution.TryAddSolution(removedSolution);
|
targetSolution.TryAddSolution(removedSolution);
|
||||||
|
|
||||||
|
|||||||
@@ -103,11 +103,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
|||||||
|
|
||||||
// TODO: Account for partial transfer.
|
// TODO: Account for partial transfer.
|
||||||
|
|
||||||
foreach (var (reagentId, quantity) in split.Contents)
|
split.DoEntityReaction(trueTarget, ReactionMethod.Ingestion);
|
||||||
{
|
|
||||||
if (!_prototypeManager.TryIndex(reagentId, out ReagentPrototype reagent)) continue;
|
|
||||||
split.RemoveReagent(reagentId, reagent.ReactionEntity(trueTarget, ReactionMethod.Ingestion, quantity));
|
|
||||||
}
|
|
||||||
|
|
||||||
firstStomach.TryTransferSolution(split);
|
firstStomach.TryTransferSolution(split);
|
||||||
|
|
||||||
|
|||||||
@@ -135,12 +135,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
|||||||
if (!Owner.TryGetComponent(out SolutionContainerComponent contents))
|
if (!Owner.TryGetComponent(out SolutionContainerComponent contents))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
foreach (var reagentQuantity in contents.ReagentList.ToArray())
|
contents.Solution.DoEntityReaction(collidedWith, ReactionMethod.Touch);
|
||||||
{
|
|
||||||
if (reagentQuantity.Quantity == ReagentUnit.Zero) continue;
|
|
||||||
var reagent = _prototypeManager.Index<ReagentPrototype>(reagentQuantity.ReagentId);
|
|
||||||
contents.TryRemoveReagent(reagentQuantity.ReagentId, reagent.ReactionEntity(collidedWith, ReactionMethod.Touch, reagentQuantity.Quantity * 0.125f));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for collision with a impassable object (e.g. wall) and stop
|
// Check for collision with a impassable object (e.g. wall) and stop
|
||||||
if (collidedWith.TryGetComponent(out IPhysicsComponent physics))
|
if (collidedWith.TryGetComponent(out IPhysicsComponent physics))
|
||||||
|
|||||||
@@ -181,11 +181,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
|||||||
|
|
||||||
// TODO: Account for partial transfer.
|
// TODO: Account for partial transfer.
|
||||||
|
|
||||||
foreach (var (reagentId, quantity) in split.Contents)
|
split.DoEntityReaction(target, ReactionMethod.Ingestion);
|
||||||
{
|
|
||||||
if (!_prototypeManager.TryIndex(reagentId, out ReagentPrototype reagent)) continue;
|
|
||||||
split.RemoveReagent(reagentId, reagent.ReactionEntity(target, ReactionMethod.Ingestion, quantity));
|
|
||||||
}
|
|
||||||
|
|
||||||
firstStomach.TryTransferSolution(split);
|
firstStomach.TryTransferSolution(split);
|
||||||
|
|
||||||
|
|||||||
@@ -183,11 +183,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
|||||||
|
|
||||||
// TODO: Account for partial transfer.
|
// TODO: Account for partial transfer.
|
||||||
|
|
||||||
foreach (var (reagentId, quantity) in split.Contents)
|
split.DoEntityReaction(trueTarget, ReactionMethod.Ingestion);
|
||||||
{
|
|
||||||
if (!_prototypeManager.TryIndex(reagentId, out ReagentPrototype reagent)) continue;
|
|
||||||
split.RemoveReagent(reagentId, reagent.ReactionEntity(trueTarget, ReactionMethod.Ingestion, quantity));
|
|
||||||
}
|
|
||||||
|
|
||||||
firstStomach.TryTransferSolution(split);
|
firstStomach.TryTransferSolution(split);
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ using System.Collections;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Content.Shared.Interfaces.GameObjects.Components;
|
||||||
|
using Robust.Shared.Interfaces.GameObjects;
|
||||||
using Robust.Shared.Interfaces.Serialization;
|
using Robust.Shared.Interfaces.Serialization;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
using Robust.Shared.Maths;
|
using Robust.Shared.Maths;
|
||||||
@@ -315,6 +317,20 @@ namespace Content.Shared.Chemistry
|
|||||||
return newSolution;
|
return newSolution;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void DoEntityReaction(IEntity entity, ReactionMethod method)
|
||||||
|
{
|
||||||
|
var proto = IoCManager.Resolve<IPrototypeManager>();
|
||||||
|
|
||||||
|
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]
|
[Serializable, NetSerializable]
|
||||||
public readonly struct ReagentQuantity: IComparable<ReagentQuantity>
|
public readonly struct ReagentQuantity: IComparable<ReagentQuantity>
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user