Added bolts to airlocks (#1138)
Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
This commit is contained in:
@@ -2,15 +2,16 @@
|
||||
using System.Threading;
|
||||
using Content.Server.GameObjects.Components.Interactable;
|
||||
using Content.Server.GameObjects.Components.Power.ApcNetComponents;
|
||||
using Content.Server.GameObjects.Components.Power.PowerNetComponents;
|
||||
using Content.Server.GameObjects.Components.VendingMachines;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Server.Interfaces;
|
||||
using Content.Shared.GameObjects.Components.Doors;
|
||||
using Content.Shared.GameObjects.Components.Interactable;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.GameObjects.EntitySystems;
|
||||
using Robust.Server.Interfaces.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Maths;
|
||||
@@ -53,6 +54,32 @@ namespace Content.Server.GameObjects.Components.Doors
|
||||
}
|
||||
}
|
||||
|
||||
private bool _boltsDown;
|
||||
|
||||
private bool BoltsDown
|
||||
{
|
||||
get => _boltsDown;
|
||||
set
|
||||
{
|
||||
_boltsDown = value;
|
||||
UpdateWiresStatus();
|
||||
UpdateBoltLightStatus();
|
||||
}
|
||||
}
|
||||
|
||||
private bool _boltLightsWirePulsed = true;
|
||||
|
||||
private bool BoltLightsVisible
|
||||
{
|
||||
get => _boltLightsWirePulsed && BoltsDown && IsPowered() && State == DoorState.Closed;
|
||||
set
|
||||
{
|
||||
_boltLightsWirePulsed = value;
|
||||
UpdateWiresStatus();
|
||||
UpdateBoltLightStatus();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateWiresStatus()
|
||||
{
|
||||
var powerLight = new StatusLightData(Color.Yellow, StatusLightState.On, "POWR");
|
||||
@@ -66,9 +93,14 @@ namespace Content.Server.GameObjects.Components.Doors
|
||||
powerLight = new StatusLightData(Color.Red, StatusLightState.On, "POWR");
|
||||
}
|
||||
|
||||
var boltStatus =
|
||||
new StatusLightData(Color.Red, BoltsDown ? StatusLightState.On : StatusLightState.Off, "BOLT");
|
||||
var boltLightsStatus = new StatusLightData(Color.Lime,
|
||||
_boltLightsWirePulsed ? StatusLightState.On : StatusLightState.Off, "BLTL");
|
||||
|
||||
_wires.SetStatus(AirlockWireStatus.PowerIndicator, powerLight);
|
||||
_wires.SetStatus(1, new StatusLightData(Color.Red, StatusLightState.Off, "BOLT"));
|
||||
_wires.SetStatus(2, new StatusLightData(Color.Lime, StatusLightState.On, "BLTL"));
|
||||
_wires.SetStatus(AirlockWireStatus.BoltIndicator, boltStatus);
|
||||
_wires.SetStatus(AirlockWireStatus.BoltLightIndicator, boltLightsStatus);
|
||||
_wires.SetStatus(3, new StatusLightData(Color.Purple, StatusLightState.BlinkingSlow, "AICT"));
|
||||
_wires.SetStatus(4, new StatusLightData(Color.Orange, StatusLightState.Off, "TIME"));
|
||||
_wires.SetStatus(5, new StatusLightData(Color.Red, StatusLightState.Off, "SAFE"));
|
||||
@@ -84,8 +116,16 @@ namespace Content.Server.GameObjects.Components.Doors
|
||||
private void UpdatePowerCutStatus()
|
||||
{
|
||||
_powerReceiver.PowerDisabled = PowerWiresPulsed ||
|
||||
_wires.IsWireCut(Wires.MainPower) ||
|
||||
_wires.IsWireCut(Wires.BackupPower);
|
||||
_wires.IsWireCut(Wires.MainPower) ||
|
||||
_wires.IsWireCut(Wires.BackupPower);
|
||||
}
|
||||
|
||||
private void UpdateBoltLightStatus()
|
||||
{
|
||||
if (Owner.TryGetComponent(out AppearanceComponent appearance))
|
||||
{
|
||||
appearance.SetData(DoorVisuals.BoltLights, BoltLightsVisible);
|
||||
}
|
||||
}
|
||||
|
||||
protected override DoorState State
|
||||
@@ -95,6 +135,8 @@ namespace Content.Server.GameObjects.Components.Doors
|
||||
base.State = value;
|
||||
// Only show the maintenance panel if the airlock is closed
|
||||
_wires.IsPanelVisible = value != DoorState.Open;
|
||||
// If the door is closed, we should look if the bolt was locked while closing
|
||||
UpdateBoltLightStatus();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,6 +165,9 @@ namespace Content.Server.GameObjects.Components.Doors
|
||||
{
|
||||
appearance.SetData(DoorVisuals.Powered, e.Powered);
|
||||
}
|
||||
|
||||
// BoltLights also got out
|
||||
UpdateBoltLightStatus();
|
||||
}
|
||||
|
||||
protected override void ActivateImpl(ActivateEventArgs args)
|
||||
@@ -151,17 +196,31 @@ namespace Content.Server.GameObjects.Components.Doors
|
||||
|
||||
/// <see cref="MainPower"/>
|
||||
BackupPower,
|
||||
|
||||
/// <summary>
|
||||
/// Pulsing causes for bolts to toggle (but only raise if power is on)
|
||||
/// Cutting causes Bolts to drop
|
||||
/// Mending does nothing
|
||||
/// </summary>
|
||||
Bolts,
|
||||
|
||||
/// <summary>
|
||||
/// Pulsing causes light to toggle
|
||||
/// Cutting causes light to go out
|
||||
/// Mending causes them to go on again
|
||||
/// </summary>
|
||||
BoltLight,
|
||||
}
|
||||
|
||||
public void RegisterWires(WiresComponent.WiresBuilder builder)
|
||||
{
|
||||
builder.CreateWire(Wires.MainPower);
|
||||
builder.CreateWire(Wires.BackupPower);
|
||||
builder.CreateWire(1);
|
||||
builder.CreateWire(2);
|
||||
builder.CreateWire(3);
|
||||
builder.CreateWire(Wires.Bolts);
|
||||
builder.CreateWire(Wires.BoltLight);
|
||||
builder.CreateWire(4);
|
||||
/*builder.CreateWire(5);
|
||||
builder.CreateWire(5);
|
||||
/*
|
||||
builder.CreateWire(6);
|
||||
builder.CreateWire(7);
|
||||
builder.CreateWire(8);
|
||||
@@ -186,6 +245,24 @@ namespace Content.Server.GameObjects.Components.Doors
|
||||
() => PowerWiresPulsed = false,
|
||||
_powerWiresPulsedTimerCancel.Token);
|
||||
break;
|
||||
case Wires.Bolts:
|
||||
if (!BoltsDown)
|
||||
{
|
||||
SetBoltsWithAudio(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (IsPowered()) // only raise again if powered
|
||||
{
|
||||
SetBoltsWithAudio(false);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case Wires.BoltLight:
|
||||
// we need to change the property here to set the appearance again
|
||||
BoltLightsVisible = !_boltLightsWirePulsed;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,6 +276,22 @@ namespace Content.Server.GameObjects.Components.Doors
|
||||
_powerWiresPulsedTimerCancel?.Cancel();
|
||||
PowerWiresPulsed = false;
|
||||
break;
|
||||
case Wires.BoltLight:
|
||||
BoltLightsVisible = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (args.Action == Cut)
|
||||
{
|
||||
switch (args.Identifier)
|
||||
{
|
||||
case Wires.Bolts:
|
||||
SetBoltsWithAudio(true);
|
||||
break;
|
||||
case Wires.BoltLight:
|
||||
BoltLightsVisible = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,17 +301,17 @@ namespace Content.Server.GameObjects.Components.Doors
|
||||
|
||||
public override bool CanOpen()
|
||||
{
|
||||
return IsPowered();
|
||||
return IsPowered() && !IsBolted();
|
||||
}
|
||||
|
||||
public override bool CanClose()
|
||||
{
|
||||
return IsPowered();
|
||||
return IsPowered() && !IsBolted();
|
||||
}
|
||||
|
||||
public override void Deny()
|
||||
{
|
||||
if (!IsPowered())
|
||||
if (!IsPowered() || IsBolted())
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -226,6 +319,11 @@ namespace Content.Server.GameObjects.Components.Doors
|
||||
base.Deny();
|
||||
}
|
||||
|
||||
private bool IsBolted()
|
||||
{
|
||||
return _boltsDown;
|
||||
}
|
||||
|
||||
private bool IsPowered()
|
||||
{
|
||||
return _powerReceiver.Powered;
|
||||
@@ -251,10 +349,18 @@ namespace Content.Server.GameObjects.Components.Doors
|
||||
|
||||
if (!tool.UseTool(eventArgs.User, Owner, ToolQuality.Prying)) return false;
|
||||
|
||||
if (IsBolted())
|
||||
{
|
||||
var notify = IoCManager.Resolve<IServerNotifyManager>();
|
||||
notify.PopupMessage(Owner, eventArgs.User,
|
||||
Loc.GetString("The airlock's bolts prevent it from being forced!"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (IsPowered())
|
||||
{
|
||||
var notify = IoCManager.Resolve<IServerNotifyManager>();
|
||||
notify.PopupMessage(Owner, eventArgs.User, "The powered motors block your efforts!");
|
||||
notify.PopupMessage(Owner, eventArgs.User, Loc.GetString("The powered motors block your efforts!"));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -265,5 +371,18 @@ namespace Content.Server.GameObjects.Components.Doors
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void SetBoltsWithAudio(bool newBolts)
|
||||
{
|
||||
if (newBolts == BoltsDown)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
BoltsDown = newBolts;
|
||||
|
||||
EntitySystem.Get<AudioSystem>()
|
||||
.PlayFromEntity(newBolts ? "/Audio/machines/boltsdown.ogg" : "/Audio/machines/boltsup.ogg", Owner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user