]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix effects of hosted anomaly when transform is parented (#37179)
authorQuantum-cross <7065792+Quantum-cross@users.noreply.github.com>
Tue, 6 May 2025 17:01:37 +0000 (13:01 -0400)
committerGitHub <noreply@github.com>
Tue, 6 May 2025 17:01:37 +0000 (13:01 -0400)
* hosted anomaly effects now are at the correct location when the host is in a container or buckled

* oops, not keeping the uid and transform together

* use world positions to get the position of the anomaly -- my previous method was reinventing the wheel.

Content.Shared/Anomaly/SharedAnomalySystem.cs

index 666d98bfc6b4dfa8b92703844cc6ab9e6843147a..dd07cf0441aa763f1cafb8619dbb2dacef0f6d9c 100644 (file)
@@ -371,13 +371,19 @@ public abstract class SharedAnomalySystem : EntitySystem
         if (!TryComp<MapGridComponent>(xform.GridUid, out var grid))
             return null;
 
+        // How many spawn points we will be aiming to return
         var amount = (int) (MathHelper.Lerp(settings.MinAmount, settings.MaxAmount, severity * stability * powerModifier) + 0.5f);
 
-        var localpos = xform.Coordinates.Position;
-        var tilerefs = _map.GetLocalTilesIntersecting(
-            xform.GridUid.Value,
-            grid,
-            new Box2(localpos + new Vector2(-settings.MaxRange, -settings.MaxRange), localpos + new Vector2(settings.MaxRange, settings.MaxRange)))
+        // When the entity is in a container or buckled (such as a hosted anomaly), local coordinates will not be comparable
+        // to tile coordinates.
+        // Get the world coordinates for the anomalous entity
+        var worldPos = _transform.GetWorldPosition(uid);
+
+        // Get a list of the tiles within the maximum range of the effect
+        var tilerefs = _map.GetTilesIntersecting(
+                xform.GridUid.Value,
+                grid,
+                new Box2(worldPos + new Vector2(-settings.MaxRange), worldPos + new Vector2(settings.MaxRange)))
             .ToList();
 
         if (tilerefs.Count == 0)
@@ -391,7 +397,10 @@ public abstract class SharedAnomalySystem : EntitySystem
                 break;
 
             var tileref = Random.Pick(tilerefs);
-            var distance = MathF.Sqrt(MathF.Pow(tileref.X - xform.LocalPosition.X, 2) + MathF.Pow(tileref.Y - xform.LocalPosition.Y, 2));
+
+            // Get the world position of the tile to calculate the distance to the anomalous object
+            var tileWorldPos = _map.GridTileToWorldPos(xform.GridUid.Value, grid, tileref.GridIndices);
+            var distance = Vector2.Distance(tileWorldPos, worldPos);
 
             //cut outer & inner circle
             if (distance > settings.MaxRange || distance < settings.MinRange)