DoorSafetyWireAction.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using Content.Server.Wires;
  2. using Content.Shared.Doors;
  3. using Content.Shared.Doors.Components;
  4. using Content.Shared.Doors.Systems;
  5. using Content.Shared.Wires;
  6. namespace Content.Server.Doors;
  7. public sealed partial class DoorSafetyWireAction : ComponentWireAction<AirlockComponent>
  8. {
  9. public override Color Color { get; set; } = Color.Red;
  10. public override string Name { get; set; } = "wire-name-door-safety";
  11. [DataField("timeout")]
  12. private int _timeout = 30;
  13. public override StatusLightState? GetLightState(Wire wire, AirlockComponent comp)
  14. => comp.Safety ? StatusLightState.On : StatusLightState.Off;
  15. public override object StatusKey { get; } = AirlockWireStatus.SafetyIndicator;
  16. public override bool Cut(EntityUid user, Wire wire, AirlockComponent door)
  17. {
  18. WiresSystem.TryCancelWireAction(wire.Owner, PulseTimeoutKey.Key);
  19. EntityManager.System<SharedAirlockSystem>().SetSafety(door, false);
  20. return true;
  21. }
  22. public override bool Mend(EntityUid user, Wire wire, AirlockComponent door)
  23. {
  24. EntityManager.System<SharedAirlockSystem>().SetSafety(door, true);
  25. return true;
  26. }
  27. public override void Pulse(EntityUid user, Wire wire, AirlockComponent door)
  28. {
  29. EntityManager.System<SharedAirlockSystem>().SetSafety(door, false);
  30. WiresSystem.StartWireAction(wire.Owner, _timeout, PulseTimeoutKey.Key, new TimedWireEvent(AwaitSafetyTimerFinish, wire));
  31. }
  32. public override void Update(Wire wire)
  33. {
  34. if (!IsPowered(wire.Owner))
  35. {
  36. WiresSystem.TryCancelWireAction(wire.Owner, PulseTimeoutKey.Key);
  37. }
  38. }
  39. private void AwaitSafetyTimerFinish(Wire wire)
  40. {
  41. if (!wire.IsCut)
  42. {
  43. if (EntityManager.TryGetComponent<AirlockComponent>(wire.Owner, out var door))
  44. {
  45. EntityManager.System<SharedAirlockSystem>().SetSafety(door, true);
  46. }
  47. }
  48. }
  49. private enum PulseTimeoutKey : byte
  50. {
  51. Key
  52. }
  53. }