Files
tbd-station-14/Content.Server/SensorMonitoring/BatterySensorSystem.cs
Tayrtahn 2935e5bd78 Remove all obsolete BatteryComponent method calls (#25871)
Removed all obsolete, non-ECS method calls to BatteryComponent
2024-03-06 16:34:50 +11:00

47 lines
1.6 KiB
C#

using Content.Server.DeviceNetwork;
using Content.Server.DeviceNetwork.Systems;
using Content.Server.Power.Components;
using Content.Shared.DeviceNetwork;
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;
}
}
}