summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAngelo Castellani <udp.castellani@gmail.com>2011-05-15 17:53:22 -0400
committerJared Adams <jaxad0127@gmail.com>2011-05-17 11:07:07 -0600
commitf248dd42dca1f57a68de2af0174c57b9ad984ef9 (patch)
tree314e0bd2055e33b40ac70a5e98d8164b65d8ce62
parentfcc7c9d2ce4471d07fe5ed9dcc5d94a4ed8ac5fb (diff)
downloadmanaserv-f248dd42dca1f57a68de2af0174c57b9ad984ef9.tar.gz
manaserv-f248dd42dca1f57a68de2af0174c57b9ad984ef9.tar.bz2
manaserv-f248dd42dca1f57a68de2af0174c57b9ad984ef9.tar.xz
manaserv-f248dd42dca1f57a68de2af0174c57b9ad984ef9.zip
Fixed an item dupe bug
Listed: http://bugs.manasource.org/view.php?id=324 Reviewed-by: Yohann Ferreira Reviewed-by: Jared Adams
-rw-r--r--src/game-server/inventory.cpp19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/game-server/inventory.cpp b/src/game-server/inventory.cpp
index 982c19e1..bdc600fa 100644
--- a/src/game-server/inventory.cpp
+++ b/src/game-server/inventory.cpp
@@ -355,12 +355,23 @@ unsigned int Inventory::insert(unsigned int itemId, unsigned int amount)
for (it = mPoss->inventory.begin(); it != it_end; ++it)
if (it->second.itemId == itemId)
{
+ // If the slot is full, try the next slot
if (it->second.amount >= maxPerSlot)
continue;
- unsigned short additions = std::min(amount, maxPerSlot)
- - it->second.amount;
- amount -= additions;
- it->second.amount += additions;
+
+ // Add everything that'll fit to the stack
+ unsigned short spaceleft = maxPerSlot - it->second.amount;
+ if (spaceleft >= amount)
+ {
+ it->second.amount += amount;
+ amount = 0;
+ }
+ else
+ {
+ it->second.amount += spaceleft;
+ amount -= spaceleft;
+ }
+
mInvMsg.writeInt16(it->first);
mInvMsg.writeInt16(itemId);
mInvMsg.writeInt16(it->second.amount);