From bccad7d4302dfd28c21cd16e515b41f44e6ad905 Mon Sep 17 00:00:00 2001 From: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> Date: Sun, 30 Apr 2023 02:06:44 -0400 Subject: [PATCH] Fix instant power cell drainage (#15927) --- .../Pinpointer/ProximityBeeperSystem.cs | 5 ++--- .../PowerCell/PowerCellDrawComponent.cs | 6 +++--- Content.Server/PowerCell/PowerCellSystem.cs | 9 +++++++++ .../UserInterface/ActivatableUISystem.Power.cs | 15 +++------------ 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/Content.Server/Pinpointer/ProximityBeeperSystem.cs b/Content.Server/Pinpointer/ProximityBeeperSystem.cs index f0d90459d8..c31c9eb34b 100644 --- a/Content.Server/Pinpointer/ProximityBeeperSystem.cs +++ b/Content.Server/Pinpointer/ProximityBeeperSystem.cs @@ -113,7 +113,7 @@ public sealed class ProximityBeeperSystem : EntitySystem component.NextBeepTime = _timing.CurTime; UpdateBeep(uid, component, false); if (draw != null) - draw.Enabled = true; + _powerCell.SetPowerCellDrawEnabled(uid, true, draw); return true; } @@ -130,8 +130,7 @@ public sealed class ProximityBeeperSystem : EntitySystem component.Enabled = false; _appearance.SetData(uid, ProximityBeeperVisuals.Enabled, false); - if (TryComp(uid, out var draw)) - draw.Enabled = true; + _powerCell.SetPowerCellDrawEnabled(uid, true); UpdateBeep(uid, component); return true; } diff --git a/Content.Server/PowerCell/PowerCellDrawComponent.cs b/Content.Server/PowerCell/PowerCellDrawComponent.cs index 743eeea973..213b414098 100644 --- a/Content.Server/PowerCell/PowerCellDrawComponent.cs +++ b/Content.Server/PowerCell/PowerCellDrawComponent.cs @@ -5,11 +5,11 @@ namespace Content.Server.PowerCell; /// /// Indicates that the entity's ActivatableUI requires power or else it closes. /// -[RegisterComponent] +[RegisterComponent, Access(typeof(PowerCellSystem))] public sealed class PowerCellDrawComponent : Component { [ViewVariables(VVAccess.ReadWrite), DataField("enabled")] - public bool Enabled = false; + public bool Enabled; /// /// How much the entity draws while the UI is open. @@ -23,7 +23,7 @@ public sealed class PowerCellDrawComponent : Component /// This is used to ensure the UI won't open again without a minimum use power. /// [ViewVariables(VVAccess.ReadWrite), DataField("useRate")] - public float UseRate = 0f; + public float UseRate; /// /// When the next automatic power draw will occur diff --git a/Content.Server/PowerCell/PowerCellSystem.cs b/Content.Server/PowerCell/PowerCellSystem.cs index 4b0f322c94..f85da633ca 100644 --- a/Content.Server/PowerCell/PowerCellSystem.cs +++ b/Content.Server/PowerCell/PowerCellSystem.cs @@ -194,6 +194,15 @@ public sealed class PowerCellSystem : SharedPowerCellSystem #endregion + public void SetPowerCellDrawEnabled(EntityUid uid, bool enabled, PowerCellDrawComponent? component = null) + { + if (!Resolve(uid, ref component, false)) + return; + + component.Enabled = enabled; + component.NextUpdateTime = _timing.CurTime; + } + /// /// Returns whether the entity has a slotted battery and charge for the requested action. /// diff --git a/Content.Server/UserInterface/ActivatableUISystem.Power.cs b/Content.Server/UserInterface/ActivatableUISystem.Power.cs index 7b36116744..918be614b8 100644 --- a/Content.Server/UserInterface/ActivatableUISystem.Power.cs +++ b/Content.Server/UserInterface/ActivatableUISystem.Power.cs @@ -19,10 +19,7 @@ public sealed partial class ActivatableUISystem private void OnPowerCellRemoved(EntityUid uid, PowerCellDrawComponent component, EntRemovedFromContainerMessage args) { - if (TryComp(uid, out var draw)) - { - draw.Enabled = false; - } + _cell.SetPowerCellDrawEnabled(uid, false); if (HasComp(uid) && TryComp(uid, out var activatable) && @@ -34,18 +31,12 @@ public sealed partial class ActivatableUISystem private void OnBatteryOpened(EntityUid uid, ActivatableUIRequiresPowerCellComponent component, BoundUIOpenedEvent args) { - if (!TryComp(uid, out var draw)) - return; - - draw.Enabled = true; + _cell.SetPowerCellDrawEnabled(uid, true); } private void OnBatteryClosed(EntityUid uid, ActivatableUIRequiresPowerCellComponent component, BoundUIClosedEvent args) { - if (!TryComp(uid, out var draw)) - return; - - draw.Enabled = false; + _cell.SetPowerCellDrawEnabled(uid, false); } ///