2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.Hands.Components;
|
|
|
|
|
using Content.Server.Interaction;
|
|
|
|
|
using Content.Server.Items;
|
|
|
|
|
using Content.Shared.Interaction.Helpers;
|
2020-06-18 22:52:44 +10:00
|
|
|
using Robust.Shared.Containers;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.GameObjects;
|
2020-06-18 22:52:44 +10:00
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.AI.Operators.Inventory
|
|
|
|
|
{
|
|
|
|
|
public class PickupEntityOperator : AiOperator
|
|
|
|
|
{
|
|
|
|
|
// Input variables
|
|
|
|
|
private readonly IEntity _owner;
|
|
|
|
|
private readonly IEntity _target;
|
|
|
|
|
|
|
|
|
|
public PickupEntityOperator(IEntity owner, IEntity target)
|
|
|
|
|
{
|
|
|
|
|
_owner = owner;
|
|
|
|
|
_target = target;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Outcome Execute(float frameTime)
|
|
|
|
|
{
|
2020-08-22 20:03:24 +10:00
|
|
|
if (_target.Deleted ||
|
2020-06-18 22:52:44 +10:00
|
|
|
!_target.HasComponent<ItemComponent>() ||
|
2020-11-13 20:25:04 +13:00
|
|
|
_target.IsInContainer() ||
|
2020-08-30 11:37:06 +02:00
|
|
|
!_owner.InRangeUnobstructed(_target, popup: true))
|
2020-06-18 22:52:44 +10:00
|
|
|
{
|
|
|
|
|
return Outcome.Failed;
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var emptyHands = false;
|
|
|
|
|
|
|
|
|
|
foreach (var hand in handsComponent.ActivePriorityEnumerable())
|
|
|
|
|
{
|
2020-07-25 15:11:16 +02:00
|
|
|
if (handsComponent.GetItem(hand) == null)
|
2020-06-18 22:52:44 +10:00
|
|
|
{
|
2020-07-25 15:11:16 +02:00
|
|
|
if (handsComponent.ActiveHand != hand)
|
2020-06-18 22:52:44 +10:00
|
|
|
{
|
2020-07-25 15:11:16 +02:00
|
|
|
handsComponent.ActiveHand = hand;
|
2020-06-18 22:52:44 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
emptyHands = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!emptyHands)
|
|
|
|
|
{
|
|
|
|
|
return Outcome.Failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var interactionSystem = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<InteractionSystem>();
|
2021-06-07 05:49:43 -07:00
|
|
|
interactionSystem.InteractHand(_owner, _target);
|
2020-06-18 22:52:44 +10:00
|
|
|
return Outcome.Success;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|