Fix anti-anomaly zones (#23357)

This commit is contained in:
Nemanja
2024-01-02 01:18:41 -05:00
committed by GitHub
parent 76bae5a17a
commit 2988d60bd4

View File

@@ -13,6 +13,7 @@ using Robust.Shared.Physics;
using Robust.Shared.Physics.Components; using Robust.Shared.Physics.Components;
using Robust.Shared.Map; using Robust.Shared.Map;
using System.Numerics; using System.Numerics;
using Robust.Server.GameObjects;
namespace Content.Server.Anomaly; namespace Content.Server.Anomaly;
@@ -23,7 +24,7 @@ namespace Content.Server.Anomaly;
/// </summary> /// </summary>
public sealed partial class AnomalySystem public sealed partial class AnomalySystem
{ {
[Dependency] private readonly MapSystem _mapSystem = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!; [Dependency] private readonly SharedTransformSystem _transform = default!;
private void InitializeGenerator() private void InitializeGenerator()
@@ -133,14 +134,19 @@ public sealed partial class AnomalySystem
if (!valid) if (!valid)
continue; continue;
var pos = _mapSystem.GridTileToLocal(grid, gridComp, tile);
var mapPos = pos.ToMap(EntityManager, _transform);
// don't spawn in AntiAnomalyZones // don't spawn in AntiAnomalyZones
var antiAnomalyZonesQueue = AllEntityQuery<AntiAnomalyZoneComponent>(); var antiAnomalyZonesQueue = AllEntityQuery<AntiAnomalyZoneComponent, TransformComponent>();
while (antiAnomalyZonesQueue.MoveNext(out var uid, out var zone)) while (antiAnomalyZonesQueue.MoveNext(out var uid, out var zone, out var antiXform))
{ {
var zoneTile = _transform.GetGridTilePositionOrDefault(uid, gridComp); if (antiXform.MapID != mapPos.MapId)
continue;
var delta = (zoneTile - tile); var antiCoordinates = _transform.GetMapCoordinates(antiXform);
if (delta.LengthSquared < zone.ZoneRadius * zone.ZoneRadius)
var delta = antiCoordinates.Position - mapPos.Position;
if (delta.LengthSquared() < zone.ZoneRadius * zone.ZoneRadius)
{ {
valid = false; valid = false;
break; break;
@@ -149,7 +155,7 @@ public sealed partial class AnomalySystem
if (!valid) if (!valid)
continue; continue;
targetCoords = gridComp.GridTileToLocal(tile); targetCoords = pos;
break; break;
} }