Files
tbd-station-14/Content.Server/GameObjects/Components/ContainerExt/ContainerExt.cs
Acruid 6c081d9d8d Shared Containers (#3331)
* Namespace changes for containers.
Moved ContainerSlot from content to engine.

* Merged client/server ContainerManagerComponents into a single shared version.

* Mapfile and nullability fixes.

* Upgrades map.

* Update engine.
2021-03-01 15:24:46 -08:00

24 lines
768 B
C#

using Robust.Shared.Containers;
namespace Content.Server.GameObjects
{
public static class ContainerExt
{
public static int CountPrototypeOccurencesRecursive(this ContainerManagerComponent mgr, string prototypeId)
{
int total = 0;
foreach (var container in mgr.GetAllContainers())
{
foreach (var entity in container.ContainedEntities)
{
if (entity.Prototype?.ID == prototypeId) total++;
if(!entity.TryGetComponent<ContainerManagerComponent>(out var component)) continue;
total += component.CountPrototypeOccurencesRecursive(prototypeId);
}
}
return total;
}
}
}