From d9c16328dd89d7f42ed42982a1b8ddce9c73c8fc Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Tue, 17 Sep 2024 21:16:41 +0200 Subject: [PATCH] Deselect magic item before selecting a spell --- apps/openmw/mwlua/magicbindings.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/apps/openmw/mwlua/magicbindings.cpp b/apps/openmw/mwlua/magicbindings.cpp index 4fac1533e8..a62e42ef0e 100644 --- a/apps/openmw/mwlua/magicbindings.cpp +++ b/apps/openmw/mwlua/magicbindings.cpp @@ -744,8 +744,19 @@ namespace MWLua const MWWorld::Ptr& ptr = obj.ptr(); auto& stats = ptr.getClass().getCreatureStats(ptr); + // We need to deselect any enchant items before we can select a spell otherwise the item will be + // reselected + const auto resetEnchantItem = [&]() { + if (ptr.getClass().hasInventoryStore(ptr)) + { + MWWorld::InventoryStore& inventory = ptr.getClass().getInventoryStore(ptr); + inventory.setSelectedEnchantItem(inventory.end()); + } + }; + if (spellId.empty()) { + resetEnchantItem(); if (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr()) MWBase::Environment::get().getWindowManager()->unsetSelectedSpell(); else @@ -755,6 +766,7 @@ namespace MWLua if (!stats.getSpells().hasSpell(spellId)) throw std::runtime_error("Actor doesn't know spell " + spellId.toDebugString()); + resetEnchantItem(); if (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr()) { int chance = MWMechanics::getSpellSuccessChance(spellId, ptr);