Files
tbd-station-14/Content.Server/AI/Operators/Inventory/CloseStorageOperator.cs
Acruid ca4fd649fe Massive Namespace Cleanup (#3120)
* Engine namespace changes.

* Automated remove redundant using statements.

* Simplified Graphics namespace.

* Apparently the container system stores full type names in the map file.😞 This updates those names.

* API Changes to LocalizationManager.LoadCulture.

* Update submodule to v0.3.2
2021-02-11 01:13:03 -08:00

77 lines
2.1 KiB
C#

using Content.Server.AI.Utility;
using Content.Server.AI.WorldState.States.Inventory;
using Content.Server.GameObjects.Components.Items.Storage;
using Content.Shared.Interfaces.GameObjects.Components;
using Content.Shared.Utility;
using Robust.Shared.GameObjects;
namespace Content.Server.AI.Operators.Inventory
{
/// <summary>
/// Close the last EntityStorage we opened
/// This will also update the State for it (which a regular InteractWith won't do)
/// </summary>
public sealed class CloseLastStorageOperator : AiOperator
{
private readonly IEntity _owner;
private IEntity _target;
public CloseLastStorageOperator(IEntity owner)
{
_owner = owner;
}
public override bool Startup()
{
if (!base.Startup())
{
return true;
}
var blackboard = UtilityAiHelpers.GetBlackboard(_owner);
if (blackboard == null)
{
return false;
}
_target = blackboard.GetState<LastOpenedStorageState>().GetValue();
return _target != null;
}
public override bool Shutdown(Outcome outcome)
{
if (!base.Shutdown(outcome))
return false;
var blackboard = UtilityAiHelpers.GetBlackboard(_owner);
blackboard?.GetState<LastOpenedStorageState>().SetValue(null);
return true;
}
public override Outcome Execute(float frameTime)
{
if (!_owner.InRangeUnobstructed(_target, popup: true))
{
return Outcome.Failed;
}
if (!_target.TryGetComponent(out EntityStorageComponent storageComponent) ||
storageComponent.IsWeldedShut)
{
return Outcome.Failed;
}
if (storageComponent.Open)
{
var activateArgs = new ActivateEventArgs {User = _owner, Target = _target};
storageComponent.Activate(activateArgs);
}
return Outcome.Success;
}
}
}