2019-09-06 10:05:02 +02:00
using System.Threading ;
2021-06-09 22:19:39 +02:00
using Content.Server.Power.Components ;
2022-05-05 19:35:06 -07:00
// using Content.Server.WireHacking;
2022-01-30 13:49:56 +13:00
using Content.Shared.Doors.Components ;
2021-07-10 17:35:33 +02:00
using Content.Shared.Sound ;
2021-03-21 09:12:03 -07:00
using Robust.Shared.Audio ;
using Robust.Shared.Player ;
2022-05-05 19:35:06 -07:00
// using static Content.Shared.Wires.SharedWiresComponent;
// using static Content.Shared.Wires.SharedWiresComponent.WiresAction;
2019-09-06 10:05:02 +02:00
2021-06-09 22:19:39 +02:00
namespace Content.Server.Doors.Components
2019-09-06 10:05:02 +02:00
{
2021-02-12 07:02:14 -08:00
/// <summary>
2022-01-30 13:49:56 +13:00
/// Companion component to DoorComponent that handles airlock-specific behavior -- wires, requiring power to operate, bolts, and allowing automatic closing.
2021-02-12 07:02:14 -08:00
/// </summary>
2019-09-06 10:05:02 +02:00
[RegisterComponent]
2022-01-30 13:49:56 +13:00
[ComponentReference(typeof(SharedAirlockComponent))]
2022-05-05 19:35:06 -07:00
public sealed class AirlockComponent : SharedAirlockComponent
2019-09-06 10:05:02 +02:00
{
2022-01-15 03:26:37 +01:00
[Dependency] private readonly IEntityManager _entityManager = default ! ;
2021-02-12 07:02:14 -08:00
2021-08-02 04:57:06 -07:00
/// <summary>
/// Sound to play when the bolts on the airlock go up.
/// </summary>
[DataField("boltUpSound")]
public SoundSpecifier BoltUpSound = new SoundPathSpecifier ( "/Audio/Machines/boltsup.ogg" ) ;
/// <summary>
/// Sound to play when the bolts on the airlock go down.
/// </summary>
[DataField("boltDownSound")]
public SoundSpecifier BoltDownSound = new SoundPathSpecifier ( "/Audio/Machines/boltsdown.ogg" ) ;
2021-02-12 07:02:14 -08:00
2019-09-06 10:05:02 +02:00
/// <summary>
/// Duration for which power will be disabled after pulsing either power wire.
/// </summary>
2021-08-02 04:57:06 -07:00
[DataField("powerWiresTimeout")]
public float PowerWiresTimeout = 5.0f ;
2019-09-06 10:05:02 +02:00
2021-08-05 19:43:58 -07:00
/// <summary>
/// Whether the maintenance panel should be visible even if the airlock is opened.
/// </summary>
[DataField("openPanelVisible")]
public bool OpenPanelVisible = false ;
2019-09-06 10:05:02 +02:00
2020-11-27 11:00:49 +01:00
private CancellationTokenSource _powerWiresPulsedTimerCancel = new ( ) ;
2019-09-06 10:05:02 +02:00
private bool _powerWiresPulsed ;
2020-05-27 15:09:22 +02:00
2019-09-06 10:05:02 +02:00
/// <summary>
/// True if either power wire was pulsed in the last <see cref="PowerWiresTimeout"/>.
/// </summary>
2020-09-08 13:30:22 +02:00
[ViewVariables(VVAccess.ReadWrite)]
2019-09-06 10:05:02 +02:00
private bool PowerWiresPulsed
{
get = > _powerWiresPulsed ;
set
{
_powerWiresPulsed = value ;
2022-05-05 19:35:06 -07:00
// UpdateWiresStatus();
// UpdatePowerCutStatus();
2019-09-06 10:05:02 +02:00
}
}
2020-07-02 15:31:06 +02:00
private bool _boltsDown ;
2020-09-08 13:30:22 +02:00
[ViewVariables(VVAccess.ReadWrite)]
2020-10-08 11:59:20 -04:00
public bool BoltsDown
2020-07-02 15:31:06 +02:00
{
get = > _boltsDown ;
set
{
_boltsDown = value ;
UpdateBoltLightStatus ( ) ;
}
}
2022-05-05 19:35:06 -07:00
private bool _boltLightsEnabled = true ;
public bool BoltLightsEnabled
{
get = > _boltLightsEnabled ;
set
{
_boltLightsEnabled = value ;
UpdateBoltLightStatus ( ) ;
}
}
2020-07-02 15:31:06 +02:00
2020-09-08 13:30:22 +02:00
[ViewVariables(VVAccess.ReadWrite)]
2022-05-05 19:35:06 -07:00
public bool BoltLightsVisible
2020-07-02 15:31:06 +02:00
{
2022-05-05 19:35:06 -07:00
get = > _boltLightsEnabled & & BoltsDown & & IsPowered ( )
2022-01-30 13:49:56 +13:00
& & _entityManager . TryGetComponent < DoorComponent > ( Owner , out var doorComponent ) & & doorComponent . State = = DoorState . Closed ;
2020-07-02 15:31:06 +02:00
set
{
2022-05-05 19:35:06 -07:00
_boltLightsEnabled = value ;
2020-07-02 15:31:06 +02:00
UpdateBoltLightStatus ( ) ;
}
}
2022-01-30 13:49:56 +13:00
/// <summary>
/// Delay until an open door automatically closes.
/// </summary>
[DataField("autoCloseDelay")]
public TimeSpan AutoCloseDelay = TimeSpan . FromSeconds ( 5f ) ;
2021-02-12 07:02:14 -08:00
2022-01-30 13:49:56 +13:00
/// <summary>
/// Multiplicative modifier for the auto-close delay. Can be modified by hacking the airlock wires. Setting to
/// zero will disable auto-closing.
/// </summary>
2021-02-12 07:02:14 -08:00
[ViewVariables(VVAccess.ReadWrite)]
2021-08-02 04:57:06 -07:00
public float AutoCloseDelayModifier = 1.0f ;
2021-02-12 07:02:14 -08:00
2021-06-19 19:41:26 -07:00
protected override void Initialize ( )
2020-07-17 10:51:43 +02:00
{
2021-02-12 07:02:14 -08:00
base . Initialize ( ) ;
2022-01-15 03:26:37 +01:00
if ( _entityManager . TryGetComponent < ApcPowerReceiverComponent > ( Owner , out var receiverComponent ) & &
_entityManager . TryGetComponent < AppearanceComponent > ( Owner , out var appearanceComponent ) )
2021-02-12 07:02:14 -08:00
{
2022-01-15 03:26:37 +01:00
appearanceComponent . SetData ( DoorVisuals . Powered , receiverComponent . Powered ) ;
2021-02-12 07:02:14 -08:00
}
}
2021-08-02 04:57:06 -07:00
public bool CanChangeState ( )
2021-02-12 07:02:14 -08:00
{
return IsPowered ( ) & & ! IsBolted ( ) ;
}
2021-08-02 04:57:06 -07:00
public bool IsBolted ( )
2021-02-12 07:02:14 -08:00
{
return _boltsDown ;
}
2021-08-02 04:57:06 -07:00
public bool IsPowered ( )
2021-02-12 07:02:14 -08:00
{
2022-01-15 20:06:48 +13:00
return ! _entityManager . TryGetComponent < ApcPowerReceiverComponent > ( Owner , out var receiverComponent ) | | receiverComponent . Powered ;
2021-02-12 07:02:14 -08:00
}
2021-08-02 04:57:06 -07:00
public void UpdateBoltLightStatus ( )
2021-02-12 07:02:14 -08:00
{
2022-01-15 03:26:37 +01:00
if ( _entityManager . TryGetComponent < AppearanceComponent > ( Owner , out var appearanceComponent ) )
2021-02-12 07:02:14 -08:00
{
2022-01-15 03:26:37 +01:00
appearanceComponent . SetData ( DoorVisuals . BoltLights , BoltLightsVisible ) ;
2021-02-12 07:02:14 -08:00
}
2020-07-17 10:51:43 +02:00
}
2020-07-02 15:31:06 +02:00
public void SetBoltsWithAudio ( bool newBolts )
{
if ( newBolts = = BoltsDown )
{
return ;
}
BoltsDown = newBolts ;
2022-06-26 15:20:45 +10:00
SoundSystem . Play ( newBolts ? BoltDownSound . GetSound ( ) : BoltUpSound . GetSound ( ) , Filter . Pvs ( Owner ) , Owner ) ;
2020-07-02 15:31:06 +02:00
}
2019-09-06 10:05:02 +02:00
}
}