From 4645dbb33c052bfc583bed1eb5e3fdb1ee310c45 Mon Sep 17 00:00:00 2001 From: ike709 Date: Wed, 6 Jul 2022 19:45:00 -0500 Subject: [PATCH] Makes storage insertion failure more explicit (#9465) --- .../PneumaticCannon/PneumaticCannonSystem.cs | 2 +- .../Storage/EntitySystems/StorageSystem.cs | 28 ++++++++++++++++--- .../en-US/components/storage-component.ftl | 3 ++ 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/Content.Server/PneumaticCannon/PneumaticCannonSystem.cs b/Content.Server/PneumaticCannon/PneumaticCannonSystem.cs index 88364fa810..e826ff3cdf 100644 --- a/Content.Server/PneumaticCannon/PneumaticCannonSystem.cs +++ b/Content.Server/PneumaticCannon/PneumaticCannonSystem.cs @@ -135,7 +135,7 @@ namespace Content.Server.PneumaticCannon if (EntityManager.TryGetComponent(args.Used, out var item) && EntityManager.TryGetComponent(component.Owner, out var storage)) { - if (_storageSystem.CanInsert(component.Owner, args.Used, storage)) + if (_storageSystem.CanInsert(component.Owner, args.Used, out _, storage)) { _storageSystem.Insert(component.Owner, args.Used, storage); args.User.PopupMessage(Loc.GetString("pneumatic-cannon-component-insert-item-success", diff --git a/Content.Server/Storage/EntitySystems/StorageSystem.cs b/Content.Server/Storage/EntitySystems/StorageSystem.cs index 95cae59875..0db9ab9d4d 100644 --- a/Content.Server/Storage/EntitySystems/StorageSystem.cs +++ b/Content.Server/Storage/EntitySystems/StorageSystem.cs @@ -474,29 +474,49 @@ namespace Content.Server.Storage.EntitySystems /// Verifies if an entity can be stored and if it fits /// /// 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, ServerStorageComponent? storageComp = null) + public bool CanInsert(EntityUid uid, EntityUid insertEnt, out string? reason, ServerStorageComponent? storageComp = null) { if (!Resolve(uid, ref storageComp)) + { + reason = null; return false; + } if (TryComp(insertEnt, out ServerStorageComponent? storage) && storage.StorageCapacityMax >= storageComp.StorageCapacityMax) + { + reason = "comp-storage-insufficient-capacity"; return false; + } if (TryComp(insertEnt, out SharedItemComponent? itemComp) && itemComp.Size > storageComp.StorageCapacityMax - storageComp.StorageUsed) + { + reason = "comp-storage-insufficient-capacity"; return false; + } if (storageComp.Whitelist?.IsValid(insertEnt, EntityManager) == false) + { + reason = "comp-storage-invalid-container"; return false; + } if (storageComp.Blacklist?.IsValid(insertEnt, EntityManager) == true) + { + reason = "comp-storage-invalid-container"; return false; + } if (TryComp(insertEnt, out TransformComponent? transformComp) && transformComp.Anchored) + { + reason = "comp-storage-anchored-failure"; return false; + } + reason = null; return true; } @@ -510,7 +530,7 @@ namespace Content.Server.Storage.EntitySystems if (!Resolve(uid, ref storageComp)) return false; - if (!CanInsert(uid, insertEnt, storageComp) || storageComp.Storage?.Insert(insertEnt) == false) + if (!CanInsert(uid, insertEnt, out _, storageComp) || storageComp.Storage?.Insert(insertEnt) == false) return false; if (storageComp.StorageInsertSound is not null) @@ -550,9 +570,9 @@ namespace Content.Server.Storage.EntitySystems var toInsert = hands.ActiveHandEntity; - if (!CanInsert(uid, toInsert.Value, storageComp) || !_sharedHandsSystem.TryDrop(player, toInsert.Value, handsComp: hands)) + if (!CanInsert(uid, toInsert.Value, out var reason, storageComp) || !_sharedHandsSystem.TryDrop(player, toInsert.Value, handsComp: hands)) { - Popup(uid, player, "comp-storage-cant-insert", storageComp); + Popup(uid, player, reason ?? "comp-storage-cant-insert", storageComp); return false; } diff --git a/Resources/Locale/en-US/components/storage-component.ftl b/Resources/Locale/en-US/components/storage-component.ftl index 7b9346fd3a..ab45c1e361 100644 --- a/Resources/Locale/en-US/components/storage-component.ftl +++ b/Resources/Locale/en-US/components/storage-component.ftl @@ -1,5 +1,8 @@ comp-storage-no-item-size = None comp-storage-cant-insert = Can't insert. +comp-storage-insufficient-capacity = Insufficient capacity. +comp-storage-invalid-container = Invalid container for this item. +comp-storage-anchored-failure = Can't insert an anchored item. comp-storage-window-title = Storage Item comp-storage-window-volume = Items: { $itemCount }, Stored: { $usedVolume }/{ $maxVolume } comp-storage-window-volume-unlimited = Items: { $itemCount }