1
0

LogWireAction.cs 2.2 KB

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