Add ReagentWhitelist to Injector component and system (#28262)

* Add reagent whitelist to Injector component and system

* Apply suggested Changes

* Remove LINQ function for performance

* Update Content.Server/Chemistry/EntitySystems/InjectorSystem.cs

Co-authored-by: Ed <96445749+TheShuEd@users.noreply.github.com>

---------

Co-authored-by: Ed <96445749+TheShuEd@users.noreply.github.com>
This commit is contained in:
blueDev2
2024-09-12 06:29:11 -04:00
committed by GitHub
parent 2a6f15dd3e
commit c8f2ddc729
3 changed files with 30 additions and 2 deletions

View File

@@ -327,8 +327,23 @@ public sealed class InjectorSystem : SharedInjectorSystem
return false;
}
var applicableTargetSolution = targetSolution.Comp.Solution;
// If a whitelist exists, remove all non-whitelisted reagents from the target solution temporarily
var temporarilyRemovedSolution = new Solution();
if (injector.Comp.ReagentWhitelist is { } reagentWhitelist)
{
string[] reagentPrototypeWhitelistArray = new string[reagentWhitelist.Count];
var i = 0;
foreach (var reagent in reagentWhitelist)
{
reagentPrototypeWhitelistArray[i] = reagent;
++i;
}
temporarilyRemovedSolution = applicableTargetSolution.SplitSolutionWithout(applicableTargetSolution.Volume, reagentPrototypeWhitelistArray);
}
// Get transfer amount. May be smaller than _transferAmount if not enough room, also make sure there's room in the injector
var realTransferAmount = FixedPoint2.Min(injector.Comp.TransferAmount, targetSolution.Comp.Solution.Volume,
var realTransferAmount = FixedPoint2.Min(injector.Comp.TransferAmount, applicableTargetSolution.Volume,
solution.AvailableVolume);
if (realTransferAmount <= 0)
@@ -350,6 +365,9 @@ public sealed class InjectorSystem : SharedInjectorSystem
// Move units from attackSolution to targetSolution
var removedSolution = SolutionContainers.Draw(target.Owner, targetSolution, realTransferAmount);
// Add back non-whitelisted reagents to the target solution
applicableTargetSolution.AddSolution(temporarilyRemovedSolution, null);
if (!SolutionContainers.TryAddSolution(soln.Value, removedSolution))
{
return false;