2021-08-02 04:57:06 -07:00
|
|
|
using Content.Server.Atmos.Components;
|
2021-06-19 13:25:05 +02:00
|
|
|
using Content.Server.Atmos.EntitySystems;
|
2022-01-30 13:49:56 +13:00
|
|
|
using Content.Server.Doors.Systems;
|
|
|
|
|
using Content.Shared.Doors.Components;
|
2021-06-19 13:25:05 +02:00
|
|
|
using Robust.Shared.GameObjects;
|
2021-12-03 14:17:01 +01:00
|
|
|
using Robust.Shared.IoC;
|
2021-08-02 04:57:06 -07:00
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2020-08-19 12:23:42 +02:00
|
|
|
|
2021-08-02 04:57:06 -07:00
|
|
|
namespace Content.Server.Doors.Components
|
2020-08-19 12:23:42 +02:00
|
|
|
{
|
2021-02-12 07:02:14 -08:00
|
|
|
/// <summary>
|
2021-08-02 04:57:06 -07:00
|
|
|
/// Companion component to ServerDoorComponent that handles firelock-specific behavior -- primarily prying,
|
|
|
|
|
/// and not being openable on open-hand click.
|
2021-02-12 07:02:14 -08:00
|
|
|
/// </summary>
|
2020-08-19 12:23:42 +02:00
|
|
|
[RegisterComponent]
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class FirelockComponent : Component
|
2020-08-19 12:23:42 +02:00
|
|
|
{
|
2021-12-08 17:17:12 +01:00
|
|
|
[Dependency] private readonly IEntityManager _entMan = default!;
|
|
|
|
|
|
2021-08-02 04:57:06 -07:00
|
|
|
/// <summary>
|
|
|
|
|
/// Pry time modifier to be used when the firelock is currently closed due to fire or pressure.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[DataField("lockedPryTimeModifier")]
|
|
|
|
|
public float LockedPryTimeModifier = 1.5f;
|
2020-08-19 12:23:42 +02:00
|
|
|
|
2021-02-12 07:02:14 -08:00
|
|
|
public bool EmergencyPressureStop()
|
2020-08-19 12:23:42 +02:00
|
|
|
{
|
2022-01-30 13:49:56 +13:00
|
|
|
var doorSys = EntitySystem.Get<DoorSystem>();
|
|
|
|
|
if (_entMan.TryGetComponent<DoorComponent>(Owner, out var door) &&
|
|
|
|
|
door.State == DoorState.Open &&
|
|
|
|
|
doorSys.CanClose(Owner, door))
|
2021-02-12 07:02:14 -08:00
|
|
|
{
|
2022-01-30 13:49:56 +13:00
|
|
|
doorSys.StartClosing(Owner, door);
|
|
|
|
|
|
|
|
|
|
// Door system also sets airtight, but only after a delay. We want it to be immediate.
|
2021-12-08 17:17:12 +01:00
|
|
|
if (_entMan.TryGetComponent(Owner, out AirtightComponent? airtight))
|
2021-02-12 07:02:14 -08:00
|
|
|
{
|
2021-07-25 09:04:58 +02:00
|
|
|
EntitySystem.Get<AirtightSystem>().SetAirblocked(airtight, true);
|
2021-02-12 07:02:14 -08:00
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2020-08-19 12:23:42 +02:00
|
|
|
}
|
|
|
|
|
|
2021-02-12 07:02:14 -08:00
|
|
|
public bool IsHoldingPressure(float threshold = 20)
|
2020-08-19 12:23:42 +02:00
|
|
|
{
|
2021-02-12 07:02:14 -08:00
|
|
|
var atmosphereSystem = EntitySystem.Get<AtmosphereSystem>();
|
2020-11-20 16:58:06 +02:00
|
|
|
|
2021-02-12 07:02:14 -08:00
|
|
|
var minMoles = float.MaxValue;
|
|
|
|
|
var maxMoles = 0f;
|
|
|
|
|
|
2021-12-08 17:17:12 +01:00
|
|
|
foreach (var adjacent in atmosphereSystem.GetAdjacentTileMixtures(_entMan.GetComponent<TransformComponent>(Owner).Coordinates))
|
2020-08-21 18:29:43 +02:00
|
|
|
{
|
2021-07-19 12:07:37 +02:00
|
|
|
var moles = adjacent.TotalMoles;
|
2021-02-12 07:02:14 -08:00
|
|
|
if (moles < minMoles)
|
|
|
|
|
minMoles = moles;
|
|
|
|
|
if (moles > maxMoles)
|
|
|
|
|
maxMoles = moles;
|
|
|
|
|
}
|
2020-08-21 18:29:43 +02:00
|
|
|
|
2021-02-12 07:02:14 -08:00
|
|
|
return (maxMoles - minMoles) > threshold;
|
|
|
|
|
}
|
2020-08-19 12:23:42 +02:00
|
|
|
|
2021-02-12 07:02:14 -08:00
|
|
|
public bool IsHoldingFire()
|
|
|
|
|
{
|
|
|
|
|
var atmosphereSystem = EntitySystem.Get<AtmosphereSystem>();
|
2020-11-20 16:58:06 +02:00
|
|
|
|
2021-12-08 17:17:12 +01:00
|
|
|
if (!atmosphereSystem.TryGetGridAndTile(_entMan.GetComponent<TransformComponent>(Owner).Coordinates, out var tuple))
|
2021-02-12 07:02:14 -08:00
|
|
|
return false;
|
2020-08-21 18:29:43 +02:00
|
|
|
|
2021-07-19 12:07:37 +02:00
|
|
|
if (atmosphereSystem.GetTileMixture(tuple.Value.Grid, tuple.Value.Tile) == null)
|
|
|
|
|
return false;
|
2020-08-19 12:23:42 +02:00
|
|
|
|
2021-07-19 12:07:37 +02:00
|
|
|
if (atmosphereSystem.IsHotspotActive(tuple.Value.Grid, tuple.Value.Tile))
|
|
|
|
|
return true;
|
2021-02-12 07:02:14 -08:00
|
|
|
|
2021-12-08 17:17:12 +01:00
|
|
|
foreach (var adjacent in atmosphereSystem.GetAdjacentTiles(_entMan.GetComponent<TransformComponent>(Owner).Coordinates))
|
2021-02-12 07:02:14 -08:00
|
|
|
{
|
2021-07-19 12:07:37 +02:00
|
|
|
if (atmosphereSystem.IsHotspotActive(tuple.Value.Grid, adjacent))
|
2021-02-12 07:02:14 -08:00
|
|
|
return true;
|
|
|
|
|
}
|
2020-11-20 16:58:06 +02:00
|
|
|
|
2020-08-21 18:29:43 +02:00
|
|
|
return false;
|
2020-08-19 12:23:42 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|