summaryrefslogtreecommitdiff
path: root/src/game-server/inventory.cpp
diff options
context:
space:
mode:
authorYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-07-27 16:02:42 +0200
committerYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-07-27 16:02:42 +0200
commitdcfd6c115a575e2fb19ff736f720f3ff67ffef7c (patch)
tree774954b3b232eb774a9374fc0ab79c3e6ac183af /src/game-server/inventory.cpp
parent8733bd880c487782f32dbf47c35d099b928450ee (diff)
downloadmanaserv-dcfd6c115a575e2fb19ff736f720f3ff67ffef7c.tar.gz
manaserv-dcfd6c115a575e2fb19ff736f720f3ff67ffef7c.tar.bz2
manaserv-dcfd6c115a575e2fb19ff736f720f3ff67ffef7c.tar.xz
manaserv-dcfd6c115a575e2fb19ff736f720f3ff67ffef7c.zip
Reviewed the Inventory::remove() function.
The unecessary equipment check was already removed, but the now useless force parameter is now also removed.
Diffstat (limited to 'src/game-server/inventory.cpp')
-rw-r--r--src/game-server/inventory.cpp23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/game-server/inventory.cpp b/src/game-server/inventory.cpp
index e0b7e1c5..83ab08de 100644
--- a/src/game-server/inventory.cpp
+++ b/src/game-server/inventory.cpp
@@ -277,15 +277,20 @@ unsigned int Inventory::count(unsigned int itemId) const
return nb;
}
-unsigned int Inventory::remove(unsigned int itemId, unsigned int amount, bool force)
+unsigned int Inventory::remove(unsigned int itemId, unsigned int amount)
{
- bool inv = false;
+ if (!itemId || !amount)
+ return amount;
+
+ LOG_DEBUG("Inventory: Request remove of " << amount << " item(s) id: "
+ << itemId << " for character: '" << mCharacter->getName()
+ << "'.");
MessageOut invMsg(GPMSG_INVENTORY);
bool triggerLeaveInventory = true;
for (InventoryData::iterator it = mPoss->inventory.begin(),
- it_end = mPoss->inventory.end();
- it != it_end; ++it)
+ it_end = mPoss->inventory.end(); it != it_end; ++it)
+ {
if (it->second.itemId == itemId)
{
if (amount)
@@ -302,18 +307,24 @@ unsigned int Inventory::remove(unsigned int itemId, unsigned int amount, bool fo
// no need to run leave invy triggers.
if (!amount)
triggerLeaveInventory = false;
+ LOG_DEBUG("Slot id: " << it->first << " has now "
+ << it->second.amount << "item(s).");
}
else
{
invMsg.writeInt16(0);
mPoss->inventory.erase(it);
+ LOG_DEBUG("Slot id: " << it->first << " is now empty.");
}
}
else
+ {
// We found an instance of them existing and have none left to
// remove, so no need to run leave invy triggers.
triggerLeaveInventory = false;
+ }
}
+ }
if (triggerLeaveInventory)
itemManager->getItem(itemId)->useTrigger(mCharacter, ITT_LEAVE_INVY);
@@ -321,9 +332,7 @@ unsigned int Inventory::remove(unsigned int itemId, unsigned int amount, bool fo
if (invMsg.getLength() > 2)
gameHandler->sendTo(mCharacter, invMsg);
- // Rather inefficient, but still usable for now assuming small invy size.
- // FIXME
- return inv && !force ? remove(itemId, amount, true) : amount;
+ return amount;
}
unsigned int Inventory::move(unsigned int slot1, unsigned int slot2,