FireAlarmSystem.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using Content.Server.AlertLevel;
  2. using Content.Server.Atmos.Monitor.Components;
  3. using Content.Server.DeviceNetwork.Components;
  4. using Content.Server.DeviceNetwork.Systems;
  5. using Content.Server.Power.Components;
  6. using Content.Server.Power.EntitySystems;
  7. using Content.Shared.Access.Systems;
  8. using Content.Shared.AlertLevel;
  9. using Content.Shared.Atmos.Monitor;
  10. using Content.Shared.CCVar;
  11. using Content.Shared.DeviceNetwork;
  12. using Content.Shared.DeviceNetwork.Systems;
  13. using Content.Shared.Interaction;
  14. using Content.Shared.Emag.Systems;
  15. using Robust.Server.GameObjects;
  16. using Robust.Shared.Configuration;
  17. namespace Content.Server.Atmos.Monitor.Systems;
  18. public sealed class FireAlarmSystem : EntitySystem
  19. {
  20. [Dependency] private readonly AtmosDeviceNetworkSystem _atmosDevNet = default!;
  21. [Dependency] private readonly AtmosAlarmableSystem _atmosAlarmable = default!;
  22. [Dependency] private readonly EmagSystem _emag = default!;
  23. [Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
  24. [Dependency] private readonly AccessReaderSystem _access = default!;
  25. [Dependency] private readonly IConfigurationManager _configManager = default!;
  26. public override void Initialize()
  27. {
  28. SubscribeLocalEvent<FireAlarmComponent, InteractHandEvent>(OnInteractHand);
  29. SubscribeLocalEvent<FireAlarmComponent, DeviceListUpdateEvent>(OnDeviceListSync);
  30. SubscribeLocalEvent<FireAlarmComponent, GotEmaggedEvent>(OnEmagged);
  31. }
  32. private void OnDeviceListSync(EntityUid uid, FireAlarmComponent component, DeviceListUpdateEvent args)
  33. {
  34. var query = GetEntityQuery<DeviceNetworkComponent>();
  35. foreach (var device in args.OldDevices)
  36. {
  37. if (!query.TryGetComponent(device, out var deviceNet))
  38. {
  39. continue;
  40. }
  41. _atmosDevNet.Deregister(uid, deviceNet.Address);
  42. }
  43. _atmosDevNet.Register(uid, null);
  44. _atmosDevNet.Sync(uid, null);
  45. }
  46. private void OnInteractHand(EntityUid uid, FireAlarmComponent component, InteractHandEvent args)
  47. {
  48. if (!_interactionSystem.InRangeUnobstructed(args.User, args.Target))
  49. return;
  50. if (!_configManager.GetCVar(CCVars.FireAlarmAllAccess) && !_access.IsAllowed(args.User, args.Target))
  51. return;
  52. if (this.IsPowered(uid, EntityManager))
  53. {
  54. if (!_atmosAlarmable.TryGetHighestAlert(uid, out var alarm))
  55. {
  56. alarm = AtmosAlarmType.Normal;
  57. }
  58. if (alarm == AtmosAlarmType.Normal)
  59. {
  60. _atmosAlarmable.ForceAlert(uid, AtmosAlarmType.Danger);
  61. }
  62. else
  63. {
  64. _atmosAlarmable.ResetAllOnNetwork(uid);
  65. }
  66. }
  67. }
  68. private void OnEmagged(EntityUid uid, FireAlarmComponent component, ref GotEmaggedEvent args)
  69. {
  70. if (!_emag.CompareFlag(args.Type, EmagType.Interaction))
  71. return;
  72. if (_emag.CheckFlag(uid, EmagType.Interaction))
  73. return;
  74. if (!TryComp<AtmosAlarmableComponent>(uid, out var alarmable))
  75. return;
  76. // Remove the atmos alarmable component permanently from this device.
  77. _atmosAlarmable.ForceAlert(uid, AtmosAlarmType.Emagged, alarmable);
  78. RemCompDeferred<AtmosAlarmableComponent>(uid);
  79. args.Handled = true;
  80. }
  81. }