2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.Hands.Components;
|
|
|
|
|
using Content.Server.Nutrition.Components;
|
2022-03-17 20:13:31 +13:00
|
|
|
using Content.Shared.Hands.EntitySystems;
|
2021-12-30 22:56:10 +01:00
|
|
|
using Content.Shared.Item;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Nutrition.Components;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.GameObjects;
|
2020-08-22 20:03:24 +10:00
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
using Robust.Shared.Random;
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.AI.Operators.Nutrition
|
|
|
|
|
{
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class UseFoodInInventoryOperator : AiOperator
|
2020-08-22 20:03:24 +10:00
|
|
|
{
|
2021-12-05 18:09:01 +01:00
|
|
|
private readonly EntityUid _owner;
|
|
|
|
|
private readonly EntityUid _target;
|
2020-08-22 20:03:24 +10:00
|
|
|
private float _interactionCooldown;
|
|
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
public UseFoodInInventoryOperator(EntityUid owner, EntityUid target)
|
2020-08-22 20:03:24 +10:00
|
|
|
{
|
|
|
|
|
_owner = owner;
|
|
|
|
|
_target = target;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Outcome Execute(float frameTime)
|
|
|
|
|
{
|
|
|
|
|
if (_interactionCooldown >= 0)
|
|
|
|
|
{
|
|
|
|
|
_interactionCooldown -= frameTime;
|
|
|
|
|
return Outcome.Continuing;
|
|
|
|
|
}
|
2020-08-22 12:24:59 +02:00
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
var entities = IoCManager.Resolve<IEntityManager>();
|
2022-03-17 20:13:31 +13:00
|
|
|
var sysMan = IoCManager.Resolve<IEntitySystemManager>();
|
|
|
|
|
var handsSys = sysMan.GetEntitySystem<SharedHandsSystem>();
|
2021-12-05 18:09:01 +01:00
|
|
|
|
2020-08-22 20:03:24 +10:00
|
|
|
// TODO: Also have this check storage a la backpack etc.
|
2021-12-09 12:29:27 +01:00
|
|
|
if (entities.Deleted(_target) ||
|
2022-03-17 20:13:31 +13:00
|
|
|
!entities.TryGetComponent(_owner, out HandsComponent? handsComponent))
|
2020-08-22 20:03:24 +10:00
|
|
|
{
|
|
|
|
|
return Outcome.Failed;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-17 20:13:31 +13:00
|
|
|
if (!handsSys.TrySelect<FoodComponent>(_owner, out var foodComponent, handsComponent))
|
|
|
|
|
return Outcome.Failed;
|
2020-08-22 20:03:24 +10:00
|
|
|
|
2022-03-17 20:13:31 +13:00
|
|
|
if (!handsSys.TryUseItemInHand(_owner, false, handsComponent))
|
2020-08-22 20:03:24 +10:00
|
|
|
return Outcome.Failed;
|
2020-08-22 12:24:59 +02:00
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
if ((!entities.EntityExists(_target) ? EntityLifeStage.Deleted : entities.GetComponent<MetaDataComponent>(_target).EntityLifeStage) >= EntityLifeStage.Deleted ||
|
2020-08-22 12:24:59 +02:00
|
|
|
foodComponent.UsesRemaining == 0 ||
|
2021-12-05 18:09:01 +01:00
|
|
|
entities.TryGetComponent(_owner, out HungerComponent? hungerComponent) &&
|
2020-08-22 20:03:24 +10:00
|
|
|
hungerComponent.CurrentHunger >= hungerComponent.HungerThresholds[HungerThreshold.Okay])
|
|
|
|
|
{
|
|
|
|
|
return Outcome.Success;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-17 20:13:31 +13:00
|
|
|
/// do afters for food might mess this up?
|
2020-08-22 20:03:24 +10:00
|
|
|
return Outcome.Continuing;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-22 12:24:59 +02:00
|
|
|
}
|