diff --git a/apps/openmw/mwmechanics/spellabsorption.cpp b/apps/openmw/mwmechanics/spellabsorption.cpp index f22cef3f6c..71e1d0aee6 100644 --- a/apps/openmw/mwmechanics/spellabsorption.cpp +++ b/apps/openmw/mwmechanics/spellabsorption.cpp @@ -12,6 +12,7 @@ #include "../mwworld/inventorystore.hpp" #include "creaturestats.hpp" +#include "spellutil.hpp" namespace MWMechanics { @@ -43,9 +44,9 @@ namespace MWMechanics } }; - bool absorbSpell (const ESM::Spell* spell, const MWWorld::Ptr& caster, const MWWorld::Ptr& target) + bool absorbSpell (const std::string& spellId, const MWWorld::Ptr& caster, const MWWorld::Ptr& target) { - if (!spell || caster == target || !target.getClass().isActor()) + if (spellId.empty() || caster == target || !target.getClass().isActor()) return false; CreatureStats& stats = target.getClass().getCreatureStats(target); @@ -62,13 +63,27 @@ namespace MWMechanics if (Misc::Rng::roll0to99() >= chance) return false; - const ESM::Static* absorbStatic = MWBase::Environment::get().getWorld()->getStore().get().find("VFX_Absorb"); + const auto& esmStore = MWBase::Environment::get().getWorld()->getStore(); + const ESM::Static* absorbStatic = esmStore.get().find("VFX_Absorb"); MWRender::Animation* animation = MWBase::Environment::get().getWorld()->getAnimation(target); if (animation && !absorbStatic->mModel.empty()) animation->addEffect( "meshes\\" + absorbStatic->mModel, ESM::MagicEffect::SpellAbsorption, false, std::string()); + const ESM::Spell* spell = esmStore.get().search(spellId); + int spellCost = 0; + if (spell) + { + spellCost = spell->mData.mCost; + } + else + { + const ESM::Enchantment* enchantment = esmStore.get().search(spellId); + if (enchantment) + spellCost = getEffectiveEnchantmentCastCost(static_cast(enchantment->mData.mCost), caster); + } + // Magicka is increased by the cost of the spell DynamicStat magicka = stats.getMagicka(); - magicka.setCurrent(magicka.getCurrent() + spell->mData.mCost); + magicka.setCurrent(magicka.getCurrent() + spellCost); stats.setMagicka(magicka); return true; } diff --git a/apps/openmw/mwmechanics/spellabsorption.hpp b/apps/openmw/mwmechanics/spellabsorption.hpp index 147090d96b..0fe501df91 100644 --- a/apps/openmw/mwmechanics/spellabsorption.hpp +++ b/apps/openmw/mwmechanics/spellabsorption.hpp @@ -1,10 +1,7 @@ #ifndef MWMECHANICS_SPELLABSORPTION_H #define MWMECHANICS_SPELLABSORPTION_H -namespace ESM -{ - struct Spell; -} +#include namespace MWWorld { @@ -14,7 +11,7 @@ namespace MWWorld namespace MWMechanics { // Try to absorb a spell based on the magnitude of every Spell Absorption effect source on the target. - bool absorbSpell(const ESM::Spell* spell, const MWWorld::Ptr& caster, const MWWorld::Ptr& target); + bool absorbSpell(const std::string& spellId, const MWWorld::Ptr& caster, const MWWorld::Ptr& target); } #endif diff --git a/apps/openmw/mwmechanics/spellcasting.cpp b/apps/openmw/mwmechanics/spellcasting.cpp index 3767acb3f3..81b3a353df 100644 --- a/apps/openmw/mwmechanics/spellcasting.cpp +++ b/apps/openmw/mwmechanics/spellcasting.cpp @@ -119,7 +119,7 @@ namespace MWMechanics // effects, we display a "can't re-cast" message // Try absorbing the spell. Some handling must still happen for absorbed effects. - bool absorbed = absorbSpell(spell, caster, target); + bool absorbed = absorbSpell(mId, caster, target); int currentEffectIndex = 0; for (std::vector::const_iterator effectIt (effects.mList.begin());