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.
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user