using System.Linq; using Content.Server.Administration; using Content.Shared.Administration; using Content.Shared.Item; using Content.Shared.Storage; using Content.Shared.Storage.EntitySystems; using Robust.Shared.Containers; using Robust.Shared.Toolshed; namespace Content.Server.Storage; [ToolshedCommand, AdminCommand(AdminFlags.Debug)] public sealed class StorageCommand : ToolshedCommand { private SharedStorageSystem? _storage; private SharedContainerSystem? _container; [CommandImplementation("insert")] public IEnumerable StorageInsert([PipedArgument] IEnumerable entsToInsert, EntityUid targetEnt) => entsToInsert.Where(x => StorageInsert(x, targetEnt) != null); public EntityUid? StorageInsert(EntityUid entToInsert, EntityUid targetEnt) { _storage ??= GetSys(); if (!EntityManager.TryGetComponent(targetEnt, out var storage)) return null; return _storage.Insert(targetEnt, entToInsert, out var stackedEntity, null, storage, false) ? entToInsert : null; } [CommandImplementation("fasttake")] public IEnumerable StorageFastTake([PipedArgument] IEnumerable storageEnts) => storageEnts.Select(StorageFastTake).OfType(); public EntityUid? StorageFastTake(EntityUid storageEnt) { _storage ??= GetSys(); _container ??= GetSys(); if (!EntityManager.TryGetComponent(storageEnt, out var storage)) return null; var removing = storage.Container.ContainedEntities[^1]; if (_container.RemoveEntity(storageEnt, removing)) return removing; return null; } }