using System.Linq; using Robust.Shared.Map; namespace Content.Server.AI.Utils { public static class Visibility { // Should this be in robust or something? Fark it public static IEnumerable GetNearestEntities(EntityCoordinates grid, Type component, float range) { var entMan = IoCManager.Resolve(); var inRange = GetEntitiesInRange(grid, component, range).ToList(); var sortedInRange = inRange.OrderBy(o => (entMan.GetComponent(o).Coordinates.Position - grid.Position).Length); return sortedInRange; } public static IEnumerable GetEntitiesInRange(EntityCoordinates grid, Type component, float range) { var entityManager = IoCManager.Resolve(); foreach (var entity in entityManager.GetAllComponents(component).Select(c => c.Owner)) { var transform = entityManager.GetComponent(entity); if (transform.Coordinates.GetGridEntityId(entityManager) != grid.GetGridEntityId(entityManager)) { continue; } if ((transform.Coordinates.Position - grid.Position).Length <= range) { yield return entity; } } } } }