From 3f3be47ae41596e8e586aaf4fe0bb7c8187f47d3 Mon Sep 17 00:00:00 2001 From: Quantum-cross <7065792+Quantum-cross@users.noreply.github.com> Date: Tue, 6 May 2025 13:01:37 -0400 Subject: [PATCH] Fix effects of hosted anomaly when transform is parented (#37179) * 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 | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/Content.Shared/Anomaly/SharedAnomalySystem.cs b/Content.Shared/Anomaly/SharedAnomalySystem.cs index 666d98bfc6..dd07cf0441 100644 --- a/Content.Shared/Anomaly/SharedAnomalySystem.cs +++ b/Content.Shared/Anomaly/SharedAnomalySystem.cs @@ -371,13 +371,19 @@ public abstract class SharedAnomalySystem : EntitySystem if (!TryComp(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)