using System.Numerics; using Robust.Shared.Map; using Robust.Shared.Map.Components; namespace Content.Shared.Random.Rules; /// /// Returns true if on a grid or in range of one. /// public sealed partial class GridInRangeRule : RulesRule { [DataField] public float Range = 10f; private List> _grids = []; public override bool Check(EntityManager entManager, EntityUid uid) { if (!entManager.TryGetComponent(uid, out TransformComponent? xform)) { return false; } if (xform.GridUid != null) { return !Inverted; } var transform = entManager.System(); var mapManager = IoCManager.Resolve(); var worldPos = transform.GetWorldPosition(xform); var gridRange = new Vector2(Range, Range); _grids.Clear(); mapManager.FindGridsIntersecting(xform.MapID, new Box2(worldPos - gridRange, worldPos + gridRange), ref _grids); if (_grids.Count > 0) return !Inverted; return Inverted; } }