Ambient music rules refactor (#29921)

* refactor

* dutypo
This commit is contained in:
Ed
2024-07-14 16:58:48 +03:00
committed by GitHub
parent 7d9653fff7
commit 1c74ffb8e4
13 changed files with 414 additions and 388 deletions

View File

@@ -0,0 +1,39 @@
using System.Numerics;
using Robust.Shared.Map;
namespace Content.Shared.Random.Rules;
/// <summary>
/// Returns true if on a grid or in range of one.
/// </summary>
public sealed partial class GridInRangeRule : RulesRule
{
[DataField]
public float Range = 10f;
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<SharedTransformSystem>();
var mapManager = IoCManager.Resolve<IMapManager>();
var worldPos = transform.GetWorldPosition(xform);
var gridRange = new Vector2(Range, Range);
foreach (var _ in mapManager.FindGridsIntersecting(xform.MapID, new Box2(worldPos - gridRange, worldPos + gridRange)))
{
return !Inverted;
}
return false;
}
}