]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
regenerate partial amounts (#15573)
authordeltanedas <39013340+deltanedas@users.noreply.github.com>
Mon, 24 Apr 2023 00:02:57 +0000 (00:02 +0000)
committerGitHub <noreply@github.com>
Mon, 24 Apr 2023 00:02:57 +0000 (10:02 +1000)
Co-authored-by: deltanedas <@deltanedas:kde.org>
Content.Server/Chemistry/EntitySystems/SolutionRegenerationSystem.cs

index d6d74820d13eb61c7e4a9f95d02ddd4fe3ce4b80..7e11044dc9367545a49c04ee9d2a682d7fe8f6b1 100644 (file)
@@ -1,5 +1,7 @@
 using Content.Server.Chemistry.Components;
 using Content.Server.Chemistry.Components.SolutionManager;
+using Content.Shared.Chemistry.Components;
+using Content.Shared.FixedPoint;
 using Robust.Shared.Timing;
 
 namespace Content.Server.Chemistry.EntitySystems;
@@ -29,7 +31,24 @@ public sealed class SolutionRegenerationSystem : EntitySystem
             // timer ignores if its full, it's just a fixed cycle
             regen.NextRegenTime = _timing.CurTime + regen.Duration;
             if (_solutionContainer.TryGetSolution(uid, regen.Solution, out var solution, manager))
-                _solutionContainer.TryAddSolution(uid, solution, regen.Generated);
+            {
+                var amount = FixedPoint2.Min(solution.AvailableVolume, regen.Generated.Volume);
+                if (amount <= FixedPoint2.Zero)
+                    continue;
+
+                // dont bother cloning and splitting if adding the whole thing
+                Solution generated;
+                if (amount == regen.Generated.Volume)
+                {
+                    generated = regen.Generated;
+                }
+                else
+                {
+                    generated = regen.Generated.Clone().SplitSolution(amount);
+                }
+
+                _solutionContainer.TryAddSolution(uid, solution, generated);
+            }
         }
     }