From 982f1842192e25e304e03208a335082b18b67dcd Mon Sep 17 00:00:00 2001 From: Luan Luciano Date: Tue, 12 Nov 2024 23:55:15 -0300 Subject: [PATCH] fix: sending items to stash interrupted by items obtained from store (#2886) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • When send items from a container to the stash, the process is interrupted when there are items obtained from the store. • Fixed issue with sending items from the loot pouch to the stash --- src/creatures/players/player.cpp | 2 +- src/game/game.cpp | 32 ++++++++++++++++++-------------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index 823bd38e9e3..4eca148a1e7 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -8018,7 +8018,7 @@ void sendStowItems(const std::shared_ptr &item, const std::shared_ptr &item, uint32_t count, bool allItems) { - if (!item || !item->isItemStorable()) { + if (!item || (!item->isItemStorable() && item->getID() != ITEM_GOLD_POUCH)) { sendCancelMessage("This item cannot be stowed here."); return; } diff --git a/src/game/game.cpp b/src/game/game.cpp index 79b96b697cd..1ec06abd02b 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -1667,7 +1667,7 @@ void Game::playerMoveItemByPlayerID(uint32_t playerId, const Position &fromPos, void Game::playerMoveItem(const std::shared_ptr &player, const Position &fromPos, uint16_t itemId, uint8_t fromStackPos, const Position &toPos, uint8_t count, std::shared_ptr item, std::shared_ptr toCylinder) { if (!player->canDoAction()) { - uint32_t delay = player->getNextActionTime(); + const uint32_t delay = player->getNextActionTime(); const auto &task = createPlayerTask( delay, [this, playerId = player->getID(), fromPos, itemId, fromStackPos, toPos, count] { @@ -1742,7 +1742,7 @@ void Game::playerMoveItem(const std::shared_ptr &player, const Position } // check if we can move this item - if (ReturnValue ret = checkMoveItemToCylinder(player, fromCylinder, toCylinder, item, toPos); ret != RETURNVALUE_NOERROR) { + if (auto ret = checkMoveItemToCylinder(player, fromCylinder, toCylinder, item, toPos); ret != RETURNVALUE_NOERROR) { player->sendCancelMessage(ret); return; } @@ -1774,8 +1774,8 @@ void Game::playerMoveItem(const std::shared_ptr &player, const Position return; } - std::shared_ptr toCylinderTile = toCylinder->getTile(); - const Position &mapToPos = toCylinderTile->getPosition(); + const auto toCylinderTile = toCylinder->getTile(); + const auto &mapToPos = toCylinderTile->getPosition(); // hangable item specific code if (item->isHangable() && toCylinderTile->hasFlag(TILESTATE_SUPPORTS_HANGABLE)) { @@ -1794,14 +1794,14 @@ void Game::playerMoveItem(const std::shared_ptr &player, const Position } if (!Position::areInRange<1, 1, 0>(playerPos, mapToPos)) { - Position walkPos = mapToPos; + auto walkPos = mapToPos; if (vertical) { walkPos.x++; } else { walkPos.y++; } - Position itemPos = fromPos; + auto itemPos = fromPos; uint8_t itemStackPos = fromStackPos; if (fromPos.x != 0xFFFF && Position::areInRange<1, 1>(mapFromPos, playerPos) @@ -1809,7 +1809,7 @@ void Game::playerMoveItem(const std::shared_ptr &player, const Position // need to pickup the item first std::shared_ptr moveItem = nullptr; - ReturnValue ret = internalMoveItem(fromCylinder, player, INDEX_WHEREEVER, item, count, &moveItem); + const auto ret = internalMoveItem(fromCylinder, player, INDEX_WHEREEVER, item, count, &moveItem); if (ret != RETURNVALUE_NOERROR) { player->sendCancelMessage(ret); return; @@ -1837,7 +1837,7 @@ void Game::playerMoveItem(const std::shared_ptr &player, const Position } } - auto throwRange = item->getThrowRange(); + const auto throwRange = item->getThrowRange(); if ((Position::getDistanceX(playerPos, mapToPos) > throwRange) || (Position::getDistanceY(playerPos, mapToPos) > throwRange) || (Position::getDistanceZ(mapFromPos, mapToPos) * 4 > throwRange)) { player->sendCancelMessage(RETURNVALUE_DESTINATIONOUTOFREACH); return; @@ -1866,8 +1866,8 @@ void Game::playerMoveItem(const std::shared_ptr &player, const Position } if (item->isWrapable() || item->isStoreItem() || (item->hasOwner() && !item->isOwner(player))) { - auto toHouseTile = map.getTile(mapToPos)->dynamic_self_cast(); - auto fromHouseTile = map.getTile(mapFromPos)->dynamic_self_cast(); + const auto toHouseTile = map.getTile(mapToPos)->dynamic_self_cast(); + const auto fromHouseTile = map.getTile(mapFromPos)->dynamic_self_cast(); if (fromHouseTile && (!toHouseTile || toHouseTile->getHouse()->getId() != fromHouseTile->getHouse()->getId())) { player->sendCancelMessage("You cannot move this item out of this house."); return; @@ -1882,12 +1882,14 @@ void Game::playerMoveItem(const std::shared_ptr &player, const Position player->sendCancelMessage(RETURNVALUE_NOTMOVABLE); return; } - ReturnValue ret = internalMoveItem(fromCylinder, toCylinder, toIndex, item, count, nullptr, 0, player); + + const auto ret = internalMoveItem(fromCylinder, toCylinder, toIndex, item, count, nullptr, 0, player); if (ret != RETURNVALUE_NOERROR) { player->sendCancelMessage(ret); } else if (toCylinder->getContainer() && fromCylinder->getContainer() && fromCylinder->getContainer()->countsToLootAnalyzerBalance() && toCylinder->getContainer()->getTopParent() == player) { player->sendLootStats(item, count); } + player->cancelPush(); item->checkDecayMapItemOnMove(); @@ -1916,7 +1918,9 @@ ReturnValue Game::checkMoveItemToCylinder(const std::shared_ptr &player, } } - if (containerID == ITEM_GOLD_POUCH) { + const auto containerToStow = isTryingToStow(toPos, toCylinder); + + if (containerID == ITEM_GOLD_POUCH && !containerToStow) { if (g_configManager().getBoolean(TOGGLE_GOLD_POUCH_QUICKLOOT_ONLY)) { return RETURNVALUE_CONTAINERNOTENOUGHROOM; } @@ -1942,7 +1946,7 @@ ReturnValue Game::checkMoveItemToCylinder(const std::shared_ptr &player, return RETURNVALUE_NOTBOUGHTINSTORE; } - if (item->isStoreItem()) { + if (item->isStoreItem() && !containerToStow) { bool isValidMoveItem = false; auto fromHouseTile = fromCylinder->getTile(); auto house = fromHouseTile ? fromHouseTile->getHouse() : nullptr; @@ -1973,7 +1977,7 @@ ReturnValue Game::checkMoveItemToCylinder(const std::shared_ptr &player, if (item->getContainer() && !item->isStoreItem()) { for (const std::shared_ptr &containerItem : item->getContainer()->getItems(true)) { - if (containerItem->isStoreItem() && ((containerID != ITEM_GOLD_POUCH && containerID != ITEM_DEPOT && containerID != ITEM_STORE_INBOX) || (topParentContainer->getParent() && topParentContainer->getParent()->getContainer() && (!topParentContainer->getParent()->getContainer()->isDepotChest() || topParentContainer->getParent()->getContainer()->getID() != ITEM_STORE_INBOX)))) { + if (containerItem->isStoreItem() && !containerToStow && ((containerID != ITEM_GOLD_POUCH && containerID != ITEM_DEPOT && containerID != ITEM_STORE_INBOX) || (topParentContainer->getParent() && topParentContainer->getParent()->getContainer() && (!topParentContainer->getParent()->getContainer()->isDepotChest() || topParentContainer->getParent()->getContainer()->getID() != ITEM_STORE_INBOX)))) { return RETURNVALUE_NOTPOSSIBLE; } }