DoorTimingWireAction.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 DoorTimingWireAction : ComponentWireAction<AirlockComponent>
  8. {
  9. public override Color Color { get; set; } = Color.Orange;
  10. public override string Name { get; set; } = "wire-name-door-timer";
  11. [DataField("timeout")]
  12. private int _timeout = 30;
  13. public override StatusLightState? GetLightState(Wire wire, AirlockComponent comp)
  14. {
  15. switch (comp.AutoCloseDelayModifier)
  16. {
  17. case 0.01f:
  18. return StatusLightState.Off;
  19. case <= 0.5f:
  20. return StatusLightState.BlinkingSlow;
  21. default:
  22. return StatusLightState.On;
  23. }
  24. }
  25. public override object StatusKey { get; } = AirlockWireStatus.TimingIndicator;
  26. public override bool Cut(EntityUid user, Wire wire, AirlockComponent door)
  27. {
  28. WiresSystem.TryCancelWireAction(wire.Owner, PulseTimeoutKey.Key);
  29. EntityManager.System<SharedAirlockSystem>().SetAutoCloseDelayModifier(door, 0.01f);
  30. return true;
  31. }
  32. public override bool Mend(EntityUid user, Wire wire, AirlockComponent door)
  33. {
  34. EntityManager.System<SharedAirlockSystem>().SetAutoCloseDelayModifier(door, 1f);
  35. return true;
  36. }
  37. public override void Pulse(EntityUid user, Wire wire, AirlockComponent door)
  38. {
  39. EntityManager.System<SharedAirlockSystem>().SetAutoCloseDelayModifier(door, 0.5f);
  40. WiresSystem.StartWireAction(wire.Owner, _timeout, PulseTimeoutKey.Key, new TimedWireEvent(AwaitTimingTimerFinish, wire));
  41. }
  42. public override void Update(Wire wire)
  43. {
  44. if (!IsPowered(wire.Owner))
  45. {
  46. WiresSystem.TryCancelWireAction(wire.Owner, PulseTimeoutKey.Key);
  47. }
  48. }
  49. // timing timer??? ???
  50. private void AwaitTimingTimerFinish(Wire wire)
  51. {
  52. if (!wire.IsCut)
  53. {
  54. if (EntityManager.TryGetComponent<AirlockComponent>(wire.Owner, out var door))
  55. {
  56. EntityManager.System<SharedAirlockSystem>().SetAutoCloseDelayModifier(door, 1f);
  57. }
  58. }
  59. }
  60. private enum PulseTimeoutKey : byte
  61. {
  62. Key
  63. }
  64. }