]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Raise powercellemptyevent on cell removed, fix powercelldraw (#15679)
authorNemanja <98561806+EmoGarbage404@users.noreply.github.com>
Sun, 23 Apr 2023 05:27:56 +0000 (01:27 -0400)
committerGitHub <noreply@github.com>
Sun, 23 Apr 2023 05:27:56 +0000 (15:27 +1000)
Content.Server/PowerCell/PowerCellSystem.cs
Content.Shared/PowerCell/SharedPowerCellSystem.cs

index c504acbdf7b8a93a587213ea508b22fccd87068b..5d2eaa01d523e15603d392fc8d961068ec6a1d70 100644 (file)
@@ -55,10 +55,10 @@ public sealed class PowerCellSystem : SharedPowerCellSystem
             if (!comp.Enabled)
                 continue;
 
-            if (!TryGetBatteryFromSlot(uid, out var battery, slot))
+            if (!TryGetBatteryFromSlot(uid, out var batteryEnt, out var battery, slot))
                 continue;
 
-            if (_battery.TryUseCharge(uid, comp.DrawRate * frameTime, battery))
+            if (_battery.TryUseCharge(batteryEnt.Value, comp.DrawRate * frameTime, battery))
                 continue;
 
             comp.Enabled = false;
@@ -119,6 +119,14 @@ public sealed class PowerCellSystem : SharedPowerCellSystem
         }
     }
 
+    protected override void OnCellRemoved(EntityUid uid, PowerCellSlotComponent component, EntRemovedFromContainerMessage args)
+    {
+        base.OnCellRemoved(uid, component, args);
+
+        var ev = new PowerCellSlotEmptyEvent();
+        RaiseLocalEvent(uid, ref ev);
+    }
+
     private void Explode(EntityUid uid, BatteryComponent? battery = null, EntityUid? cause = null)
     {
         if (!Resolve(uid, ref battery))
@@ -216,18 +224,29 @@ public sealed class PowerCellSystem : SharedPowerCellSystem
     }
 
     public bool TryGetBatteryFromSlot(EntityUid uid, [NotNullWhen(true)] out BatteryComponent? battery, PowerCellSlotComponent? component = null)
+    {
+        return TryGetBatteryFromSlot(uid, out _, out battery, component);
+    }
+
+    public bool TryGetBatteryFromSlot(EntityUid uid,
+        [NotNullWhen(true)] out EntityUid? batteryEnt,
+        [NotNullWhen(true)] out BatteryComponent? battery,
+        PowerCellSlotComponent? component = null)
     {
         if (!Resolve(uid, ref component, false))
         {
+            batteryEnt = null;
             battery = null;
             return false;
         }
 
         if (_itemSlotsSystem.TryGetSlot(uid, component.CellSlotId, out ItemSlot? slot))
         {
+            batteryEnt = slot.Item;
             return TryComp(slot.Item, out battery);
         }
 
+        batteryEnt = null;
         battery = null;
         return false;
     }
index 1e9094e90336d209111c9009c66e33160e02bd18..00a9895f88e5a6cf9907c3b646f430f44a5ecc0c 100644 (file)
@@ -52,7 +52,7 @@ public abstract class SharedPowerCellSystem : EntitySystem
         RaiseLocalEvent(uid, new PowerCellChangedEvent(false), false);
     }
 
-    private void OnCellRemoved(EntityUid uid, PowerCellSlotComponent component, EntRemovedFromContainerMessage args)
+    protected virtual void OnCellRemoved(EntityUid uid, PowerCellSlotComponent component, EntRemovedFromContainerMessage args)
     {
         if (args.Container.ID != component.CellSlotId)
             return;