Updates GasTankSystem and InternalsSystem to not use Component.Owner (#29934)
* blah, setup * Updates GasTankSystem and InternalsSystem to not use Component.Owner * squish the diff * Fixa the rest --------- Co-authored-by: plykiya <plykiya@protonmail.com>
This commit is contained in:
@@ -81,7 +81,7 @@ namespace Content.Server.Atmos.EntitySystems
|
|||||||
TankPressure = component.Air?.Pressure ?? 0,
|
TankPressure = component.Air?.Pressure ?? 0,
|
||||||
OutputPressure = initialUpdate ? component.OutputPressure : null,
|
OutputPressure = initialUpdate ? component.OutputPressure : null,
|
||||||
InternalsConnected = component.IsConnected,
|
InternalsConnected = component.IsConnected,
|
||||||
CanConnectInternals = CanConnectToInternals(component)
|
CanConnectInternals = CanConnectToInternals(ent)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,24 +217,24 @@ namespace Content.Server.Atmos.EntitySystems
|
|||||||
return air;
|
return air;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CanConnectToInternals(GasTankComponent component)
|
public bool CanConnectToInternals(Entity<GasTankComponent> ent)
|
||||||
{
|
{
|
||||||
var internals = GetInternalsComponent(component, component.User);
|
TryGetInternalsComp(ent, out _, out var internalsComp, ent.Comp.User);
|
||||||
return internals != null && internals.BreathTools.Count != 0 && !component.IsValveOpen;
|
return internalsComp != null && internalsComp.BreathTools.Count != 0 && !ent.Comp.IsValveOpen;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ConnectToInternals(Entity<GasTankComponent> ent)
|
public void ConnectToInternals(Entity<GasTankComponent> ent)
|
||||||
{
|
{
|
||||||
var (owner, component) = ent;
|
var (owner, component) = ent;
|
||||||
if (component.IsConnected || !CanConnectToInternals(component))
|
if (component.IsConnected || !CanConnectToInternals(ent))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var internals = GetInternalsComponent(component);
|
TryGetInternalsComp(ent, out var internalsUid, out var internalsComp, ent.Comp.User);
|
||||||
if (internals == null)
|
if (internalsUid == null || internalsComp == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_internals.TryConnectTank((internals.Owner, internals), owner))
|
if (_internals.TryConnectTank((internalsUid.Value, internalsComp), owner))
|
||||||
component.User = internals.Owner;
|
component.User = internalsUid.Value;
|
||||||
|
|
||||||
_actions.SetToggled(component.ToggleActionEntity, component.IsConnected);
|
_actions.SetToggled(component.ToggleActionEntity, component.IsConnected);
|
||||||
|
|
||||||
@@ -243,7 +243,7 @@ namespace Content.Server.Atmos.EntitySystems
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
component.ConnectStream = _audioSys.Stop(component.ConnectStream);
|
component.ConnectStream = _audioSys.Stop(component.ConnectStream);
|
||||||
component.ConnectStream = _audioSys.PlayPvs(component.ConnectSound, component.Owner)?.Entity;
|
component.ConnectStream = _audioSys.PlayPvs(component.ConnectSound, owner)?.Entity;
|
||||||
|
|
||||||
UpdateUserInterface(ent);
|
UpdateUserInterface(ent);
|
||||||
}
|
}
|
||||||
@@ -251,29 +251,59 @@ namespace Content.Server.Atmos.EntitySystems
|
|||||||
public void DisconnectFromInternals(Entity<GasTankComponent> ent)
|
public void DisconnectFromInternals(Entity<GasTankComponent> ent)
|
||||||
{
|
{
|
||||||
var (owner, component) = ent;
|
var (owner, component) = ent;
|
||||||
|
|
||||||
if (component.User == null)
|
if (component.User == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var internals = GetInternalsComponent(component);
|
TryGetInternalsComp(ent, out var internalsUid, out var internalsComp, component.User);
|
||||||
component.User = null;
|
component.User = null;
|
||||||
|
|
||||||
_actions.SetToggled(component.ToggleActionEntity, false);
|
_actions.SetToggled(component.ToggleActionEntity, false);
|
||||||
|
|
||||||
_internals.DisconnectTank(internals);
|
if (internalsUid != null && internalsComp != null)
|
||||||
|
_internals.DisconnectTank((internalsUid.Value, internalsComp));
|
||||||
component.DisconnectStream = _audioSys.Stop(component.DisconnectStream);
|
component.DisconnectStream = _audioSys.Stop(component.DisconnectStream);
|
||||||
component.DisconnectStream = _audioSys.PlayPvs(component.DisconnectSound, component.Owner)?.Entity;
|
component.DisconnectStream = _audioSys.PlayPvs(component.DisconnectSound, owner)?.Entity;
|
||||||
|
|
||||||
UpdateUserInterface(ent);
|
UpdateUserInterface(ent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private InternalsComponent? GetInternalsComponent(GasTankComponent component, EntityUid? owner = null)
|
/// <summary>
|
||||||
|
/// Tries to retrieve the internals component of either the gas tank's user,
|
||||||
|
/// or the gas tank's... containing container
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="user">The user of the gas tank</param>
|
||||||
|
/// <returns>True if internals comp isn't null, false if it is null</returns>
|
||||||
|
private bool TryGetInternalsComp(Entity<GasTankComponent> ent, out EntityUid? internalsUid, out InternalsComponent? internalsComp, EntityUid? user = null)
|
||||||
{
|
{
|
||||||
owner ??= component.User;
|
internalsUid = default;
|
||||||
if (Deleted(component.Owner))return null;
|
internalsComp = default;
|
||||||
if (owner != null) return CompOrNull<InternalsComponent>(owner.Value);
|
|
||||||
return _containers.TryGetContainingContainer(component.Owner, out var container)
|
// If the gas tank doesn't exist for whatever reason, don't even bother
|
||||||
? CompOrNull<InternalsComponent>(container.Owner)
|
if (TerminatingOrDeleted(ent.Owner))
|
||||||
: null;
|
return false;
|
||||||
|
|
||||||
|
user ??= ent.Comp.User;
|
||||||
|
// Check if the gas tank's user actually has the component that allows them to use a gas tank and mask
|
||||||
|
if (TryComp<InternalsComponent>(user, out var userInternalsComp) && userInternalsComp != null)
|
||||||
|
{
|
||||||
|
internalsUid = user;
|
||||||
|
internalsComp = userInternalsComp;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Yeah I have no clue what this actually does, I appreciate the lack of comments on the original function
|
||||||
|
if (_containers.TryGetContainingContainer((ent.Owner, Transform(ent.Owner)), out var container) && container != null)
|
||||||
|
{
|
||||||
|
if (TryComp<InternalsComponent>(container.Owner, out var containerInternalsComp) && containerInternalsComp != null)
|
||||||
|
{
|
||||||
|
internalsUid = container.Owner;
|
||||||
|
internalsComp = containerInternalsComp;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AssumeAir(Entity<GasTankComponent> ent, GasMixture giver)
|
public void AssumeAir(Entity<GasTankComponent> ent, GasMixture giver)
|
||||||
@@ -321,7 +351,7 @@ namespace Content.Server.Atmos.EntitySystems
|
|||||||
if(environment != null)
|
if(environment != null)
|
||||||
_atmosphereSystem.Merge(environment, component.Air);
|
_atmosphereSystem.Merge(environment, component.Air);
|
||||||
|
|
||||||
_audioSys.PlayPvs(component.RuptureSound, Transform(component.Owner).Coordinates, AudioParams.Default.WithVariation(0.125f));
|
_audioSys.PlayPvs(component.RuptureSound, Transform(owner).Coordinates, AudioParams.Default.WithVariation(0.125f));
|
||||||
|
|
||||||
QueueDel(owner);
|
QueueDel(owner);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ public sealed class InternalsSystem : EntitySystem
|
|||||||
{
|
{
|
||||||
if (force)
|
if (force)
|
||||||
{
|
{
|
||||||
DisconnectTank(internals);
|
DisconnectTank((uid, internals));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,16 +199,13 @@ public sealed class InternalsSystem : EntitySystem
|
|||||||
_alerts.ShowAlert(ent, ent.Comp.InternalsAlert, GetSeverity(ent));
|
_alerts.ShowAlert(ent, ent.Comp.InternalsAlert, GetSeverity(ent));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DisconnectTank(InternalsComponent? component)
|
public void DisconnectTank(Entity<InternalsComponent> ent)
|
||||||
{
|
{
|
||||||
if (component is null)
|
if (TryComp(ent.Comp.GasTankEntity, out GasTankComponent? tank))
|
||||||
return;
|
_gasTank.DisconnectFromInternals((ent.Comp.GasTankEntity.Value, tank));
|
||||||
|
|
||||||
if (TryComp(component.GasTankEntity, out GasTankComponent? tank))
|
ent.Comp.GasTankEntity = null;
|
||||||
_gasTank.DisconnectFromInternals((component.GasTankEntity.Value, tank));
|
_alerts.ShowAlert(ent.Owner, ent.Comp.InternalsAlert, GetSeverity(ent.Comp));
|
||||||
|
|
||||||
component.GasTankEntity = null;
|
|
||||||
_alerts.ShowAlert(component.Owner, component.InternalsAlert, GetSeverity(component));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TryConnectTank(Entity<InternalsComponent> ent, EntityUid tankEntity)
|
public bool TryConnectTank(Entity<InternalsComponent> ent, EntityUid tankEntity)
|
||||||
@@ -267,21 +264,21 @@ public sealed class InternalsSystem : EntitySystem
|
|||||||
|
|
||||||
if (_inventory.TryGetSlotEntity(user, "back", out var backEntity, user.Comp2, user.Comp3) &&
|
if (_inventory.TryGetSlotEntity(user, "back", out var backEntity, user.Comp2, user.Comp3) &&
|
||||||
TryComp<GasTankComponent>(backEntity, out var backGasTank) &&
|
TryComp<GasTankComponent>(backEntity, out var backGasTank) &&
|
||||||
_gasTank.CanConnectToInternals(backGasTank))
|
_gasTank.CanConnectToInternals((backEntity.Value, backGasTank)))
|
||||||
{
|
{
|
||||||
return (backEntity.Value, backGasTank);
|
return (backEntity.Value, backGasTank);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_inventory.TryGetSlotEntity(user, "suitstorage", out var entity, user.Comp2, user.Comp3) &&
|
if (_inventory.TryGetSlotEntity(user, "suitstorage", out var entity, user.Comp2, user.Comp3) &&
|
||||||
TryComp<GasTankComponent>(entity, out var gasTank) &&
|
TryComp<GasTankComponent>(entity, out var gasTank) &&
|
||||||
_gasTank.CanConnectToInternals(gasTank))
|
_gasTank.CanConnectToInternals((entity.Value, gasTank)))
|
||||||
{
|
{
|
||||||
return (entity.Value, gasTank);
|
return (entity.Value, gasTank);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var item in _inventory.GetHandOrInventoryEntities((user.Owner, user.Comp1, user.Comp2)))
|
foreach (var item in _inventory.GetHandOrInventoryEntities((user.Owner, user.Comp1, user.Comp2)))
|
||||||
{
|
{
|
||||||
if (TryComp(item, out gasTank) && _gasTank.CanConnectToInternals(gasTank))
|
if (TryComp(item, out gasTank) && _gasTank.CanConnectToInternals((item, gasTank)))
|
||||||
return (item, gasTank);
|
return (item, gasTank);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user