using System.Collections.Generic; using Content.Server.AI.Components; using Content.Server.AI.Utils; using Content.Server.Nutrition.Components; using Content.Server.Storage.Components; using JetBrains.Annotations; using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.IoC; namespace Content.Server.AI.WorldState.States.Nutrition { [UsedImplicitly] public sealed class NearbyFoodState : CachedStateData> { public override string Name => "NearbyFood"; protected override List GetTrueValue() { var result = new List(); var entMan = IoCManager.Resolve(); if (!entMan.TryGetComponent(Owner, out AiControllerComponent? controller)) { return result; } foreach (var entity in Visibility .GetNearestEntities(entMan.GetComponent(Owner).Coordinates, typeof(FoodComponent), controller.VisionRadius)) { if (entity.TryGetContainer(out var container)) { if (!entMan.HasComponent(container.Owner)) { continue; } } result.Add(entity); } return result; } } }