From b7e9e95567eea142a82b276dc9e8182bf4762ebd Mon Sep 17 00:00:00 2001 From: Rane <60792108+Elijahrane@users.noreply.github.com> Date: Sat, 2 Jul 2022 22:46:24 -0400 Subject: [PATCH] Rotting fixes (#9338) --- .../Atmos/Miasma/BodyPreservedComponent.cs | 11 ++++++ Content.Server/Atmos/Miasma/MiasmaSystem.cs | 35 ++++++++++++++++--- 2 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 Content.Server/Atmos/Miasma/BodyPreservedComponent.cs diff --git a/Content.Server/Atmos/Miasma/BodyPreservedComponent.cs b/Content.Server/Atmos/Miasma/BodyPreservedComponent.cs new file mode 100644 index 0000000000..e67a90c056 --- /dev/null +++ b/Content.Server/Atmos/Miasma/BodyPreservedComponent.cs @@ -0,0 +1,11 @@ +namespace Content.Server.Atmos.Miasma +{ + [RegisterComponent] + /// + /// Way for natural sources of rotting to tell if there are more unnatural preservation forces at play. + /// + public sealed class BodyPreservedComponent : Component + { + public int PreservationSources = 0; + } +} diff --git a/Content.Server/Atmos/Miasma/MiasmaSystem.cs b/Content.Server/Atmos/Miasma/MiasmaSystem.cs index c8fe1418fb..76f1a54df9 100644 --- a/Content.Server/Atmos/Miasma/MiasmaSystem.cs +++ b/Content.Server/Atmos/Miasma/MiasmaSystem.cs @@ -5,6 +5,7 @@ using Content.Server.Atmos.EntitySystems; using Content.Server.Temperature.Systems; using Content.Server.Body.Components; using Content.Shared.Examine; +using Content.Shared.Tag; using Robust.Shared.Containers; using Robust.Shared.Random; @@ -145,6 +146,8 @@ namespace Content.Server.Atmos.Miasma private void OnTempChange(EntityUid uid, RottingComponent component, OnTemperatureChangeEvent args) { + if (HasComp(uid)) + return; bool decompose = (args.CurrentTemperature > 274f); ToggleDecomposition(uid, decompose); } @@ -184,12 +187,18 @@ namespace Content.Server.Atmos.Miasma private void OnEntInserted(EntityUid uid, AntiRottingContainerComponent component, EntInsertedIntoContainerMessage args) { if (TryComp(args.Entity, out var perishable)) + { + ModifyPreservationSource(args.Entity, true); ToggleDecomposition(args.Entity, false, perishable); + } } private void OnEntRemoved(EntityUid uid, AntiRottingContainerComponent component, EntRemovedFromContainerMessage args) { if (TryComp(args.Entity, out var perishable)) + { + ModifyPreservationSource(args.Entity, false); ToggleDecomposition(args.Entity, true, perishable); + } } @@ -216,23 +225,41 @@ namespace Content.Server.Atmos.Miasma if (decompose == perishable.Progressing) // Saved a few cycles return; - if (!HasComp(uid)) - return; + perishable.Progressing = decompose; if (!perishable.Rotting) return; if (decompose) { - perishable.Progressing = true; EnsureComp(uid); return; } - perishable.Progressing = false; RemComp(uid); } + /// + /// Add or remove a preservation source. + /// Remove is just "add = false" + /// If we have 0 we remove the whole component. + /// + public void ModifyPreservationSource(EntityUid uid, bool add) + { + var component = EnsureComp(uid); + + if (add) + { + component.PreservationSources++; + return; + } + + component.PreservationSources--; + + if (component.PreservationSources == 0) + RemCompDeferred(uid, component); + } + public string RequestPoolDisease() { // We reset the current time on this outbreak so people don't get unlucky at the transition time