Files

88 lines
3.1 KiB
C#
Raw Permalink Normal View History

2022-05-17 21:05:31 -07:00
using Content.Server.AlertLevel;
using Content.Server.Atmos.Monitor.Components;
using Content.Server.DeviceNetwork.Components;
using Content.Server.DeviceNetwork.Systems;
using Content.Server.Power.Components;
using Content.Server.Power.EntitySystems;
using Content.Shared.Access.Systems;
2022-05-17 21:05:31 -07:00
using Content.Shared.AlertLevel;
using Content.Shared.Atmos.Monitor;
using Content.Shared.CCVar;
using Content.Shared.DeviceNetwork;
using Content.Shared.DeviceNetwork.Systems;
using Content.Shared.Interaction;
2022-02-17 21:43:24 -05:00
using Content.Shared.Emag.Systems;
using Robust.Server.GameObjects;
using Robust.Shared.Configuration;
2022-08-23 10:55:46 -07:00
namespace Content.Server.Atmos.Monitor.Systems;
public sealed class FireAlarmSystem : EntitySystem
{
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!;
[Dependency] private readonly AccessReaderSystem _access = default!;
[Dependency] private readonly IConfigurationManager _configManager = default!;
2022-08-23 10:55:46 -07:00
public override void Initialize()
{
2022-08-23 10:55:46 -07:00
SubscribeLocalEvent<FireAlarmComponent, InteractHandEvent>(OnInteractHand);
SubscribeLocalEvent<FireAlarmComponent, DeviceListUpdateEvent>(OnDeviceListSync);
SubscribeLocalEvent<FireAlarmComponent, GotEmaggedEvent>(OnEmagged);
}
2022-08-23 10:55:46 -07:00
private void OnDeviceListSync(EntityUid uid, FireAlarmComponent component, DeviceListUpdateEvent args)
{
var query = GetEntityQuery<DeviceNetworkComponent>();
foreach (var device in args.OldDevices)
{
if (!query.TryGetComponent(device, out var deviceNet))
{
continue;
}
_atmosDevNet.Deregister(uid, deviceNet.Address);
}
2022-08-23 10:55:46 -07:00
_atmosDevNet.Register(uid, null);
_atmosDevNet.Sync(uid, null);
}
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;
if (!_configManager.GetCVar(CCVars.FireAlarmAllAccess) && !_access.IsAllowed(args.User, args.Target))
return;
2022-08-23 10:55:46 -07:00
if (this.IsPowered(uid, EntityManager))
{
2022-08-23 10:55:46 -07:00
if (!_atmosAlarmable.TryGetHighestAlert(uid, out var alarm))
{
alarm = AtmosAlarmType.Normal;
2022-08-23 10:55:46 -07:00
}
if (alarm == AtmosAlarmType.Normal)
2022-08-23 10:55:46 -07:00
{
_atmosAlarmable.ForceAlert(uid, AtmosAlarmType.Danger);
2022-08-23 10:55:46 -07:00
}
else
{
_atmosAlarmable.ResetAllOnNetwork(uid);
}
}
2022-08-23 10:55:46 -07:00
}
2022-02-17 21:43:24 -05:00
private void OnEmagged(EntityUid uid, FireAlarmComponent component, ref GotEmaggedEvent args)
2022-08-23 10:55:46 -07:00
{
if (TryComp<AtmosAlarmableComponent>(uid, out var alarmable))
2022-02-17 21:43:24 -05:00
{
// Remove the atmos alarmable component permanently from this device.
_atmosAlarmable.ForceAlert(uid, AtmosAlarmType.Emagged, alarmable);
RemCompDeferred<AtmosAlarmableComponent>(uid);
2022-02-17 21:43:24 -05:00
}
}
}