From 3fc3a4f98fcbd5a5f89d34aa4529f651c45d0cf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Ja=C5=82ocha?= Date: Fri, 20 Dec 2024 00:15:11 +0100 Subject: [PATCH] fix bugs --- src/game.cpp | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/game.cpp b/src/game.cpp index 0344956df6..6471e778d8 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1196,22 +1196,23 @@ ReturnValue Game::internalMoveItem(Cylinder* fromCylinder, Cylinder* toCylinder, } } - Item* moveItem = nullptr; - - // remove the item + Item* moveItem = item; int32_t itemIndex = fromCylinder->getThingIndex(item); Item* updateItem = nullptr; - fromCylinder->removeThing(item, moveCount); + // update item(s) if (item->isStackable()) { // lets find out how much we need to move uint32_t allowedCount = 0; - if (item->equals(toItem)) { + // when item is moved onto another equal item + if (item->equals(toItem) && moveCount != ITEM_STACK_SIZE) { allowedCount = std::min(ITEM_STACK_SIZE - toItem->getItemCount(), moveCount); if (allowedCount > 0) { + fromCylinder->removeThing(item, allowedCount); toCylinder->updateThing(toItem, toItem->getID(), toItem->getItemCount() + allowedCount); updateItem = toItem; + moveItem = nullptr; } } @@ -1222,27 +1223,21 @@ ReturnValue Game::internalMoveItem(Cylinder* fromCylinder, Cylinder* toCylinder, moveItem = item->clone(); moveItem->setItemCount(newCount); - // source item may get deleted if move count is actually the whole source count, so let's release it if - // needed if (item->isRemoved()) { - ReleaseItem(item); + item->onRemoved(); } - } else { - // whole source item is moved - moveItem = item; } } - } else { - moveItem = item; } // add item if (moveItem) { + fromCylinder->removeThing(item, moveCount); toCylinder->addThing(index, moveItem); } - if (itemIndex != -1 && !item->hasParent()) { - fromCylinder->postRemoveNotification(item, toCylinder, itemIndex); + if (itemIndex != -1) { + fromCylinder->postRemoveNotification(item, toCylinder, itemIndex, LINK_OWNER); } if (moveItem) {