diff options
author | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-08-18 00:55:12 +0200 |
---|---|---|
committer | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-08-18 00:55:12 +0200 |
commit | 10fd0338203a46cec913859fd5e38b61fa24a30f (patch) | |
tree | 8bb8b15d69f4823104d27b135330e8455665b2c1 /src/game-server/inventory.cpp | |
parent | caf715fc482e700d80eab7592a4e61e4a0417294 (diff) | |
download | manaserv-10fd0338203a46cec913859fd5e38b61fa24a30f.tar.gz manaserv-10fd0338203a46cec913859fd5e38b61fa24a30f.tar.bz2 manaserv-10fd0338203a46cec913859fd5e38b61fa24a30f.tar.xz manaserv-10fd0338203a46cec913859fd5e38b61fa24a30f.zip |
Change the unequip function to make use of the item instance id.
It will make the client capable to tell which item
is to be unequipped when there are several item equipped
within a slot type, for instance.
The client has now yet to be upgraded to follow the new protocol.
Diffstat (limited to 'src/game-server/inventory.cpp')
-rw-r--r-- | src/game-server/inventory.cpp | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/src/game-server/inventory.cpp b/src/game-server/inventory.cpp index e244f651..c3d2bfcb 100644 --- a/src/game-server/inventory.cpp +++ b/src/game-server/inventory.cpp @@ -726,6 +726,8 @@ bool Inventory::equip(int inventorySlot) equipMsg.writeInt16(it2->first); // Capacity used equipMsg.writeInt16(it2->second); + // Item instance + equipMsg.writeInt16(itemInstance); } // New item trigger @@ -740,27 +742,21 @@ bool Inventory::equip(int inventorySlot) return true; } -bool Inventory::unequip(unsigned int equipmentSlot) +bool Inventory::unequip(unsigned int itemInstance) { // map of { itemInstance, itemId } std::map<unsigned int, unsigned int> itemIdListToInventory; - bool changed = false; MessageOut equipMsg(GPMSG_EQUIP); equipMsg.writeInt16(0); // Item Id, useless in case of unequip. - equipMsg.writeInt16(1); // Number of slot types touched, - // 1 in case of unequip. // 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(), it_end = mPoss->equipSlots.end(); it != it_end; ++it) { - if (it->first == equipmentSlot && it->second.itemId != 0) + if (it->second.itemInstance == itemInstance) { - if (!it->second.itemInstance) - continue; - // Add the item to the inventory list if not already present there std::map<unsigned int, unsigned int>::const_iterator it2 = itemIdListToInventory.find(it->second.itemInstance); @@ -771,12 +767,14 @@ bool Inventory::unequip(unsigned int equipmentSlot) (it->second.itemInstance, it->second.itemId)); } - changed = true; it->second.itemId = 0; it->second.itemInstance = 0; } } + // Number of slot types touched, + equipMsg.writeInt16(itemIdListToInventory.size()); + // Apply unequip trigger(s), and move the item(s) back to inventory. for (std::map<unsigned int, unsigned int>::const_iterator it2 = itemIdListToInventory.begin(), it2_end = itemIdListToInventory.end(); @@ -784,16 +782,16 @@ bool Inventory::unequip(unsigned int equipmentSlot) { updateEquipmentTrigger(it2->second, 0); insert(it2->second, 1); - } - if (changed) - { - equipMsg.writeInt16(equipmentSlot); + equipMsg.writeInt16(it2->first); equipMsg.writeInt16(0); // Capacity used, set to 0 to unequip. } if (equipMsg.getLength() > 2) + { gameHandler->sendTo(mCharacter, equipMsg); + return true; + } - return changed; + return false; } |