2021-09-04 19:42:32 +02:00
|
|
|
|
using Content.Server.Storage.Components;
|
|
|
|
|
|
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]
|
|
|
|
|
|
public class ItemCounterSystem : SharedItemCounterSystem
|
|
|
|
|
|
{
|
2021-09-04 19:42:32 +02:00
|
|
|
|
protected override int? GetCount(ContainerModifiedMessage msg, ItemCounterComponent itemCounter)
|
2021-07-22 11:56:55 +02:00
|
|
|
|
{
|
2021-09-04 19:42:32 +02:00
|
|
|
|
if (!msg.Container.Owner.TryGetComponent(out ServerStorageComponent? component)
|
|
|
|
|
|
|| component.StoredEntities == null)
|
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;
|
|
|
|
|
|
foreach (var entity in component.StoredEntities)
|
|
|
|
|
|
{
|
|
|
|
|
|
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-09-04 19:42:32 +02:00
|
|
|
|
}
|