From 09c16ff620b2cd9cfd5a25af97f493aa2c8ad9bf Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Fri, 27 Sep 2024 23:47:15 -0300 Subject: [PATCH] fix: can't sell containers with items inside (#2911) # Description It will not be possible to sell backpacks that contain items inside. --- src/creatures/npcs/npc.cpp | 7 +++++++ src/creatures/players/player.cpp | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/src/creatures/npcs/npc.cpp b/src/creatures/npcs/npc.cpp index 6d38524aef3..05f22780ada 100644 --- a/src/creatures/npcs/npc.cpp +++ b/src/creatures/npcs/npc.cpp @@ -387,6 +387,13 @@ void Npc::onPlayerSellItem(std::shared_ptr player, uint16_t itemId, uint continue; } + if (const auto &container = item->getContainer()) { + if (container->size() > 0) { + player->sendTextMessage(MESSAGE_EVENT_ADVANCE, "You must empty the container before selling it."); + continue; + } + } + if (parent && item->getParent() != parent) { continue; } diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index f9fafee1f14..b923dd952d2 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -4120,6 +4120,12 @@ std::map &Player::getAllItemTypeCount(std::map &Player::getAllSaleItemIdAndCount(std::map &countMap) const { for (const auto &item : getAllInventoryItems(false, true)) { + if (const auto &container = item->getContainer()) { + if (container->size() > 0) { + continue; + } + } + countMap[item->getID()] += item->getItemCount(); }