Skip to content

Commit

Permalink
fix: sending items to stash interrupted by items obtained from store (
Browse files Browse the repository at this point in the history
…#2886)

• 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
  • Loading branch information
Luan Luciano authored Nov 13, 2024
1 parent 1382b77 commit 982f184
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8018,7 +8018,7 @@ void sendStowItems(const std::shared_ptr<Item> &item, const std::shared_ptr<Item
}

void Player::stowItem(const std::shared_ptr<Item> &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;
}
Expand Down
32 changes: 18 additions & 14 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1667,7 +1667,7 @@ void Game::playerMoveItemByPlayerID(uint32_t playerId, const Position &fromPos,

void Game::playerMoveItem(const std::shared_ptr<Player> &player, const Position &fromPos, uint16_t itemId, uint8_t fromStackPos, const Position &toPos, uint8_t count, std::shared_ptr<Item> item, std::shared_ptr<Cylinder> 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] {
Expand Down Expand Up @@ -1742,7 +1742,7 @@ void Game::playerMoveItem(const std::shared_ptr<Player> &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;
}
Expand Down Expand Up @@ -1774,8 +1774,8 @@ void Game::playerMoveItem(const std::shared_ptr<Player> &player, const Position
return;
}

std::shared_ptr<Tile> 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)) {
Expand All @@ -1794,22 +1794,22 @@ void Game::playerMoveItem(const std::shared_ptr<Player> &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)
&& !Position::areInRange<1, 1, 0>(mapFromPos, walkPos)) {
// need to pickup the item first
std::shared_ptr<Item> 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;
Expand Down Expand Up @@ -1837,7 +1837,7 @@ void Game::playerMoveItem(const std::shared_ptr<Player> &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;
Expand Down Expand Up @@ -1866,8 +1866,8 @@ void Game::playerMoveItem(const std::shared_ptr<Player> &player, const Position
}

if (item->isWrapable() || item->isStoreItem() || (item->hasOwner() && !item->isOwner(player))) {
auto toHouseTile = map.getTile(mapToPos)->dynamic_self_cast<HouseTile>();
auto fromHouseTile = map.getTile(mapFromPos)->dynamic_self_cast<HouseTile>();
const auto toHouseTile = map.getTile(mapToPos)->dynamic_self_cast<HouseTile>();
const auto fromHouseTile = map.getTile(mapFromPos)->dynamic_self_cast<HouseTile>();
if (fromHouseTile && (!toHouseTile || toHouseTile->getHouse()->getId() != fromHouseTile->getHouse()->getId())) {
player->sendCancelMessage("You cannot move this item out of this house.");
return;
Expand All @@ -1882,12 +1882,14 @@ void Game::playerMoveItem(const std::shared_ptr<Player> &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();
Expand Down Expand Up @@ -1916,7 +1918,9 @@ ReturnValue Game::checkMoveItemToCylinder(const std::shared_ptr<Player> &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;
}
Expand All @@ -1942,7 +1946,7 @@ ReturnValue Game::checkMoveItemToCylinder(const std::shared_ptr<Player> &player,
return RETURNVALUE_NOTBOUGHTINSTORE;
}

if (item->isStoreItem()) {
if (item->isStoreItem() && !containerToStow) {
bool isValidMoveItem = false;
auto fromHouseTile = fromCylinder->getTile();
auto house = fromHouseTile ? fromHouseTile->getHouse() : nullptr;
Expand Down Expand Up @@ -1973,7 +1977,7 @@ ReturnValue Game::checkMoveItemToCylinder(const std::shared_ptr<Player> &player,

if (item->getContainer() && !item->isStoreItem()) {
for (const std::shared_ptr<Item> &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;
}
}
Expand Down

0 comments on commit 982f184

Please sign in to comment.