]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix instant power cell drainage (#15927)
authorNemanja <98561806+EmoGarbage404@users.noreply.github.com>
Sun, 30 Apr 2023 06:06:44 +0000 (02:06 -0400)
committerGitHub <noreply@github.com>
Sun, 30 Apr 2023 06:06:44 +0000 (16:06 +1000)
Content.Server/Pinpointer/ProximityBeeperSystem.cs
Content.Server/PowerCell/PowerCellDrawComponent.cs
Content.Server/PowerCell/PowerCellSystem.cs
Content.Server/UserInterface/ActivatableUISystem.Power.cs

index f0d90459d89c2b1ff324db8d841fb49cf7640187..c31c9eb34b964a962de4e6615c95e9abb310fc36 100644 (file)
@@ -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<PowerCellDrawComponent>(uid, out var draw))
-            draw.Enabled = true;
+        _powerCell.SetPowerCellDrawEnabled(uid, true);
         UpdateBeep(uid, component);
         return true;
     }
index 743eeea973a485e3afa5a0e9243fbbc863e024b3..213b414098af7afae2cf601e62f25f1ef4f08de9 100644 (file)
@@ -5,11 +5,11 @@ namespace Content.Server.PowerCell;
 /// <summary>
 /// Indicates that the entity's ActivatableUI requires power or else it closes.
 /// </summary>
-[RegisterComponent]
+[RegisterComponent, Access(typeof(PowerCellSystem))]
 public sealed class PowerCellDrawComponent : Component
 {
     [ViewVariables(VVAccess.ReadWrite), DataField("enabled")]
-    public bool Enabled = false;
+    public bool Enabled;
 
     /// <summary>
     /// 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.
     /// </summary>
     [ViewVariables(VVAccess.ReadWrite), DataField("useRate")]
-    public float UseRate = 0f;
+    public float UseRate;
 
     /// <summary>
     /// When the next automatic power draw will occur
index 4b0f322c940a0be00af47fee24fd5e0b5c8d172d..f85da633ca4152f9619d47fb72727393fe2e74c2 100644 (file)
@@ -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;
+    }
+
     /// <summary>
     /// Returns whether the entity has a slotted battery and charge for the requested action.
     /// </summary>
index 7b3611674470759c815d744e11518570c46b01c0..918be614b87c5110d0f726c9a814ab994dfc7802 100644 (file)
@@ -19,10 +19,7 @@ public sealed partial class ActivatableUISystem
 
     private void OnPowerCellRemoved(EntityUid uid, PowerCellDrawComponent component, EntRemovedFromContainerMessage args)
     {
-        if (TryComp<PowerCellDrawComponent>(uid, out var draw))
-        {
-            draw.Enabled = false;
-        }
+        _cell.SetPowerCellDrawEnabled(uid, false);
 
         if (HasComp<ActivatableUIRequiresPowerCellComponent>(uid) &&
             TryComp<ActivatableUIComponent>(uid, out var activatable) &&
@@ -34,18 +31,12 @@ public sealed partial class ActivatableUISystem
 
     private void OnBatteryOpened(EntityUid uid, ActivatableUIRequiresPowerCellComponent component, BoundUIOpenedEvent args)
     {
-        if (!TryComp<PowerCellDrawComponent>(uid, out var draw))
-            return;
-
-        draw.Enabled = true;
+        _cell.SetPowerCellDrawEnabled(uid, true);
     }
 
     private void OnBatteryClosed(EntityUid uid, ActivatableUIRequiresPowerCellComponent component, BoundUIClosedEvent args)
     {
-        if (!TryComp<PowerCellDrawComponent>(uid, out var draw))
-            return;
-
-        draw.Enabled = false;
+        _cell.SetPowerCellDrawEnabled(uid, false);
     }
 
     /// <summary>