2023-05-07 08:07:24 +02:00
|
|
|
using Content.Server.DeviceLinking.Events;
|
2021-08-02 04:57:06 -07:00
|
|
|
using Content.Server.Power.Components;
|
2022-05-05 19:35:06 -07:00
|
|
|
using Content.Server.Wires;
|
2022-01-30 13:49:56 +13:00
|
|
|
using Content.Shared.Doors.Components;
|
|
|
|
|
using Content.Shared.Doors.Systems;
|
|
|
|
|
using Content.Shared.Interaction;
|
2023-03-24 03:09:45 +03:00
|
|
|
using Content.Shared.Wires;
|
2023-10-29 04:21:02 +11:00
|
|
|
using Robust.Shared.Player;
|
2021-08-02 04:57:06 -07:00
|
|
|
|
2023-08-10 03:33:03 -05:00
|
|
|
namespace Content.Server.Doors.Systems;
|
|
|
|
|
|
|
|
|
|
public sealed class AirlockSystem : SharedAirlockSystem
|
2021-08-02 04:57:06 -07:00
|
|
|
{
|
2023-08-10 03:33:03 -05:00
|
|
|
[Dependency] private readonly WiresSystem _wiresSystem = default!;
|
2022-05-05 19:35:06 -07:00
|
|
|
|
2023-08-10 03:33:03 -05:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
2021-08-02 04:57:06 -07:00
|
|
|
|
2023-08-10 03:33:03 -05:00
|
|
|
SubscribeLocalEvent<AirlockComponent, ComponentInit>(OnAirlockInit);
|
|
|
|
|
SubscribeLocalEvent<AirlockComponent, SignalReceivedEvent>(OnSignalReceived);
|
2023-04-19 03:47:01 -04:00
|
|
|
|
2023-08-10 03:33:03 -05:00
|
|
|
SubscribeLocalEvent<AirlockComponent, PowerChangedEvent>(OnPowerChanged);
|
2023-09-28 11:34:21 +00:00
|
|
|
SubscribeLocalEvent<AirlockComponent, ActivateInWorldEvent>(OnActivate, before: new[] { typeof(DoorSystem) });
|
2023-08-10 03:33:03 -05:00
|
|
|
}
|
2021-08-02 04:57:06 -07:00
|
|
|
|
2023-08-10 03:33:03 -05:00
|
|
|
private void OnAirlockInit(EntityUid uid, AirlockComponent component, ComponentInit args)
|
|
|
|
|
{
|
|
|
|
|
if (TryComp<ApcPowerReceiverComponent>(uid, out var receiverComponent))
|
2023-01-18 05:44:32 +11:00
|
|
|
{
|
2023-08-10 03:33:03 -05:00
|
|
|
Appearance.SetData(uid, DoorVisuals.Powered, receiverComponent.Powered);
|
2023-01-18 05:44:32 +11:00
|
|
|
}
|
2023-08-10 03:33:03 -05:00
|
|
|
}
|
2023-01-18 05:44:32 +11:00
|
|
|
|
2023-08-10 03:33:03 -05:00
|
|
|
private void OnSignalReceived(EntityUid uid, AirlockComponent component, ref SignalReceivedEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (args.Port == component.AutoClosePort)
|
2023-04-19 03:47:01 -04:00
|
|
|
{
|
2023-08-10 03:33:03 -05:00
|
|
|
component.AutoClose = false;
|
2023-04-19 03:47:01 -04:00
|
|
|
}
|
2023-08-10 03:33:03 -05:00
|
|
|
}
|
2023-04-19 03:47:01 -04:00
|
|
|
|
2023-08-10 03:33:03 -05:00
|
|
|
private void OnPowerChanged(EntityUid uid, AirlockComponent component, ref PowerChangedEvent args)
|
|
|
|
|
{
|
2024-02-22 18:01:31 -05:00
|
|
|
component.Powered = args.Powered;
|
|
|
|
|
Dirty(uid, component);
|
|
|
|
|
|
2023-08-10 03:33:03 -05:00
|
|
|
if (TryComp<AppearanceComponent>(uid, out var appearanceComponent))
|
2021-08-02 04:57:06 -07:00
|
|
|
{
|
2023-08-10 03:33:03 -05:00
|
|
|
Appearance.SetData(uid, DoorVisuals.Powered, args.Powered, appearanceComponent);
|
|
|
|
|
}
|
2021-08-02 04:57:06 -07:00
|
|
|
|
2023-08-10 03:33:03 -05:00
|
|
|
if (!TryComp(uid, out DoorComponent? door))
|
|
|
|
|
return;
|
2022-01-30 17:47:24 +13:00
|
|
|
|
2023-08-10 03:33:03 -05:00
|
|
|
if (!args.Powered)
|
|
|
|
|
{
|
|
|
|
|
// stop any scheduled auto-closing
|
|
|
|
|
if (door.State == DoorState.Open)
|
|
|
|
|
DoorSystem.SetNextStateChange(uid, null);
|
2021-08-02 04:57:06 -07:00
|
|
|
}
|
2023-08-10 03:33:03 -05:00
|
|
|
else
|
2021-08-02 04:57:06 -07:00
|
|
|
{
|
2023-08-10 03:33:03 -05:00
|
|
|
UpdateAutoClose(uid, door: door);
|
2021-08-02 04:57:06 -07:00
|
|
|
}
|
2023-08-10 03:33:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnActivate(EntityUid uid, AirlockComponent component, ActivateInWorldEvent args)
|
|
|
|
|
{
|
2023-09-14 00:54:49 -05:00
|
|
|
if (TryComp<WiresPanelComponent>(uid, out var panel) &&
|
|
|
|
|
panel.Open &&
|
|
|
|
|
TryComp<ActorComponent>(args.User, out var actor))
|
2022-08-31 23:22:25 -04:00
|
|
|
{
|
2023-10-06 16:26:02 -05:00
|
|
|
if (TryComp<WiresPanelSecurityComponent>(uid, out var wiresPanelSecurity) &&
|
|
|
|
|
!wiresPanelSecurity.WiresAccessible)
|
|
|
|
|
return;
|
|
|
|
|
|
2023-08-10 03:33:03 -05:00
|
|
|
_wiresSystem.OpenUserInterface(uid, actor.PlayerSession);
|
|
|
|
|
args.Handled = true;
|
|
|
|
|
return;
|
2022-08-31 23:22:25 -04:00
|
|
|
}
|
|
|
|
|
|
2023-08-10 03:33:03 -05:00
|
|
|
if (component.KeepOpenIfClicked)
|
2021-08-02 04:57:06 -07:00
|
|
|
{
|
2023-08-10 03:33:03 -05:00
|
|
|
// Disable auto close
|
|
|
|
|
component.AutoClose = false;
|
2021-08-02 04:57:06 -07:00
|
|
|
}
|
2023-08-10 03:33:03 -05:00
|
|
|
}
|
2021-08-02 04:57:06 -07:00
|
|
|
}
|