From d05baa8c22e5aa3e06824f6fb80d1bfa9206a9f1 Mon Sep 17 00:00:00 2001 From: Emanuel Guevel Date: Fri, 1 Nov 2013 00:54:54 +0100 Subject: [PATCH] Add method InventoryStore::unequipSlot() This will permit to do run a treatment when an item is unequipped. --- apps/openmw/mwworld/inventorystore.cpp | 37 +++++++++++++++++--------- apps/openmw/mwworld/inventorystore.hpp | 4 +-- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/apps/openmw/mwworld/inventorystore.cpp b/apps/openmw/mwworld/inventorystore.cpp index 2aba0b5489..4bda723183 100644 --- a/apps/openmw/mwworld/inventorystore.cpp +++ b/apps/openmw/mwworld/inventorystore.cpp @@ -129,18 +129,7 @@ void MWWorld::InventoryStore::equip (int slot, const ContainerStoreIterator& ite void MWWorld::InventoryStore::unequipAll(const MWWorld::Ptr& actor) { for (int slot=0; slot < MWWorld::InventoryStore::Slots; ++slot) - { - MWWorld::ContainerStoreIterator it = getSlot(slot); - if (it != end()) - { - equip(slot, end()); - std::string script = MWWorld::Class::get(*it).getScript(*it); - - // Unset OnPCEquip Variable on item's script, if it has a script with that variable declared - if((actor.getRefData().getHandle() == "player") && (script != "")) - (*it).getRefData().getLocals().setVarByInt(script, "onpcequip", 0); - } - } + unequipSlot(slot, actor); } MWWorld::ContainerStoreIterator MWWorld::InventoryStore::getSlot (int slot) @@ -328,5 +317,29 @@ MWWorld::ContainerStoreIterator MWWorld::InventoryStore::getSelectedEnchantItem( int MWWorld::InventoryStore::remove(const Ptr& item, int count, const Ptr& actor) { + for (int slot=0; slot < MWWorld::InventoryStore::Slots; ++slot) + { + if (mSlots[slot] == end()) + continue; + + if (*mSlots[slot] == item) + { + unequipSlot(slot, actorPtr); + break; + } + } + return ContainerStore::remove(item, count, actor); } + +void MWWorld::InventoryStore::unequipSlot(int slot, const MWWorld::Ptr& actor) +{ + ContainerStoreIterator it = getSlot(slot); + if (it != end()) + { + equip(slot, end()); + + + /// \todo update actor model + } +} diff --git a/apps/openmw/mwworld/inventorystore.hpp b/apps/openmw/mwworld/inventorystore.hpp index f1168dda1a..fd9f3fa7a5 100644 --- a/apps/openmw/mwworld/inventorystore.hpp +++ b/apps/openmw/mwworld/inventorystore.hpp @@ -111,9 +111,9 @@ namespace MWWorld virtual int remove(const Ptr& item, int count, const Ptr& actor); ///< Remove \a count item(s) designated by \a item from this inventory. /// - /// \todo check if the item is equipped and do stuff - /// /// @return the number of items actually removed + + void unequipSlot(int slot, const Ptr& actor); }; }