]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Updates GasTankSystem and InternalsSystem to not use Component.Owner (#29934)
authorPlykiya <58439124+Plykiya@users.noreply.github.com>
Fri, 12 Jul 2024 11:44:45 +0000 (04:44 -0700)
committerGitHub <noreply@github.com>
Fri, 12 Jul 2024 11:44:45 +0000 (21:44 +1000)
* blah, setup

* Updates GasTankSystem and InternalsSystem to not use Component.Owner

* squish the diff

* Fixa the rest

---------

Co-authored-by: plykiya <plykiya@protonmail.com>
Content.Server/Atmos/EntitySystems/GasTankSystem.cs
Content.Server/Body/Systems/InternalsSystem.cs

index baad739804b80ed91e6895a4a11ddf2c2bc47b65..2d703439c0f82eb2a4fbe412fa1e66bed096ecea 100644 (file)
@@ -81,7 +81,7 @@ namespace Content.Server.Atmos.EntitySystems
                     TankPressure = component.Air?.Pressure ?? 0,
                     OutputPressure = initialUpdate ? component.OutputPressure : null,
                     InternalsConnected = component.IsConnected,
-                    CanConnectInternals = CanConnectToInternals(component)
+                    CanConnectInternals = CanConnectToInternals(ent)
                 });
         }
 
@@ -217,24 +217,24 @@ namespace Content.Server.Atmos.EntitySystems
             return air;
         }
 
-        public bool CanConnectToInternals(GasTankComponent component)
+        public bool CanConnectToInternals(Entity<GasTankComponent> ent)
         {
-            var internals = GetInternalsComponent(component, component.User);
-            return internals != null && internals.BreathTools.Count != 0 && !component.IsValveOpen;
+            TryGetInternalsComp(ent, out _, out var internalsComp, ent.Comp.User);
+            return internalsComp != null && internalsComp.BreathTools.Count != 0 && !ent.Comp.IsValveOpen;
         }
 
         public void ConnectToInternals(Entity<GasTankComponent> ent)
         {
             var (owner, component) = ent;
-            if (component.IsConnected || !CanConnectToInternals(component))
+            if (component.IsConnected || !CanConnectToInternals(ent))
                 return;
 
-            var internals = GetInternalsComponent(component);
-            if (internals == null)
+            TryGetInternalsComp(ent, out var internalsUid, out var internalsComp, ent.Comp.User);
+            if (internalsUid == null || internalsComp == null)
                 return;
 
-            if (_internals.TryConnectTank((internals.Owner, internals), owner))
-                component.User = internals.Owner;
+            if (_internals.TryConnectTank((internalsUid.Value, internalsComp), owner))
+                component.User = internalsUid.Value;
 
             _actions.SetToggled(component.ToggleActionEntity, component.IsConnected);
 
@@ -243,7 +243,7 @@ namespace Content.Server.Atmos.EntitySystems
                 return;
 
             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);
         }
@@ -251,29 +251,59 @@ namespace Content.Server.Atmos.EntitySystems
         public void DisconnectFromInternals(Entity<GasTankComponent> ent)
         {
             var (owner, component) = ent;
+
             if (component.User == null)
                 return;
 
-            var internals = GetInternalsComponent(component);
+            TryGetInternalsComp(ent, out var internalsUid, out var internalsComp, component.User);
             component.User = null;
 
             _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.PlayPvs(component.DisconnectSound, component.Owner)?.Entity;
+            component.DisconnectStream = _audioSys.PlayPvs(component.DisconnectSound, owner)?.Entity;
 
             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;
-            if (Deleted(component.Owner))return null;
-            if (owner != null) return CompOrNull<InternalsComponent>(owner.Value);
-            return _containers.TryGetContainingContainer(component.Owner, out var container)
-                ? CompOrNull<InternalsComponent>(container.Owner)
-                : null;
+            internalsUid = default;
+            internalsComp = default;
+
+            // If the gas tank doesn't exist for whatever reason, don't even bother
+            if (TerminatingOrDeleted(ent.Owner))
+                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)
@@ -321,7 +351,7 @@ namespace Content.Server.Atmos.EntitySystems
                     if(environment != null)
                         _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);
                     return;
index d6ece39d590a365d24048231cc93c7a1737dcaf8..10ebd934aa46035af0ca83094545a729a5929bcb 100644 (file)
@@ -102,7 +102,7 @@ public sealed class InternalsSystem : EntitySystem
         {
             if (force)
             {
-                DisconnectTank(internals);
+                DisconnectTank((uid, internals));
                 return;
             }
 
@@ -199,16 +199,13 @@ public sealed class InternalsSystem : EntitySystem
         _alerts.ShowAlert(ent, ent.Comp.InternalsAlert, GetSeverity(ent));
     }
 
-    public void DisconnectTank(InternalsComponent? component)
+    public void DisconnectTank(Entity<InternalsComponent> ent)
     {
-        if (component is null)
-            return;
-
-        if (TryComp(component.GasTankEntity, out GasTankComponent? tank))
-            _gasTank.DisconnectFromInternals((component.GasTankEntity.Value, tank));
+        if (TryComp(ent.Comp.GasTankEntity, out GasTankComponent? tank))
+            _gasTank.DisconnectFromInternals((ent.Comp.GasTankEntity.Value, tank));
 
-        component.GasTankEntity = null;
-        _alerts.ShowAlert(component.Owner, component.InternalsAlert, GetSeverity(component));
+        ent.Comp.GasTankEntity = null;
+        _alerts.ShowAlert(ent.Owner, ent.Comp.InternalsAlert, GetSeverity(ent.Comp));
     }
 
     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) &&
             TryComp<GasTankComponent>(backEntity, out var backGasTank) &&
-            _gasTank.CanConnectToInternals(backGasTank))
+            _gasTank.CanConnectToInternals((backEntity.Value, backGasTank)))
         {
             return (backEntity.Value, backGasTank);
         }
 
         if (_inventory.TryGetSlotEntity(user, "suitstorage", out var entity, user.Comp2, user.Comp3) &&
             TryComp<GasTankComponent>(entity, out var gasTank) &&
-            _gasTank.CanConnectToInternals(gasTank))
+            _gasTank.CanConnectToInternals((entity.Value, gasTank)))
         {
             return (entity.Value, gasTank);
         }
 
         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);
         }