Split Door Bolt functionality out of AirlockDoor (#16354)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
90
Content.Server/Doors/Systems/DoorBoltSystem.cs
Normal file
90
Content.Server/Doors/Systems/DoorBoltSystem.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -6,31 +6,31 @@ using Content.Shared.Wires;
|
||||
|
||||
namespace Content.Server.Doors;
|
||||
|
||||
public sealed class DoorBoltLightWireAction : ComponentWireAction<AirlockComponent>
|
||||
public sealed class DoorBoltLightWireAction : ComponentWireAction<DoorBoltComponent>
|
||||
{
|
||||
public override Color Color { get; set; } = Color.Lime;
|
||||
public override string Name { get; set; } = "wire-name-bolt-light";
|
||||
|
||||
public override StatusLightState? GetLightState(Wire wire, AirlockComponent comp)
|
||||
public override StatusLightState? GetLightState(Wire wire, DoorBoltComponent comp)
|
||||
=> comp.BoltLightsEnabled ? StatusLightState.On : StatusLightState.Off;
|
||||
|
||||
public override object StatusKey { get; } = AirlockWireStatus.BoltLightIndicator;
|
||||
|
||||
public override bool Cut(EntityUid user, Wire wire, AirlockComponent door)
|
||||
public override bool Cut(EntityUid user, Wire wire, DoorBoltComponent door)
|
||||
{
|
||||
EntityManager.System<AirlockSystem>().SetBoltLightsEnabled(wire.Owner, door, false);
|
||||
EntityManager.System<DoorBoltSystem>().SetBoltLightsEnabled(wire.Owner, door, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool Mend(EntityUid user, Wire wire, AirlockComponent door)
|
||||
public override bool Mend(EntityUid user, Wire wire, DoorBoltComponent door)
|
||||
{
|
||||
|
||||
EntityManager.System<AirlockSystem>().SetBoltLightsEnabled(wire.Owner, door, true);
|
||||
EntityManager.System<DoorBoltSystem>().SetBoltLightsEnabled(wire.Owner, door, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Pulse(EntityUid user, Wire wire, AirlockComponent door)
|
||||
public override void Pulse(EntityUid user, Wire wire, DoorBoltComponent door)
|
||||
{
|
||||
EntityManager.System<AirlockSystem>().SetBoltLightsEnabled(wire.Owner, door, !door.BoltLightsEnabled);
|
||||
EntityManager.System<DoorBoltSystem>().SetBoltLightsEnabled(wire.Owner, door, !door.BoltLightsEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,36 +7,36 @@ using Content.Shared.Wires;
|
||||
|
||||
namespace Content.Server.Doors;
|
||||
|
||||
public sealed class DoorBoltWireAction : ComponentWireAction<AirlockComponent>
|
||||
public sealed class DoorBoltWireAction : ComponentWireAction<DoorBoltComponent>
|
||||
{
|
||||
public override Color Color { get; set; } = Color.Red;
|
||||
public override string Name { get; set; } = "wire-name-door-bolt";
|
||||
|
||||
public override StatusLightState? GetLightState(Wire wire, AirlockComponent comp)
|
||||
|
||||
public override StatusLightState? GetLightState(Wire wire, DoorBoltComponent comp)
|
||||
=> comp.BoltsDown ? StatusLightState.On : StatusLightState.Off;
|
||||
|
||||
public override object StatusKey { get; } = AirlockWireStatus.BoltIndicator;
|
||||
|
||||
public override bool Cut(EntityUid user, Wire wire, AirlockComponent airlock)
|
||||
public override bool Cut(EntityUid user, Wire wire, DoorBoltComponent airlock)
|
||||
{
|
||||
EntityManager.System<SharedAirlockSystem>().SetBoltWireCut(airlock, true);
|
||||
EntityManager.System<DoorBoltSystem>().SetBoltWireCut(airlock, true);
|
||||
if (!airlock.BoltsDown && IsPowered(wire.Owner))
|
||||
EntityManager.System<AirlockSystem>().SetBoltsWithAudio(wire.Owner, airlock, true);
|
||||
EntityManager.System<DoorBoltSystem>().SetBoltsWithAudio(wire.Owner, airlock, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool Mend(EntityUid user, Wire wire, AirlockComponent door)
|
||||
public override bool Mend(EntityUid user, Wire wire, DoorBoltComponent door)
|
||||
{
|
||||
EntityManager.System<SharedAirlockSystem>().SetBoltWireCut(door, true);
|
||||
EntityManager.System<DoorBoltSystem>().SetBoltWireCut(door, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Pulse(EntityUid user, Wire wire, AirlockComponent door)
|
||||
public override void Pulse(EntityUid user, Wire wire, DoorBoltComponent door)
|
||||
{
|
||||
if (IsPowered(wire.Owner))
|
||||
EntityManager.System<AirlockSystem>().SetBoltsWithAudio(wire.Owner, door, !door.BoltsDown);
|
||||
EntityManager.System<DoorBoltSystem>().SetBoltsWithAudio(wire.Owner, door, !door.BoltsDown);
|
||||
else if (!door.BoltsDown)
|
||||
EntityManager.System<AirlockSystem>().SetBoltsWithAudio(wire.Owner, door, true);
|
||||
EntityManager.System<DoorBoltSystem>().SetBoltsWithAudio(wire.Owner, door, true);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user