2022-05-17 21:05:31 -07:00
|
|
|
using Content.Server.AlertLevel;
|
2022-01-01 20:56:24 -08:00
|
|
|
using Content.Server.Atmos.Monitor.Components;
|
2022-08-22 08:44:03 -07:00
|
|
|
using Content.Server.DeviceNetwork.Systems;
|
2022-01-01 20:56:24 -08:00
|
|
|
using Content.Server.Power.Components;
|
2022-05-27 10:36:12 +10:00
|
|
|
using Content.Server.Power.EntitySystems;
|
2022-05-17 21:05:31 -07:00
|
|
|
using Content.Shared.AlertLevel;
|
2022-01-01 20:56:24 -08:00
|
|
|
using Content.Shared.Atmos.Monitor;
|
|
|
|
|
using Content.Shared.Interaction;
|
2022-02-17 21:43:24 -05:00
|
|
|
using Content.Shared.Emag.Systems;
|
2022-01-01 20:56:24 -08:00
|
|
|
using Robust.Server.GameObjects;
|
|
|
|
|
|
2022-08-23 10:55:46 -07:00
|
|
|
namespace Content.Server.Atmos.Monitor.Systems;
|
|
|
|
|
|
|
|
|
|
public sealed class FireAlarmSystem : EntitySystem
|
2022-01-01 20:56:24 -08:00
|
|
|
{
|
2022-08-23 10:55:46 -07:00
|
|
|
[Dependency] private readonly AtmosDeviceNetworkSystem _atmosDevNet = default!;
|
|
|
|
|
[Dependency] private readonly AtmosAlarmableSystem _atmosAlarmable = default!;
|
|
|
|
|
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
|
|
|
|
|
|
|
|
|
|
public override void Initialize()
|
2022-01-01 20:56:24 -08:00
|
|
|
{
|
2022-08-23 10:55:46 -07:00
|
|
|
SubscribeLocalEvent<FireAlarmComponent, InteractHandEvent>(OnInteractHand);
|
|
|
|
|
SubscribeLocalEvent<FireAlarmComponent, DeviceListUpdateEvent>(OnDeviceListSync);
|
|
|
|
|
SubscribeLocalEvent<FireAlarmComponent, GotEmaggedEvent>(OnEmagged);
|
|
|
|
|
}
|
2022-01-01 20:56:24 -08:00
|
|
|
|
2022-08-23 10:55:46 -07:00
|
|
|
private void OnDeviceListSync(EntityUid uid, FireAlarmComponent component, DeviceListUpdateEvent args)
|
|
|
|
|
{
|
|
|
|
|
_atmosDevNet.Register(uid, null);
|
|
|
|
|
_atmosDevNet.Sync(uid, null);
|
|
|
|
|
}
|
2022-01-01 20:56:24 -08:00
|
|
|
|
2022-08-23 10:55:46 -07:00
|
|
|
private void OnInteractHand(EntityUid uid, FireAlarmComponent component, InteractHandEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (!_interactionSystem.InRangeUnobstructed(args.User, args.Target))
|
|
|
|
|
return;
|
2022-08-22 08:44:03 -07:00
|
|
|
|
2022-08-23 10:55:46 -07:00
|
|
|
if (this.IsPowered(uid, EntityManager))
|
2022-01-01 20:56:24 -08:00
|
|
|
{
|
2022-08-23 10:55:46 -07:00
|
|
|
if (!_atmosAlarmable.TryGetHighestAlert(uid, out var alarm))
|
2022-01-01 20:56:24 -08:00
|
|
|
{
|
2022-08-23 10:55:46 -07:00
|
|
|
alarm = AtmosMonitorAlarmType.Normal;
|
|
|
|
|
}
|
2022-08-22 05:49:51 -07:00
|
|
|
|
2022-08-23 10:55:46 -07:00
|
|
|
if (alarm == AtmosMonitorAlarmType.Normal)
|
|
|
|
|
{
|
|
|
|
|
_atmosAlarmable.ForceAlert(uid, AtmosMonitorAlarmType.Danger);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_atmosAlarmable.ResetAllOnNetwork(uid);
|
2022-01-01 20:56:24 -08:00
|
|
|
}
|
|
|
|
|
}
|
2022-08-23 10:55:46 -07:00
|
|
|
}
|
2022-02-17 21:43:24 -05:00
|
|
|
|
2022-08-23 10:55:46 -07:00
|
|
|
private void OnEmagged(EntityUid uid, FireAlarmComponent component, GotEmaggedEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (TryComp<AtmosMonitorComponent>(uid, out var atmosMonitor))
|
2022-02-17 21:43:24 -05:00
|
|
|
{
|
2022-08-23 10:55:46 -07:00
|
|
|
if (atmosMonitor?.MonitorFire == true)
|
2022-02-17 21:43:24 -05:00
|
|
|
{
|
2022-08-23 10:55:46 -07:00
|
|
|
atmosMonitor.MonitorFire = false;
|
|
|
|
|
_atmosAlarmable.ForceAlert(uid, AtmosMonitorAlarmType.Emagged);
|
|
|
|
|
args.Handled = true;
|
2022-02-17 21:43:24 -05:00
|
|
|
}
|
|
|
|
|
}
|
2022-01-01 20:56:24 -08:00
|
|
|
}
|
|
|
|
|
}
|