Browse Source

Invalidate removed inventory items

inv
Anders Jenbo 4 years ago
parent
commit
ef669d3469
  1. 25
      Source/player.cpp

25
Source/player.cpp

@ -1937,34 +1937,35 @@ bool Player::HasItem(int item, int *idx) const
void Player::RemoveInvItem(int iv, bool calcScrolls) void Player::RemoveInvItem(int iv, bool calcScrolls)
{ {
iv++;
// Iterate through invGrid and remove every reference to item // Iterate through invGrid and remove every reference to item
for (int8_t &itemId : InvGrid) { for (int8_t &itemIndex : InvGrid) {
if (itemId == iv || itemId == -iv) { if (abs(itemIndex) - 1 == iv) {
itemId = 0; itemIndex = 0;
} }
} }
iv--; InvList[iv]._itype = ItemType::None;
_pNumInv--; _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 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) { if (_pNumInv > 0 && _pNumInv != iv) {
InvList[iv] = InvList[_pNumInv]; InvList[iv] = InvList[_pNumInv];
InvList[_pNumInv]._itype = ItemType::None;
for (int8_t &itemId : InvGrid) { for (int8_t &itemIndex : InvGrid) {
if (itemId == _pNumInv + 1) { if (itemIndex == _pNumInv + 1) {
itemId = iv + 1; itemIndex = iv + 1;
} }
if (itemId == -(_pNumInv + 1)) { if (itemIndex == -(_pNumInv + 1)) {
itemId = -(iv + 1); itemIndex = -(iv + 1);
} }
} }
} }
if (calcScrolls) if (calcScrolls) {
CalcScrolls(); CalcScrolls();
}
} }
bool Player::TryRemoveInvItemById(int item) bool Player::TryRemoveInvItemById(int item)

Loading…
Cancel
Save