Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makes storage insertion failure more explicit #9465

Merged
merged 3 commits into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Content.Server/PneumaticCannon/PneumaticCannonSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private void OnInteractUsing(EntityUid uid, PneumaticCannonComponent component,
if (EntityManager.TryGetComponent<SharedItemComponent?>(args.Used, out var item)
&& EntityManager.TryGetComponent<ServerStorageComponent?>(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",
Expand Down
28 changes: 24 additions & 4 deletions Content.Server/Storage/EntitySystems/StorageSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -474,29 +474,49 @@ public void TransferEntities(EntityUid source, EntityUid target,
/// Verifies if an entity can be stored and if it fits
/// </summary>
/// <param name="entity">The entity to check</param>
/// <param name="reason">If returning false, the reason displayed to the player</param>
/// <returns>true if it can be inserted, false otherwise</returns>
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;
}

Expand All @@ -510,7 +530,7 @@ public bool Insert(EntityUid uid, EntityUid insertEnt, ServerStorageComponent? s
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)
Expand Down Expand Up @@ -550,9 +570,9 @@ public bool PlayerInsertHeldEntity(EntityUid uid, EntityUid player, ServerStorag

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;
}

Expand Down
3 changes: 3 additions & 0 deletions Resources/Locale/en-US/components/storage-component.ftl
Original file line number Diff line number Diff line change
@@ -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 }