Files
tbd-station-14/Content.Server/AI/WorldState/States/Nutrition/NearbyFoodState.cs
2021-12-08 17:04:21 +01:00

46 lines
1.4 KiB
C#

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<List<EntityUid>>
{
public override string Name => "NearbyFood";
protected override List<EntityUid> GetTrueValue()
{
var result = new List<EntityUid>();
var entMan = IoCManager.Resolve<IEntityManager>();
if (!entMan.TryGetComponent(Owner, out AiControllerComponent? controller))
{
return result;
}
foreach (var entity in Visibility
.GetNearestEntities(entMan.GetComponent<TransformComponent>(Owner).Coordinates, typeof(FoodComponent), controller.VisionRadius))
{
if (entity.TryGetContainer(out var container))
{
if (!entMan.HasComponent<EntityStorageComponent>(container.Owner))
{
continue;
}
}
result.Add(entity);
}
return result;
}
}
}