diff --git a/Content.Server/Inventory/InventoryCommand.cs b/Content.Server/Inventory/InventoryCommand.cs index 8197889259..e628ee6e01 100644 --- a/Content.Server/Inventory/InventoryCommand.cs +++ b/Content.Server/Inventory/InventoryCommand.cs @@ -12,6 +12,27 @@ public sealed class InventoryCommand : ToolshedCommand { private InventorySystem? _inventorySystem; + [CommandImplementation("query")] + public IEnumerable InventoryQuery([PipedArgument] IEnumerable entities) => + entities.SelectMany(InventoryQuery); + + private IEnumerable InventoryQuery(EntityUid entity) + { + _inventorySystem ??= GetSys(); + + if (!EntityManager.TryGetComponent(entity, out var inventory)) + return []; + + List result = new(); + + foreach (var slot in inventory.Slots) + { + if (_inventorySystem.TryGetSlotEntity(entity, slot.Name, out var item, inventory)) + result.Add(item.Value); + } + return result; + } + [CommandImplementation("getflags")] public IEnumerable InventoryGetFlags([PipedArgument] IEnumerable ents, SlotFlags slotFlag) { @@ -44,7 +65,6 @@ public sealed class InventoryCommand : ToolshedCommand return items; } - [CommandImplementation("getnamed")] public IEnumerable InventoryGetNamed([PipedArgument] IEnumerable ents, string slotName) { @@ -81,6 +101,7 @@ public sealed class InventoryCommand : ToolshedCommand public EntityUid? InventoryForcePut([PipedArgument] IEnumerable ents, EntityUid itemEnt, SlotFlags slotFlag) => InventoryPutEnumerableBase(ents, itemEnt, slotFlag, PutType.ForcePut); + [CommandImplementation("forcespawn")] public EntityUid? InventoryForceSpawn([PipedArgument] IEnumerable ents, EntProtoId itemEnt, @@ -90,6 +111,7 @@ public sealed class InventoryCommand : ToolshedCommand public EntityUid? InventoryPut([PipedArgument] IEnumerable ents, EntityUid itemEnt, SlotFlags slotFlag) => InventoryPutEnumerableBase(ents, itemEnt, slotFlag, PutType.Put); + [CommandImplementation("spawn")] public EntityUid? InventorySpawn([PipedArgument] IEnumerable ents, EntProtoId itemEnt, @@ -99,6 +121,7 @@ public sealed class InventoryCommand : ToolshedCommand public EntityUid? InventoryTryPut([PipedArgument] IEnumerable ents, EntityUid itemEnt, SlotFlags slotFlag) => InventoryPutEnumerableBase(ents, itemEnt, slotFlag, PutType.Put); + [CommandImplementation("tryspawn")] public EntityUid? InventoryTrySpawn([PipedArgument] IEnumerable ents, EntProtoId itemEnt, @@ -108,12 +131,12 @@ public sealed class InventoryCommand : ToolshedCommand public EntityUid? InventoryEnsure([PipedArgument] IEnumerable ents, EntityUid itemEnt, SlotFlags slotFlag) => InventoryPutEnumerableBase(ents, itemEnt, slotFlag, PutType.Ensure); + [CommandImplementation("ensurespawn")] public EntityUid? InventoryEnsureSpawn([PipedArgument] IEnumerable ents, EntProtoId itemEnt, SlotFlags slotFlag) => InventorySpawnEnumerableBase(ents, itemEnt, slotFlag, PutType.Ensure); - private EntityUid? InventorySpawnEnumerableBase(IEnumerable targetEnts, EntProtoId itemToInsert, SlotFlags slotFlags, @@ -136,6 +159,7 @@ public sealed class InventoryCommand : ToolshedCommand Del(spawnedItem); return null; } + private EntityUid? InventoryPutEnumerableBase(IEnumerable targetEnts, EntityUid itemToInsert, SlotFlags slotFlags, diff --git a/Content.Server/Storage/StorageCommand.cs b/Content.Server/Storage/StorageCommand.cs index b7aee26aa9..1c39801622 100644 --- a/Content.Server/Storage/StorageCommand.cs +++ b/Content.Server/Storage/StorageCommand.cs @@ -20,7 +20,7 @@ public sealed class StorageCommand : ToolshedCommand public IEnumerable StorageInsert([PipedArgument] IEnumerable entsToInsert, EntityUid targetEnt) => entsToInsert.Where(x => StorageInsert(x, targetEnt) != null); - public EntityUid? StorageInsert(EntityUid entToInsert, EntityUid targetEnt) + private EntityUid? StorageInsert(EntityUid entToInsert, EntityUid targetEnt) { _storage ??= GetSys(); @@ -32,7 +32,6 @@ public sealed class StorageCommand : ToolshedCommand : null; } - [CommandImplementation("fasttake")] public IEnumerable StorageFastTake([PipedArgument] IEnumerable storageEnts) => storageEnts.Select(StorageFastTake).OfType(); @@ -53,6 +52,29 @@ public sealed class StorageCommand : ToolshedCommand return null; } + [CommandImplementation("query")] + public IEnumerable StorageQuery([PipedArgument] IEnumerable storageEnts, bool recursive) => + storageEnts.SelectMany(x => StorageQueryRecursiveBase(x, recursive)); + public IEnumerable StorageQueryRecursiveBase(EntityUid storageEnt, bool recursive) + { + _storage ??= GetSys(); + _container ??= GetSys(); + if (!EntityManager.TryGetComponent(storageEnt, out var storage)) + return []; + + IEnumerable containedEntities = storage.Container.ContainedEntities; + + if (recursive) + { + foreach (var ent in containedEntities) + { + containedEntities = containedEntities.Concat(StorageQueryRecursiveBase(ent, true)); + } + + } + + return containedEntities; + } } diff --git a/Resources/Locale/en-US/commands/toolshed/inventory-command.ftl b/Resources/Locale/en-US/commands/toolshed/inventory-command.ftl index 3ded73915a..f430197495 100644 --- a/Resources/Locale/en-US/commands/toolshed/inventory-command.ftl +++ b/Resources/Locale/en-US/commands/toolshed/inventory-command.ftl @@ -18,3 +18,5 @@ command-description-inventory-ensure = Puts a given entity on the first piped entity that has a slot matching the given flag if none exists, passing through the UID of whatever is in the slot by the end. command-description-inventory-ensurespawn = Spawns a given prototype on the first piped entity that has a slot matching the given flag if none exists, passing through the UID of whatever is in the slot by the end. +command-description-inventory-query = + Gets the entities in the inventory slots of the piped entities and passes them along. diff --git a/Resources/Locale/en-US/commands/toolshed/storage-command.ftl b/Resources/Locale/en-US/commands/toolshed/storage-command.ftl index 46fe1a2627..154196fbb1 100644 --- a/Resources/Locale/en-US/commands/toolshed/storage-command.ftl +++ b/Resources/Locale/en-US/commands/toolshed/storage-command.ftl @@ -2,3 +2,5 @@ command-description-storage-fasttake = Takes the most recently placed item from the piped storage entity. command-description-storage-insert = Inserts the piped entity into the given storage entity. +command-description-storage-query = + Gets the entities in the storagebase of the piped entities and passes them along.