From a03ab2c08779988703c28448b1f40c02573f7449 Mon Sep 17 00:00:00 2001 From: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> Date: Sat, 15 Oct 2022 17:39:30 -0400 Subject: [PATCH] stasis bed machine part scaling (#11773) --- Content.Server/Bed/BedSystem.cs | 29 ++++++++++++------- .../Bed/Components/StasisBedComponent.cs | 18 +++++++++++- .../Structures/Machines/stasisbed.yml | 2 +- 3 files changed, 36 insertions(+), 13 deletions(-) diff --git a/Content.Server/Bed/BedSystem.cs b/Content.Server/Bed/BedSystem.cs index 27e3e2a786..f4d36c1113 100644 --- a/Content.Server/Bed/BedSystem.cs +++ b/Content.Server/Bed/BedSystem.cs @@ -10,8 +10,8 @@ using Content.Server.Bed.Sleep; using Content.Server.Power.Components; using Content.Server.Power.EntitySystems; using Content.Shared.Emag.Systems; -using Content.Shared.MobState.Components; using Content.Server.Actions; +using Content.Server.Construction; using Content.Server.MobState; using Content.Shared.Actions.ActionTypes; using Robust.Shared.Prototypes; @@ -24,6 +24,7 @@ namespace Content.Server.Bed [Dependency] private readonly ActionsSystem _actionsSystem = default!; [Dependency] private readonly IPrototypeManager _prototypeManager = default!; [Dependency] private readonly SleepingSystem _sleepingSystem = default!; + [Dependency] private readonly SharedAppearanceSystem _appearance = default!; [Dependency] private readonly MobStateSystem _mobStateSystem = default!; public override void Initialize() { @@ -32,6 +33,7 @@ namespace Content.Server.Bed SubscribeLocalEvent(OnBuckleChange); SubscribeLocalEvent(OnPowerChanged); SubscribeLocalEvent(OnEmagged); + SubscribeLocalEvent(OnRefreshParts); } private void ManageUpdateList(EntityUid uid, HealOnBuckleComponent component, BuckleChangeEvent args) @@ -46,7 +48,7 @@ namespace Content.Server.Bed } if (sleepAction != null) - _actionsSystem.RemoveAction(args.BuckledEntity, sleepAction, null); + _actionsSystem.RemoveAction(args.BuckledEntity, sleepAction); _sleepingSystem.TryWaking(args.BuckledEntity); RemComp(uid); @@ -85,25 +87,22 @@ namespace Content.Server.Bed private void UpdateAppearance(EntityUid uid, bool isOn) { - if (!TryComp(uid, out var appearance)) - return; - - appearance.SetData(StasisBedVisuals.IsOn, isOn); + _appearance.SetData(uid, StasisBedVisuals.IsOn, isOn); } private void OnBuckleChange(EntityUid uid, StasisBedComponent component, BuckleChangeEvent args) { // In testing this also received an unbuckle event when the bed is destroyed // So don't worry about that - if (!TryComp(args.BuckledEntity, out var body)) + if (!HasComp(args.BuckledEntity)) return; if (!this.IsPowered(uid, EntityManager)) return; - var metabolicEvent = new ApplyMetabolicMultiplierEvent() + var metabolicEvent = new ApplyMetabolicMultiplierEvent {Uid = args.BuckledEntity, Multiplier = component.Multiplier, Apply = args.Buckling}; - RaiseLocalEvent(args.BuckledEntity, metabolicEvent, false); + RaiseLocalEvent(args.BuckledEntity, metabolicEvent); } private void OnPowerChanged(EntityUid uid, StasisBedComponent component, ref PowerChangedEvent args) @@ -129,11 +128,19 @@ namespace Content.Server.Bed foreach (var buckledEntity in strap.BuckledEntities) { - var metabolicEvent = new ApplyMetabolicMultiplierEvent() + var metabolicEvent = new ApplyMetabolicMultiplierEvent {Uid = buckledEntity, Multiplier = component.Multiplier, Apply = shouldApply}; - RaiseLocalEvent(buckledEntity, metabolicEvent, false); + RaiseLocalEvent(buckledEntity, metabolicEvent); } } + + private void OnRefreshParts(EntityUid uid, StasisBedComponent component, RefreshPartsEvent args) + { + var metabolismRating = args.PartRatings[component.MachinePartMetabolismModifier]; + component.Multiplier = component.BaseMultiplier * metabolismRating; //linear scaling so it's not OP + if (component.Emagged) + component.Multiplier = 1f / component.Multiplier; + } } } diff --git a/Content.Server/Bed/Components/StasisBedComponent.cs b/Content.Server/Bed/Components/StasisBedComponent.cs index c0bd7a9b9a..4309ba48de 100644 --- a/Content.Server/Bed/Components/StasisBedComponent.cs +++ b/Content.Server/Bed/Components/StasisBedComponent.cs @@ -1,13 +1,29 @@ +using Content.Shared.Construction.Prototypes; +using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; + namespace Content.Server.Bed.Components { [RegisterComponent] public sealed class StasisBedComponent : Component { + /// + /// Stores whether or not the stasis bed has been emagged, + /// which causes the multiplier to speed up rather than + /// slow down. Needs to be stored for machine upgrades. + /// + [ViewVariables(VVAccess.ReadWrite)] + public bool Emagged = false; + + [DataField("baseMultiplier", required: true), ViewVariables(VVAccess.ReadWrite)] + public float BaseMultiplier = 10f; + /// /// What the metabolic update rate will be multiplied by (higher = slower metabolism) /// - [DataField("multiplier", required: true)] [ViewVariables(VVAccess.ReadWrite)] public float Multiplier = 10f; + + [DataField("machinePartMetabolismModifier", customTypeSerializer: typeof(PrototypeIdSerializer))] + public string MachinePartMetabolismModifier = "Manipulator"; } } diff --git a/Resources/Prototypes/Entities/Structures/Machines/stasisbed.yml b/Resources/Prototypes/Entities/Structures/Machines/stasisbed.yml index 52d01484dd..b03b80159a 100644 --- a/Resources/Prototypes/Entities/Structures/Machines/stasisbed.yml +++ b/Resources/Prototypes/Entities/Structures/Machines/stasisbed.yml @@ -5,7 +5,7 @@ description: A bed that massively slows down the patient's metabolism, allowing more time to administer a proper treatment for stabilization. components: - type: StasisBed - multiplier: 10 + baseMultiplier: 10 - type: Sprite sprite: Structures/Machines/stasis_bed.rsi netsync: false