]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Make PowerCellDraw not tick dependent, buff anomaly locator power drain (#15719)
authorNemanja <98561806+EmoGarbage404@users.noreply.github.com>
Mon, 24 Apr 2023 03:35:19 +0000 (23:35 -0400)
committerGitHub <noreply@github.com>
Mon, 24 Apr 2023 03:35:19 +0000 (13:35 +1000)
Content.Server/PowerCell/PowerCellDrawComponent.cs
Content.Server/PowerCell/PowerCellSystem.cs
Resources/Prototypes/Entities/Objects/Specific/Research/anomaly.yml

index 7697fa2654a6535f48ca335d4d7dcfe4be6d82c3..743eeea973a485e3afa5a0e9243fbbc863e024b3 100644 (file)
@@ -1,3 +1,5 @@
+using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
+
 namespace Content.Server.PowerCell;
 
 /// <summary>
@@ -22,4 +24,10 @@ public sealed class PowerCellDrawComponent : Component
     /// </summary>
     [ViewVariables(VVAccess.ReadWrite), DataField("useRate")]
     public float UseRate = 0f;
+
+    /// <summary>
+    /// When the next automatic power draw will occur
+    /// </summary>
+    [DataField("nextUpdate", customTypeSerializer: typeof(TimeOffsetSerializer))]
+    public TimeSpan NextUpdateTime;
 }
index 5d2eaa01d523e15603d392fc8d961068ec6a1d70..c6112c73553243d051ec5061183b735fb434b8f3 100644 (file)
@@ -15,12 +15,14 @@ using Content.Server.UserInterface;
 using Content.Shared.Containers.ItemSlots;
 using Content.Shared.Popups;
 using Content.Shared.Rejuvenate;
+using Robust.Shared.Timing;
 
 namespace Content.Server.PowerCell;
 
 public sealed class PowerCellSystem : SharedPowerCellSystem
 {
     [Dependency] private readonly IAdminLogManager _adminLogger = default!;
+    [Dependency] private readonly IGameTiming _timing = default!;
     [Dependency] private readonly ActivatableUISystem _activatable = default!;
     [Dependency] private readonly BatterySystem _battery = default!;
     [Dependency] private readonly SolutionContainerSystem _solutionsSystem = default!;
@@ -40,6 +42,9 @@ public sealed class PowerCellSystem : SharedPowerCellSystem
 
         SubscribeLocalEvent<PowerCellComponent, ExaminedEvent>(OnCellExamined);
 
+        SubscribeLocalEvent<PowerCellDrawComponent, MapInitEvent>(OnMapInit);
+        SubscribeLocalEvent<PowerCellDrawComponent, EntityUnpausedEvent>(OnUnpaused);
+
         // funny
         SubscribeLocalEvent<PowerCellSlotComponent, BeingMicrowavedEvent>(OnSlotMicrowaved);
         SubscribeLocalEvent<BatteryComponent, BeingMicrowavedEvent>(OnMicrowaved);
@@ -55,10 +60,14 @@ public sealed class PowerCellSystem : SharedPowerCellSystem
             if (!comp.Enabled)
                 continue;
 
+            if (_timing.CurTime < comp.NextUpdateTime)
+                continue;
+            comp.NextUpdateTime += TimeSpan.FromSeconds(1);
+
             if (!TryGetBatteryFromSlot(uid, out var batteryEnt, out var battery, slot))
                 continue;
 
-            if (_battery.TryUseCharge(batteryEnt.Value, comp.DrawRate * frameTime, battery))
+            if (_battery.TryUseCharge(batteryEnt.Value, comp.DrawRate, battery))
                 continue;
 
             comp.Enabled = false;
@@ -127,6 +136,17 @@ public sealed class PowerCellSystem : SharedPowerCellSystem
         RaiseLocalEvent(uid, ref ev);
     }
 
+    private void OnMapInit(EntityUid uid, PowerCellDrawComponent component, MapInitEvent args)
+    {
+        if (component.NextUpdateTime < _timing.CurTime)
+            component.NextUpdateTime = _timing.CurTime;
+    }
+
+    private void OnUnpaused(EntityUid uid, PowerCellDrawComponent component, ref EntityUnpausedEvent args)
+    {
+        component.NextUpdateTime += args.PausedTime;
+    }
+
     private void Explode(EntityUid uid, BatteryComponent? battery = null, EntityUid? cause = null)
     {
         if (!Resolve(uid, ref battery))
index f58ee19e65777ef4468c47f7171065387ed6c57a..32d8caa07e77009d498428b2852ca2696a396767 100644 (file)
@@ -44,7 +44,7 @@
           True: { visible: true }
           False: { visible: false }
   - type: PowerCellDraw
-    drawRate: 10
+    drawRate: 5
     useRate: 0
   - type: ProximityBeeper
     component: Anomaly