Refactor reaction effects to use reagent effects (#5426)

* reaction effect refactor

* works now
This commit is contained in:
mirrorcult
2021-11-21 00:35:02 -07:00
committed by GitHub
parent 9b39838db7
commit 1ab7170adb
36 changed files with 83 additions and 82 deletions

View File

@@ -6,6 +6,7 @@ using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
namespace Content.Shared.Chemistry.Reaction
{
@@ -16,6 +17,7 @@ namespace Content.Shared.Chemistry.Reaction
private const int MaxReactionIterations = 20;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IRobustRandom _random = default!;
public override void Initialize()
{
@@ -58,6 +60,9 @@ namespace Content.Shared.Chemistry.Reaction
/// </summary>
private Solution PerformReaction(Solution solution, EntityUid ownerUid, ReactionPrototype reaction, FixedPoint2 unitReactions)
{
// We do this so that ReagentEffect can have something to work with, even if it's
// a little meaningless.
var randomReagent = _prototypeManager.Index<ReagentPrototype>(_random.Pick(reaction.Reactants).Key);
//Remove reactants
foreach (var reactant in reaction.Reactants)
{
@@ -76,16 +81,23 @@ namespace Content.Shared.Chemistry.Reaction
}
// Trigger reaction effects
OnReaction(solution, reaction, ownerUid, unitReactions);
OnReaction(solution, reaction, randomReagent, ownerUid, unitReactions);
return products;
}
protected virtual void OnReaction(Solution solution, ReactionPrototype reaction, EntityUid ownerUid, FixedPoint2 unitReactions)
protected virtual void OnReaction(Solution solution, ReactionPrototype reaction, ReagentPrototype randomReagent, EntityUid ownerUid, FixedPoint2 unitReactions)
{
var args = new ReagentEffectArgs(ownerUid, null, solution,
randomReagent,
unitReactions, EntityManager, null);
foreach (var effect in reaction.Effects)
{
effect.React(solution, ownerUid, unitReactions.Double(), EntityManager);
if (!effect.ShouldApply(args))
continue;
effect.Effect(args);
}
}