diff options
author | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-08-18 00:59:10 +0200 |
---|---|---|
committer | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-08-18 00:59:10 +0200 |
commit | 70f3c0e3d530304b1b1162b1bdc6c1177522b7ff (patch) | |
tree | 3dd79c4755851fd102d6e41a679fc1e04f7cfe9a /src | |
parent | 9527d079307454178fea3b2958e301875cecc15a (diff) | |
parent | 10fd0338203a46cec913859fd5e38b61fa24a30f (diff) | |
download | manaserv-70f3c0e3d530304b1b1162b1bdc6c1177522b7ff.tar.gz manaserv-70f3c0e3d530304b1b1162b1bdc6c1177522b7ff.tar.bz2 manaserv-70f3c0e3d530304b1b1162b1bdc6c1177522b7ff.tar.xz manaserv-70f3c0e3d530304b1b1162b1bdc6c1177522b7ff.zip |
Merge git://gitorious.org/~bertram/mana/manaserv-equipment-fix into equipment-fix
Diffstat (limited to 'src')
-rw-r--r-- | src/common/manaserv_protocol.h | 4 | ||||
-rw-r--r-- | src/game-server/inventory.cpp | 28 | ||||
-rw-r--r-- | src/game-server/inventory.h | 4 |
3 files changed, 17 insertions, 19 deletions
diff --git a/src/common/manaserv_protocol.h b/src/common/manaserv_protocol.h index 710d2f45..78cbbbf1 100644 --- a/src/common/manaserv_protocol.h +++ b/src/common/manaserv_protocol.h @@ -93,11 +93,11 @@ enum { PGMSG_PICKUP = 0x0110, // W*2 position
PGMSG_DROP = 0x0111, // B slot, B amount
PGMSG_EQUIP = 0x0112, // W inventory slot
- PGMSG_UNEQUIP = 0x0113, // W equipment slot
+ PGMSG_UNEQUIP = 0x0113, // W item Instance id
PGMSG_MOVE_ITEM = 0x0114, // W slot1, W slot2, W amount
GPMSG_INVENTORY = 0x0120, // { W slot, W item id [, W amount] (if item id is nonzero) }*
GPMSG_INVENTORY_FULL = 0x0121, // W inventory slot count { W slot, W itemId, W amount }, { W equip slot, W item Id, W item Instance}*
- GPMSG_EQUIP = 0x0122, // W item Id, W equip slot type count { W equip slot, W capacity used}*
+ GPMSG_EQUIP = 0x0122, // W item Id, W equip slot type count //{ W equip slot, W capacity used}*//<- When equipping, //{ W item instance, W 0}*//<- When unequipping
GPMSG_PLAYER_ATTRIBUTE_CHANGE = 0x0130, // { W attribute, D base value (in 1/256ths), D modified value (in 1/256ths)}*
GPMSG_PLAYER_EXP_CHANGE = 0x0140, // { W skill, D exp got, D exp needed }*
GPMSG_LEVELUP = 0x0150, // W new level, W character points, W correction points
diff --git a/src/game-server/inventory.cpp b/src/game-server/inventory.cpp index 1eaf8b91..c3d2bfcb 100644 --- a/src/game-server/inventory.cpp +++ b/src/game-server/inventory.cpp @@ -119,7 +119,7 @@ void Inventory::initialize() << it2->second.itemId << " from the equipment of '" << mCharacter->getName() << "'!"); - mPoss->equipSlots.erase(++it2); + mPoss->equipSlots.erase(it2++); continue; } @@ -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; } diff --git a/src/game-server/inventory.h b/src/game-server/inventory.h index 06f55e06..39f83216 100644 --- a/src/game-server/inventory.h +++ b/src/game-server/inventory.h @@ -65,10 +65,10 @@ class Inventory /** * Unequips item from given equipment slot. - * @param equipmentSlot Where to remove item(s). + * @param itemInstance The item instance id used to know what to unequip * @returns Whether it was unequipped. */ - bool unequip(unsigned int equipmentSlot); + bool unequip(unsigned int itemInstance); /** * Inserts some items into the inventory. |