1
0

SharedFirelockSystem.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. using Content.Shared.Access.Systems;
  2. using Content.Shared.Doors.Components;
  3. using Content.Shared.Examine;
  4. using Content.Shared.Popups;
  5. using Content.Shared.Prying.Components;
  6. using Robust.Shared.Timing;
  7. namespace Content.Shared.Doors.Systems;
  8. public abstract class SharedFirelockSystem : EntitySystem
  9. {
  10. [Dependency] private readonly AccessReaderSystem _accessReaderSystem = default!;
  11. [Dependency] private readonly SharedPopupSystem _popupSystem = default!;
  12. [Dependency] private readonly SharedAppearanceSystem _appearance = default!;
  13. [Dependency] private readonly SharedDoorSystem _doorSystem = default!;
  14. [Dependency] private readonly IGameTiming _gameTiming = default!;
  15. public override void Initialize()
  16. {
  17. base.Initialize();
  18. // Access/Prying
  19. SubscribeLocalEvent<FirelockComponent, BeforeDoorOpenedEvent>(OnBeforeDoorOpened);
  20. SubscribeLocalEvent<FirelockComponent, BeforePryEvent>(OnBeforePry);
  21. SubscribeLocalEvent<FirelockComponent, GetPryTimeModifierEvent>(OnDoorGetPryTimeModifier);
  22. SubscribeLocalEvent<FirelockComponent, PriedEvent>(OnAfterPried);
  23. // Visuals
  24. SubscribeLocalEvent<FirelockComponent, MapInitEvent>(UpdateVisuals);
  25. SubscribeLocalEvent<FirelockComponent, ComponentStartup>(UpdateVisuals);
  26. SubscribeLocalEvent<FirelockComponent, ExaminedEvent>(OnExamined);
  27. }
  28. public bool EmergencyPressureStop(EntityUid uid, FirelockComponent? firelock = null, DoorComponent? door = null)
  29. {
  30. if (!Resolve(uid, ref firelock, ref door))
  31. return false;
  32. if (door.State != DoorState.Open
  33. || firelock.EmergencyCloseCooldown != null
  34. && _gameTiming.CurTime < firelock.EmergencyCloseCooldown)
  35. return false;
  36. if (!_doorSystem.TryClose(uid, door))
  37. return false;
  38. return _doorSystem.OnPartialClose(uid, door);
  39. }
  40. #region Access/Prying
  41. private void OnBeforeDoorOpened(EntityUid uid, FirelockComponent component, BeforeDoorOpenedEvent args)
  42. {
  43. // Give the Door remote the ability to force a firelock open even if it is holding back dangerous gas
  44. var overrideAccess = (args.User != null) && _accessReaderSystem.IsAllowed(args.User.Value, uid);
  45. if (!component.Powered || (!overrideAccess && component.IsLocked))
  46. args.Cancel();
  47. else if (args.User != null)
  48. WarnPlayer((uid, component), args.User.Value);
  49. }
  50. private void OnBeforePry(EntityUid uid, FirelockComponent component, ref BeforePryEvent args)
  51. {
  52. if (args.Cancelled || !component.Powered || args.StrongPry || args.PryPowered)
  53. return;
  54. args.Cancelled = true;
  55. }
  56. private void OnDoorGetPryTimeModifier(EntityUid uid, FirelockComponent component, ref GetPryTimeModifierEvent args)
  57. {
  58. WarnPlayer((uid, component), args.User);
  59. if (component.IsLocked)
  60. args.PryTimeModifier *= component.LockedPryTimeModifier;
  61. }
  62. private void WarnPlayer(Entity<FirelockComponent> ent, EntityUid user)
  63. {
  64. if (ent.Comp.Temperature)
  65. {
  66. _popupSystem.PopupClient(Loc.GetString("firelock-component-is-holding-fire-message"),
  67. ent.Owner,
  68. user,
  69. PopupType.MediumCaution);
  70. }
  71. else if (ent.Comp.Pressure)
  72. {
  73. _popupSystem.PopupClient(Loc.GetString("firelock-component-is-holding-pressure-message"),
  74. ent.Owner,
  75. user,
  76. PopupType.MediumCaution);
  77. }
  78. }
  79. private void OnAfterPried(EntityUid uid, FirelockComponent component, ref PriedEvent args)
  80. {
  81. component.EmergencyCloseCooldown = _gameTiming.CurTime + component.EmergencyCloseCooldownDuration;
  82. }
  83. #endregion
  84. #region Visuals
  85. private void UpdateVisuals(EntityUid uid, FirelockComponent component, EntityEventArgs args) => UpdateVisuals(uid, component);
  86. private void UpdateVisuals(EntityUid uid,
  87. FirelockComponent? firelock = null,
  88. DoorComponent? door = null,
  89. AppearanceComponent? appearance = null)
  90. {
  91. if (!Resolve(uid, ref door, ref appearance, false))
  92. return;
  93. // only bother to check pressure on doors that are some variation of closed.
  94. if (door.State != DoorState.Closed
  95. && door.State != DoorState.Welded
  96. && door.State != DoorState.Denying)
  97. {
  98. _appearance.SetData(uid, DoorVisuals.ClosedLights, false, appearance);
  99. return;
  100. }
  101. if (!Resolve(uid, ref firelock, ref appearance, false))
  102. return;
  103. _appearance.SetData(uid, DoorVisuals.ClosedLights, firelock.IsLocked, appearance);
  104. }
  105. #endregion
  106. private void OnExamined(Entity<FirelockComponent> ent, ref ExaminedEvent args)
  107. {
  108. using (args.PushGroup(nameof(FirelockComponent)))
  109. {
  110. if (ent.Comp.Pressure)
  111. args.PushMarkup(Loc.GetString("firelock-component-examine-pressure-warning"));
  112. if (ent.Comp.Temperature)
  113. args.PushMarkup(Loc.GetString("firelock-component-examine-temperature-warning"));
  114. }
  115. }
  116. }