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))
|
if (!TryComp<MapGridComponent>(xform.GridUid, out var grid))
|
||||||
return null;
|
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 amount = (int) (MathHelper.Lerp(settings.MinAmount, settings.MaxAmount, severity * stability * powerModifier) + 0.5f);
|
||||||
|
|
||||||
var localpos = xform.Coordinates.Position;
|
// When the entity is in a container or buckled (such as a hosted anomaly), local coordinates will not be comparable
|
||||||
var tilerefs = _map.GetLocalTilesIntersecting(
|
// to tile coordinates.
|
||||||
xform.GridUid.Value,
|
// Get the world coordinates for the anomalous entity
|
||||||
grid,
|
var worldPos = _transform.GetWorldPosition(uid);
|
||||||
new Box2(localpos + new Vector2(-settings.MaxRange, -settings.MaxRange), localpos + new Vector2(settings.MaxRange, settings.MaxRange)))
|
|
||||||
|
// 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();
|
.ToList();
|
||||||
|
|
||||||
if (tilerefs.Count == 0)
|
if (tilerefs.Count == 0)
|
||||||
@@ -391,7 +397,10 @@ public abstract class SharedAnomalySystem : EntitySystem
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
var tileref = Random.Pick(tilerefs);
|
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
|
//cut outer & inner circle
|
||||||
if (distance > settings.MaxRange || distance < settings.MinRange)
|
if (distance > settings.MaxRange || distance < settings.MinRange)
|
||||||
|
|||||||
Reference in New Issue
Block a user