2020-06-18 22:52:44 +10:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Content.Server.AI.Utils;
|
2020-07-03 14:54:45 +02:00
|
|
|
using Content.Server.GameObjects.Components.Items.Storage;
|
2020-06-18 22:52:44 +10:00
|
|
|
using Content.Server.GameObjects.Components.Movement;
|
|
|
|
|
using Content.Server.GameObjects.Components.Nutrition;
|
|
|
|
|
using JetBrains.Annotations;
|
|
|
|
|
using Robust.Shared.Containers;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.GameObjects;
|
2020-06-18 22:52:44 +10:00
|
|
|
|
|
|
|
|
namespace Content.Server.AI.WorldState.States.Nutrition
|
|
|
|
|
{
|
|
|
|
|
[UsedImplicitly]
|
|
|
|
|
public sealed class NearbyFoodState : CachedStateData<List<IEntity>>
|
|
|
|
|
{
|
|
|
|
|
public override string Name => "NearbyFood";
|
|
|
|
|
|
|
|
|
|
protected override List<IEntity> GetTrueValue()
|
|
|
|
|
{
|
|
|
|
|
var result = new List<IEntity>();
|
|
|
|
|
|
2021-03-16 15:50:20 +01:00
|
|
|
if (!Owner.TryGetComponent(out AiControllerComponent? controller))
|
2020-06-18 22:52:44 +10:00
|
|
|
{
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var entity in Visibility
|
2020-09-06 16:11:53 +02:00
|
|
|
.GetNearestEntities(Owner.Transform.Coordinates, typeof(FoodComponent), controller.VisionRadius))
|
2020-06-18 22:52:44 +10:00
|
|
|
{
|
2020-11-13 20:25:04 +13:00
|
|
|
if (entity.TryGetContainer(out var container))
|
2020-06-18 22:52:44 +10:00
|
|
|
{
|
|
|
|
|
if (!container.Owner.HasComponent<EntityStorageComponent>())
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
result.Add(entity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|