From 6fb78790412db6d8f0f0c2b7260a5ec41aebd639 Mon Sep 17 00:00:00 2001 From: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> Date: Tue, 27 Jun 2023 20:30:03 -0400 Subject: [PATCH] Stack storage fixes (#17651) --- Content.Server/Item/ItemSystem.cs | 17 ++++++++++++++++- .../Storage/EntitySystems/StorageSystem.cs | 14 +++----------- Content.Shared/Item/SharedItemSystem.cs | 2 +- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/Content.Server/Item/ItemSystem.cs b/Content.Server/Item/ItemSystem.cs index 9053ec05cd..33c95d3780 100644 --- a/Content.Server/Item/ItemSystem.cs +++ b/Content.Server/Item/ItemSystem.cs @@ -1,7 +1,22 @@ -using Content.Shared.Item; +using Content.Server.Storage.Components; +using Content.Server.Storage.EntitySystems; +using Content.Shared.Item; +using Content.Shared.Stacks; namespace Content.Server.Item; public sealed class ItemSystem : SharedItemSystem { + [Dependency] private readonly StorageSystem _storage = default!; + + protected override void OnStackCountChanged(EntityUid uid, ItemComponent component, StackCountChangedEvent args) + { + base.OnStackCountChanged(uid, component, args); + + if (!Container.TryGetContainingContainer(uid, out var container) || + !TryComp(container.Owner, out var storage)) + return; + _storage.RecalculateStorageUsed(storage); + _storage.UpdateStorageUI(container.Owner, storage); + } } diff --git a/Content.Server/Storage/EntitySystems/StorageSystem.cs b/Content.Server/Storage/EntitySystems/StorageSystem.cs index 9ce1585c9c..d946702e6d 100644 --- a/Content.Server/Storage/EntitySystems/StorageSystem.cs +++ b/Content.Server/Storage/EntitySystems/StorageSystem.cs @@ -484,7 +484,7 @@ namespace Content.Server.Storage.EntitySystems /// /// Verifies if an entity can be stored and if it fits /// - /// The entity to check + /// The entity to check /// If returning false, the reason displayed to the player /// true if it can be inserted, false otherwise public bool CanInsert(EntityUid uid, EntityUid insertEnt, out string? reason, ServerStorageComponent? storageComp = null) @@ -523,16 +523,8 @@ namespace Content.Server.Storage.EntitySystems if (TryComp(insertEnt, out ItemComponent? itemComp) && itemComp.Size > storageComp.StorageCapacityMax - storageComp.StorageUsed) { - // If this is a stack, we may be able to combine it with an existing stack in the storage. - // If so, no extra space would be used. - // - // TODO: This doesn't allow any sort of top-up behavior. - // You either combine the whole stack, or insert nothing. - if (!TryComp(insertEnt, out StackComponent? stackComp) || !CanCombineStacks(storageComp, stackComp)) - { - reason = "comp-storage-insufficient-capacity"; - return false; - } + reason = "comp-storage-insufficient-capacity"; + return false; } reason = null; diff --git a/Content.Shared/Item/SharedItemSystem.cs b/Content.Shared/Item/SharedItemSystem.cs index da9b486748..cd68c3e31a 100644 --- a/Content.Shared/Item/SharedItemSystem.cs +++ b/Content.Shared/Item/SharedItemSystem.cs @@ -78,7 +78,7 @@ public abstract class SharedItemSystem : EntitySystem args.Handled = _handsSystem.TryPickup(args.User, uid, animateUser: false); } - private void OnStackCountChanged(EntityUid uid, ItemComponent component, StackCountChangedEvent args) + protected virtual void OnStackCountChanged(EntityUid uid, ItemComponent component, StackCountChangedEvent args) { if (!TryComp(uid, out var stack)) return;