From 2a092bff6a889415d68b63db6e11942aa2d2bb33 Mon Sep 17 00:00:00 2001 From: Yohann Ferreira Date: Sat, 3 Dec 2011 00:41:08 +0100 Subject: Added unequip lua script functions. You can unequip using the slot or an item id. + Fixes from Ablu's review. Resolves: Mana-Mantis #350. Reviewed-by: Ablu. --- src/game-server/inventory.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/game-server/inventory.cpp') diff --git a/src/game-server/inventory.cpp b/src/game-server/inventory.cpp index 1cc92145..4d447d3a 100644 --- a/src/game-server/inventory.cpp +++ b/src/game-server/inventory.cpp @@ -711,6 +711,37 @@ bool Inventory::equip(int inventorySlot) return true; } +unsigned int Inventory::getSlotItemInstance(unsigned int slot) +{ + EquipData::iterator it = mPoss->equipSlots.find(slot); + if (it != mPoss->equipSlots.end()) + return it->second.itemInstance; + return 0; +} + +bool Inventory::unequipItem(unsigned int itemId) +{ + std::set itemInstances; + for (EquipData::iterator it = mPoss->equipSlots.begin(), + it_end = mPoss->equipSlots.end(); it != it_end; ++it) + { + if (it->second.itemId == itemId) + itemInstances.insert(it->second.itemInstance); + } + + // Nothing to do but it's a success + if (itemInstances.empty()) + return true; + + for (std::set::const_iterator it = itemInstances.begin(), + it_end = itemInstances.end(); it != it_end; ++it) + { + if (!unequip(*it)); + return false; + } + return true; +} + bool Inventory::unequip(unsigned int itemInstance) { if (!itemInstance) -- cgit v1.2.3-60-g2f50