Files
OldThink/Content.Server/AI/Operators/Nutrition/UseDrinkInInventoryOperator.cs

60 lines
2.1 KiB
C#
Raw Normal View History

2021-06-09 22:19:39 +02:00
using Content.Server.Hands.Components;
using Content.Server.Nutrition.Components;
using Content.Server.Nutrition.EntitySystems;
2022-03-17 20:13:31 +13:00
using Content.Shared.Hands.EntitySystems;
using Robust.Shared.Random;
namespace Content.Server.AI.Operators.Nutrition
{
public sealed class UseDrinkInInventoryOperator : AiOperator
{
2021-12-05 18:09:01 +01:00
private readonly EntityUid _owner;
private readonly EntityUid _target;
private float _interactionCooldown;
2021-12-05 18:09:01 +01:00
public UseDrinkInInventoryOperator(EntityUid owner, EntityUid target)
{
_owner = owner;
_target = target;
}
2020-08-22 12:24:59 +02:00
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
// 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))
{
return Outcome.Failed;
}
2022-03-17 20:13:31 +13:00
if (!handsSys.TrySelect<DrinkComponent>(_owner, out var drinkComponent, handsComponent))
return Outcome.Failed;
2022-03-17 20:13:31 +13:00
if (!handsSys.TryUseItemInHand(_owner, false, handsComponent))
return Outcome.Failed;
2022-03-17 20:13:31 +13:00
_interactionCooldown = IoCManager.Resolve<IRobustRandom>().NextFloat() + 0.5f;
2020-08-22 12:24:59 +02:00
2021-12-03 15:53:09 +01:00
if (drinkComponent.Deleted || EntitySystem.Get<DrinkSystem>().IsEmpty(drinkComponent.Owner, drinkComponent)
2021-12-05 18:09:01 +01:00
|| entities.TryGetComponent(_owner, out ThirstComponent? thirstComponent) &&
thirstComponent.CurrentThirst >= thirstComponent.ThirstThresholds[ThirstThreshold.Okay])
{
return Outcome.Success;
}
2022-03-17 20:13:31 +13:00
/// uuhhh do afters for drinks might mess this up?
return Outcome.Continuing;
}
}
2020-08-22 12:24:59 +02:00
}