Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sending items to stash interrupted by items obtained from store #2886

Merged
merged 9 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6520,7 +6520,7 @@ void sendStowItems(const std::shared_ptr<Item> &item, const std::shared_ptr<Item
}

void Player::stowItem(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
40 changes: 22 additions & 18 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1600,7 +1600,7 @@ void Game::playerMoveItemByPlayerID(uint32_t playerId, const Position &fromPos,

void Game::playerMoveItem(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();
std::shared_ptr<Task> task = createPlayerTask(
delay, [this, playerId = player->getID(), fromPos, itemId, fromStackPos, toPos, count] {
playerMoveItemByPlayerID(playerId, fromPos, itemId, fromStackPos, toPos, count);
Expand Down Expand Up @@ -1631,7 +1631,7 @@ void Game::playerMoveItem(std::shared_ptr<Player> player, const Position &fromPo
fromIndex = fromStackPos;
}

std::shared_ptr<Thing> thing = internalGetThing(player, fromPos, fromIndex, itemId, STACKPOS_MOVE);
const auto thing = internalGetThing(player, fromPos, fromIndex, itemId, STACKPOS_MOVE);
if (!thing || !thing->getItem()) {
player->sendCancelMessage(RETURNVALUE_NOTPOSSIBLE);
return;
Expand Down Expand Up @@ -1674,14 +1674,14 @@ void Game::playerMoveItem(std::shared_ptr<Player> player, const Position &fromPo
}

// 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;
}

const Position &playerPos = player->getPosition();
auto cylinderTile = fromCylinder->getTile();
const Position &mapFromPos = cylinderTile ? cylinderTile->getPosition() : item->getPosition();
const auto &playerPos = player->getPosition();
const auto cylinderTile = fromCylinder->getTile();
const auto &mapFromPos = cylinderTile ? cylinderTile->getPosition() : item->getPosition();
if (playerPos.z != mapFromPos.z) {
player->sendCancelMessage(playerPos.z > mapFromPos.z ? RETURNVALUE_FIRSTGOUPSTAIRS : RETURNVALUE_FIRSTGODOWNSTAIRS);
return;
Expand All @@ -1706,8 +1706,8 @@ void Game::playerMoveItem(std::shared_ptr<Player> player, const Position &fromPo
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 @@ -1726,22 +1726,22 @@ void Game::playerMoveItem(std::shared_ptr<Player> player, const Position &fromPo
}

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 @@ -1769,7 +1769,7 @@ void Game::playerMoveItem(std::shared_ptr<Player> player, const Position &fromPo
}
}

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 @@ -1798,8 +1798,8 @@ void Game::playerMoveItem(std::shared_ptr<Player> player, const Position &fromPo
}

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 @@ -1814,12 +1814,14 @@ void Game::playerMoveItem(std::shared_ptr<Player> player, const Position &fromPo
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 @@ -1848,7 +1850,9 @@ ReturnValue Game::checkMoveItemToCylinder(std::shared_ptr<Player> player, std::s
}
}

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, __FUNCTION__)) {
return RETURNVALUE_CONTAINERNOTENOUGHROOM;
}
Expand All @@ -1874,7 +1878,7 @@ ReturnValue Game::checkMoveItemToCylinder(std::shared_ptr<Player> player, std::s
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 @@ -1905,7 +1909,7 @@ ReturnValue Game::checkMoveItemToCylinder(std::shared_ptr<Player> player, std::s

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
Loading