2022-05-05 19:35:06 -07:00
|
|
|
using Content.Server.Wires;
|
|
|
|
|
using Content.Shared.Access;
|
|
|
|
|
using Content.Shared.Access.Components;
|
2023-02-19 01:03:06 +00:00
|
|
|
using Content.Shared.Emag.Components;
|
2022-05-05 19:35:06 -07:00
|
|
|
using Content.Shared.Wires;
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.Access;
|
|
|
|
|
|
2023-08-22 18:14:33 -07:00
|
|
|
public sealed partial class AccessWireAction : ComponentWireAction<AccessReaderComponent>
|
2022-05-05 19:35:06 -07:00
|
|
|
{
|
2023-01-21 12:51:02 +13:00
|
|
|
public override Color Color { get; set; } = Color.Green;
|
|
|
|
|
public override string Name { get; set; } = "wire-name-access";
|
2022-05-05 19:35:06 -07:00
|
|
|
|
|
|
|
|
[DataField("pulseTimeout")]
|
|
|
|
|
private int _pulseTimeout = 30;
|
|
|
|
|
|
2023-01-21 12:51:02 +13:00
|
|
|
public override StatusLightState? GetLightState(Wire wire, AccessReaderComponent comp)
|
2023-02-19 01:03:06 +00:00
|
|
|
{
|
2023-03-13 22:55:18 -04:00
|
|
|
return comp.Enabled ? StatusLightState.On : StatusLightState.Off;
|
2023-02-19 01:03:06 +00:00
|
|
|
}
|
2022-05-05 19:35:06 -07:00
|
|
|
|
2023-03-13 22:55:18 -04:00
|
|
|
public override object StatusKey => AccessWireActionKey.Status;
|
2022-05-05 19:35:06 -07:00
|
|
|
|
2023-01-21 12:51:02 +13:00
|
|
|
public override bool Cut(EntityUid user, Wire wire, AccessReaderComponent comp)
|
2022-05-05 19:35:06 -07:00
|
|
|
{
|
2023-01-21 12:51:02 +13:00
|
|
|
WiresSystem.TryCancelWireAction(wire.Owner, PulseTimeoutKey.Key);
|
2023-03-13 22:55:18 -04:00
|
|
|
comp.Enabled = false;
|
2024-02-13 22:48:39 +01:00
|
|
|
EntityManager.Dirty(wire.Owner, comp);
|
2022-05-05 19:35:06 -07:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-21 12:51:02 +13:00
|
|
|
public override bool Mend(EntityUid user, Wire wire, AccessReaderComponent comp)
|
2022-05-05 19:35:06 -07:00
|
|
|
{
|
2023-03-13 22:55:18 -04:00
|
|
|
if (!EntityManager.HasComponent<EmaggedComponent>(wire.Owner))
|
|
|
|
|
{
|
|
|
|
|
comp.Enabled = true;
|
2024-02-13 22:48:39 +01:00
|
|
|
EntityManager.Dirty(wire.Owner, comp);
|
2023-03-13 22:55:18 -04:00
|
|
|
}
|
2022-05-05 19:35:06 -07:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-21 12:51:02 +13:00
|
|
|
public override void Pulse(EntityUid user, Wire wire, AccessReaderComponent comp)
|
2022-05-05 19:35:06 -07:00
|
|
|
{
|
2023-03-13 22:55:18 -04:00
|
|
|
comp.Enabled = false;
|
2024-02-13 22:48:39 +01:00
|
|
|
EntityManager.Dirty(wire.Owner, comp);
|
2023-01-21 12:51:02 +13:00
|
|
|
WiresSystem.StartWireAction(wire.Owner, _pulseTimeout, PulseTimeoutKey.Key, new TimedWireEvent(AwaitPulseCancel, wire));
|
2022-05-05 19:35:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Update(Wire wire)
|
|
|
|
|
{
|
|
|
|
|
if (!IsPowered(wire.Owner))
|
|
|
|
|
{
|
|
|
|
|
WiresSystem.TryCancelWireAction(wire.Owner, PulseTimeoutKey.Key);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AwaitPulseCancel(Wire wire)
|
|
|
|
|
{
|
|
|
|
|
if (!wire.IsCut)
|
|
|
|
|
{
|
2023-03-13 22:55:18 -04:00
|
|
|
if (EntityManager.TryGetComponent<AccessReaderComponent>(wire.Owner, out var access) && !EntityManager.HasComponent<EmaggedComponent>(wire.Owner))
|
2022-05-05 19:35:06 -07:00
|
|
|
{
|
2023-03-13 22:55:18 -04:00
|
|
|
access.Enabled = true;
|
2024-02-13 22:48:39 +01:00
|
|
|
EntityManager.Dirty(wire.Owner, access);
|
2022-05-05 19:35:06 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private enum PulseTimeoutKey : byte
|
|
|
|
|
{
|
|
|
|
|
Key
|
|
|
|
|
}
|
|
|
|
|
}
|