2020-08-22 20:03:24 +10:00
|
|
|
#nullable enable
|
2020-07-25 15:11:16 +02:00
|
|
|
using Content.Server.GameObjects.Components.GUI;
|
2020-08-13 14:40:27 +02:00
|
|
|
using Content.Server.GameObjects.Components.Items.Storage;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.GameObjects;
|
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>
|
2020-08-22 20:03:24 +10:00
|
|
|
public class UseItemInInventoryOperator : AiOperator
|
2020-06-18 22:52:44 +10:00
|
|
|
{
|
|
|
|
|
private readonly IEntity _owner;
|
|
|
|
|
private readonly IEntity _target;
|
|
|
|
|
|
2020-08-22 20:03:24 +10:00
|
|
|
public UseItemInInventoryOperator(IEntity owner, IEntity target)
|
2020-06-18 22:52:44 +10:00
|
|
|
{
|
|
|
|
|
_owner = owner;
|
|
|
|
|
_target = target;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Outcome Execute(float frameTime)
|
|
|
|
|
{
|
|
|
|
|
// TODO: Also have this check storage a la backpack etc.
|
2020-08-22 12:24:59 +02:00
|
|
|
if (!_owner.TryGetComponent(out HandsComponent? handsComponent))
|
2020-06-18 22:52:44 +10:00
|
|
|
{
|
|
|
|
|
return Outcome.Failed;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-22 12:24:59 +02:00
|
|
|
if (!_target.TryGetComponent(out ItemComponent? 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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|