diff options
author | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-07-27 15:56:01 +0200 |
---|---|---|
committer | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-07-27 15:56:01 +0200 |
commit | 8733bd880c487782f32dbf47c35d099b928450ee (patch) | |
tree | f598bc73e0f7dac3b3aeabda0ab62066a8d3bfd0 | |
parent | 000979800f13964ba70507ee569f458a7fdd270a (diff) | |
download | manaserv-8733bd880c487782f32dbf47c35d099b928450ee.tar.gz manaserv-8733bd880c487782f32dbf47c35d099b928450ee.tar.bz2 manaserv-8733bd880c487782f32dbf47c35d099b928450ee.tar.xz manaserv-8733bd880c487782f32dbf47c35d099b928450ee.zip |
Reviewed the Inventory::insertion function.
-rw-r--r-- | src/game-server/inventory.cpp | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/game-server/inventory.cpp b/src/game-server/inventory.cpp index 4f08fc67..e0b7e1c5 100644 --- a/src/game-server/inventory.cpp +++ b/src/game-server/inventory.cpp @@ -196,9 +196,14 @@ unsigned int Inventory::insert(unsigned int itemId, unsigned int amount) MessageOut invMsg(GPMSG_INVENTORY); unsigned int maxPerSlot = itemManager->getItem(itemId)->getMaxPerSlot(); + + LOG_DEBUG("Inventory: Inserting " << amount << " item(s) Id: " << itemId + << " for character '" << mCharacter->getName() << "'."); + InventoryData::iterator it, it_end = mPoss->inventory.end(); // Add to slots with existing items of this type first. for (it = mPoss->inventory.begin(); it != it_end; ++it) + { if (it->second.itemId == itemId) { // If the slot is full, try the next slot @@ -206,16 +211,19 @@ unsigned int Inventory::insert(unsigned int itemId, unsigned int amount) continue; // Add everything that'll fit to the stack - unsigned short spaceleft = maxPerSlot - it->second.amount; - if (spaceleft >= amount) + unsigned short spaceLeft = maxPerSlot - it->second.amount; + if (spaceLeft >= amount) { it->second.amount += amount; amount = 0; + LOG_DEBUG("Everything inserted at slot id: " << it->first); } else { - it->second.amount += spaceleft; - amount -= spaceleft; + it->second.amount += spaceLeft; + amount -= spaceLeft; + LOG_DEBUG(spaceLeft << " item(s) inserted at slot id: " + << it->first); } invMsg.writeInt16(it->first); @@ -224,6 +232,7 @@ unsigned int Inventory::insert(unsigned int itemId, unsigned int amount) if (!amount) break; } + } int slot = 0; // We still have some left, so add to blank slots. @@ -238,12 +247,14 @@ unsigned int Inventory::insert(unsigned int itemId, unsigned int amount) mPoss->inventory[slot].itemId = itemId; mPoss->inventory[slot].amount = additions; amount -= additions; + LOG_DEBUG(additions << " item(s) inserted at slot id: " << slot); invMsg.writeInt16(slot++); // Last read, so also increment invMsg.writeInt16(itemId); invMsg.writeInt16(additions); } ++slot; // Skip the slot that the iterator points to - if (it == it_end) break; + if (it == it_end) + break; } // Send that first, before checking potential removals |