mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-20 21:53:52 +00:00
Issue #256: consider equipped items when calculating magic effects
This commit is contained in:
parent
372efaafd7
commit
124ea77612
4 changed files with 62 additions and 4 deletions
|
@ -47,7 +47,13 @@ namespace MWMechanics
|
|||
|
||||
MagicEffects now = creatureStats.mSpells.getMagicEffects();
|
||||
|
||||
/// \todo add effects from active spells and equipment
|
||||
if (creature.getTypeName()==typeid (ESM::NPC).name())
|
||||
{
|
||||
MWWorld::InventoryStore& store = MWWorld::Class::get (creature).getInventoryStore (creature);
|
||||
now += store.getMagicEffects();
|
||||
}
|
||||
|
||||
/// \todo add effects from active spells
|
||||
|
||||
MagicEffects diff = MagicEffects::diff (creatureStats.mMagicEffects, now);
|
||||
|
||||
|
|
|
@ -90,7 +90,7 @@ namespace MWWorld
|
|||
void clear();
|
||||
///< Empty container.
|
||||
|
||||
void flagAsModified();
|
||||
virtual void flagAsModified();
|
||||
///< \attention This function is internal to the world model and should not be called from
|
||||
/// outside.
|
||||
|
||||
|
|
|
@ -4,6 +4,12 @@
|
|||
#include <iterator>
|
||||
#include <algorithm>
|
||||
|
||||
#include <components/esm/loadench.hpp>
|
||||
|
||||
#include "../mwbase/environment.hpp"
|
||||
|
||||
#include "../mwworld/world.hpp"
|
||||
|
||||
#include "../mwmechanics/npcstats.hpp"
|
||||
|
||||
#include "class.hpp"
|
||||
|
@ -32,13 +38,13 @@ void MWWorld::InventoryStore::initSlots (TSlots& slots)
|
|||
slots.push_back (end());
|
||||
}
|
||||
|
||||
MWWorld::InventoryStore::InventoryStore()
|
||||
MWWorld::InventoryStore::InventoryStore() : mMagicEffectsUpToDate (false)
|
||||
{
|
||||
initSlots (mSlots);
|
||||
}
|
||||
|
||||
MWWorld::InventoryStore::InventoryStore (const InventoryStore& store)
|
||||
: ContainerStore (store)
|
||||
: ContainerStore (store), mMagicEffectsUpToDate (false)
|
||||
{
|
||||
copySlots (store);
|
||||
}
|
||||
|
@ -201,6 +207,38 @@ void MWWorld::InventoryStore::autoEquip (const MWMechanics::NpcStats& stats)
|
|||
}
|
||||
}
|
||||
|
||||
const MWMechanics::MagicEffects& MWWorld::InventoryStore::getMagicEffects()
|
||||
{
|
||||
if (!mMagicEffectsUpToDate)
|
||||
{
|
||||
mMagicEffects = MWMechanics::MagicEffects();
|
||||
|
||||
for (TSlots::const_iterator iter (mSlots.begin()); iter!=mSlots.end(); ++iter)
|
||||
if (*iter!=end())
|
||||
{
|
||||
std::string enchantmentId = MWWorld::Class::get (**iter).getEnchantment (**iter);
|
||||
|
||||
if (!enchantmentId.empty())
|
||||
{
|
||||
const ESM::Enchantment& enchantment =
|
||||
*MWBase::Environment::get().getWorld()->getStore().enchants.find (enchantmentId);
|
||||
|
||||
if (enchantment.data.type==ESM::Enchantment::ConstantEffect)
|
||||
mMagicEffects.add (enchantment.effects);
|
||||
}
|
||||
}
|
||||
|
||||
mMagicEffectsUpToDate = true;
|
||||
}
|
||||
|
||||
return mMagicEffects;
|
||||
}
|
||||
|
||||
void MWWorld::InventoryStore::flagAsModified()
|
||||
{
|
||||
mMagicEffectsUpToDate = false;
|
||||
}
|
||||
|
||||
bool MWWorld::InventoryStore::stacks(const Ptr& ptr1, const Ptr& ptr2)
|
||||
{
|
||||
bool canStack = MWWorld::ContainerStore::stacks(ptr1, ptr2);
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include "containerstore.hpp"
|
||||
|
||||
#include "../mwmechanics/magiceffects.hpp"
|
||||
|
||||
namespace MWMechanics
|
||||
{
|
||||
struct NpcStats;
|
||||
|
@ -41,6 +43,9 @@ namespace MWWorld
|
|||
|
||||
private:
|
||||
|
||||
mutable MWMechanics::MagicEffects mMagicEffects;
|
||||
mutable bool mMagicEffectsUpToDate;
|
||||
|
||||
typedef std::vector<ContainerStoreIterator> TSlots;
|
||||
|
||||
mutable TSlots mSlots;
|
||||
|
@ -65,6 +70,15 @@ namespace MWWorld
|
|||
void autoEquip (const MWMechanics::NpcStats& stats);
|
||||
///< Auto equip items according to stats and item value.
|
||||
|
||||
const MWMechanics::MagicEffects& getMagicEffects();
|
||||
///< Return magic effects from worn items.
|
||||
///
|
||||
/// \todo make this const again, after the constness of Ptrs and iterators has been addressed.
|
||||
|
||||
virtual void flagAsModified();
|
||||
///< \attention This function is internal to the world model and should not be called from
|
||||
/// outside.
|
||||
|
||||
protected:
|
||||
|
||||
virtual bool stacks (const Ptr& ptr1, const Ptr& ptr2);
|
||||
|
|
Loading…
Reference in a new issue