ItemCounterSystem.cs 1001 B

12345678910111213141516171819202122232425262728293031
  1. using Content.Shared.Storage;
  2. using Content.Shared.Storage.Components;
  3. using Content.Shared.Storage.EntitySystems;
  4. using Content.Shared.Whitelist;
  5. using JetBrains.Annotations;
  6. using Robust.Shared.Containers;
  7. namespace Content.Server.Storage.EntitySystems
  8. {
  9. [UsedImplicitly]
  10. public sealed class ItemCounterSystem : SharedItemCounterSystem
  11. {
  12. [Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
  13. protected override int? GetCount(ContainerModifiedMessage msg, ItemCounterComponent itemCounter)
  14. {
  15. if (!EntityManager.TryGetComponent(msg.Container.Owner, out StorageComponent? component))
  16. {
  17. return null;
  18. }
  19. var count = 0;
  20. foreach (var entity in component.Container.ContainedEntities)
  21. {
  22. if (_whitelistSystem.IsWhitelistPass(itemCounter.Count, entity))
  23. count++;
  24. }
  25. return count;
  26. }
  27. }
  28. }