]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix accidentally selling mobs (#15578)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Thu, 20 Apr 2023 12:09:48 +0000 (22:09 +1000)
committerGitHub <noreply@github.com>
Thu, 20 Apr 2023 12:09:48 +0000 (22:09 +1000)
Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs

index 6796cf26765dc0535e6a075456b8d8b822e85498..f9cc9e6dcfaeea0697bc72384db77958d7d9f0fb 100644 (file)
@@ -405,8 +405,8 @@ public sealed partial class CargoSystem
                 // - anything anchored (e.g. light fixtures)
                 // - anything blacklisted (e.g. players).
                 if (toSell.Contains(ent) ||
-                    (xformQuery.TryGetComponent(ent, out var xform) && xform.Anchored) ||
-                    !CanSell(ent, mobStateQuery))
+                    xformQuery.TryGetComponent(ent, out var xform) &&
+                    (xform.Anchored || !CanSell(ent, xform, mobStateQuery, xformQuery)))
                 {
                     continue;
                 }
@@ -423,7 +423,7 @@ public sealed partial class CargoSystem
         }
     }
 
-    private bool CanSell(EntityUid uid, EntityQuery<MobStateComponent> mobStateQuery)
+    private bool CanSell(EntityUid uid, TransformComponent xform, EntityQuery<MobStateComponent> mobStateQuery, EntityQuery<TransformComponent> xformQuery)
     {
         if (mobStateQuery.TryGetComponent(uid, out var mobState) &&
             mobState.CurrentState != MobState.Dead)
@@ -431,6 +431,14 @@ public sealed partial class CargoSystem
             return false;
         }
 
+        // Recursively check for mobs at any point.
+        var children = xform.ChildEnumerator;
+        while (children.MoveNext(out var child))
+        {
+            if (!CanSell(child.Value, xformQuery.GetComponent(child.Value), mobStateQuery, xformQuery))
+                return false;
+        }
+
         return true;
     }