AirlockSystem.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using Content.Server.DeviceLinking.Events;
  2. using Content.Server.Power.Components;
  3. using Content.Server.Wires;
  4. using Content.Shared.Doors.Components;
  5. using Content.Shared.Doors.Systems;
  6. using Content.Shared.Interaction;
  7. using Content.Shared.Power;
  8. using Content.Shared.Wires;
  9. using Robust.Shared.Player;
  10. namespace Content.Server.Doors.Systems;
  11. public sealed class AirlockSystem : SharedAirlockSystem
  12. {
  13. [Dependency] private readonly WiresSystem _wiresSystem = default!;
  14. public override void Initialize()
  15. {
  16. base.Initialize();
  17. SubscribeLocalEvent<AirlockComponent, SignalReceivedEvent>(OnSignalReceived);
  18. SubscribeLocalEvent<AirlockComponent, PowerChangedEvent>(OnPowerChanged);
  19. SubscribeLocalEvent<AirlockComponent, ActivateInWorldEvent>(OnActivate, before: new[] { typeof(DoorSystem) });
  20. }
  21. private void OnSignalReceived(EntityUid uid, AirlockComponent component, ref SignalReceivedEvent args)
  22. {
  23. if (args.Port == component.AutoClosePort && component.AutoClose)
  24. {
  25. component.AutoClose = false;
  26. Dirty(uid, component);
  27. }
  28. }
  29. private void OnPowerChanged(EntityUid uid, AirlockComponent component, ref PowerChangedEvent args)
  30. {
  31. component.Powered = args.Powered;
  32. Dirty(uid, component);
  33. if (!TryComp(uid, out DoorComponent? door))
  34. return;
  35. if (!args.Powered)
  36. {
  37. // stop any scheduled auto-closing
  38. if (door.State == DoorState.Open)
  39. DoorSystem.SetNextStateChange(uid, null);
  40. }
  41. else
  42. {
  43. UpdateAutoClose(uid, door: door);
  44. }
  45. }
  46. private void OnActivate(EntityUid uid, AirlockComponent component, ActivateInWorldEvent args)
  47. {
  48. if (args.Handled || !args.Complex)
  49. return;
  50. if (TryComp<WiresPanelComponent>(uid, out var panel) &&
  51. panel.Open &&
  52. TryComp<ActorComponent>(args.User, out var actor))
  53. {
  54. if (TryComp<WiresPanelSecurityComponent>(uid, out var wiresPanelSecurity) &&
  55. !wiresPanelSecurity.WiresAccessible)
  56. return;
  57. _wiresSystem.OpenUserInterface(uid, actor.PlayerSession);
  58. args.Handled = true;
  59. return;
  60. }
  61. if (component.KeepOpenIfClicked && component.AutoClose)
  62. {
  63. // Disable auto close
  64. component.AutoClose = false;
  65. Dirty(uid, component);
  66. }
  67. }
  68. }