Files
tbd-station-14/Content.Server/Atmos/Monitor/Systems/AtmosAlarmableSystem.cs
Flipp Syder b1584793bf Adds fire/air alarms (#5018)
Co-authored-by: Vera Aguilera Puerto <6766154+Zumorica@users.noreply.github.com>
Co-authored-by: E F R <602406+Efruit@users.noreply.github.com>
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
2022-01-02 15:56:24 +11:00

44 lines
1.8 KiB
C#

using Content.Server.Atmos.Monitor.Components;
using Content.Server.DeviceNetwork;
using Content.Server.DeviceNetwork.Components;
using Content.Server.DeviceNetwork.Systems;
using Content.Shared.Atmos.Monitor;
using Robust.Shared.GameObjects;
namespace Content.Server.Atmos.Monitor.Systems
{
public class AtmosAlarmableSystem : EntitySystem
{
public override void Initialize()
{
SubscribeLocalEvent<AtmosAlarmableComponent, PacketSentEvent>(OnPacketRecv);
}
private void OnPacketRecv(EntityUid uid, AtmosAlarmableComponent component, PacketSentEvent args)
{
if (component.IgnoreAlarms) return;
if (!EntityManager.TryGetComponent(uid, out DeviceNetworkComponent netConn))
return;
if (args.Data.TryGetValue(DeviceNetworkConstants.Command, out string? cmd)
&& cmd == AtmosMonitorSystem.AtmosMonitorAlarmCmd)
{
// does it have a state & network max state?
// does it have a source?
// and can this be alarmed by the source?
// if so, raise an alarm
if (args.Data.TryGetValue(DeviceNetworkConstants.CmdSetState, out AtmosMonitorAlarmType state)
&& args.Data.TryGetValue(AtmosMonitorSystem.AtmosMonitorAlarmNetMax, out AtmosMonitorAlarmType netMax)
&& args.Data.TryGetValue(AtmosMonitorSystem.AtmosMonitorAlarmSrc, out string? source)
&& component.AlarmedByPrototypes.Contains(source))
{
component.LastAlarmState = state;
component.HighestNetworkState = netMax;
RaiseLocalEvent(component.Owner, new AtmosMonitorAlarmEvent(state, netMax));
}
}
}
}
}