From 9410d17f7e9eed67b8ae3a1de95b72d2344fc7ef Mon Sep 17 00:00:00 2001 From: Damian-I Date: Sat, 8 Mar 2025 16:32:29 +0000 Subject: [PATCH] Prevent Duplicate Item Pickup in Inventory --- index.html | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index 432a58f..61caa3d 100644 --- a/index.html +++ b/index.html @@ -2595,6 +2595,13 @@ } try { + // Check if the item is already in the inventory + const isAlreadyInInventory = inventory.items.some(item => item.name === sprite.name); + if (isAlreadyInInventory) { + console.log(`Item ${sprite.name} is already in inventory, not adding again`); + return false; + } + // Remove from room if it exists if (currentRoom && rooms[currentRoom] && @@ -3032,10 +3039,15 @@ // Allow the item to be picked up even if locked if (type === 'item' && lockable.scenarioData?.takeable) { - addToInventory(lockable); - // Remove from room objects if it exists there - if (currentRoom && rooms[currentRoom].objects) { - delete rooms[currentRoom].objects[lockable.name]; + // Check if the item is already in the inventory before adding it + const isAlreadyInInventory = inventory.items.some(item => item.name === lockable.name); + + if (!isAlreadyInInventory) { + addToInventory(lockable); + // Remove from room objects if it exists there + if (currentRoom && rooms[currentRoom].objects) { + delete rooms[currentRoom].objects[lockable.name]; + } } } return;