diff --git a/Source/player.cpp b/Source/player.cpp index fbf481dc8..8a017072f 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -1937,34 +1937,35 @@ bool Player::HasItem(int item, int *idx) const void Player::RemoveInvItem(int iv, bool calcScrolls) { - iv++; - // Iterate through invGrid and remove every reference to item - for (int8_t &itemId : InvGrid) { - if (itemId == iv || itemId == -iv) { - itemId = 0; + for (int8_t &itemIndex : InvGrid) { + if (abs(itemIndex) - 1 == iv) { + itemIndex = 0; } } - iv--; + InvList[iv]._itype = ItemType::None; + _pNumInv--; // If the item at the end of inventory array isn't the one we removed, we need to swap its position in the array with the removed item if (_pNumInv > 0 && _pNumInv != iv) { InvList[iv] = InvList[_pNumInv]; + InvList[_pNumInv]._itype = ItemType::None; - for (int8_t &itemId : InvGrid) { - if (itemId == _pNumInv + 1) { - itemId = iv + 1; + for (int8_t &itemIndex : InvGrid) { + if (itemIndex == _pNumInv + 1) { + itemIndex = iv + 1; } - if (itemId == -(_pNumInv + 1)) { - itemId = -(iv + 1); + if (itemIndex == -(_pNumInv + 1)) { + itemIndex = -(iv + 1); } } } - if (calcScrolls) + if (calcScrolls) { CalcScrolls(); + } } bool Player::TryRemoveInvItemById(int item)