SharedStationAiSystem.Airlock.cs 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using Content.Shared.Doors.Components;
  2. using Robust.Shared.Serialization;
  3. using Content.Shared.Electrocution;
  4. namespace Content.Shared.Silicons.StationAi;
  5. public abstract partial class SharedStationAiSystem
  6. {
  7. // Handles airlock radial
  8. private void InitializeAirlock()
  9. {
  10. SubscribeLocalEvent<DoorBoltComponent, StationAiBoltEvent>(OnAirlockBolt);
  11. SubscribeLocalEvent<AirlockComponent, StationAiEmergencyAccessEvent>(OnAirlockEmergencyAccess);
  12. SubscribeLocalEvent<ElectrifiedComponent, StationAiElectrifiedEvent>(OnElectrified);
  13. }
  14. /// <summary>
  15. /// Attempts to bolt door. If wire was cut (AI or for bolts) or its not powered - notifies AI and does nothing.
  16. /// </summary>
  17. private void OnAirlockBolt(EntityUid ent, DoorBoltComponent component, StationAiBoltEvent args)
  18. {
  19. if (component.BoltWireCut)
  20. {
  21. ShowDeviceNotRespondingPopup(args.User);
  22. return;
  23. }
  24. var setResult = _doors.TrySetBoltDown((ent, component), args.Bolted, args.User, predicted: true);
  25. if (!setResult)
  26. {
  27. ShowDeviceNotRespondingPopup(args.User);
  28. }
  29. }
  30. /// <summary>
  31. /// Attempts to toggle the door's emergency access. If wire was cut (AI) or its not powered - notifies AI and does nothing.
  32. /// </summary>
  33. private void OnAirlockEmergencyAccess(EntityUid ent, AirlockComponent component, StationAiEmergencyAccessEvent args)
  34. {
  35. if (!PowerReceiver.IsPowered(ent))
  36. {
  37. ShowDeviceNotRespondingPopup(args.User);
  38. return;
  39. }
  40. _airlocks.SetEmergencyAccess((ent, component), args.EmergencyAccess, args.User, predicted: true);
  41. }
  42. /// <summary>
  43. /// Attempts to electrify the door. If wire was cut (AI or for one of power-wires) or its not powered - notifies AI and does nothing.
  44. /// </summary>
  45. private void OnElectrified(EntityUid ent, ElectrifiedComponent component, StationAiElectrifiedEvent args)
  46. {
  47. if (
  48. component.IsWireCut
  49. || !PowerReceiver.IsPowered(ent)
  50. )
  51. {
  52. ShowDeviceNotRespondingPopup(args.User);
  53. return;
  54. }
  55. _electrify.SetElectrified((ent, component), args.Electrified);
  56. var soundToPlay = component.Enabled
  57. ? component.AirlockElectrifyDisabled
  58. : component.AirlockElectrifyEnabled;
  59. _audio.PlayLocal(soundToPlay, ent, args.User);
  60. }
  61. }
  62. /// <summary> Event for StationAI attempt at bolting/unbolting door. </summary>
  63. [Serializable, NetSerializable]
  64. public sealed class StationAiBoltEvent : BaseStationAiAction
  65. {
  66. /// <summary> Marker, should be door bolted or unbolted. </summary>
  67. public bool Bolted;
  68. }
  69. /// <summary> Event for StationAI attempt at setting emergency access for door on/off. </summary>
  70. [Serializable, NetSerializable]
  71. public sealed class StationAiEmergencyAccessEvent : BaseStationAiAction
  72. {
  73. /// <summary> Marker, should door have emergency access on or off. </summary>
  74. public bool EmergencyAccess;
  75. }
  76. /// <summary> Event for StationAI attempt at electrifying/de-electrifying door. </summary>
  77. [Serializable, NetSerializable]
  78. public sealed class StationAiElectrifiedEvent : BaseStationAiAction
  79. {
  80. /// <summary> Marker, should door be electrified or no. </summary>
  81. public bool Electrified;
  82. }