Split Door Bolt functionality out of AirlockDoor (#16354)

This commit is contained in:
Tom Leys
2023-06-01 02:23:35 +12:00
committed by GitHub
parent f419c20c49
commit a196756124
26 changed files with 283 additions and 161 deletions

View File

@@ -18,6 +18,7 @@ namespace Content.Server.Doors.Systems
[Dependency] private readonly WiresSystem _wiresSystem = default!;
[Dependency] private readonly PowerReceiverSystem _power = default!;
[Dependency] private readonly SignalLinkerSystem _signalSystem = default!;
[Dependency] private readonly DoorBoltSystem _bolts = default!;
public override void Initialize()
{
@@ -70,14 +71,8 @@ namespace Content.Server.Doors.Systems
}
else
{
if (component.BoltWireCut)
SetBoltsWithAudio(uid, component, true);
UpdateAutoClose(uid, door: door);
}
// BoltLights also got out
UpdateBoltLightStatus(uid, component);
}
private void OnStateChanged(EntityUid uid, AirlockComponent component, DoorStateChangedEvent args)
@@ -91,7 +86,6 @@ namespace Content.Server.Doors.Systems
_wiresSystem.ChangePanelVisibility(uid, wiresPanel, component.OpenPanelVisible || args.State != DoorState.Open);
}
// If the door is closed, we should look if the bolt was locked while closing
UpdateBoltLightStatus(uid, component);
UpdateAutoClose(uid, component);
// Make sure the airlock auto closes again next time it is opened
@@ -180,12 +174,6 @@ namespace Content.Server.Doors.Systems
private void OnDoorPry(EntityUid uid, AirlockComponent component, BeforeDoorPryEvent args)
{
if (component.BoltsDown)
{
Popup.PopupEntity(Loc.GetString("airlock-component-cannot-pry-is-bolted-message"), uid, args.User);
args.Cancel();
}
if (this.IsPowered(uid, EntityManager))
{
if (HasComp<ToolForcePoweredComponent>(args.Tool))
@@ -197,52 +185,7 @@ namespace Content.Server.Doors.Systems
public bool CanChangeState(EntityUid uid, AirlockComponent component)
{
return this.IsPowered(uid, EntityManager) && !component.BoltsDown;
}
public void UpdateBoltLightStatus(EntityUid uid, AirlockComponent component)
{
if (!TryComp<AppearanceComponent>(uid, out var appearance))
return;
Appearance.SetData(uid, DoorVisuals.BoltLights, GetBoltLightsVisible(uid, component), appearance);
}
public void SetBoltsWithAudio(EntityUid uid, AirlockComponent component, bool newBolts)
{
if (newBolts == component.BoltsDown)
return;
component.BoltsDown = newBolts;
Audio.PlayPvs(newBolts ? component.BoltDownSound : component.BoltUpSound, uid);
UpdateBoltLightStatus(uid, component);
}
public bool GetBoltLightsVisible(EntityUid uid, AirlockComponent component)
{
return component.BoltLightsEnabled &&
component.BoltsDown &&
this.IsPowered(uid, EntityManager) &&
TryComp<DoorComponent>(uid, out var doorComponent) &&
doorComponent.State == DoorState.Closed;
}
public void SetBoltLightsEnabled(EntityUid uid, AirlockComponent component, bool value)
{
if (component.BoltLightsEnabled == value)
return;
component.BoltLightsEnabled = value;
UpdateBoltLightStatus(uid, component);
}
public void SetBoltsDown(EntityUid uid, AirlockComponent component, bool value)
{
if (component.BoltsDown == value)
return;
component.BoltsDown = value;
UpdateBoltLightStatus(uid, component);
return this.IsPowered(uid, EntityManager) && !_bolts.IsBolted(uid);
}
}
}

View File

@@ -0,0 +1,90 @@
using Content.Server.Power.Components;
using Content.Server.Power.EntitySystems;
using Content.Shared.Doors;
using Content.Shared.Doors.Components;
using Content.Shared.Doors.Systems;
namespace Content.Server.Doors.Systems;
public sealed class DoorBoltSystem : SharedDoorBoltSystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<DoorBoltComponent, PowerChangedEvent>(OnPowerChanged);
SubscribeLocalEvent<DoorBoltComponent, DoorStateChangedEvent>(OnStateChanged);
}
private void OnPowerChanged(EntityUid uid, DoorBoltComponent component, ref PowerChangedEvent args)
{
if (args.Powered)
{
if (component.BoltWireCut)
SetBoltsWithAudio(uid, component, true);
}
UpdateBoltLightStatus(uid, component);
}
public void UpdateBoltLightStatus(EntityUid uid, DoorBoltComponent component)
{
if (!TryComp<AppearanceComponent>(uid, out var appearance))
return;
Appearance.SetData(uid, DoorVisuals.BoltLights, GetBoltLightsVisible(uid, component), appearance);
}
public bool GetBoltLightsVisible(EntityUid uid, DoorBoltComponent component)
{
return component.BoltLightsEnabled &&
component.BoltsDown &&
this.IsPowered(uid, EntityManager);
}
public void SetBoltLightsEnabled(EntityUid uid, DoorBoltComponent component, bool value)
{
if (component.BoltLightsEnabled == value)
return;
component.BoltLightsEnabled = value;
UpdateBoltLightStatus(uid, component);
}
public void SetBoltsDown(EntityUid uid, DoorBoltComponent component, bool value)
{
if (component.BoltsDown == value)
return;
component.BoltsDown = value;
UpdateBoltLightStatus(uid, component);
}
private void OnStateChanged(EntityUid uid, DoorBoltComponent component, DoorStateChangedEvent args)
{
// If the door is closed, we should look if the bolt was locked while closing
UpdateBoltLightStatus(uid, component);
}
public void SetBoltsWithAudio(EntityUid uid, DoorBoltComponent component, bool newBolts)
{
if (newBolts == component.BoltsDown)
return;
component.BoltsDown = newBolts;
Audio.PlayPvs(newBolts ? component.BoltDownSound : component.BoltUpSound, uid);
UpdateBoltLightStatus(uid, component);
}
public bool IsBolted(EntityUid uid, DoorBoltComponent? component = null)
{
if (!Resolve(uid, ref component))
{
return false;
}
return component.BoltsDown;
}
}

View File

@@ -27,7 +27,7 @@ namespace Content.Server.Doors.Systems;
public sealed class DoorSystem : SharedDoorSystem
{
[Dependency] private readonly AirlockSystem _airlock = default!;
[Dependency] private readonly DoorBoltSystem _bolts = default!;
[Dependency] private readonly AirtightSystem _airtightSystem = default!;
[Dependency] private readonly SharedToolSystem _toolSystem = default!;
@@ -231,7 +231,7 @@ public sealed class DoorSystem : SharedDoorSystem
{
if(TryComp<AirlockComponent>(uid, out var airlockComponent))
{
if (airlockComponent.BoltsDown || !this.IsPowered(uid, EntityManager))
if (_bolts.IsBolted(uid) || !this.IsPowered(uid, EntityManager))
return;
if (door.State == DoorState.Closed)
@@ -255,8 +255,8 @@ public sealed class DoorSystem : SharedDoorSystem
if (door.OpenSound != null)
PlaySound(uid, door.OpenSound, AudioParams.Default.WithVolume(-5), user, predicted);
if(lastState == DoorState.Emagging && TryComp<AirlockComponent>(uid, out var airlockComponent))
_airlock.SetBoltsWithAudio(uid, airlockComponent, !airlockComponent.BoltsDown);
if(lastState == DoorState.Emagging && TryComp<DoorBoltComponent>(uid, out var doorBoltComponent))
_bolts.SetBoltsWithAudio(uid, doorBoltComponent, !doorBoltComponent.BoltsDown);
}
protected override void CheckDoorBump(DoorComponent component, PhysicsComponent body)