summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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);