Stack storage fixes (#17651)

This commit is contained in:
Nemanja
2023-06-27 20:30:03 -04:00
committed by GitHub
parent 76cd2be31a
commit 6fb7879041
3 changed files with 20 additions and 13 deletions

View File

@@ -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; namespace Content.Server.Item;
public sealed class ItemSystem : SharedItemSystem 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<ServerStorageComponent>(container.Owner, out var storage))
return;
_storage.RecalculateStorageUsed(storage);
_storage.UpdateStorageUI(container.Owner, storage);
}
} }

View File

@@ -484,7 +484,7 @@ namespace Content.Server.Storage.EntitySystems
/// <summary> /// <summary>
/// Verifies if an entity can be stored and if it fits /// Verifies if an entity can be stored and if it fits
/// </summary> /// </summary>
/// <param name="entity">The entity to check</param> /// <param name="uid">The entity to check</param>
/// <param name="reason">If returning false, the reason displayed to the player</param> /// <param name="reason">If returning false, the reason displayed to the player</param>
/// <returns>true if it can be inserted, false otherwise</returns> /// <returns>true if it can be inserted, false otherwise</returns>
public bool CanInsert(EntityUid uid, EntityUid insertEnt, out string? reason, ServerStorageComponent? storageComp = null) 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) && if (TryComp(insertEnt, out ItemComponent? itemComp) &&
itemComp.Size > storageComp.StorageCapacityMax - storageComp.StorageUsed) 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. reason = "comp-storage-insufficient-capacity";
// If so, no extra space would be used. return false;
//
// 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 = null; reason = null;

View File

@@ -78,7 +78,7 @@ public abstract class SharedItemSystem : EntitySystem
args.Handled = _handsSystem.TryPickup(args.User, uid, animateUser: false); 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<StackComponent>(uid, out var stack)) if (!TryComp<StackComponent>(uid, out var stack))
return; return;