summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-11-04 18:28:12 +0100
committerYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-11-12 13:35:18 +0100
commit7ef4c5e7a13d1555536bbd2471eee11fb8ed1b5f (patch)
tree89299c36cc9573a98424fbc092489b59119e2c2e /src
parent6cf1c2fc269626f9c621ab4a5e72dcf19ddfecd1 (diff)
downloadmanaserv-7ef4c5e7a13d1555536bbd2471eee11fb8ed1b5f.tar.gz
manaserv-7ef4c5e7a13d1555536bbd2471eee11fb8ed1b5f.tar.bz2
manaserv-7ef4c5e7a13d1555536bbd2471eee11fb8ed1b5f.tar.xz
manaserv-7ef4c5e7a13d1555536bbd2471eee11fb8ed1b5f.zip
Prevented the equipment to remove the item when something went wrong.
Reviewed-by: Thorbjorn Lindeijer.
Diffstat (limited to 'src')
-rw-r--r--src/game-server/inventory.cpp22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/game-server/inventory.cpp b/src/game-server/inventory.cpp
index 1c52bcfc..11065545 100644
--- a/src/game-server/inventory.cpp
+++ b/src/game-server/inventory.cpp
@@ -707,13 +707,12 @@ bool Inventory::unequip(unsigned int itemInstance)
if (!itemInstance)
return false;
- MessageOut equipMsg(GPMSG_EQUIP);
- equipMsg.writeInt16(0); // Item Id, useless in case of unequip.
-
// The itemId to unequip
unsigned int itemId = 0;
unsigned int slotTypeId = 0;
+ bool addedToInventory = false;
+
// Empties all equip entries that point to the given equipment slot
// The equipment slots should NEVER be erased after initialization!
for (EquipData::iterator it = mPoss->equipSlots.begin(),
@@ -723,6 +722,13 @@ bool Inventory::unequip(unsigned int itemInstance)
{
// Add the item to the inventory list if not already present there
itemId = it->second.itemId;
+
+ // Move the item back to inventory and return false when it failed.
+ if (!addedToInventory && insert(itemId, 1) > 0)
+ return false;
+ else
+ addedToInventory = true;
+
it->second.itemId = 0;
it->second.itemInstance = 0;
@@ -737,15 +743,11 @@ bool Inventory::unequip(unsigned int itemInstance)
if (!itemId)
return false;
- // Number of slot types touched,
- equipMsg.writeInt16(1);
-
- // Move the item back to inventory.
- insert(itemId, 1);
-
+ MessageOut equipMsg(GPMSG_EQUIP);
+ equipMsg.writeInt16(0); // Item Id, useless in case of unequip.
+ equipMsg.writeInt16(1); // Number of slot types touched.
equipMsg.writeInt16(itemInstance);
equipMsg.writeInt16(0); // Capacity used, set to 0 to unequip.
-
gameHandler->sendTo(mCharacter, equipMsg);
// Apply unequip trigger