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