2020-08-22 20:03:24 +10:00
|
|
|
|
#nullable enable
|
|
|
|
|
|
using Content.Server.AI.Utility;
|
2020-06-18 22:52:44 +10:00
|
|
|
|
using Content.Server.AI.WorldState.States.Inventory;
|
2020-07-26 20:49:41 +02:00
|
|
|
|
using Content.Server.GameObjects.Components.Items.Storage;
|
2020-07-18 22:51:56 -07:00
|
|
|
|
using Content.Shared.Interfaces.GameObjects.Components;
|
2020-08-30 11:37:06 +02:00
|
|
|
|
using Content.Shared.Utility;
|
2020-06-18 22:52:44 +10:00
|
|
|
|
using Robust.Shared.Containers;
|
|
|
|
|
|
using Robust.Shared.Interfaces.GameObjects;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.AI.Operators.Inventory
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// If the target is in EntityStorage will open its parent container
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public sealed class OpenStorageOperator : AiOperator
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly IEntity _owner;
|
|
|
|
|
|
private readonly IEntity _target;
|
2020-07-06 14:27:03 -07:00
|
|
|
|
|
2020-06-18 22:52:44 +10:00
|
|
|
|
public OpenStorageOperator(IEntity owner, IEntity target)
|
|
|
|
|
|
{
|
|
|
|
|
|
_owner = owner;
|
|
|
|
|
|
_target = target;
|
|
|
|
|
|
}
|
2020-07-06 14:27:03 -07:00
|
|
|
|
|
2020-06-18 22:52:44 +10:00
|
|
|
|
public override Outcome Execute(float frameTime)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!ContainerHelpers.TryGetContainer(_target, out var container))
|
|
|
|
|
|
{
|
|
|
|
|
|
return Outcome.Success;
|
|
|
|
|
|
}
|
2020-07-07 00:23:41 +02:00
|
|
|
|
|
2020-08-30 11:37:06 +02:00
|
|
|
|
if (!_owner.InRangeUnobstructed(container, popup: true))
|
2020-06-22 05:48:22 +10:00
|
|
|
|
{
|
|
|
|
|
|
return Outcome.Failed;
|
|
|
|
|
|
}
|
2020-06-18 22:52:44 +10:00
|
|
|
|
|
2020-08-22 12:24:59 +02:00
|
|
|
|
if (!container.Owner.TryGetComponent(out EntityStorageComponent? storageComponent) ||
|
2020-06-18 22:52:44 +10:00
|
|
|
|
storageComponent.IsWeldedShut)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Outcome.Failed;
|
|
|
|
|
|
}
|
2020-07-06 14:27:03 -07:00
|
|
|
|
|
2020-06-18 22:52:44 +10:00
|
|
|
|
if (!storageComponent.Open)
|
|
|
|
|
|
{
|
|
|
|
|
|
var activateArgs = new ActivateEventArgs {User = _owner, Target = _target};
|
|
|
|
|
|
storageComponent.Activate(activateArgs);
|
|
|
|
|
|
}
|
2020-07-06 14:27:03 -07:00
|
|
|
|
|
2020-06-18 22:52:44 +10:00
|
|
|
|
var blackboard = UtilityAiHelpers.GetBlackboard(_owner);
|
|
|
|
|
|
blackboard?.GetState<LastOpenedStorageState>().SetValue(container.Owner);
|
2020-07-06 14:27:03 -07:00
|
|
|
|
|
2020-06-18 22:52:44 +10:00
|
|
|
|
return Outcome.Success;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-07-06 14:27:03 -07:00
|
|
|
|
}
|