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)
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)