1
0

AccessWireAction.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using Content.Server.Wires;
  2. using Content.Shared.Access;
  3. using Content.Shared.Access.Components;
  4. using Content.Shared.Wires;
  5. namespace Content.Server.Access;
  6. public sealed partial class AccessWireAction : ComponentWireAction<AccessReaderComponent>
  7. {
  8. public override Color Color { get; set; } = Color.Green;
  9. public override string Name { get; set; } = "wire-name-access";
  10. [DataField("pulseTimeout")]
  11. private int _pulseTimeout = 30;
  12. public override StatusLightState? GetLightState(Wire wire, AccessReaderComponent comp)
  13. {
  14. return comp.Enabled ? StatusLightState.On : StatusLightState.Off;
  15. }
  16. public override object StatusKey => AccessWireActionKey.Status;
  17. public override bool Cut(EntityUid user, Wire wire, AccessReaderComponent comp)
  18. {
  19. WiresSystem.TryCancelWireAction(wire.Owner, PulseTimeoutKey.Key);
  20. comp.Enabled = false;
  21. EntityManager.Dirty(wire.Owner, comp);
  22. return true;
  23. }
  24. public override bool Mend(EntityUid user, Wire wire, AccessReaderComponent comp)
  25. {
  26. comp.Enabled = true;
  27. EntityManager.Dirty(wire.Owner, comp);
  28. return true;
  29. }
  30. public override void Pulse(EntityUid user, Wire wire, AccessReaderComponent comp)
  31. {
  32. comp.Enabled = false;
  33. EntityManager.Dirty(wire.Owner, comp);
  34. WiresSystem.StartWireAction(wire.Owner, _pulseTimeout, PulseTimeoutKey.Key, new TimedWireEvent(AwaitPulseCancel, wire));
  35. }
  36. public override void Update(Wire wire)
  37. {
  38. if (!IsPowered(wire.Owner))
  39. {
  40. WiresSystem.TryCancelWireAction(wire.Owner, PulseTimeoutKey.Key);
  41. }
  42. }
  43. private void AwaitPulseCancel(Wire wire)
  44. {
  45. if (!wire.IsCut)
  46. {
  47. if (EntityManager.TryGetComponent<AccessReaderComponent>(wire.Owner, out var access))
  48. {
  49. access.Enabled = true;
  50. EntityManager.Dirty(wire.Owner, access);
  51. }
  52. }
  53. }
  54. private enum PulseTimeoutKey : byte
  55. {
  56. Key
  57. }
  58. }