Gas tank internals alerts (#9567)

This commit is contained in:
metalgearsloth
2022-07-25 14:42:25 +10:00
committed by GitHub
parent dad26db137
commit 40a7584c2f
25 changed files with 570 additions and 354 deletions

View File

@@ -1,68 +1,12 @@
using Content.Server.Atmos.Components;
namespace Content.Server.Body.Components
namespace Content.Server.Body.Components
{
/// <summary>
/// Handles hooking up a mask (breathing tool) / gas tank together and allowing the Owner to breathe through it.
/// </summary>
[RegisterComponent]
public sealed class InternalsComponent : Component
{
[Dependency] private readonly IEntityManager _entMan = default!;
[ViewVariables] public EntityUid? GasTankEntity { get; set; }
[ViewVariables] public EntityUid? BreathToolEntity { get; set; }
public void DisconnectBreathTool()
{
var old = BreathToolEntity;
BreathToolEntity = null;
if (_entMan.TryGetComponent(old, out BreathToolComponent? breathTool) )
{
breathTool.DisconnectInternals();
DisconnectTank();
}
}
public void ConnectBreathTool(EntityUid toolEntity)
{
if (_entMan.TryGetComponent(BreathToolEntity, out BreathToolComponent? tool))
{
tool.DisconnectInternals();
}
BreathToolEntity = toolEntity;
}
public void DisconnectTank()
{
if (_entMan.TryGetComponent(GasTankEntity, out GasTankComponent? tank))
{
tank.DisconnectFromInternals(Owner);
}
GasTankEntity = null;
}
public bool TryConnectTank(EntityUid tankEntity)
{
if (BreathToolEntity == null)
return false;
if (_entMan.TryGetComponent(GasTankEntity, out GasTankComponent? tank))
{
tank.DisconnectFromInternals(Owner);
}
GasTankEntity = tankEntity;
return true;
}
public bool AreInternalsWorking()
{
return _entMan.TryGetComponent(BreathToolEntity, out BreathToolComponent? breathTool) &&
breathTool.IsFunctional &&
_entMan.TryGetComponent(GasTankEntity, out GasTankComponent? gasTank) &&
gasTank.Air != null;
}
}
}