Files
OldThink/Content.Shared/Doors/Systems/SharedAirlockSystem.cs

67 lines
2.2 KiB
C#
Raw Normal View History

2022-01-30 13:49:56 +13:00
using Content.Shared.Doors.Components;
2023-01-18 05:44:32 +11:00
using Content.Shared.Popups;
2022-01-30 13:49:56 +13:00
using Robust.Shared.GameStates;
namespace Content.Shared.Doors.Systems;
public abstract class SharedAirlockSystem : EntitySystem
{
2022-10-04 14:24:19 +11:00
[Dependency] protected readonly SharedAppearanceSystem Appearance = default!;
2022-01-30 13:49:56 +13:00
[Dependency] protected readonly SharedDoorSystem DoorSystem = default!;
2023-01-18 05:44:32 +11:00
[Dependency] protected readonly SharedPopupSystem Popup = default!;
2022-01-30 13:49:56 +13:00
public override void Initialize()
{
base.Initialize();
2023-01-18 05:44:32 +11:00
SubscribeLocalEvent<AirlockComponent, ComponentGetState>(OnGetState);
SubscribeLocalEvent<AirlockComponent, ComponentHandleState>(OnHandleState);
SubscribeLocalEvent<AirlockComponent, BeforeDoorClosedEvent>(OnBeforeDoorClosed);
2022-01-30 13:49:56 +13:00
}
2023-01-18 05:44:32 +11:00
private void OnGetState(EntityUid uid, AirlockComponent airlock, ref ComponentGetState args)
2022-01-30 13:49:56 +13:00
{
// Need to network airlock safety state to avoid mis-predicts when a door auto-closes as the client walks through the door.
args.State = new AirlockComponentState(airlock.Safety);
}
2023-01-18 05:44:32 +11:00
private void OnHandleState(EntityUid uid, AirlockComponent airlock, ref ComponentHandleState args)
2022-01-30 13:49:56 +13:00
{
if (args.Current is not AirlockComponentState state)
return;
airlock.Safety = state.Safety;
}
2023-01-18 05:44:32 +11:00
protected virtual void OnBeforeDoorClosed(EntityUid uid, AirlockComponent airlock, BeforeDoorClosedEvent args)
2022-01-30 13:49:56 +13:00
{
if (!airlock.Safety)
args.PerformCollisionCheck = false;
2022-01-30 13:49:56 +13:00
}
2023-01-18 05:44:32 +11:00
public void UpdateEmergencyLightStatus(EntityUid uid, AirlockComponent component)
{
2023-01-18 05:44:32 +11:00
Appearance.SetData(uid, DoorVisuals.EmergencyLights, component.EmergencyAccess);
}
2023-01-18 05:44:32 +11:00
public void ToggleEmergencyAccess(EntityUid uid, AirlockComponent component)
{
component.EmergencyAccess = !component.EmergencyAccess;
2023-01-18 05:44:32 +11:00
UpdateEmergencyLightStatus(uid, component);
}
public void SetAutoCloseDelayModifier(AirlockComponent component, float value)
{
if (component.AutoCloseDelayModifier.Equals(value))
return;
component.AutoCloseDelayModifier = value;
}
public void SetSafety(AirlockComponent component, bool value)
{
component.Safety = value;
}
2022-01-30 13:49:56 +13:00
}