Files
tbd-station-14/Content.Server/SensorMonitoring/BatterySensorSystem.cs
slarticodefast 5227489360 Predict EMPs (#39802)
* predicted emps

* fixes

* fix

* review
2025-10-04 11:24:42 +00:00

48 lines
1.7 KiB
C#

using Content.Server.DeviceNetwork.Systems;
using Content.Server.Power.Components;
using Content.Shared.DeviceNetwork;
using Content.Shared.DeviceNetwork.Events;
using Content.Shared.Power.Components;
namespace Content.Server.SensorMonitoring;
public sealed class BatterySensorSystem : EntitySystem
{
public const string DeviceNetworkCommandSyncData = "bat_sync_data";
[Dependency] private readonly DeviceNetworkSystem _deviceNetwork = default!;
public override void Initialize()
{
SubscribeLocalEvent<BatterySensorComponent, DeviceNetworkPacketEvent>(PacketReceived);
}
private void PacketReceived(EntityUid uid, BatterySensorComponent component, DeviceNetworkPacketEvent args)
{
if (!args.Data.TryGetValue(DeviceNetworkConstants.Command, out string? cmd))
return;
switch (cmd)
{
case DeviceNetworkCommandSyncData:
var battery = Comp<BatteryComponent>(uid);
var netBattery = Comp<PowerNetworkBatteryComponent>(uid);
var payload = new NetworkPayload
{
[DeviceNetworkConstants.Command] = DeviceNetworkCommandSyncData,
[DeviceNetworkCommandSyncData] = new BatterySensorData(
battery.CurrentCharge,
battery.MaxCharge,
netBattery.CurrentReceiving,
netBattery.MaxChargeRate,
netBattery.CurrentSupply,
netBattery.MaxSupply)
};
_deviceNetwork.QueuePacket(uid, args.SenderAddress, payload);
break;
}
}
}