Skip to content

Commit

Permalink
Fixed buying npc items when there are no slots available (#454)
Browse files Browse the repository at this point in the history
Example: when trying to buy 100 non-stackable items with a free slot, it would remove the money from 100 but only deliver one item
  • Loading branch information
dudantas authored Jul 26, 2022
1 parent ac2f5b2 commit beafc99
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/creatures/npcs/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,18 +222,18 @@ void Npc::onThink(uint32_t interval)
void Npc::onPlayerBuyItem(Player* player, uint16_t itemId,
uint8_t subType, uint8_t amount, bool ignore, bool inBackpacks)
{
if (!player) {
if (player == nullptr) {
SPDLOG_ERROR("[Npc::onPlayerBuyItem] - Player is nullptr");
return;
}

// Check if the player not have empty slots
if (player->getFreeBackpackSlots() == 0) {
const ItemType& itemType = Item::items[itemId];
if (!itemType.stackable && player->getFreeBackpackSlots() < amount || player->getFreeBackpackSlots() == 0) {
player->sendCancelMessage(RETURNVALUE_NOTENOUGHROOM);
return;
}

uint32_t buyPrice = 0;
const ItemType& itemType = Item::items[itemId];
const std::vector<ShopBlock> &shopVector = getShopItemVector();
for (ShopBlock shopBlock : shopVector)
{
Expand Down

0 comments on commit beafc99

Please sign in to comment.