diff --git a/apps/openmw/mwlua/magicbindings.cpp b/apps/openmw/mwlua/magicbindings.cpp index a62e42ef0e..7259d03f4c 100644 --- a/apps/openmw/mwlua/magicbindings.cpp +++ b/apps/openmw/mwlua/magicbindings.cpp @@ -830,10 +830,10 @@ namespace MWLua spellsT["add"] = [context](const ActorSpells& spells, const sol::object& spellOrId) { if (spells.mActor.isLObject()) throw std::runtime_error("Local scripts can modify only spells of the actor they are attached to."); - context.mLuaManager->addAction([obj = spells.mActor.object(), id = toSpellId(spellOrId)]() { + context.mLuaManager->addAction([obj = spells.mActor.object(), spell = toSpell(spellOrId)]() { const MWWorld::Ptr& ptr = obj.ptr(); if (ptr.getClass().isActor()) - ptr.getClass().getCreatureStats(ptr).getSpells().add(id); + ptr.getClass().getCreatureStats(ptr).getSpells().add(spell, false); }); }; @@ -841,10 +841,10 @@ namespace MWLua spellsT["remove"] = [context](const ActorSpells& spells, const sol::object& spellOrId) { if (spells.mActor.isLObject()) throw std::runtime_error("Local scripts can modify only spells of the actor they are attached to."); - context.mLuaManager->addAction([obj = spells.mActor.object(), id = toSpellId(spellOrId)]() { + context.mLuaManager->addAction([obj = spells.mActor.object(), spell = toSpell(spellOrId)]() { const MWWorld::Ptr& ptr = obj.ptr(); if (ptr.getClass().isActor()) - ptr.getClass().getCreatureStats(ptr).getSpells().remove(id); + ptr.getClass().getCreatureStats(ptr).getSpells().remove(spell, false); }); }; diff --git a/apps/openmw/mwmechanics/spells.cpp b/apps/openmw/mwmechanics/spells.cpp index 26f0ebe4a2..d2baedab0f 100644 --- a/apps/openmw/mwmechanics/spells.cpp +++ b/apps/openmw/mwmechanics/spells.cpp @@ -60,14 +60,17 @@ namespace MWMechanics return std::find(mSpells.begin(), mSpells.end(), spell) != mSpells.end(); } - void Spells::add(const ESM::Spell* spell) + void Spells::add(const ESM::Spell* spell, bool modifyBase) { - mSpellList->add(spell); + if (modifyBase) + mSpellList->add(spell); + else + addSpell(spell); } - void Spells::add(const ESM::RefId& spellId) + void Spells::add(const ESM::RefId& spellId, bool modifyBase) { - add(SpellList::getSpell(spellId)); + add(SpellList::getSpell(spellId), modifyBase); } void Spells::addSpell(const ESM::Spell* spell) @@ -76,13 +79,17 @@ namespace MWMechanics mSpells.emplace_back(spell); } - void Spells::remove(const ESM::RefId& spellId) + void Spells::remove(const ESM::RefId& spellId, bool modifyBase) { - const auto spell = SpellList::getSpell(spellId); - removeSpell(spell); - mSpellList->remove(spell); + remove(SpellList::getSpell(spellId), modifyBase); + } - if (spellId == mSelectedSpell) + void Spells::remove(const ESM::Spell* spell, bool modifyBase) + { + removeSpell(spell); + if (modifyBase) + mSpellList->remove(spell); + if (spell->mId == mSelectedSpell) mSelectedSpell = ESM::RefId(); } diff --git a/apps/openmw/mwmechanics/spells.hpp b/apps/openmw/mwmechanics/spells.hpp index 685823b131..36c50b47c3 100644 --- a/apps/openmw/mwmechanics/spells.hpp +++ b/apps/openmw/mwmechanics/spells.hpp @@ -74,24 +74,25 @@ namespace MWMechanics bool hasSpell(const ESM::RefId& spell) const; bool hasSpell(const ESM::Spell* spell) const; - void add(const ESM::RefId& spell); + void add(const ESM::RefId& spell, bool modifyBase = true); ///< Adding a spell that is already listed in *this is a no-op. - void add(const ESM::Spell* spell); + void add(const ESM::Spell* spell, bool modifyBase = true); ///< Adding a spell that is already listed in *this is a no-op. - void remove(const ESM::RefId& spell); + void remove(const ESM::RefId& spell, bool modifyBase = true); + void remove(const ESM::Spell* spell, bool modifyBase = true); ///< If the spell to be removed is the selected spell, the selected spell will be changed to - /// no spell (empty string). + /// no spell (empty id). void clear(bool modifyBase = false); - ///< Remove all spells of al types. + ///< Remove all spells of all types. void setSelectedSpell(const ESM::RefId& spellId); ///< This function does not verify, if the spell is available. const ESM::RefId& getSelectedSpell() const; - ///< May return an empty string. + ///< May return an empty id. bool hasCommonDisease() const;