diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-11-03 15:54:23 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-11-03 15:54:23 +0300 |
commit | cd636f7e367cfb7fa2c348d00071301a480d62c3 (patch) | |
tree | 2ed2f2565362aec0b02a1de0f4bdc5d6f6c3bc6e /src/inventory.cpp | |
parent | b86f75e0faf7d646d5414cb6a6893bbb07131315 (diff) | |
download | manaplus-cd636f7e367cfb7fa2c348d00071301a480d62c3.tar.gz manaplus-cd636f7e367cfb7fa2c348d00071301a480d62c3.tar.bz2 manaplus-cd636f7e367cfb7fa2c348d00071301a480d62c3.tar.xz manaplus-cd636f7e367cfb7fa2c348d00071301a480d62c3.zip |
Fix removing items from npc inventory (restore amount in player inventory)
Diffstat (limited to 'src/inventory.cpp')
-rw-r--r-- | src/inventory.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/inventory.cpp b/src/inventory.cpp index 29df424e1..3240f9d8f 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -443,3 +443,19 @@ void Inventory::restoreVirtuals() } mVirtualRemove.clear(); } + +void Inventory::virtualRestore(const Item *const item, + const int amount) +{ + const int index = item->getTag(); + const IntMapCIter it = mVirtualRemove.find(index); + if (it != mVirtualRemove.end()) + { + mVirtualRemove[index] -= amount; + if (mVirtualRemove[index] < 0) + mVirtualRemove.erase(index); + if (index < 0 || index >= static_cast<int>(mSize) || !mItems[index]) + return; + mItems[index]->mQuantity += amount; + } +} |