From 9d86e5b02803550d7406a6cff53d6e12534d3a16 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 10 May 2015 13:04:50 +0200 Subject: [PATCH] GetSpellEffects returns true for active abilities (Fixes #2530) --- apps/openmw/mwmechanics/spells.cpp | 14 ++++++++++++++ apps/openmw/mwmechanics/spells.hpp | 3 +++ apps/openmw/mwscript/miscextensions.cpp | 3 ++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwmechanics/spells.cpp b/apps/openmw/mwmechanics/spells.cpp index 04225b43e..b1829964b 100644 --- a/apps/openmw/mwmechanics/spells.cpp +++ b/apps/openmw/mwmechanics/spells.cpp @@ -143,6 +143,20 @@ namespace MWMechanics return mSelectedSpell; } + bool Spells::isSpellActive(const std::string &id) const + { + TContainer::const_iterator found = mSpells.find(id); + if (found != mSpells.end()) + { + const ESM::Spell *spell = + MWBase::Environment::get().getWorld()->getStore().get().find (id); + + return (spell->mData.mType==ESM::Spell::ST_Ability || spell->mData.mType==ESM::Spell::ST_Blight || + spell->mData.mType==ESM::Spell::ST_Disease || spell->mData.mType==ESM::Spell::ST_Curse); + } + return false; + } + bool Spells::hasCommonDisease() const { for (TIterator iter = mSpells.begin(); iter!=mSpells.end(); ++iter) diff --git a/apps/openmw/mwmechanics/spells.hpp b/apps/openmw/mwmechanics/spells.hpp index 064b2c1e5..6b4149939 100644 --- a/apps/openmw/mwmechanics/spells.hpp +++ b/apps/openmw/mwmechanics/spells.hpp @@ -98,6 +98,9 @@ namespace MWMechanics const std::string getSelectedSpell() const; ///< May return an empty string. + bool isSpellActive(const std::string& id) const; + ///< Are we under the effects of the given spell ID? + bool hasCommonDisease() const; bool hasBlightDisease() const; diff --git a/apps/openmw/mwscript/miscextensions.cpp b/apps/openmw/mwscript/miscextensions.cpp index 29f586a65..38106340a 100644 --- a/apps/openmw/mwscript/miscextensions.cpp +++ b/apps/openmw/mwscript/miscextensions.cpp @@ -595,7 +595,8 @@ namespace MWScript std::string id = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); - runtime.push(ptr.getClass().getCreatureStats(ptr).getActiveSpells().isSpellActive(id)); + const MWMechanics::CreatureStats& stats = ptr.getClass().getCreatureStats(ptr); + runtime.push(stats.getActiveSpells().isSpellActive(id) || stats.getSpells().isSpellActive(id)); } };