Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
nekiro committed Dec 19, 2024
1 parent 3b94ced commit 43ae494
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1196,22 +1196,22 @@ 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);

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

Expand All @@ -1222,26 +1222,20 @@ 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);
}
} 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()) {
if (itemIndex != -1) {
fromCylinder->postRemoveNotification(item, toCylinder, itemIndex);
}

Expand Down

0 comments on commit 43ae494

Please sign in to comment.