2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.Hands.Components;
|
2021-12-30 22:56:10 +01:00
|
|
|
using Content.Shared.Item;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.GameObjects;
|
2021-12-03 14:17:01 +01:00
|
|
|
using Robust.Shared.IoC;
|
2020-06-18 22:52:44 +10:00
|
|
|
|
|
|
|
|
namespace Content.Server.AI.Operators.Inventory
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Will find the item in storage, put it in an active hand, then use it
|
|
|
|
|
/// </summary>
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class UseItemInInventoryOperator : AiOperator
|
2020-06-18 22:52:44 +10:00
|
|
|
{
|
2021-12-05 18:09:01 +01:00
|
|
|
private readonly EntityUid _owner;
|
|
|
|
|
private readonly EntityUid _target;
|
2020-06-18 22:52:44 +10:00
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
public UseItemInInventoryOperator(EntityUid owner, EntityUid target)
|
2020-06-18 22:52:44 +10:00
|
|
|
{
|
|
|
|
|
_owner = owner;
|
|
|
|
|
_target = target;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Outcome Execute(float frameTime)
|
|
|
|
|
{
|
2021-12-08 17:04:21 +01:00
|
|
|
var entMan = IoCManager.Resolve<IEntityManager>();
|
|
|
|
|
|
2020-06-18 22:52:44 +10:00
|
|
|
// TODO: Also have this check storage a la backpack etc.
|
2021-12-08 17:04:21 +01:00
|
|
|
if (!entMan.TryGetComponent(_owner, out HandsComponent? handsComponent))
|
2020-06-18 22:52:44 +10:00
|
|
|
{
|
|
|
|
|
return Outcome.Failed;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-30 22:56:10 +01:00
|
|
|
if (!entMan.TryGetComponent(_target, out SharedItemComponent? itemComponent))
|
2020-06-18 22:52:44 +10:00
|
|
|
{
|
|
|
|
|
return Outcome.Failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var slot in handsComponent.ActivePriorityEnumerable())
|
|
|
|
|
{
|
2020-07-25 15:11:16 +02:00
|
|
|
if (handsComponent.GetItem(slot) != itemComponent) continue;
|
|
|
|
|
handsComponent.ActiveHand = slot;
|
2020-06-18 22:52:44 +10:00
|
|
|
handsComponent.ActivateItem();
|
|
|
|
|
return Outcome.Success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Outcome.Failed;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|