Internals are kept on as long as any breathing tool is on (#28595)

This commit is contained in:
Plykiya
2024-06-06 00:01:45 -07:00
committed by GitHub
parent 180f1e8005
commit dec1c281a8
5 changed files with 23 additions and 27 deletions

View File

@@ -10,21 +10,21 @@ public sealed partial class AtmosphereSystem
SubscribeLocalEvent<BreathToolComponent, ComponentShutdown>(OnBreathToolShutdown);
}
private void OnBreathToolShutdown(EntityUid uid, BreathToolComponent component, ComponentShutdown args)
private void OnBreathToolShutdown(Entity<BreathToolComponent> entity, ref ComponentShutdown args)
{
DisconnectInternals(component);
DisconnectInternals(entity);
}
public void DisconnectInternals(BreathToolComponent component)
public void DisconnectInternals(Entity<BreathToolComponent> entity)
{
var old = component.ConnectedInternalsEntity;
component.ConnectedInternalsEntity = null;
var old = entity.Comp.ConnectedInternalsEntity;
entity.Comp.ConnectedInternalsEntity = null;
if (TryComp<InternalsComponent>(old, out var internalsComponent))
{
_internals.DisconnectBreathTool((old.Value, internalsComponent));
_internals.DisconnectBreathTool((old.Value, internalsComponent), entity.Owner);
}
component.IsFunctional = false;
entity.Comp.IsFunctional = false;
}
}

View File

@@ -220,7 +220,7 @@ namespace Content.Server.Atmos.EntitySystems
public bool CanConnectToInternals(GasTankComponent component)
{
var internals = GetInternalsComponent(component, component.User);
return internals != null && internals.BreathToolEntity != null && !component.IsValveOpen;
return internals != null && internals.BreathTools.Count != 0 && !component.IsValveOpen;
}
public void ConnectToInternals(Entity<GasTankComponent> ent)

View File

@@ -13,7 +13,7 @@ namespace Content.Server.Body.Components
public EntityUid? GasTankEntity;
[ViewVariables]
public EntityUid? BreathToolEntity;
public HashSet<EntityUid> BreathTools { get; set; } = new();
/// <summary>
/// Toggle Internals delay when the target is not you.

View File

@@ -44,7 +44,7 @@ public sealed class InternalsSystem : EntitySystem
private void OnStartingGear(EntityUid uid, InternalsComponent component, ref StartingGearEquippedEvent args)
{
if (component.BreathToolEntity == null)
if (component.BreathTools.Count == 0)
return;
if (component.GasTankEntity != null)
@@ -111,7 +111,7 @@ public sealed class InternalsSystem : EntitySystem
}
// If they're not on then check if we have a mask to use
if (internals.BreathToolEntity is null)
if (internals.BreathTools.Count == 0)
{
_popupSystem.PopupEntity(Loc.GetString("internals-no-breath-tool"), uid, user);
return;
@@ -178,28 +178,24 @@ public sealed class InternalsSystem : EntitySystem
_alerts.ShowAlert(ent, ent.Comp.InternalsAlert, GetSeverity(ent));
}
}
public void DisconnectBreathTool(Entity<InternalsComponent> ent)
public void DisconnectBreathTool(Entity<InternalsComponent> ent, EntityUid toolEntity)
{
var old = ent.Comp.BreathToolEntity;
ent.Comp.BreathToolEntity = null;
ent.Comp.BreathTools.Remove(toolEntity);
if (TryComp(old, out BreathToolComponent? breathTool))
{
_atmos.DisconnectInternals(breathTool);
if (TryComp(toolEntity, out BreathToolComponent? breathTool))
_atmos.DisconnectInternals((toolEntity, breathTool));
if (ent.Comp.BreathTools.Count == 0)
DisconnectTank(ent);
}
_alerts.ShowAlert(ent, ent.Comp.InternalsAlert, GetSeverity(ent));
}
public void ConnectBreathTool(Entity<InternalsComponent> ent, EntityUid toolEntity)
{
if (TryComp(ent.Comp.BreathToolEntity, out BreathToolComponent? tool))
{
_atmos.DisconnectInternals(tool);
}
if (!ent.Comp.BreathTools.Add(toolEntity))
return;
ent.Comp.BreathToolEntity = toolEntity;
_alerts.ShowAlert(ent, ent.Comp.InternalsAlert, GetSeverity(ent));
}
@@ -217,7 +213,7 @@ public sealed class InternalsSystem : EntitySystem
public bool TryConnectTank(Entity<InternalsComponent> ent, EntityUid tankEntity)
{
if (ent.Comp.BreathToolEntity is null)
if (ent.Comp.BreathTools.Count == 0)
return false;
if (TryComp(ent.Comp.GasTankEntity, out GasTankComponent? tank))
@@ -236,14 +232,14 @@ public sealed class InternalsSystem : EntitySystem
public bool AreInternalsWorking(InternalsComponent component)
{
return TryComp(component.BreathToolEntity, out BreathToolComponent? breathTool)
return TryComp(component.BreathTools.FirstOrNull(), out BreathToolComponent? breathTool)
&& breathTool.IsFunctional
&& HasComp<GasTankComponent>(component.GasTankEntity);
}
private short GetSeverity(InternalsComponent component)
{
if (component.BreathToolEntity is null || !AreInternalsWorking(component))
if (component.BreathTools.Count == 0 || !AreInternalsWorking(component))
return 2;
// If pressure in the tank is below low pressure threshold, flash warning on internals UI

View File

@@ -59,7 +59,7 @@ public sealed class LungSystem : EntitySystem
{
if (args.IsToggled || args.IsEquip)
{
_atmos.DisconnectInternals(ent.Comp);
_atmos.DisconnectInternals(ent);
}
else
{