Files
space-station-14/Content.Shared/PowerCell/PowerCellSystem.Relay.cs
slarticodefast e2ff167062 Predict powercells, chargers and PowerCellDraw (#41379)
* cleanup

* fix fixtures

* prediction

* fix test

* review

* fix svalinn visuals

* fix chargers

* fix portable recharger and its unlit visuals

* fix borgs

* oomba review

* fix examination prediction
2025-11-24 16:52:11 +00:00

41 lines
1.8 KiB
C#

using Content.Shared.Emp;
using Content.Shared.Kitchen;
using Content.Shared.Power;
using Content.Shared.PowerCell.Components;
using Content.Shared.Rejuvenate;
namespace Content.Shared.PowerCell;
public sealed partial class PowerCellSystem
{
public void InitializeRelay()
{
SubscribeLocalEvent<PowerCellSlotComponent, BeingMicrowavedEvent>(RelayToCell);
SubscribeLocalEvent<PowerCellSlotComponent, RejuvenateEvent>(RelayToCell);
SubscribeLocalEvent<PowerCellSlotComponent, GetChargeEvent>(RelayToCell);
SubscribeLocalEvent<PowerCellSlotComponent, ChangeChargeEvent>(RelayToCell);
SubscribeLocalEvent<PowerCellComponent, EmpAttemptEvent>(RelayToCellSlot); // Prevent the ninja from EMPing its own battery
SubscribeLocalEvent<PowerCellComponent, PredictedBatteryChargeChangedEvent>(RelayToCellSlot);
SubscribeLocalEvent<PowerCellComponent, PredictedBatteryStateChangedEvent>(RelayToCellSlot); // For shutting down devices if the battery is empty
SubscribeLocalEvent<PowerCellComponent, RefreshChargeRateEvent>(RelayToCellSlot); // Allow devices to charge/drain inserted batteries
}
private void RelayToCell<T>(Entity<PowerCellSlotComponent> ent, ref T args) where T : notnull
{
if (!_itemSlots.TryGetSlot(ent.Owner, ent.Comp.CellSlotId, out var slot) || !slot.Item.HasValue)
return;
// Relay the event to the power cell.
RaiseLocalEvent(slot.Item.Value, ref args);
}
private void RelayToCellSlot<T>(Entity<PowerCellComponent> ent, ref T args) where T : notnull
{
var parent = Transform(ent).ParentUid;
// Relay the event to the slot entity.
if (HasComp<PowerCellSlotComponent>(parent))
RaiseLocalEvent(parent, ref args);
}
}