Auto-equip when items are added to the inventory

We limit that to armor pieces and clothing items.
No auto-equiping for the player nor werewolves.
actorid
Emanuel Guevel 12 years ago
parent e0d0cdd18a
commit 48d2554ac3

@ -76,7 +76,7 @@ void ContainerItemModel::copyItem (const ItemStack& item, size_t count)
const MWWorld::Ptr& source = mItemSources[mItemSources.size()-1];
int origCount = item.mBase.getRefData().getCount();
item.mBase.getRefData().setCount(count);
MWWorld::ContainerStoreIterator it = MWWorld::Class::get(source).getContainerStore(source).add(item.mBase);
MWWorld::ContainerStoreIterator it = MWWorld::Class::get(source).getContainerStore(source).add(item.mBase, source);
if (*it != item.mBase)
item.mBase.getRefData().setCount(origCount);
else

@ -42,7 +42,7 @@ void InventoryItemModel::copyItem (const ItemStack& item, size_t count)
{
int origCount = item.mBase.getRefData().getCount();
item.mBase.getRefData().setCount(count);
MWWorld::ContainerStoreIterator it = MWWorld::Class::get(mActor).getContainerStore(mActor).add(item.mBase);
MWWorld::ContainerStoreIterator it = MWWorld::Class::get(mActor).getContainerStore(mActor).add(item.mBase, mActor);
if (*it != item.mBase)
item.mBase.getRefData().setCount(origCount);
else

@ -304,7 +304,7 @@ namespace MWGui
int origCount = ptr.getRefData().getCount();
ptr.getRefData().setCount(mDragAndDrop->mDraggedCount);
it = invStore.add(ptr);
it = invStore.add(ptr, mPtr);
ptr.getRefData().setCount(origCount);
mDragAndDrop->mSourceModel->removeItem(mDragAndDrop->mItem, mDragAndDrop->mDraggedCount);
@ -481,7 +481,7 @@ namespace MWGui
// add to player inventory
// can't use ActionTake here because we need an MWWorld::Ptr to the newly inserted object
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
MWWorld::Ptr newObject = *MWWorld::Class::get (player).getContainerStore (player).add (object);
MWWorld::Ptr newObject = *MWWorld::Class::get (player).getContainerStore (player).add (object, player);
// remove from world
MWBase::Environment::get().getWorld()->deleteObject (object);

@ -225,7 +225,7 @@ namespace MWGui
assert(amount > 0);
MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), "Gold_001");
ref.getPtr().getRefData().setCount(amount);
playerStore.add(ref.getPtr());
playerStore.add(ref.getPtr(), player);
}
}

@ -287,7 +287,7 @@ void MWMechanics::Alchemy::addPotion (const std::string& name)
}
MWWorld::ManualRef ref (MWBase::Environment::get().getWorld()->getStore(), record->mId);
MWWorld::Class::get (mAlchemist).getContainerStore (mAlchemist).add (ref.getPtr());
MWWorld::Class::get (mAlchemist).getContainerStore (mAlchemist).add (ref.getPtr(), mAlchemist);
}
void MWMechanics::Alchemy::increaseSkill()

@ -65,7 +65,7 @@ namespace MWMechanics
if(boost::iequals(mSoulGemPtr.get<ESM::Miscellaneous>()->mBase->mId, "Misc_SoulGem_Azura"))
{
MWWorld::ManualRef azura (MWBase::Environment::get().getWorld()->getStore(), "Misc_SoulGem_Azura");
MWWorld::Class::get (player).getContainerStore (player).add (azura.getPtr());
MWWorld::Class::get (player).getContainerStore (player).add (azura.getPtr(), player);
}
if(mSelfEnchanting)
@ -93,7 +93,7 @@ namespace MWMechanics
MWWorld::ManualRef ref (MWBase::Environment::get().getWorld()->getStore(), mOldItemId);
ref.getPtr().getRefData().setCount (mOldItemCount-1);
MWWorld::Class::get (player).getContainerStore (player).add (ref.getPtr());
MWWorld::Class::get (player).getContainerStore (player).add (ref.getPtr(), player);
if(!mSelfEnchanting)
payForEnchantment();

@ -32,7 +32,7 @@ void Repair::repair(const MWWorld::Ptr &itemToRepair)
if (mTool.getRefData().getCount() > 1 && uses == ref->mBase->mData.mUses)
{
MWWorld::ContainerStore& store = MWWorld::Class::get(player).getContainerStore(player);
MWWorld::ContainerStoreIterator it = store.add(mTool);
MWWorld::ContainerStoreIterator it = store.add(mTool, player);
it->getRefData().setCount(mTool.getRefData().getCount()-1);
it->getCellRef().mCharge = -1;

@ -64,7 +64,7 @@ namespace MWScript
ref.getPtr().getRefData().setLocals(*esmscript);
}
MWWorld::Class::get (ptr).getContainerStore (ptr).add (ref.getPtr());
MWWorld::Class::get (ptr).getContainerStore (ptr).add (ref.getPtr(), ptr);
// Spawn a messagebox (only for items added to player's inventory and if player is talking to someone)
if (ptr == MWBase::Environment::get().getWorld ()->getPlayer ().getPlayer() )

@ -346,7 +346,7 @@ namespace MWScript
ref.getPtr().getCellRef().mSoul = creature;
MWWorld::Class::get (ptr).getContainerStore (ptr).add (ref.getPtr());
MWWorld::Class::get (ptr).getContainerStore (ptr).add (ref.getPtr(), ptr);
}
};

@ -17,7 +17,7 @@ namespace MWWorld
// insert into player's inventory
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPtr ("player", true);
MWWorld::Class::get (player).getContainerStore (player).add (getTarget());
MWWorld::Class::get (player).getContainerStore (player).add (getTarget(), player);
MWBase::Environment::get().getWorld()->deleteObject (getTarget());
}

@ -74,9 +74,9 @@ bool MWWorld::ContainerStore::stacks(const Ptr& ptr1, const Ptr& ptr2)
return false;
}
MWWorld::ContainerStoreIterator MWWorld::ContainerStore::add (const Ptr& ptr)
MWWorld::ContainerStoreIterator MWWorld::ContainerStore::add (const Ptr& itemPtr, const Ptr& actorPtr)
{
MWWorld::ContainerStoreIterator it = addImp(ptr);
MWWorld::ContainerStoreIterator it = addImp(itemPtr);
MWWorld::Ptr item = *it;
std::string script = MWWorld::Class::get(item).getScript(item);

@ -65,7 +65,7 @@ namespace MWWorld
ContainerStoreIterator end();
ContainerStoreIterator add (const Ptr& ptr);
virtual ContainerStoreIterator add (const Ptr& itemPtr, const Ptr& actorPtr);
///< Add the item pointed to by \a ptr to this container. (Stacks automatically if needed)
///
/// \note The item pointed to is not required to exist beyond this function call.

@ -64,6 +64,22 @@ MWWorld::InventoryStore& MWWorld::InventoryStore::operator= (const InventoryStor
return *this;
}
MWWorld::ContainerStoreIterator MWWorld::InventoryStore::add(const Ptr& itemPtr, const Ptr& actorPtr)
{
const MWWorld::ContainerStoreIterator& retVal = MWWorld::ContainerStore::add(itemPtr, actorPtr);
// Auto-equip items if an armor/clothing item is added, but not for the player nor werewolves
if ((actorPtr.getRefData().getHandle() != "player")
&& !(MWWorld::Class::get(actorPtr).getNpcStats(actorPtr).isWerewolf()))
{
std::string type = itemPtr.getTypeName();
if ((type == typeid(ESM::Armor).name()) || (type == typeid(ESM::Clothing).name()))
autoEquip(actorPtr);
}
return retVal;
}
void MWWorld::InventoryStore::equip (int slot, const ContainerStoreIterator& iterator)
{
if (slot<0 || slot>=static_cast<int> (mSlots.size()))

@ -65,6 +65,17 @@ namespace MWWorld
InventoryStore& operator= (const InventoryStore& store);
virtual ContainerStoreIterator add (const Ptr& itemPtr, const Ptr& actorPtr);
///< Add the item pointed to by \a ptr to this container. (Stacks automatically if needed)
/// Auto-equip items if specific conditions are fulfilled (see the implementation).
///
/// \note The item pointed to is not required to exist beyond this function call.
///
/// \attention Do not add items to an existing stack by increasing the count instead of
/// calling this function!
///
/// @return if stacking happened, return iterator to the item that was stacked against, otherwise iterator to the newly inserted item.
void equip (int slot, const ContainerStoreIterator& iterator);
///< \note \a iterator can be an end-iterator

Loading…
Cancel
Save