Skip to content

Commit

Permalink
Merge branch 'enchantedimsure' into 'master'
Browse files Browse the repository at this point in the history
Deselect magic item before selecting a spell

Closes #8162

See merge request OpenMW/openmw!4379
  • Loading branch information
jvoisin committed Sep 19, 2024
2 parents 74d699c + d9c1632 commit 879c23b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions apps/openmw/mwlua/magicbindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down

0 comments on commit 879c23b

Please sign in to comment.