From e97fd47a8764f973193e22e45512acb5335bdf17 Mon Sep 17 00:00:00 2001 From: Kot <1192090+koteq@users.noreply.github.com> Date: Tue, 9 Jan 2024 10:40:52 +0400 Subject: [PATCH] Powered stasis bed prevents body decay (#23520) * Powered stasis bed prevents body decay * Update following CR comments * Remove unused import * Simplify if-statements * Change implementation following CR suggestions * Add comment & remove explicit get/set --- Content.Server/Atmos/Rotting/RottingSystem.cs | 4 +-- .../Buckle/Systems/AntiRotOnBuckleSystem.cs | 29 +++++++++++++++++++ .../Atmos/Rotting/AntiRotOnBuckleComponent.cs | 22 ++++++++++++++ .../Structures/Machines/stasisbed.yml | 3 +- 4 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 Content.Server/Buckle/Systems/AntiRotOnBuckleSystem.cs create mode 100644 Content.Shared/Atmos/Rotting/AntiRotOnBuckleComponent.cs diff --git a/Content.Server/Atmos/Rotting/RottingSystem.cs b/Content.Server/Atmos/Rotting/RottingSystem.cs index 2d430a74ac..db0815f3a6 100644 --- a/Content.Server/Atmos/Rotting/RottingSystem.cs +++ b/Content.Server/Atmos/Rotting/RottingSystem.cs @@ -101,7 +101,7 @@ public sealed class RottingSystem : EntitySystem var ev = new IsRottingEvent(); RaiseLocalEvent(uid, ref ev); - return ev.Handled; + return !ev.Handled; } public bool IsRotten(EntityUid uid, RottingComponent? rotting = null) @@ -154,7 +154,7 @@ public sealed class RottingSystem : EntitySystem { if (args.Handled) return; - args.Handled = component.CurrentTemperature > Atmospherics.T0C + 0.85f; + args.Handled = component.CurrentTemperature < Atmospherics.T0C + 0.85f; } public override void Update(float frameTime) diff --git a/Content.Server/Buckle/Systems/AntiRotOnBuckleSystem.cs b/Content.Server/Buckle/Systems/AntiRotOnBuckleSystem.cs new file mode 100644 index 0000000000..4458b020a1 --- /dev/null +++ b/Content.Server/Buckle/Systems/AntiRotOnBuckleSystem.cs @@ -0,0 +1,29 @@ +using Content.Server.Power.Components; +using Content.Shared.Atmos.Rotting; +using Content.Shared.Buckle.Components; + +namespace Content.Server.Buckle.Systems; + +public sealed class AntiRotOnBuckleSystem : EntitySystem +{ + public override void Initialize() + { + base.Initialize(); + SubscribeLocalEvent(OnIsRotting); + SubscribeLocalEvent(OnPowerChanged); + } + + private void OnIsRotting(EntityUid uid, BuckleComponent buckle, ref IsRottingEvent args) + { + if (args.Handled) + return; + args.Handled = buckle is { Buckled: true, BuckledTo: not null } && + TryComp(buckle.BuckledTo.Value, out var antiRot) && + antiRot.Enabled; + } + + private void OnPowerChanged(EntityUid uid, AntiRotOnBuckleComponent component, ref PowerChangedEvent args) + { + component.Enabled = !component.RequiresPower || args.Powered; + } +} diff --git a/Content.Shared/Atmos/Rotting/AntiRotOnBuckleComponent.cs b/Content.Shared/Atmos/Rotting/AntiRotOnBuckleComponent.cs new file mode 100644 index 0000000000..59c5543625 --- /dev/null +++ b/Content.Shared/Atmos/Rotting/AntiRotOnBuckleComponent.cs @@ -0,0 +1,22 @@ +using Robust.Shared.GameStates; + +namespace Content.Shared.Atmos.Rotting; + +/// +/// Perishable entities buckled to an entity with this component will stop rotting. +/// +[RegisterComponent, NetworkedComponent] +public sealed partial class AntiRotOnBuckleComponent : Component +{ + /// + /// Does this component require power to function. + /// + [DataField("requiresPower"), ViewVariables(VVAccess.ReadWrite)] + public bool RequiresPower = true; + + /// + /// Whether this component is active or not. + /// + [ViewVariables(VVAccess.ReadWrite)] + public bool Enabled = true; +} diff --git a/Resources/Prototypes/Entities/Structures/Machines/stasisbed.yml b/Resources/Prototypes/Entities/Structures/Machines/stasisbed.yml index 45d5d2b75c..5f7182f7dd 100644 --- a/Resources/Prototypes/Entities/Structures/Machines/stasisbed.yml +++ b/Resources/Prototypes/Entities/Structures/Machines/stasisbed.yml @@ -2,10 +2,11 @@ id: StasisBed name: stasis bed parent: [ BaseMachinePowered, ConstructibleMachine ] - description: A bed that massively slows down the patient's metabolism, allowing more time to administer a proper treatment for stabilization. + description: A bed that massively slows down the patient's metabolism and prevents bodily decay, allowing more time to administer a proper treatment for stabilization. components: - type: StasisBed baseMultiplier: 10 + - type: AntiRotOnBuckle - type: Sprite sprite: Structures/Machines/stasis_bed.rsi noRot: true