diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index 9ee7d5097e..266ea5a9f5 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -1426,30 +1426,31 @@ bool CharacterController::updateWeaponState() else if (!spellid.empty() && spellCastResult != MWWorld::SpellCastState::PowerAlreadyUsed) { world->breakInvisibility(mPtr); - MWMechanics::CastSpell cast(mPtr, nullptr, false, mCastingManualSpell); - cast.playSpellCastingEffects(spellid, isMagicItem); + MWMechanics::CastSpell cast(mPtr, {}, false, mCastingManualSpell); - std::vector effects; + const std::vector* effects{nullptr}; const MWWorld::ESMStore &store = world->getStore(); if (isMagicItem) { const ESM::Enchantment *enchantment = store.get().find(spellid); - effects = enchantment->mEffects.mList; + effects = &enchantment->mEffects.mList; + cast.playSpellCastingEffects(enchantment); } else { const ESM::Spell *spell = store.get().find(spellid); - effects = spell->mEffects.mList; + effects = &spell->mEffects.mList; + cast.playSpellCastingEffects(spell); } if (mCanCast) { - const ESM::MagicEffect *effect = store.get().find(effects.back().mEffectID); // use last effect of list for color of VFX_Hands + const ESM::MagicEffect *effect = store.get().find(effects->back().mEffectID); // use last effect of list for color of VFX_Hands const ESM::Static* castStatic = world->getStore().get().find ("VFX_Hands"); const VFS::Manager* const vfs = MWBase::Environment::get().getResourceSystem()->getVFS(); - for (size_t iter = 0; iter < effects.size(); ++iter) // play hands vfx for each effect + if (!effects->empty()) { if (mAnimation->getNode("Bip01 L Hand")) mAnimation->addEffect( @@ -1463,7 +1464,7 @@ bool CharacterController::updateWeaponState() } } - const ESM::ENAMstruct &firstEffect = effects.at(0); // first effect used for casting animation + const ESM::ENAMstruct& firstEffect = effects->at(0); // first effect used for casting animation std::string startKey; std::string stopKey; diff --git a/apps/openmw/mwmechanics/spellcasting.cpp b/apps/openmw/mwmechanics/spellcasting.cpp index 9fbf601463..06d504ef6c 100644 --- a/apps/openmw/mwmechanics/spellcasting.cpp +++ b/apps/openmw/mwmechanics/spellcasting.cpp @@ -169,24 +169,6 @@ namespace MWMechanics if (!found) return; - const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get().search (mId); - if (spell && targetIsActor && (spell->mData.mType == ESM::Spell::ST_Disease || spell->mData.mType == ESM::Spell::ST_Blight)) - { - int requiredResistance = (spell->mData.mType == ESM::Spell::ST_Disease) ? - ESM::MagicEffect::ResistCommonDisease - : ESM::MagicEffect::ResistBlightDisease; - float x = target.getClass().getCreatureStats(target).getMagicEffects().get(requiredResistance).getMagnitude(); - - auto& prng = MWBase::Environment::get().getWorld()->getPrng(); - if (Misc::Rng::roll0to99(prng) <= x) - { - // Fully resisted, show message - if (target == getPlayer()) - MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicPCResisted}"); - return; - } - } - ActiveSpells::ActiveSpellParams params(*this, mCaster); bool castByPlayer = (!mCaster.isEmpty() && mCaster == getPlayer()); @@ -522,19 +504,14 @@ namespace MWMechanics return true; } - void CastSpell::playSpellCastingEffects(std::string_view spellid, bool enchantment) const + void CastSpell::playSpellCastingEffects(const ESM::Enchantment* enchantment) const { - const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); - if (enchantment) - { - if (const auto spell = store.get().search(spellid)) - playSpellCastingEffects(spell->mEffects.mList); - } - else - { - if (const auto spell = store.get().search(spellid)) - playSpellCastingEffects(spell->mEffects.mList); - } + playSpellCastingEffects(enchantment->mEffects.mList); + } + + void CastSpell::playSpellCastingEffects(const ESM::Spell* spell) const + { + playSpellCastingEffects(spell->mEffects.mList); } void CastSpell::playSpellCastingEffects(const std::vector& effects) const diff --git a/apps/openmw/mwmechanics/spellcasting.hpp b/apps/openmw/mwmechanics/spellcasting.hpp index e92902b175..bc17a00042 100644 --- a/apps/openmw/mwmechanics/spellcasting.hpp +++ b/apps/openmw/mwmechanics/spellcasting.hpp @@ -12,6 +12,7 @@ namespace ESM struct Ingredient; struct Potion; struct EffectList; + struct Enchantment; struct MagicEffect; } @@ -58,7 +59,9 @@ namespace MWMechanics /// @note Auto detects if spell, ingredient or potion bool cast (const std::string& id); - void playSpellCastingEffects(std::string_view spellid, bool enchantment) const; + void playSpellCastingEffects(const ESM::Enchantment* enchantment) const; + + void playSpellCastingEffects(const ESM::Spell* spell) const; /// @note \a target can be any type of object, not just actors. void inflict(const MWWorld::Ptr& target, const ESM::EffectList& effects, ESM::RangeType range, bool exploded = false) const; diff --git a/apps/openmw/mwscript/miscextensions.cpp b/apps/openmw/mwscript/miscextensions.cpp index 2563704fdc..a005594490 100644 --- a/apps/openmw/mwscript/miscextensions.cpp +++ b/apps/openmw/mwscript/miscextensions.cpp @@ -1263,7 +1263,7 @@ namespace MWScript return; MWMechanics::CastSpell cast(ptr, target, false, true); - cast.playSpellCastingEffects(spell->mId, false); + cast.playSpellCastingEffects(spell); cast.mHitPosition = target.getRefData().getPosition().asVec3(); cast.mAlwaysSucceed = true; cast.cast(spell);