From aabd5a98c779995933022883a1c5f222868cb9bf Mon Sep 17 00:00:00 2001 From: Petr Mikheev Date: Sat, 31 Dec 2022 13:12:12 +0100 Subject: [PATCH] Fix 'toggle spell' control (was broken by !2541) --- apps/openmw/mwlua/types/actor.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/apps/openmw/mwlua/types/actor.cpp b/apps/openmw/mwlua/types/actor.cpp index 1067ce40d3..9663e842a7 100644 --- a/apps/openmw/mwlua/types/actor.cpp +++ b/apps/openmw/mwlua/types/actor.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -165,13 +166,24 @@ namespace MWLua MWMechanics::DrawState newDrawState = static_cast(stance); if (stats.getDrawState() == newDrawState) return; - if (newDrawState == MWMechanics::DrawState::Spell && stats.getSpells().getSelectedSpell().empty()) + if (newDrawState == MWMechanics::DrawState::Spell) { - if (!cls.hasInventoryStore(self.ptr())) - return; // No selected spell and no items; can't use magic stance. - MWWorld::InventoryStore& store = cls.getInventoryStore(self.ptr()); - if (store.getSelectedEnchantItem() == store.end()) - return; // No selected spell and no selected enchanted item; can't use magic stance. + bool hasSelectedSpell; + if (self.ptr() == MWBase::Environment::get().getWorld()->getPlayerPtr()) + // For the player selecting spell in UI doesn't change selected spell in CreatureStats (was + // implemented this way to prevent changing spell during casting, probably should be refactored), so + // we have to handle the player separately. + hasSelectedSpell = !MWBase::Environment::get().getWindowManager()->getSelectedSpell().empty(); + else + hasSelectedSpell = !stats.getSpells().getSelectedSpell().empty(); + if (!hasSelectedSpell) + { + if (!cls.hasInventoryStore(self.ptr())) + return; // No selected spell and no items; can't use magic stance. + MWWorld::InventoryStore& store = cls.getInventoryStore(self.ptr()); + if (store.getSelectedEnchantItem() == store.end()) + return; // No selected spell and no selected enchanted item; can't use magic stance. + } } MWBase::MechanicsManager* mechanics = MWBase::Environment::get().getMechanicsManager(); // We want to interrupt animation only if attack is preparing, but still is not triggered.