From 3e6bf54727c3f42ceb5dc0ff2d9ad4eca938a59e Mon Sep 17 00:00:00 2001 From: mirrorcult Date: Sat, 19 Feb 2022 17:42:01 -0700 Subject: [PATCH] Disposals air + new atmos expose event (#6798) Co-authored-by: Vera Aguilera Puerto <6766154+Zumorica@users.noreply.github.com> --- .../Atmos/EntitySystems/AtmosExposedSystem.cs | 6 +++ .../Atmos/EntitySystems/AtmosphereSystem.cs | 12 ++++-- .../Unit/Components/BeingDisposedComponent.cs | 11 +++++ .../Components/DisposalHolderComponent.cs | 2 +- .../Unit/EntitySystems/BeingDisposedSystem.cs | 40 +++++++++++++++++++ .../Unit/EntitySystems/DisposableSystem.cs | 9 +++++ .../Unit/EntitySystems/DisposalUnitSystem.cs | 2 +- 7 files changed, 77 insertions(+), 5 deletions(-) create mode 100644 Content.Server/Disposal/Unit/Components/BeingDisposedComponent.cs create mode 100644 Content.Server/Disposal/Unit/EntitySystems/BeingDisposedSystem.cs diff --git a/Content.Server/Atmos/EntitySystems/AtmosExposedSystem.cs b/Content.Server/Atmos/EntitySystems/AtmosExposedSystem.cs index 8d0d6c4f26..001b5388fe 100644 --- a/Content.Server/Atmos/EntitySystems/AtmosExposedSystem.cs +++ b/Content.Server/Atmos/EntitySystems/AtmosExposedSystem.cs @@ -24,4 +24,10 @@ namespace Content.Server.Atmos.EntitySystems GasMixture = mixture; } } + + [ByRefEvent] + public struct AtmosExposedGetAirEvent + { + public GasMixture? Gas; + } } diff --git a/Content.Server/Atmos/EntitySystems/AtmosphereSystem.cs b/Content.Server/Atmos/EntitySystems/AtmosphereSystem.cs index 6062659433..cef954fe00 100644 --- a/Content.Server/Atmos/EntitySystems/AtmosphereSystem.cs +++ b/Content.Server/Atmos/EntitySystems/AtmosphereSystem.cs @@ -85,9 +85,15 @@ namespace Content.Server.Atmos.EntitySystems foreach (var (exposed, transform) in EntityManager.EntityQuery()) { - var tile = GetTileMixture(transform.Coordinates); - if (tile == null) continue; - var updateEvent = new AtmosExposedUpdateEvent(transform.Coordinates, tile); + // Used for things like disposals/cryo to change which air people are exposed to. + var airEvent = new AtmosExposedGetAirEvent(); + RaiseLocalEvent(exposed.Owner, ref airEvent, false); + + airEvent.Gas ??= GetTileMixture(transform.Coordinates); + if (airEvent.Gas == null) + continue; + + var updateEvent = new AtmosExposedUpdateEvent(transform.Coordinates, airEvent.Gas); RaiseLocalEvent(exposed.Owner, ref updateEvent); } diff --git a/Content.Server/Disposal/Unit/Components/BeingDisposedComponent.cs b/Content.Server/Disposal/Unit/Components/BeingDisposedComponent.cs new file mode 100644 index 0000000000..0cec11aae0 --- /dev/null +++ b/Content.Server/Disposal/Unit/Components/BeingDisposedComponent.cs @@ -0,0 +1,11 @@ +namespace Content.Server.Disposal.Unit.Components; + +/// +/// A component added to entities that are currently in disposals. +/// +[RegisterComponent] +public sealed class BeingDisposedComponent : Component +{ + [ViewVariables] + public EntityUid Holder; +} diff --git a/Content.Server/Disposal/Unit/Components/DisposalHolderComponent.cs b/Content.Server/Disposal/Unit/Components/DisposalHolderComponent.cs index c9257aef0e..3cee2e4c9d 100644 --- a/Content.Server/Disposal/Unit/Components/DisposalHolderComponent.cs +++ b/Content.Server/Disposal/Unit/Components/DisposalHolderComponent.cs @@ -63,7 +63,7 @@ namespace Content.Server.Disposal.Unit.Components [ViewVariables] [DataField("air")] - public GasMixture Air { get; set; } = new GasMixture(Atmospherics.CellVolume); + public GasMixture Air { get; set; } = new (70); protected override void Initialize() { diff --git a/Content.Server/Disposal/Unit/EntitySystems/BeingDisposedSystem.cs b/Content.Server/Disposal/Unit/EntitySystems/BeingDisposedSystem.cs new file mode 100644 index 0000000000..e4b7f9062d --- /dev/null +++ b/Content.Server/Disposal/Unit/EntitySystems/BeingDisposedSystem.cs @@ -0,0 +1,40 @@ +using Content.Server.Atmos.EntitySystems; +using Content.Server.Disposal.Unit.Components; + +namespace Content.Server.Disposal.Unit.EntitySystems; + +public sealed class BeingDisposedSystem : EntitySystem +{ + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(OnInhaleLocation); + SubscribeLocalEvent(OnExhaleLocation); + SubscribeLocalEvent(OnGetAir); + } + + private void OnGetAir(EntityUid uid, BeingDisposedComponent component, ref AtmosExposedGetAirEvent args) + { + if (TryComp(component.Holder, out var holder)) + { + args.Gas = holder.Air; + } + } + + private void OnInhaleLocation(EntityUid uid, BeingDisposedComponent component, InhaleLocationEvent args) + { + if (TryComp(component.Holder, out var holder)) + { + args.Gas = holder.Air; + } + } + + private void OnExhaleLocation(EntityUid uid, BeingDisposedComponent component, ExhaleLocationEvent args) + { + if (TryComp(component.Holder, out var holder)) + { + args.Gas = holder.Air; + } + } +} diff --git a/Content.Server/Disposal/Unit/EntitySystems/DisposableSystem.cs b/Content.Server/Disposal/Unit/EntitySystems/DisposableSystem.cs index 867fee4dd4..035e386eeb 100644 --- a/Content.Server/Disposal/Unit/EntitySystems/DisposableSystem.cs +++ b/Content.Server/Disposal/Unit/EntitySystems/DisposableSystem.cs @@ -47,6 +47,9 @@ namespace Content.Server.Disposal.Unit.EntitySystems foreach (var entity in holder.Container.ContainedEntities.ToArray()) { + if (HasComp(entity)) + RemComp (entity); + if (EntityManager.TryGetComponent(entity, out IPhysBody? physics)) { physics.CanCollide = true; @@ -101,6 +104,12 @@ namespace Content.Server.Disposal.Unit.EntitySystems return false; } + foreach (var ent in holder.Container.ContainedEntities) + { + var comp = EnsureComp(ent); + comp.Holder = holder.Owner; + } + // Insert into next tube holderTransform.Coordinates = new EntityCoordinates(toUid, Vector2.Zero); if (!to.Contents.Insert(holder.Owner)) diff --git a/Content.Server/Disposal/Unit/EntitySystems/DisposalUnitSystem.cs b/Content.Server/Disposal/Unit/EntitySystems/DisposalUnitSystem.cs index e85253ae0d..f089f6f5be 100644 --- a/Content.Server/Disposal/Unit/EntitySystems/DisposalUnitSystem.cs +++ b/Content.Server/Disposal/Unit/EntitySystems/DisposalUnitSystem.cs @@ -486,7 +486,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems if (_atmosSystem.GetTileMixture(EntityManager.GetComponent(component.Owner).Coordinates, true) is {Temperature: > 0} environment) { - var transferMoles = 0.1f * (0.05f * Atmospherics.OneAtmosphere * 1.01f - air.Pressure) * air.Volume / (environment.Temperature * Atmospherics.R); + var transferMoles = 0.1f * (0.25f * Atmospherics.OneAtmosphere * 1.01f - air.Pressure) * air.Volume / (environment.Temperature * Atmospherics.R); component.Air = environment.Remove(transferMoles); }