]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix position swapping with QSI and artifacts (#26364)
authorNemanja <98561806+EmoGarbage404@users.noreply.github.com>
Mon, 29 Apr 2024 09:11:07 +0000 (05:11 -0400)
committerGitHub <noreply@github.com>
Mon, 29 Apr 2024 09:11:07 +0000 (19:11 +1000)
Content.Server/Xenoarchaeology/XenoArtifacts/Effects/Systems/PortalArtifactSystem.cs
Content.Server/Xenoarchaeology/XenoArtifacts/Effects/Systems/ShuffleArtifactSystem.cs
Content.Shared/Teleportation/Systems/SwapTeleporterSystem.cs

index e2d21723550b9e44b8c76e14b814eb1eea52e687..e44ee6baa12f8375e6319d31b753914832ab5da7 100644 (file)
@@ -35,8 +35,7 @@ public sealed class PortalArtifactSystem : EntitySystem
         var secondPortal = Spawn(artifact.Comp.PortalProto, _transform.GetMapCoordinates(target));
 
         //Manual position swapping, because the portal that opens doesn't trigger a collision, and doesn't teleport targets the first time.
-        _transform.SetCoordinates(artifact, Transform(secondPortal).Coordinates);
-        _transform.SetCoordinates(target, Transform(firstPortal).Coordinates);
+        _transform.SwapPositions(target, secondPortal);
 
         _link.TryLink(firstPortal, secondPortal, true);
     }
index b977cb038c982c2d829307ed59f9b59c65e9258d..c39627818a1f176e20e5bce4a528f0aa01c4e349 100644 (file)
@@ -22,7 +22,6 @@ public sealed class ShuffleArtifactSystem : EntitySystem
     {
         var mobState = GetEntityQuery<MobStateComponent>();
 
-        List<EntityCoordinates> allCoords = new();
         List<Entity<TransformComponent>> toShuffle = new();
 
         foreach (var ent in _lookup.GetEntitiesInRange(uid, component.Radius, LookupFlags.Dynamic | LookupFlags.Sundries))
@@ -33,13 +32,15 @@ public sealed class ShuffleArtifactSystem : EntitySystem
             var xform = Transform(ent);
 
             toShuffle.Add((ent, xform));
-            allCoords.Add(xform.Coordinates);
         }
 
-        foreach (var xform in toShuffle)
+        _random.Shuffle(toShuffle);
+
+        while (toShuffle.Count > 1)
         {
-            var xformUid = xform.Owner;
-            _xform.SetCoordinates(xformUid, xform, _random.PickAndTake(allCoords));
+            var ent1 = _random.PickAndTake(toShuffle);
+            var ent2 = _random.PickAndTake(toShuffle);
+            _xform.SwapPositions((ent1, ent1), (ent2, ent2));
         }
     }
 }
index e69a31a1d406e7be2e1a7975d19a1266efd4700b..62c0b0f44e416c0dea2675d5ef64d0695c89c087 100644 (file)
@@ -145,27 +145,14 @@ public sealed class SwapTeleporterSystem : EntitySystem
         }
 
         var teleEnt = GetTeleportingEntity((uid, xform));
-        var teleEntXform = Transform(teleEnt);
         var otherTeleEnt = GetTeleportingEntity((linkedEnt, Transform(linkedEnt)));
-        var otherTeleEntXform = Transform(otherTeleEnt);
 
         _popup.PopupEntity(Loc.GetString("swap-teleporter-popup-teleport-other",
             ("entity", Identity.Entity(linkedEnt, EntityManager))),
             otherTeleEnt,
             otherTeleEnt,
             PopupType.MediumCaution);
-        var pos = teleEntXform.Coordinates;
-        var otherPos = otherTeleEntXform.Coordinates;
-
-        if (_transform.ContainsEntity(teleEnt, (otherTeleEnt, otherTeleEntXform)) ||
-            _transform.ContainsEntity(otherTeleEnt, (teleEnt, teleEntXform)))
-        {
-            Log.Error($"Invalid teleport swap attempt between {ToPrettyString(teleEnt)} and {ToPrettyString(otherTeleEnt)}");
-            return;
-        }
-
-        _transform.SetCoordinates(teleEnt, otherPos);
-        _transform.SetCoordinates(otherTeleEnt, pos);
+        _transform.SwapPositions(teleEnt, otherTeleEnt);
     }
 
     /// <remarks>