Files
Delta-v/Content.Shared/_DV/Chemistry/Components/Solution.cs
T
Sir Warockandpre-commit-ci[bot] 65b32f441f QoL for cryotubes (#4456)
* Port EvenlySplitting for Cryotubes

* Make Trinox consistent

* Bring into DV_Systems

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-10-26 10:47:19 +11:00

62 lines
1.9 KiB
C#

using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
namespace Content.Shared.Chemistry.Components;
public sealed partial class Solution
{
/// <summary>
/// splits the solution taking up to the specified amount of each reagent from the solution.
/// If the solution has less of a reagent than the specified amount, it will take all of that reagent.
/// </summary>
/// <param name="toTakePer">How much of each reagent to take</param>
/// <returns>a new solution containing the reagents taken from the original solution</returns>
public Solution SplitSolutionReagentsEvenly(FixedPoint2 toTakePer)
{
var splitSolution = new Solution();
if (toTakePer <= FixedPoint2.Zero)
return splitSolution;
var reagentsCount = Contents.Count;
var reagentsToRemove = new List<ReagentQuantity>();
for (var i = 0; i < reagentsCount; i++)
{
var currentReagent = Contents[i];
if (currentReagent.Quantity <= FixedPoint2.Zero)
{
reagentsToRemove.Add(currentReagent);
continue;
}
if (currentReagent.Quantity <= toTakePer)
{
splitSolution.AddReagent(currentReagent);
reagentsToRemove.Add(currentReagent);
}
else
{
splitSolution.AddReagent(currentReagent.Reagent, toTakePer);
RemoveReagent(currentReagent.Reagent, toTakePer);
}
}
foreach (var reagent in reagentsToRemove)
{
RemoveReagent(reagent);
}
if (Volume == FixedPoint2.Zero)
RemoveAllSolution();
_heatCapacityDirty = true;
splitSolution._heatCapacityDirty = true;
ValidateSolution();
splitSolution.ValidateSolution();
return splitSolution;
}
}