Files

30 lines
857 B
C#
Raw Permalink Normal View History

2023-09-11 21:20:46 +10:00
using Content.Shared.Storage;
using Content.Shared.Storage.Components;
using Content.Shared.Storage.EntitySystems;
using JetBrains.Annotations;
using Robust.Shared.Containers;
namespace Content.Server.Storage.EntitySystems
{
[UsedImplicitly]
public sealed class ItemCounterSystem : SharedItemCounterSystem
{
protected override int? GetCount(ContainerModifiedMessage msg, ItemCounterComponent itemCounter)
{
2023-09-11 21:20:46 +10:00
if (!EntityManager.TryGetComponent(msg.Container.Owner, out StorageComponent? component))
{
return null;
}
var count = 0;
2023-09-11 21:20:46 +10:00
foreach (var entity in component.Container.ContainedEntities)
{
2023-09-11 21:20:46 +10:00
if (itemCounter.Count.IsValid(entity))
count++;
}
return count;
}
}
2021-11-09 13:08:09 +01:00
}