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.
This commit is contained in:
moneyl
2019-12-04 07:51:05 -05:00
committed by Pieter-Jan Briers
parent 6df5028d7a
commit 4cf8e18d1f

View File

@@ -191,6 +191,9 @@ namespace Content.Server.GameObjects.Components.Chemistry
}
private void CheckForReaction()
{
bool checkForNewReaction = false;
while (true)
{
//Check the solution for every reaction
foreach (var reaction in _reactions)
@@ -198,9 +201,19 @@ namespace Content.Server.GameObjects.Components.Chemistry
if (SolutionValidReaction(reaction, out int unitReactions))
{
PerformReaction(reaction, unitReactions);
break; //Only perform one reaction per solution per update.
checkForNewReaction = true;
break;
}
}
//Check for a new reaction if a reaction occurs, run loop again.
if (checkForNewReaction)
{
checkForNewReaction = false;
continue;
}
return;
}
}
public bool TryAddReagent(string reagentId, int quantity, out int acceptedQuantity, bool skipReactionCheck = false, bool skipColor = false)