This commit is contained in:
Leon Friedrich
2022-01-30 13:49:56 +13:00
committed by GitHub
parent 6fb492aae7
commit c465715273
37 changed files with 1400 additions and 1429 deletions

View File

@@ -1,16 +1,19 @@
using Content.Server.Doors.Components;
using Content.Server.Doors.Components;
using Content.Server.Power.Components;
using Content.Server.WireHacking;
using Content.Shared.Doors;
using Content.Shared.Doors.Components;
using Content.Shared.Doors.Systems;
using Content.Shared.Interaction;
using Content.Shared.Popups;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using System;
namespace Content.Server.Doors.Systems
{
public class AirlockSystem : EntitySystem
public sealed class AirlockSystem : SharedAirlockSystem
{
public override void Initialize()
{
@@ -19,12 +22,8 @@ namespace Content.Server.Doors.Systems
SubscribeLocalEvent<AirlockComponent, PowerChangedEvent>(OnPowerChanged);
SubscribeLocalEvent<AirlockComponent, DoorStateChangedEvent>(OnStateChanged);
SubscribeLocalEvent<AirlockComponent, BeforeDoorOpenedEvent>(OnBeforeDoorOpened);
SubscribeLocalEvent<AirlockComponent, BeforeDoorClosedEvent>(OnBeforeDoorClosed);
SubscribeLocalEvent<AirlockComponent, BeforeDoorDeniedEvent>(OnBeforeDoorDenied);
SubscribeLocalEvent<AirlockComponent, DoorSafetyEnabledEvent>(OnDoorSafetyCheck);
SubscribeLocalEvent<AirlockComponent, BeforeDoorAutoCloseEvent>(OnDoorAutoCloseCheck);
SubscribeLocalEvent<AirlockComponent, DoorGetCloseTimeModifierEvent>(OnDoorCloseTimeModifier);
SubscribeLocalEvent<AirlockComponent, DoorClickShouldActivateEvent>(OnDoorClickShouldActivate);
SubscribeLocalEvent<AirlockComponent, ActivateInWorldEvent>(OnActivate, before: new [] {typeof(DoorSystem)});
SubscribeLocalEvent<AirlockComponent, BeforeDoorPryEvent>(OnDoorPry);
}
@@ -35,21 +34,59 @@ namespace Content.Server.Doors.Systems
appearanceComponent.SetData(DoorVisuals.Powered, args.Powered);
}
if (!args.Powered)
{
// stop any scheduled auto-closing
DoorSystem.SetNextStateChange(uid, null);
}
else
{
// door received power. Lets "wake" the door up, in case it is currently open and needs to auto-close.
DoorSystem.SetNextStateChange(uid, TimeSpan.FromSeconds(1));
}
// BoltLights also got out
component.UpdateBoltLightStatus();
}
private void OnStateChanged(EntityUid uid, AirlockComponent component, DoorStateChangedEvent args)
{
// TODO move to shared? having this be server-side, but having client-side door opening/closing & prediction
// means that sometimes the panels & bolt lights may be visible despite a door being completely open.
// Only show the maintenance panel if the airlock is closed
if (TryComp<WiresComponent>(uid, out var wiresComponent))
{
wiresComponent.IsPanelVisible =
component.OpenPanelVisible
|| args.State != SharedDoorComponent.DoorState.Open;
|| args.State != DoorState.Open;
}
// If the door is closed, we should look if the bolt was locked while closing
component.UpdateBoltLightStatus();
UpdateAutoClose(uid, component);
}
/// <summary>
/// Updates the auto close timer.
/// </summary>
public void UpdateAutoClose(EntityUid uid, AirlockComponent? airlock = null, DoorComponent? door = null)
{
if (!Resolve(uid, ref airlock, ref door))
return;
if (door.State != DoorState.Open)
return;
if (!airlock.CanChangeState())
return;
var autoev = new BeforeDoorAutoCloseEvent();
RaiseLocalEvent(uid, autoev, false);
if (autoev.Cancelled)
return;
DoorSystem.SetNextStateChange(uid, airlock.AutoCloseDelay * airlock.AutoCloseDelayModifier);
}
private void OnBeforeDoorOpened(EntityUid uid, AirlockComponent component, BeforeDoorOpenedEvent args)
@@ -58,10 +95,23 @@ namespace Content.Server.Doors.Systems
args.Cancel();
}
private void OnBeforeDoorClosed(EntityUid uid, AirlockComponent component, BeforeDoorClosedEvent args)
protected override void OnBeforeDoorClosed(EntityUid uid, SharedAirlockComponent component, BeforeDoorClosedEvent args)
{
if (!component.CanChangeState())
base.OnBeforeDoorClosed(uid, component, args);
if (args.Cancelled)
return;
// only block based on bolts / power status when initially closing the door, not when its already
// mid-transition. Particularly relevant for when the door was pried-closed with a crowbar, which bypasses
// the initial power-check.
if (TryComp(uid, out DoorComponent? door)
&& !door.Partial
&& !Comp<AirlockComponent>(uid).CanChangeState())
{
args.Cancel();
}
}
private void OnBeforeDoorDenied(EntityUid uid, AirlockComponent component, BeforeDoorDeniedEvent args)
@@ -70,26 +120,10 @@ namespace Content.Server.Doors.Systems
args.Cancel();
}
private void OnDoorSafetyCheck(EntityUid uid, AirlockComponent component, DoorSafetyEnabledEvent args)
{
args.Safety = component.Safety;
}
private void OnDoorAutoCloseCheck(EntityUid uid, AirlockComponent component, BeforeDoorAutoCloseEvent args)
{
if (!component.AutoClose)
args.Cancel();
}
private void OnDoorCloseTimeModifier(EntityUid uid, AirlockComponent component, DoorGetCloseTimeModifierEvent args)
{
args.CloseTimeModifier *= component.AutoCloseDelayModifier;
}
private void OnDoorClickShouldActivate(EntityUid uid, AirlockComponent component, DoorClickShouldActivateEvent args)
private void OnActivate(EntityUid uid, AirlockComponent component, ActivateInWorldEvent args)
{
if (TryComp<WiresComponent>(uid, out var wiresComponent) && wiresComponent.IsPanelOpen &&
EntityManager.TryGetComponent(args.Args.User, out ActorComponent? actor))
EntityManager.TryGetComponent(args.User, out ActorComponent? actor))
{
wiresComponent.OpenInterface(actor.PlayerSession);
args.Handled = true;
@@ -100,12 +134,12 @@ namespace Content.Server.Doors.Systems
{
if (component.IsBolted())
{
component.Owner.PopupMessage(args.Args.User, Loc.GetString("airlock-component-cannot-pry-is-bolted-message"));
component.Owner.PopupMessage(args.User, Loc.GetString("airlock-component-cannot-pry-is-bolted-message"));
args.Cancel();
}
if (component.IsPowered())
{
component.Owner.PopupMessage(args.Args.User, Loc.GetString("airlock-component-cannot-pry-is-powered-message"));
component.Owner.PopupMessage(args.User, Loc.GetString("airlock-component-cannot-pry-is-powered-message"));
args.Cancel();
}
}