2021-06-19 13:25:05 +02:00
|
|
|
using Content.Server.Atmos.EntitySystems;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.Doors;
|
|
|
|
|
using Content.Server.Doors.Components;
|
|
|
|
|
using Content.Shared.Doors;
|
|
|
|
|
using Content.Shared.Interaction;
|
2021-06-13 14:52:40 +02:00
|
|
|
using Content.Shared.Notification.Managers;
|
2021-06-19 13:25:05 +02:00
|
|
|
using Robust.Shared.GameObjects;
|
2021-02-12 07:02:14 -08:00
|
|
|
using Robust.Shared.Localization;
|
2020-08-19 12:23:42 +02:00
|
|
|
|
2021-06-19 13:25:05 +02:00
|
|
|
namespace Content.Server.Atmos.Components
|
2020-08-19 12:23:42 +02:00
|
|
|
{
|
2021-02-12 07:02:14 -08:00
|
|
|
/// <summary>
|
|
|
|
|
/// Companion component to ServerDoorComponent that handles firelock-specific behavior -- primarily prying, and not being openable on open-hand click.
|
|
|
|
|
/// </summary>
|
2020-08-19 12:23:42 +02:00
|
|
|
[RegisterComponent]
|
2021-02-12 07:02:14 -08:00
|
|
|
[ComponentReference(typeof(IDoorCheck))]
|
|
|
|
|
public class FirelockComponent : Component, IDoorCheck
|
2020-08-19 12:23:42 +02:00
|
|
|
{
|
|
|
|
|
public override string Name => "Firelock";
|
|
|
|
|
|
2021-02-12 07:02:14 -08:00
|
|
|
[ComponentDependency]
|
|
|
|
|
private readonly ServerDoorComponent? _doorComponent = null;
|
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
|
|
|
{
|
2021-02-12 07:02:14 -08:00
|
|
|
if (_doorComponent != null && _doorComponent.State == SharedDoorComponent.DoorState.Open && _doorComponent.CanCloseGeneric())
|
|
|
|
|
{
|
|
|
|
|
_doorComponent.Close();
|
|
|
|
|
if (Owner.TryGetComponent(out AirtightComponent? airtight))
|
|
|
|
|
{
|
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
|
|
|
bool IDoorCheck.OpenCheck()
|
2020-08-19 12:23:42 +02:00
|
|
|
{
|
2021-02-12 07:02:14 -08:00
|
|
|
return !IsHoldingFire() && !IsHoldingPressure();
|
|
|
|
|
}
|
2020-08-19 12:23:42 +02:00
|
|
|
|
2021-02-12 07:02:14 -08:00
|
|
|
bool IDoorCheck.DenyCheck() => false;
|
2020-09-07 13:57:04 +02:00
|
|
|
|
2021-02-12 07:02:14 -08:00
|
|
|
float? IDoorCheck.GetPryTime()
|
|
|
|
|
{
|
|
|
|
|
if (IsHoldingFire() || IsHoldingPressure())
|
2020-09-07 13:57:04 +02:00
|
|
|
{
|
2021-02-12 07:02:14 -08:00
|
|
|
return 1.5f;
|
2020-09-07 13:57:04 +02:00
|
|
|
}
|
2021-02-12 07:02:14 -08:00
|
|
|
return null;
|
2020-08-19 12:23:42 +02:00
|
|
|
}
|
|
|
|
|
|
2021-02-12 07:02:14 -08:00
|
|
|
bool IDoorCheck.BlockActivate(ActivateEventArgs eventArgs) => true;
|
2020-08-19 12:23:42 +02:00
|
|
|
|
2021-02-12 07:02:14 -08:00
|
|
|
void IDoorCheck.OnStartPry(InteractUsingEventArgs eventArgs)
|
2020-08-19 12:23:42 +02:00
|
|
|
{
|
2021-02-12 07:02:14 -08:00
|
|
|
if (_doorComponent == null || _doorComponent.State != SharedDoorComponent.DoorState.Closed)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-04-13 13:17:10 +02:00
|
|
|
|
2021-02-12 07:02:14 -08:00
|
|
|
if (IsHoldingPressure())
|
|
|
|
|
{
|
2021-06-21 02:13:54 +02:00
|
|
|
Owner.PopupMessage(eventArgs.User, Loc.GetString("firelock-component-is-holding-pressure-message"));
|
2021-02-12 07:02:14 -08:00
|
|
|
}
|
|
|
|
|
else if (IsHoldingFire())
|
|
|
|
|
{
|
2021-06-21 02:13:54 +02:00
|
|
|
Owner.PopupMessage(eventArgs.User, Loc.GetString("firelock-component-is-holding-fire-message"));
|
2021-02-12 07:02:14 -08:00
|
|
|
}
|
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-07-19 12:07:37 +02:00
|
|
|
foreach (var adjacent in atmosphereSystem.GetAdjacentTileMixtures(Owner.Transform.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-07-19 12:07:37 +02:00
|
|
|
if (!atmosphereSystem.TryGetGridAndTile(Owner.Transform.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-07-19 12:07:37 +02:00
|
|
|
foreach (var adjacent in atmosphereSystem.GetAdjacentTiles(Owner.Transform.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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|