@@ -1,5 +1,6 @@
|
|||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using Robust.Shared.Map;
|
using Robust.Shared.Map;
|
||||||
|
using Robust.Shared.Map.Components;
|
||||||
|
|
||||||
namespace Content.Shared.Random.Rules;
|
namespace Content.Shared.Random.Rules;
|
||||||
|
|
||||||
@@ -11,6 +12,8 @@ public sealed partial class GridInRangeRule : RulesRule
|
|||||||
[DataField]
|
[DataField]
|
||||||
public float Range = 10f;
|
public float Range = 10f;
|
||||||
|
|
||||||
|
private List<Entity<MapGridComponent>> _grids = [];
|
||||||
|
|
||||||
public override bool Check(EntityManager entManager, EntityUid uid)
|
public override bool Check(EntityManager entManager, EntityUid uid)
|
||||||
{
|
{
|
||||||
if (!entManager.TryGetComponent(uid, out TransformComponent? xform))
|
if (!entManager.TryGetComponent(uid, out TransformComponent? xform))
|
||||||
@@ -29,10 +32,10 @@ public sealed partial class GridInRangeRule : RulesRule
|
|||||||
var worldPos = transform.GetWorldPosition(xform);
|
var worldPos = transform.GetWorldPosition(xform);
|
||||||
var gridRange = new Vector2(Range, Range);
|
var gridRange = new Vector2(Range, Range);
|
||||||
|
|
||||||
foreach (var _ in mapManager.FindGridsIntersecting(xform.MapID, new Box2(worldPos - gridRange, worldPos + gridRange)))
|
_grids.Clear();
|
||||||
{
|
mapManager.FindGridsIntersecting(xform.MapID, new Box2(worldPos - gridRange, worldPos + gridRange), ref _grids);
|
||||||
|
if (_grids.Count > 0)
|
||||||
return !Inverted;
|
return !Inverted;
|
||||||
}
|
|
||||||
|
|
||||||
return Inverted;
|
return Inverted;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user