Changed all int and some float things in Reagent code to Decimals
This commit is contained in:
@@ -7,6 +7,7 @@ using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Server.Interfaces;
|
||||
using Content.Shared.Chemistry;
|
||||
using Content.Shared.GameObjects;
|
||||
using Content.Shared.Maths;
|
||||
using Robust.Server.GameObjects.EntitySystems;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
@@ -205,7 +206,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
//Check the solution for every reaction
|
||||
foreach (var reaction in _reactions)
|
||||
{
|
||||
if (SolutionValidReaction(reaction, out int unitReactions))
|
||||
if (SolutionValidReaction(reaction, out var unitReactions))
|
||||
{
|
||||
PerformReaction(reaction, unitReactions);
|
||||
checkForNewReaction = true;
|
||||
@@ -223,11 +224,13 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryAddReagent(string reagentId, int quantity, out int acceptedQuantity, bool skipReactionCheck = false, bool skipColor = false)
|
||||
public bool TryAddReagent(string reagentId, decimal quantity, out decimal acceptedQuantity, bool skipReactionCheck = false, bool skipColor = false)
|
||||
{
|
||||
if (quantity > _maxVolume - _containedSolution.TotalVolume)
|
||||
quantity = quantity.RoundForReagents();
|
||||
var toAcceptQuantity = (_maxVolume - _containedSolution.TotalVolume).RoundForReagents();
|
||||
if (quantity > toAcceptQuantity)
|
||||
{
|
||||
acceptedQuantity = _maxVolume - _containedSolution.TotalVolume;
|
||||
acceptedQuantity = toAcceptQuantity;
|
||||
if (acceptedQuantity == 0) return false;
|
||||
}
|
||||
else
|
||||
@@ -267,16 +270,16 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
/// <param name="reaction">The reaction whose reactants will be checked for in the solution.</param>
|
||||
/// <param name="unitReactions">The number of times the reaction can occur with the given solution.</param>
|
||||
/// <returns></returns>
|
||||
private bool SolutionValidReaction(ReactionPrototype reaction, out int unitReactions)
|
||||
private bool SolutionValidReaction(ReactionPrototype reaction, out decimal unitReactions)
|
||||
{
|
||||
unitReactions = int.MaxValue; //Set to some impossibly large number initially
|
||||
unitReactions = decimal.MaxValue; //Set to some impossibly large number initially
|
||||
foreach (var reactant in reaction.Reactants)
|
||||
{
|
||||
if (!ContainsReagent(reactant.Key, out int reagentQuantity))
|
||||
if (!ContainsReagent(reactant.Key, out decimal reagentQuantity))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
int currentUnitReactions = reagentQuantity / reactant.Value.Amount;
|
||||
var currentUnitReactions = (reagentQuantity / reactant.Value.Amount).RoundForReagents();
|
||||
if (currentUnitReactions < unitReactions)
|
||||
{
|
||||
unitReactions = currentUnitReactions;
|
||||
@@ -299,21 +302,21 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
/// <param name="solution">Solution to be reacted.</param>
|
||||
/// <param name="reaction">Reaction to occur.</param>
|
||||
/// <param name="unitReactions">The number of times to cause this reaction.</param>
|
||||
private void PerformReaction(ReactionPrototype reaction, int unitReactions)
|
||||
private void PerformReaction(ReactionPrototype reaction, decimal unitReactions)
|
||||
{
|
||||
//Remove non-catalysts
|
||||
foreach (var reactant in reaction.Reactants)
|
||||
{
|
||||
if (!reactant.Value.Catalyst)
|
||||
{
|
||||
int amountToRemove = unitReactions * reactant.Value.Amount;
|
||||
var amountToRemove = (unitReactions * reactant.Value.Amount).RoundForReagents();
|
||||
TryRemoveReagent(reactant.Key, amountToRemove);
|
||||
}
|
||||
}
|
||||
//Add products
|
||||
foreach (var product in reaction.Products)
|
||||
{
|
||||
TryAddReagent(product.Key, (int)(unitReactions * product.Value), out int acceptedQuantity, true);
|
||||
TryAddReagent(product.Key, (int)(unitReactions * product.Value), out var acceptedQuantity, true);
|
||||
}
|
||||
//Trigger reaction effects
|
||||
foreach (var effect in reaction.Effects)
|
||||
|
||||
Reference in New Issue
Block a user