Fix being able to use enchantments of items that failed to equip (Fixes #2215)

moveref
scrawl 10 years ago
parent 4e0d16da8c
commit 4d5adfb5dd

@ -99,14 +99,8 @@ void InventoryItemModel::update()
if (mActor.getClass().hasInventoryStore(mActor))
{
MWWorld::InventoryStore& store = mActor.getClass().getInventoryStore(mActor);
for (int slot=0; slot<MWWorld::InventoryStore::Slots; ++slot)
{
MWWorld::ContainerStoreIterator equipped = store.getSlot(slot);
if (equipped == store.end())
continue;
if (*equipped == newItem.mBase)
newItem.mType = ItemStack::Type_Equipped;
}
if (store.isEquipped(newItem.mBase))
newItem.mType = ItemStack::Type_Equipped;
}
mItems.push_back(newItem);

@ -326,6 +326,10 @@ namespace MWGui
if (!item.getClass().getEquipmentSlots(item).first.empty())
{
MWBase::Environment::get().getWindowManager()->getInventoryWindow()->useItem(item);
// make sure that item was successfully equipped
if (!store.isEquipped(item))
return;
}
store.setSelectedEnchantItem(it);

@ -108,16 +108,7 @@ namespace MWGui
std::string charge = boost::lexical_cast<std::string>(currentCharge);
newSpell.mCostColumn = cost + "/" + charge;
bool equipped = false;
for (int i=0; i < MWWorld::InventoryStore::Slots; ++i)
{
if (invStore.getSlot(i) != invStore.end() && *invStore.getSlot(i) == item)
{
equipped = true;
break;
}
}
newSpell.mActive = equipped;
newSpell.mActive = invStore.isEquipped(item);
}
mSpells.push_back(newSpell);
}

@ -86,6 +86,9 @@ namespace MWGui
&& !item.getClass().getEquipmentSlots(item).first.empty())
{
MWBase::Environment::get().getWindowManager()->getInventoryWindow()->useItem(item);
// make sure that item was successfully equipped
if (!store.isEquipped(item))
return;
}
MWBase::Environment::get().getWindowManager()->unsetSelectedSpell();

@ -175,17 +175,8 @@ namespace MWGui
// don't show equipped items
if(mMerchant.getClass().hasInventoryStore(mMerchant))
{
bool isEquipped = false;
MWWorld::InventoryStore& store = mMerchant.getClass().getInventoryStore(mMerchant);
for (int slot=0; slot<MWWorld::InventoryStore::Slots; ++slot)
{
MWWorld::ContainerStoreIterator equipped = store.getSlot(slot);
if (equipped == store.end())
continue;
if (*equipped == base)
isEquipped = true;
}
if (isEquipped)
if (store.isEquipped(base))
continue;
}
}

@ -201,12 +201,16 @@ namespace MWMechanics
return 0.f;
const ESM::Enchantment* enchantment = MWBase::Environment::get().getWorld()->getStore().get<ESM::Enchantment>().find(ptr.getClass().getEnchantment(ptr));
if (enchantment->mData.mType == ESM::Enchantment::CastOnce)
{
return rateEffects(enchantment->mEffects, actor, target);
}
else
{
//if (!ptr.getClass().canBeEquipped(ptr, actor))
return 0.f;
}
}
float rateEffect(const ESM::ENAMstruct &effect, const MWWorld::Ptr &actor, const MWWorld::Ptr &target)

@ -643,3 +643,13 @@ void MWWorld::InventoryStore::clear()
initSlots (mSlots);
ContainerStore::clear();
}
bool MWWorld::InventoryStore::isEquipped(const MWWorld::Ptr &item)
{
for (int i=0; i < MWWorld::InventoryStore::Slots; ++i)
{
if (getSlot(i) != end() && *getSlot(i) == item)
return true;
}
return false;
}

@ -145,6 +145,9 @@ namespace MWWorld
void equip (int slot, const ContainerStoreIterator& iterator, const Ptr& actor);
///< \warning \a iterator can not be an end()-iterator, use unequip function instead
bool isEquipped(const MWWorld::Ptr& item);
///< Utility function, returns true if the given item is equipped in any slot
void setSelectedEnchantItem(const ContainerStoreIterator& iterator);
///< set the selected magic item (for using enchantments of type "Cast once" or "Cast when used")
/// \note to unset the selected item, call this method with end() iterator

Loading…
Cancel
Save