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-12-03 14:17:01 +01:00
|
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
|
using Robust.Shared.IoC;
|
2021-07-22 11:56:55 +02:00
|
|
|
|
|
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
|
|
|
|
{
|
2021-12-08 13:00:43 +01:00
|
|
|
|
if (!EntityManager.TryGetComponent(msg.Container.Owner, out ServerStorageComponent? component)
|
2021-09-04 19:42:32 +02:00
|
|
|
|
|| 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)
|
|
|
|
|
|
{
|
2021-12-03 15:53:09 +01: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
|
|
|
|
}
|