Skip to content

Commit

Permalink
fix: can't sell containers with items inside (#2911)
Browse files Browse the repository at this point in the history
# Description

It will not be possible to sell backpacks that contain items inside.
  • Loading branch information
dudantas authored Sep 28, 2024
1 parent edeff04 commit 09c16ff
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/creatures/npcs/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,13 @@ void Npc::onPlayerSellItem(std::shared_ptr<Player> player, uint16_t itemId, uint
continue;
}

if (const auto &container = item->getContainer()) {
if (container->size() > 0) {

Check warning on line 391 in src/creatures/npcs/npc.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

container-size-empty

the 'empty' method should be used to check for emptiness instead of 'size'
player->sendTextMessage(MESSAGE_EVENT_ADVANCE, "You must empty the container before selling it.");
continue;
}
}

if (parent && item->getParent() != parent) {
continue;
}
Expand Down
6 changes: 6 additions & 0 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4120,6 +4120,12 @@ std::map<uint32_t, uint32_t> &Player::getAllItemTypeCount(std::map<uint32_t, uin

std::map<uint16_t, uint16_t> &Player::getAllSaleItemIdAndCount(std::map<uint16_t, uint16_t> &countMap) const {
for (const auto &item : getAllInventoryItems(false, true)) {
if (const auto &container = item->getContainer()) {
if (container->size() > 0) {

Check warning on line 4124 in src/creatures/players/player.cpp

View workflow job for this annotation

GitHub Actions / Qodana for C/C++

container-size-empty

the 'empty' method should be used to check for emptiness instead of 'size'
continue;
}
}

countMap[item->getID()] += item->getItemCount();
}

Expand Down

0 comments on commit 09c16ff

Please sign in to comment.