Revert 'Revert 'Solution Entities'' (#23168)

This commit is contained in:
TemporalOroboros
2023-12-29 04:47:43 -08:00
committed by GitHub
parent 93e1af2f8d
commit d23c8d5c19
180 changed files with 3541 additions and 2956 deletions

View File

@@ -34,52 +34,52 @@ namespace Content.Server.Body.Components
/// <summary>
/// How much should bleeding should be reduced every update interval?
/// </summary>
[DataField("bleedReductionAmount")]
[DataField]
public float BleedReductionAmount = 1.0f;
/// <summary>
/// How high can <see cref="BleedAmount"/> go?
/// </summary>
[DataField("maxBleedAmount")]
[DataField]
public float MaxBleedAmount = 10.0f;
/// <summary>
/// What percentage of current blood is necessary to avoid dealing blood loss damage?
/// </summary>
[DataField("bloodlossThreshold")]
[DataField]
public float BloodlossThreshold = 0.9f;
/// <summary>
/// The base bloodloss damage to be incurred if below <see cref="BloodlossThreshold"/>
/// The default values are defined per mob/species in YML.
/// </summary>
[DataField("bloodlossDamage", required: true)]
[DataField(required: true)]
public DamageSpecifier BloodlossDamage = new();
/// <summary>
/// The base bloodloss damage to be healed if above <see cref="BloodlossThreshold"/>
/// The default values are defined per mob/species in YML.
/// </summary>
[DataField("bloodlossHealDamage", required: true)]
[DataField(required: true)]
public DamageSpecifier BloodlossHealDamage = new();
/// <summary>
/// How frequently should this bloodstream update, in seconds?
/// </summary>
[DataField("updateInterval")]
[DataField]
public float UpdateInterval = 3.0f;
// TODO shouldn't be hardcoded, should just use some organ simulation like bone marrow or smth.
/// <summary>
/// How much reagent of blood should be restored each update interval?
/// </summary>
[DataField("bloodRefreshAmount")]
[DataField]
public float BloodRefreshAmount = 1.0f;
/// <summary>
/// How much blood needs to be in the temporary solution in order to create a puddle?
/// </summary>
[DataField("bleedPuddleThreshold")]
[DataField]
public FixedPoint2 BleedPuddleThreshold = 1.0f;
/// <summary>
@@ -89,19 +89,19 @@ namespace Content.Server.Body.Components
/// <remarks>
/// For example, piercing damage is increased while poison damage is nullified entirely.
/// </remarks>
[DataField("damageBleedModifiers", customTypeSerializer:typeof(PrototypeIdSerializer<DamageModifierSetPrototype>))]
[DataField(customTypeSerializer:typeof(PrototypeIdSerializer<DamageModifierSetPrototype>))]
public string DamageBleedModifiers = "BloodlossHuman";
/// <summary>
/// The sound to be played when a weapon instantly deals blood loss damage.
/// </summary>
[DataField("instantBloodSound")]
[DataField]
public SoundSpecifier InstantBloodSound = new SoundCollectionSpecifier("blood");
/// <summary>
/// The sound to be played when some damage actually heals bleeding rather than starting it.
/// </summary>
[DataField("bloodHealedSound")]
[DataField]
public SoundSpecifier BloodHealedSound = new SoundPathSpecifier("/Audio/Effects/lightburn.ogg");
// TODO probably damage bleed thresholds.
@@ -109,14 +109,14 @@ namespace Content.Server.Body.Components
/// <summary>
/// Max volume of internal chemical solution storage
/// </summary>
[DataField("chemicalMaxVolume")]
[DataField]
public FixedPoint2 ChemicalMaxVolume = FixedPoint2.New(250);
/// <summary>
/// Max volume of internal blood storage,
/// and starting level of blood.
/// </summary>
[DataField("bloodMaxVolume")]
[DataField]
public FixedPoint2 BloodMaxVolume = FixedPoint2.New(300);
/// <summary>
@@ -125,29 +125,40 @@ namespace Content.Server.Body.Components
/// <remarks>
/// Slime-people might use slime as their blood or something like that.
/// </remarks>
[DataField("bloodReagent")]
[DataField]
public string BloodReagent = "Blood";
/// <summary>
/// Internal solution for reagent storage
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[Access(typeof(BloodstreamSystem), Other = AccessPermissions.ReadExecute)] // FIXME Friends
public Solution ChemicalSolution = default!;
/// <summary>Name/Key that <see cref="BloodSolution"/> is indexed by.</summary>
[DataField]
public string BloodSolutionName = DefaultBloodSolutionName;
/// <summary>Name/Key that <see cref="ChemicalSolution"/> is indexed by.</summary>
[DataField]
public string ChemicalSolutionName = DefaultChemicalsSolutionName;
/// <summary>Name/Key that <see cref="TemporarySolution"/> is indexed by.</summary>
[DataField]
public string BloodTemporarySolutionName = DefaultBloodTemporarySolutionName;
/// <summary>
/// Internal solution for blood storage
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public Solution BloodSolution = default!;
[DataField]
public Entity<SolutionComponent>? BloodSolution = null;
/// <summary>
/// Internal solution for reagent storage
/// </summary>
[DataField]
public Entity<SolutionComponent>? ChemicalSolution = null;
/// <summary>
/// Temporary blood solution.
/// When blood is lost, it goes to this solution, and when this
/// solution hits a certain cap, the blood is actually spilled as a puddle.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public Solution BloodTemporarySolution = default!;
[DataField]
public Entity<SolutionComponent>? TemporarySolution = null;
/// <summary>
/// Variable that stores the amount of status time added by having a low blood level.

View File

@@ -8,7 +8,7 @@ namespace Content.Server.Body.Components;
[RegisterComponent, Access(typeof(LungSystem))]
public sealed partial class LungComponent : Component
{
[DataField("air")]
[DataField]
[Access(typeof(LungSystem), Other = AccessPermissions.ReadExecute)] // FIXME Friends
public GasMixture Air { get; set; } = new()
{
@@ -16,7 +16,15 @@ public sealed partial class LungComponent : Component
Temperature = Atmospherics.NormalBodyTemperature
};
[ViewVariables]
[Access(typeof(LungSystem), Other = AccessPermissions.ReadExecute)] // FIXME Friends
public Solution LungSolution = default!;
/// <summary>
/// The name/key of the solution on this entity which these lungs act on.
/// </summary>
[DataField]
public string SolutionName = LungSystem.LungSolutionName;
/// <summary>
/// The solution on this entity that these lungs act on.
/// </summary>
[DataField]
public Entity<SolutionComponent>? Solution = null;
}

View File

@@ -18,7 +18,7 @@ namespace Content.Server.Body.Components
/// How often to metabolize reagents, in seconds.
/// </summary>
/// <returns></returns>
[DataField("updateFrequency")]
[DataField]
public float UpdateFrequency = 1.0f;
/// <summary>
@@ -33,13 +33,13 @@ namespace Content.Server.Body.Components
/// <remarks>
/// Most things will use the parent entity (bloodstream).
/// </remarks>
[DataField("solutionOnBody")]
[DataField]
public bool SolutionOnBody = true;
/// <summary>
/// List of metabolizer types that this organ is. ex. Human, Slime, Felinid, w/e.
/// </summary>
[DataField("metabolizerTypes", customTypeSerializer:typeof(PrototypeIdHashSetSerializer<MetabolizerTypePrototype>))]
[DataField(customTypeSerializer:typeof(PrototypeIdHashSetSerializer<MetabolizerTypePrototype>))]
[Access(typeof(MetabolizerSystem), Other = AccessPermissions.ReadExecute)] // FIXME Friends
public HashSet<string>? MetabolizerTypes = null;
@@ -47,7 +47,7 @@ namespace Content.Server.Body.Components
/// Should this metabolizer remove chemicals that have no metabolisms defined?
/// As a stop-gap, basically.
/// </summary>
[DataField("removeEmpty")]
[DataField]
public bool RemoveEmpty = false;
/// <summary>
@@ -72,7 +72,7 @@ namespace Content.Server.Body.Components
[DataDefinition]
public sealed partial class MetabolismGroupEntry
{
[DataField("id", required: true, customTypeSerializer:typeof(PrototypeIdSerializer<MetabolismGroupPrototype>))]
[DataField(required: true, customTypeSerializer:typeof(PrototypeIdSerializer<MetabolismGroupPrototype>))]
public string Id = default!;
[DataField("rateModifier")]

View File

@@ -2,7 +2,6 @@
using Content.Server.Nutrition.EntitySystems;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
using Content.Shared.Whitelist;
namespace Content.Server.Body.Components
@@ -15,26 +14,32 @@ namespace Content.Server.Body.Components
/// <summary>
/// How fast should this component update, in seconds?
/// </summary>
[DataField("updateInterval")]
[DataField]
public float UpdateInterval = 1.0f;
/// <summary>
/// The solution inside of this stomach this transfers reagents to the body.
/// </summary>
[DataField]
public Entity<SolutionComponent>? Solution = null;
/// <summary>
/// What solution should this stomach push reagents into, on the body?
/// </summary>
[DataField("bodySolutionName")]
[DataField]
public string BodySolutionName = BloodstreamComponent.DefaultChemicalsSolutionName;
/// <summary>
/// Time in seconds between reagents being ingested and them being
/// transferred to <see cref="BloodstreamComponent"/>
/// </summary>
[DataField("digestionDelay")]
[DataField]
public float DigestionDelay = 20;
/// <summary>
/// A whitelist for what special-digestible-required foods this stomach is capable of eating.
/// </summary>
[DataField("specialDigestible")]
[DataField]
public EntityWhitelist? SpecialDigestible = null;
/// <summary>

View File

@@ -1,6 +1,8 @@
using Content.Server.Body.Components;
using Content.Server.Chemistry.Containers.EntitySystems;
using Content.Server.Chemistry.ReactionEffects;
using Content.Server.Fluids.EntitySystems;
using Content.Server.Forensics;
using Content.Server.HealthExaminable;
using Content.Server.Popups;
using Content.Shared.Alert;
@@ -16,13 +18,9 @@ using Content.Shared.Mobs.Systems;
using Content.Shared.Popups;
using Content.Shared.Rejuvenate;
using Content.Shared.Speech.EntitySystems;
using Robust.Server.GameObjects;
using Robust.Server.Audio;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Content.Shared.Speech.EntitySystems;
using Robust.Server.Audio;
using Robust.Shared.GameObjects;
using Content.Server.Forensics;
namespace Content.Server.Body.Systems;
@@ -51,14 +49,13 @@ public sealed class BloodstreamSystem : EntitySystem
SubscribeLocalEvent<BloodstreamComponent, BeingGibbedEvent>(OnBeingGibbed);
SubscribeLocalEvent<BloodstreamComponent, ApplyMetabolicMultiplierEvent>(OnApplyMetabolicMultiplier);
SubscribeLocalEvent<BloodstreamComponent, ReactionAttemptEvent>(OnReactionAttempt);
SubscribeLocalEvent<BloodstreamComponent, SolutionRelayEvent<ReactionAttemptEvent>>(OnReactionAttempt);
SubscribeLocalEvent<BloodstreamComponent, RejuvenateEvent>(OnRejuvenate);
}
private void OnReactionAttempt(EntityUid uid, BloodstreamComponent component, ReactionAttemptEvent args)
private void OnReactionAttempt(Entity<BloodstreamComponent> entity, ref ReactionAttemptEvent args)
{
if (args.Solution.Name != BloodstreamComponent.DefaultBloodSolutionName
&& args.Solution.Name != BloodstreamComponent.DefaultChemicalsSolutionName
&& args.Solution.Name != BloodstreamComponent.DefaultBloodTemporarySolutionName)
if (args.Cancelled)
return;
foreach (var effect in args.Reaction.Effects)
@@ -67,7 +64,7 @@ public sealed class BloodstreamSystem : EntitySystem
{
case CreateEntityReactionEffect: // Prevent entities from spawning in the bloodstream
case AreaReactionEffect: // No spontaneous smoke or foam leaking out of blood vessels.
args.Cancel();
args.Cancelled = true;
return;
}
}
@@ -81,6 +78,16 @@ public sealed class BloodstreamSystem : EntitySystem
// Having cheese-clots form in your veins can't be good for you.
}
private void OnReactionAttempt(Entity<BloodstreamComponent> entity, ref SolutionRelayEvent<ReactionAttemptEvent> args)
{
if (args.Name != entity.Comp.BloodSolutionName
&& args.Name != entity.Comp.ChemicalSolutionName
&& args.Name != entity.Comp.BloodTemporarySolutionName)
return;
OnReactionAttempt(entity, ref args.Event);
}
public override void Update(float frameTime)
{
base.Update(frameTime);
@@ -95,8 +102,11 @@ public sealed class BloodstreamSystem : EntitySystem
bloodstream.AccumulatedFrametime -= bloodstream.UpdateInterval;
if (!_solutionContainerSystem.ResolveSolution(uid, bloodstream.BloodSolutionName, ref bloodstream.BloodSolution, out var bloodSolution))
continue;
// Adds blood to their blood level if it is below the maximum; Blood regeneration. Must be alive.
if (bloodstream.BloodSolution.Volume < bloodstream.BloodSolution.MaxVolume && !_mobStateSystem.IsDead(uid))
if (bloodSolution.Volume < bloodSolution.MaxVolume && !_mobStateSystem.IsDead(uid))
{
TryModifyBloodLevel(uid, bloodstream.BloodRefreshAmount, bloodstream);
}
@@ -143,19 +153,18 @@ public sealed class BloodstreamSystem : EntitySystem
}
}
private void OnComponentInit(EntityUid uid, BloodstreamComponent component, ComponentInit args)
private void OnComponentInit(Entity<BloodstreamComponent> entity, ref ComponentInit args)
{
component.ChemicalSolution = _solutionContainerSystem.EnsureSolution(uid, BloodstreamComponent.DefaultChemicalsSolutionName);
component.BloodSolution = _solutionContainerSystem.EnsureSolution(uid, BloodstreamComponent.DefaultBloodSolutionName);
component.BloodTemporarySolution = _solutionContainerSystem.EnsureSolution(uid, BloodstreamComponent.DefaultBloodTemporarySolutionName);
var chemicalSolution = _solutionContainerSystem.EnsureSolution(entity.Owner, entity.Comp.ChemicalSolutionName);
var bloodSolution = _solutionContainerSystem.EnsureSolution(entity.Owner, entity.Comp.BloodSolutionName);
var tempSolution = _solutionContainerSystem.EnsureSolution(entity.Owner, entity.Comp.BloodTemporarySolutionName);
component.ChemicalSolution.MaxVolume = component.ChemicalMaxVolume;
component.BloodSolution.MaxVolume = component.BloodMaxVolume;
component.BloodTemporarySolution.MaxVolume = component.BleedPuddleThreshold * 4; // give some leeway, for chemstream as well
chemicalSolution.MaxVolume = entity.Comp.ChemicalMaxVolume;
bloodSolution.MaxVolume = entity.Comp.BloodMaxVolume;
tempSolution.MaxVolume = entity.Comp.BleedPuddleThreshold * 4; // give some leeway, for chemstream as well
// Fill blood solution with BLOOD
_solutionContainerSystem.TryAddReagent(uid, component.BloodSolution, component.BloodReagent,
component.BloodMaxVolume, out _);
bloodSolution.AddReagent(entity.Comp.BloodReagent, entity.Comp.BloodMaxVolume - bloodSolution.Volume);
}
private void OnDamageChanged(EntityUid uid, BloodstreamComponent component, DamageChangedEvent args)
@@ -250,34 +259,45 @@ public sealed class BloodstreamSystem : EntitySystem
component.AccumulatedFrametime = component.UpdateInterval;
}
private void OnRejuvenate(EntityUid uid, BloodstreamComponent component, RejuvenateEvent args)
private void OnRejuvenate(Entity<BloodstreamComponent> entity, ref RejuvenateEvent args)
{
TryModifyBleedAmount(uid, -component.BleedAmount, component);
TryModifyBloodLevel(uid, component.BloodSolution.AvailableVolume, component);
_solutionContainerSystem.RemoveAllSolution(uid, component.ChemicalSolution);
TryModifyBleedAmount(entity.Owner, -entity.Comp.BleedAmount, entity.Comp);
if (_solutionContainerSystem.ResolveSolution(entity.Owner, entity.Comp.BloodSolutionName, ref entity.Comp.BloodSolution, out var bloodSolution))
TryModifyBloodLevel(entity.Owner, bloodSolution.AvailableVolume, entity.Comp);
if (_solutionContainerSystem.ResolveSolution(entity.Owner, entity.Comp.ChemicalSolutionName, ref entity.Comp.ChemicalSolution))
_solutionContainerSystem.RemoveAllSolution(entity.Comp.ChemicalSolution.Value);
}
/// <summary>
/// Attempt to transfer provided solution to internal solution.
/// </summary>
public bool TryAddToChemicals(EntityUid uid, Solution solution, BloodstreamComponent? component=null)
public bool TryAddToChemicals(EntityUid uid, Solution solution, BloodstreamComponent? component = null)
{
if (!Resolve(uid, ref component, false))
return false;
return _solutionContainerSystem.TryAddSolution(uid, component.ChemicalSolution, solution);
if (!_solutionContainerSystem.ResolveSolution(uid, component.ChemicalSolutionName, ref component.ChemicalSolution))
return false;
return _solutionContainerSystem.TryAddSolution(component.ChemicalSolution.Value, solution);
}
public bool FlushChemicals(EntityUid uid, string excludedReagentID, FixedPoint2 quantity, BloodstreamComponent? component = null) {
public bool FlushChemicals(EntityUid uid, string excludedReagentID, FixedPoint2 quantity, BloodstreamComponent? component = null)
{
if (!Resolve(uid, ref component, false))
return false;
for (var i = component.ChemicalSolution.Contents.Count - 1; i >= 0; i--)
if (!_solutionContainerSystem.ResolveSolution(uid, component.ChemicalSolutionName, ref component.ChemicalSolution, out var chemSolution))
return false;
for (var i = chemSolution.Contents.Count - 1; i >= 0; i--)
{
var (reagentId, _) = component.ChemicalSolution.Contents[i];
var (reagentId, _) = chemSolution.Contents[i];
if (reagentId.Prototype != excludedReagentID)
{
_solutionContainerSystem.RemoveReagent(uid, component.ChemicalSolution, reagentId, quantity);
_solutionContainerSystem.RemoveReagent(component.ChemicalSolution.Value, reagentId, quantity);
}
}
@@ -289,7 +309,10 @@ public sealed class BloodstreamSystem : EntitySystem
if (!Resolve(uid, ref component))
return 0.0f;
return component.BloodSolution.FillFraction;
if (!_solutionContainerSystem.ResolveSolution(uid, component.BloodSolutionName, ref component.BloodSolution, out var bloodSolution))
return 0.0f;
return bloodSolution.FillFraction;
}
public void SetBloodLossThreshold(EntityUid uid, float threshold, BloodstreamComponent? comp = null)
@@ -308,28 +331,41 @@ public sealed class BloodstreamSystem : EntitySystem
if (!Resolve(uid, ref component, false))
return false;
if (!_solutionContainerSystem.ResolveSolution(uid, component.BloodSolutionName, ref component.BloodSolution))
return false;
if (amount >= 0)
return _solutionContainerSystem.TryAddReagent(uid, component.BloodSolution, component.BloodReagent, amount, out _);
return _solutionContainerSystem.TryAddReagent(component.BloodSolution.Value, component.BloodReagent, amount, out _);
// Removal is more involved,
// since we also wanna handle moving it to the temporary solution
// and then spilling it if necessary.
var newSol = component.BloodSolution.SplitSolution(-amount);
component.BloodTemporarySolution.AddSolution(newSol, _prototypeManager);
var newSol = _solutionContainerSystem.SplitSolution(component.BloodSolution.Value, -amount);
if (component.BloodTemporarySolution.Volume > component.BleedPuddleThreshold)
if (!_solutionContainerSystem.ResolveSolution(uid, component.BloodTemporarySolutionName, ref component.TemporarySolution, out var tempSolution))
return true;
tempSolution.AddSolution(newSol, _prototypeManager);
if (tempSolution.Volume > component.BleedPuddleThreshold)
{
// Pass some of the chemstream into the spilled blood.
var temp = component.ChemicalSolution.SplitSolution(component.BloodTemporarySolution.Volume / 10);
component.BloodTemporarySolution.AddSolution(temp, _prototypeManager);
if (_puddleSystem.TrySpillAt(uid, component.BloodTemporarySolution, out var puddleUid, false))
if (_solutionContainerSystem.ResolveSolution(uid, component.ChemicalSolutionName, ref component.ChemicalSolution))
{
var temp = _solutionContainerSystem.SplitSolution(component.ChemicalSolution.Value, tempSolution.Volume / 10);
tempSolution.AddSolution(temp, _prototypeManager);
}
if (_puddleSystem.TrySpillAt(uid, tempSolution, out var puddleUid, false))
{
_forensicsSystem.TransferDna(puddleUid, uid, false);
}
component.BloodTemporarySolution.RemoveAllSolution();
tempSolution.RemoveAllSolution();
}
_solutionContainerSystem.UpdateChemicals(component.TemporarySolution.Value);
return true;
}
@@ -363,16 +399,28 @@ public sealed class BloodstreamSystem : EntitySystem
if (!Resolve(uid, ref component))
return;
var max = component.BloodSolution.MaxVolume + component.BloodTemporarySolution.MaxVolume +
component.ChemicalSolution.MaxVolume;
var tempSol = new Solution() { MaxVolume = max };
var tempSol = new Solution();
tempSol.AddSolution(component.BloodSolution, _prototypeManager);
component.BloodSolution.RemoveAllSolution();
tempSol.AddSolution(component.BloodTemporarySolution, _prototypeManager);
component.BloodTemporarySolution.RemoveAllSolution();
tempSol.AddSolution(component.ChemicalSolution, _prototypeManager);
component.ChemicalSolution.RemoveAllSolution();
if (_solutionContainerSystem.ResolveSolution(uid, component.BloodSolutionName, ref component.BloodSolution, out var bloodSolution))
{
tempSol.MaxVolume += bloodSolution.MaxVolume;
tempSol.AddSolution(bloodSolution, _prototypeManager);
_solutionContainerSystem.RemoveAllSolution(component.BloodSolution.Value);
}
if (_solutionContainerSystem.ResolveSolution(uid, component.ChemicalSolutionName, ref component.ChemicalSolution, out var chemSolution))
{
tempSol.MaxVolume += chemSolution.MaxVolume;
tempSol.AddSolution(chemSolution, _prototypeManager);
_solutionContainerSystem.RemoveAllSolution(component.ChemicalSolution.Value);
}
if (_solutionContainerSystem.ResolveSolution(uid, component.BloodTemporarySolutionName, ref component.TemporarySolution, out var tempSolution))
{
tempSol.MaxVolume += tempSolution.MaxVolume;
tempSol.AddSolution(tempSolution, _prototypeManager);
_solutionContainerSystem.RemoveAllSolution(component.TemporarySolution.Value);
}
if (_puddleSystem.TrySpillAt(uid, tempSol, out var puddleUid))
{
@@ -388,13 +436,20 @@ public sealed class BloodstreamSystem : EntitySystem
if (!Resolve(uid, ref component, false))
return;
if(reagent == component.BloodReagent)
if (reagent == component.BloodReagent)
return;
var currentVolume = component.BloodSolution.Volume;
if (!_solutionContainerSystem.ResolveSolution(uid, component.BloodSolutionName, ref component.BloodSolution, out var bloodSolution))
{
component.BloodReagent = reagent;
return;
}
var currentVolume = bloodSolution.RemoveReagent(component.BloodReagent, bloodSolution.Volume);
component.BloodReagent = reagent;
component.BloodSolution.RemoveAllSolution();
_solutionContainerSystem.TryAddReagent(uid, component.BloodSolution, component.BloodReagent, currentVolume, out _);
if (currentVolume > 0)
_solutionContainerSystem.TryAddReagent(component.BloodSolution.Value, component.BloodReagent, currentVolume, out _);
}
}

View File

@@ -1,8 +1,8 @@
using Content.Server.Atmos.Components;
using Content.Server.Atmos.EntitySystems;
using Content.Server.Body.Components;
using Content.Server.Chemistry.Containers.EntitySystems;
using Content.Shared.Atmos;
using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.Clothing;
using Content.Shared.Inventory.Events;
@@ -44,11 +44,11 @@ public sealed class LungSystem : EntitySystem
}
}
private void OnComponentInit(EntityUid uid, LungComponent component, ComponentInit args)
private void OnComponentInit(Entity<LungComponent> entity, ref ComponentInit args)
{
component.LungSolution = _solutionContainerSystem.EnsureSolution(uid, LungSolutionName);
component.LungSolution.MaxVolume = 100.0f;
component.LungSolution.CanReact = false; // No dexalin lungs
var solution = _solutionContainerSystem.EnsureSolution(entity.Owner, entity.Comp.SolutionName);
solution.MaxVolume = 100.0f;
solution.CanReact = false; // No dexalin lungs
}
private void OnMaskToggled(Entity<BreathToolComponent> ent, ref ItemMaskToggledEvent args)
@@ -71,6 +71,9 @@ public sealed class LungSystem : EntitySystem
public void GasToReagent(EntityUid uid, LungComponent lung)
{
if (!_solutionContainerSystem.ResolveSolution(uid, lung.SolutionName, ref lung.Solution, out var solution))
return;
foreach (var gas in Enum.GetValues<Gas>())
{
var i = (int) gas;
@@ -81,11 +84,13 @@ public sealed class LungSystem : EntitySystem
if (reagent == null) continue;
var amount = moles * Atmospherics.BreathMolesToReagentMultiplier;
_solutionContainerSystem.TryAddReagent(uid, lung.LungSolution, reagent, amount, out _);
solution.AddReagent(reagent, amount);
// We don't remove the gas from the lung mix,
// that's the responsibility of whatever gas is being metabolized.
// Most things will just want to exhale again.
}
_solutionContainerSystem.UpdateChemicals(lung.Solution.Value);
}
}

View File

@@ -1,9 +1,9 @@
using Content.Server.Body.Components;
using Content.Server.Chemistry.Containers.EntitySystems;
using Content.Shared.Administration.Logs;
using Content.Shared.Body.Organ;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Components.SolutionManager;
using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.Database;
using Content.Shared.FixedPoint;
@@ -37,15 +37,15 @@ namespace Content.Server.Body.Systems
SubscribeLocalEvent<MetabolizerComponent, ApplyMetabolicMultiplierEvent>(OnApplyMetabolicMultiplier);
}
private void OnMetabolizerInit(EntityUid uid, MetabolizerComponent component, ComponentInit args)
private void OnMetabolizerInit(Entity<MetabolizerComponent> entity, ref ComponentInit args)
{
if (!component.SolutionOnBody)
if (!entity.Comp.SolutionOnBody)
{
_solutionContainerSystem.EnsureSolution(uid, component.SolutionName);
_solutionContainerSystem.EnsureSolution(entity.Owner, entity.Comp.SolutionName);
}
else if (_organQuery.CompOrNull(uid)?.Body is { } body)
else if (_organQuery.CompOrNull(entity)?.Body is { } body)
{
_solutionContainerSystem.EnsureSolution(body, component.SolutionName);
_solutionContainerSystem.EnsureSolution(body, entity.Comp.SolutionName);
}
}
@@ -95,6 +95,7 @@ namespace Content.Server.Body.Systems
// First step is get the solution we actually care about
Solution? solution = null;
Entity<SolutionComponent>? soln = default!;
EntityUid? solutionEntityUid = null;
SolutionContainerManagerComponent? manager = null;
@@ -106,7 +107,7 @@ namespace Content.Server.Body.Systems
if (!_solutionQuery.Resolve(body, ref manager, false))
return;
_solutionContainerSystem.TryGetSolution(body, meta.SolutionName, out solution, manager);
_solutionContainerSystem.TryGetSolution((body, manager), meta.SolutionName, out soln, out solution);
solutionEntityUid = body;
}
}
@@ -115,11 +116,11 @@ namespace Content.Server.Body.Systems
if (!_solutionQuery.Resolve(uid, ref manager, false))
return;
_solutionContainerSystem.TryGetSolution(uid, meta.SolutionName, out solution, manager);
_solutionContainerSystem.TryGetSolution((uid, manager), meta.SolutionName, out soln, out solution);
solutionEntityUid = uid;
}
if (solutionEntityUid == null || solution == null || solution.Contents.Count == 0)
if (solutionEntityUid == null || soln is null || solution is null || solution.Contents.Count == 0)
return;
// randomize the reagent list so we don't have any weird quirks
@@ -138,8 +139,7 @@ namespace Content.Server.Body.Systems
{
if (meta.RemoveEmpty)
{
_solutionContainerSystem.RemoveReagent(solutionEntityUid.Value, solution, reagent,
FixedPoint2.New(1));
solution.RemoveReagent(reagent, FixedPoint2.New(1));
}
continue;
@@ -198,12 +198,14 @@ namespace Content.Server.Body.Systems
// remove a certain amount of reagent
if (mostToRemove > FixedPoint2.Zero)
{
_solutionContainerSystem.RemoveReagent(solutionEntityUid.Value, solution, reagent, mostToRemove);
solution.RemoveReagent(reagent, mostToRemove);
// We have processed a reagant, so count it towards the cap
reagents += 1;
}
}
_solutionContainerSystem.UpdateChemicals(soln.Value);
}
}

View File

@@ -2,6 +2,7 @@ using Content.Server.Administration.Logs;
using Content.Server.Atmos;
using Content.Server.Atmos.EntitySystems;
using Content.Server.Body.Components;
using Content.Server.Chemistry.Containers.EntitySystems;
using Content.Server.Popups;
using Content.Shared.Alert;
using Content.Shared.Atmos;
@@ -26,6 +27,7 @@ namespace Content.Server.Body.Systems
[Dependency] private readonly LungSystem _lungSystem = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly MobStateSystem _mobState = default!;
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
public override void Initialize()
{
@@ -144,7 +146,9 @@ namespace Content.Server.Body.Systems
{
_atmosSys.Merge(outGas, lung.Air);
lung.Air.Clear();
lung.LungSolution.RemoveAllSolution();
if (_solutionContainerSystem.ResolveSolution(lung.Owner, lung.SolutionName, ref lung.Solution))
_solutionContainerSystem.RemoveAllSolution(lung.Solution.Value);
}
_atmosSys.Merge(ev.Gas, outGas);

View File

@@ -1,8 +1,8 @@
using Content.Server.Body.Components;
using Content.Server.Chemistry.Containers.EntitySystems;
using Content.Shared.Body.Organ;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Components.SolutionManager;
using Content.Shared.Chemistry.EntitySystems;
using Robust.Shared.Utility;
namespace Content.Server.Body.Systems
@@ -31,8 +31,7 @@ namespace Content.Server.Body.Systems
stomach.AccumulatedFrameTime -= stomach.UpdateInterval;
// Get our solutions
if (!_solutionContainerSystem.TryGetSolution(uid, DefaultSolutionName,
out var stomachSolution, sol))
if (!_solutionContainerSystem.ResolveSolution((uid, sol), DefaultSolutionName, ref stomach.Solution, out var stomachSolution))
continue;
if (organ.Body is not { } body || !_solutionContainerSystem.TryGetSolution(body, stomach.BodySolutionName, out var bodySolution))
@@ -51,7 +50,7 @@ namespace Content.Server.Body.Systems
if (reagent.Quantity > delta.ReagentQuantity.Quantity)
reagent = new(reagent.Reagent, delta.ReagentQuantity.Quantity);
_solutionContainerSystem.RemoveReagent(uid, stomachSolution, reagent);
stomachSolution.RemoveReagent(reagent);
transferSolution.AddReagent(reagent);
}
@@ -64,8 +63,10 @@ namespace Content.Server.Body.Systems
stomach.ReagentDeltas.Remove(item);
}
_solutionContainerSystem.UpdateChemicals(stomach.Solution.Value);
// Transfer everything to the body solution!
_solutionContainerSystem.TryAddSolution(body, bodySolution, transferSolution);
_solutionContainerSystem.TryAddSolution(bodySolution.Value, transferSolution);
}
}
@@ -86,12 +87,13 @@ namespace Content.Server.Body.Systems
}
public bool CanTransferSolution(EntityUid uid, Solution solution,
StomachComponent? stomach = null,
SolutionContainerManagerComponent? solutions = null)
{
if (!Resolve(uid, ref solutions, false))
if (!Resolve(uid, ref stomach, ref solutions, false))
return false;
if (!_solutionContainerSystem.TryGetSolution(uid, DefaultSolutionName, out var stomachSolution, solutions))
if (!_solutionContainerSystem.ResolveSolution((uid, solutions), DefaultSolutionName, ref stomach.Solution, out var stomachSolution))
return false;
// TODO: For now no partial transfers. Potentially change by design
@@ -108,11 +110,11 @@ namespace Content.Server.Body.Systems
if (!Resolve(uid, ref stomach, ref solutions, false))
return false;
if (!_solutionContainerSystem.TryGetSolution(uid, DefaultSolutionName, out var stomachSolution, solutions)
|| !CanTransferSolution(uid, solution, solutions))
if (!_solutionContainerSystem.ResolveSolution((uid, solutions), DefaultSolutionName, ref stomach.Solution)
|| !CanTransferSolution(uid, solution, stomach, solutions))
return false;
_solutionContainerSystem.TryAddSolution(uid, stomachSolution, solution);
_solutionContainerSystem.TryAddSolution(stomach.Solution.Value, solution);
// Add each reagent to ReagentDeltas. Used to track how long each reagent has been in the stomach
foreach (var reagent in solution.Contents)
{