Allow solutions to store extra reagent data (#19323)

This commit is contained in:
Leon Friedrich
2023-09-05 09:55:10 +12:00
committed by GitHub
parent a6b81058d0
commit e4ca6f4fb9
52 changed files with 932 additions and 538 deletions

View File

@@ -1,5 +1,7 @@
using Content.Server.Body.Systems;
using Content.Server.Nutrition.EntitySystems;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
using Content.Shared.Whitelist;
@@ -46,14 +48,12 @@ namespace Content.Server.Body.Components
/// </summary>
public sealed class ReagentDelta
{
public readonly string ReagentId;
public readonly FixedPoint2 Quantity;
public readonly ReagentQuantity ReagentQuantity;
public float Lifetime { get; private set; }
public ReagentDelta(string reagentId, FixedPoint2 quantity)
public ReagentDelta(ReagentQuantity reagentQuantity)
{
ReagentId = reagentId;
Quantity = quantity;
ReagentQuantity = reagentQuantity;
Lifetime = 0.0f;
}

View File

@@ -274,9 +274,9 @@ public sealed class BloodstreamSystem : EntitySystem
for (var i = component.ChemicalSolution.Contents.Count - 1; i >= 0; i--)
{
var (reagentId, _) = component.ChemicalSolution.Contents[i];
if (reagentId != excludedReagentID)
if (reagentId.Prototype != excludedReagentID)
{
_solutionContainerSystem.TryRemoveReagent(uid, component.ChemicalSolution, reagentId, quantity);
_solutionContainerSystem.RemoveReagent(uid, component.ChemicalSolution, reagentId, quantity);
}
}

View File

@@ -128,9 +128,9 @@ namespace Content.Server.Body.Systems
_random.Shuffle(list);
int reagents = 0;
foreach (var reagent in list)
foreach (var (reagent, quantity) in list)
{
if (!_prototypeManager.TryIndex<ReagentPrototype>(reagent.ReagentId, out var proto))
if (!_prototypeManager.TryIndex<ReagentPrototype>(reagent.Prototype, out var proto))
continue;
var mostToRemove = FixedPoint2.Zero;
@@ -138,7 +138,7 @@ namespace Content.Server.Body.Systems
{
if (meta.RemoveEmpty)
{
_solutionContainerSystem.TryRemoveReagent(solutionEntityUid.Value, solution, reagent.ReagentId,
_solutionContainerSystem.RemoveReagent(solutionEntityUid.Value, solution, reagent,
FixedPoint2.New(1));
}
@@ -168,7 +168,7 @@ namespace Content.Server.Body.Systems
mostToRemove *= group.MetabolismRateModifier;
mostToRemove = FixedPoint2.Clamp(mostToRemove, 0, reagent.Quantity);
mostToRemove = FixedPoint2.Clamp(mostToRemove, 0, quantity);
float scale = (float) mostToRemove / (float) entry.MetabolismRate;
@@ -204,8 +204,7 @@ namespace Content.Server.Body.Systems
// remove a certain amount of reagent
if (mostToRemove > FixedPoint2.Zero)
{
_solutionContainerSystem.TryRemoveReagent(solutionEntityUid.Value, solution, reagent.ReagentId,
mostToRemove);
_solutionContainerSystem.RemoveReagent(solutionEntityUid.Value, solution, reagent, mostToRemove);
}
}
}

View File

@@ -45,14 +45,13 @@ namespace Content.Server.Body.Systems
delta.Increment(stomach.UpdateInterval);
if (delta.Lifetime > stomach.DigestionDelay)
{
if (stomachSolution.TryGetReagent(delta.ReagentId, out var quant))
if (stomachSolution.TryGetReagent(delta.ReagentQuantity.Reagent, out var reagent))
{
if (quant > delta.Quantity)
quant = delta.Quantity;
if (reagent.Quantity > delta.ReagentQuantity.Quantity)
reagent = new(reagent.Reagent, delta.ReagentQuantity.Quantity);
_solutionContainerSystem.TryRemoveReagent((stomach).Owner, stomachSolution,
delta.ReagentId, quant);
transferSolution.AddReagent(delta.ReagentId, quant);
_solutionContainerSystem.RemoveReagent((stomach).Owner, stomachSolution, reagent);
transferSolution.AddReagent(reagent);
}
queue.Add(delta);
@@ -116,7 +115,7 @@ namespace Content.Server.Body.Systems
// Add each reagent to ReagentDeltas. Used to track how long each reagent has been in the stomach
foreach (var reagent in solution.Contents)
{
stomach.ReagentDeltas.Add(new StomachComponent.ReagentDelta(reagent.ReagentId, reagent.Quantity));
stomach.ReagentDeltas.Add(new StomachComponent.ReagentDelta(reagent));
}
return true;