From: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> Date: Sun, 23 Apr 2023 05:27:56 +0000 (-0400) Subject: Raise powercellemptyevent on cell removed, fix powercelldraw (#15679) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=ef28cfd55fe0d352620d0322e065bf0328b84460;p=space-station-14.git Raise powercellemptyevent on cell removed, fix powercelldraw (#15679) --- diff --git a/Content.Server/PowerCell/PowerCellSystem.cs b/Content.Server/PowerCell/PowerCellSystem.cs index c504acbdf7..5d2eaa01d5 100644 --- a/Content.Server/PowerCell/PowerCellSystem.cs +++ b/Content.Server/PowerCell/PowerCellSystem.cs @@ -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; } diff --git a/Content.Shared/PowerCell/SharedPowerCellSystem.cs b/Content.Shared/PowerCell/SharedPowerCellSystem.cs index 1e9094e903..00a9895f88 100644 --- a/Content.Shared/PowerCell/SharedPowerCellSystem.cs +++ b/Content.Shared/PowerCell/SharedPowerCellSystem.cs @@ -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;