From 4cf8e18d1fdc353dd1ca1fa39e5b0fc2952c0673 Mon Sep 17 00:00:00 2001 From: moneyl <8206401+Moneyl@users.noreply.github.com> Date: Wed, 4 Dec 2019 07:51:05 -0500 Subject: [PATCH] Fix bug with chemical reactions which cause other reactions (#475) SolutionComponent.CheckForReaction only checks for a reaction once, meaning that if a reaction generates reagents that create a solution that's valid for another reaction, that second reaction doesn't occur. This fixes that by repeatedly checking for a reaction until no more occur. --- .../Components/Chemistry/SolutionComponent.cs | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/Content.Server/GameObjects/Components/Chemistry/SolutionComponent.cs b/Content.Server/GameObjects/Components/Chemistry/SolutionComponent.cs index 01b417a933..ffd687b476 100644 --- a/Content.Server/GameObjects/Components/Chemistry/SolutionComponent.cs +++ b/Content.Server/GameObjects/Components/Chemistry/SolutionComponent.cs @@ -192,14 +192,27 @@ namespace Content.Server.GameObjects.Components.Chemistry private void CheckForReaction() { - //Check the solution for every reaction - foreach (var reaction in _reactions) + bool checkForNewReaction = false; + while (true) { - if (SolutionValidReaction(reaction, out int unitReactions)) + //Check the solution for every reaction + foreach (var reaction in _reactions) { - PerformReaction(reaction, unitReactions); - break; //Only perform one reaction per solution per update. + if (SolutionValidReaction(reaction, out int unitReactions)) + { + PerformReaction(reaction, unitReactions); + checkForNewReaction = true; + break; + } } + + //Check for a new reaction if a reaction occurs, run loop again. + if (checkForNewReaction) + { + checkForNewReaction = false; + continue; + } + return; } }