2021-03-01 15:24:46 -08:00
|
|
|
using Robust.Shared.Containers;
|
2021-12-03 11:13:58 +01:00
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
using Robust.Shared.Prototypes;
|
2020-11-22 08:38:07 +01:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.Containers
|
2020-11-22 08:38:07 +01:00
|
|
|
{
|
|
|
|
|
public static class ContainerExt
|
|
|
|
|
{
|
|
|
|
|
public static int CountPrototypeOccurencesRecursive(this ContainerManagerComponent mgr, string prototypeId)
|
|
|
|
|
{
|
2021-12-08 17:17:12 +01:00
|
|
|
var entMan = IoCManager.Resolve<IEntityManager>();
|
2020-11-22 08:38:07 +01:00
|
|
|
int total = 0;
|
|
|
|
|
foreach (var container in mgr.GetAllContainers())
|
|
|
|
|
{
|
|
|
|
|
foreach (var entity in container.ContainedEntities)
|
|
|
|
|
{
|
2021-12-08 17:17:12 +01:00
|
|
|
if (entMan.GetComponent<MetaDataComponent>(entity).EntityPrototype?.ID == prototypeId) total++;
|
|
|
|
|
if(!entMan.TryGetComponent<ContainerManagerComponent?>(entity, out var component)) continue;
|
2020-11-22 08:38:07 +01:00
|
|
|
total += component.CountPrototypeOccurencesRecursive(prototypeId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return total;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|