| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- using Content.Server.Wires;
- using Content.Shared.Access;
- using Content.Shared.Access.Components;
- using Content.Shared.Wires;
- namespace Content.Server.Access;
- public sealed partial class AccessWireAction : ComponentWireAction<AccessReaderComponent>
- {
- public override Color Color { get; set; } = Color.Green;
- public override string Name { get; set; } = "wire-name-access";
- [DataField("pulseTimeout")]
- private int _pulseTimeout = 30;
- public override StatusLightState? GetLightState(Wire wire, AccessReaderComponent comp)
- {
- return comp.Enabled ? StatusLightState.On : StatusLightState.Off;
- }
- public override object StatusKey => AccessWireActionKey.Status;
- public override bool Cut(EntityUid user, Wire wire, AccessReaderComponent comp)
- {
- WiresSystem.TryCancelWireAction(wire.Owner, PulseTimeoutKey.Key);
- comp.Enabled = false;
- EntityManager.Dirty(wire.Owner, comp);
- return true;
- }
- public override bool Mend(EntityUid user, Wire wire, AccessReaderComponent comp)
- {
- comp.Enabled = true;
- EntityManager.Dirty(wire.Owner, comp);
- return true;
- }
- public override void Pulse(EntityUid user, Wire wire, AccessReaderComponent comp)
- {
- comp.Enabled = false;
- EntityManager.Dirty(wire.Owner, comp);
- WiresSystem.StartWireAction(wire.Owner, _pulseTimeout, PulseTimeoutKey.Key, new TimedWireEvent(AwaitPulseCancel, wire));
- }
- public override void Update(Wire wire)
- {
- if (!IsPowered(wire.Owner))
- {
- WiresSystem.TryCancelWireAction(wire.Owner, PulseTimeoutKey.Key);
- }
- }
- private void AwaitPulseCancel(Wire wire)
- {
- if (!wire.IsCut)
- {
- if (EntityManager.TryGetComponent<AccessReaderComponent>(wire.Owner, out var access))
- {
- access.Enabled = true;
- EntityManager.Dirty(wire.Owner, access);
- }
- }
- }
- private enum PulseTimeoutKey : byte
- {
- Key
- }
- }
|