From ce324623587bc261a8b6c6e81e63766fd80a0be2 Mon Sep 17 00:00:00 2001 From: Grigorii Latyshev Date: Sat, 25 Nov 2017 17:27:04 +0100 Subject: [PATCH] Move code to apps/openmw/mwmechanics/spellcasting.cpp, move reduce mana code to CastSpell::cast(const ESM::Spell*) --- apps/openmw/mwgui/spellmodel.cpp | 7 +------ apps/openmw/mwmechanics/spellcasting.cpp | 18 ++++++++++++------ apps/openmw/mwworld/worldimp.cpp | 7 ------- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/apps/openmw/mwgui/spellmodel.cpp b/apps/openmw/mwgui/spellmodel.cpp index 9d71d9247..6953d682b 100644 --- a/apps/openmw/mwgui/spellmodel.cpp +++ b/apps/openmw/mwgui/spellmodel.cpp @@ -8,7 +8,6 @@ #include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/spellcasting.hpp" -#include "../mwmechanics/actorutil.hpp" #include "../mwworld/esmstore.hpp" #include "../mwworld/inventorystore.hpp" @@ -61,11 +60,7 @@ namespace MWGui { newSpell.mType = Spell::Type_Spell; std::string cost = std::to_string(spell->mData.mCost); - std::string chance = std::to_string( - (stats.getMagicka().getCurrent() >= spell->mData.mCost || - (mActor == MWMechanics::getPlayer() && MWBase::Environment::get().getWorld()->getGodModeState()) - ) ? int(MWMechanics::getSpellSuccessChance(spell, mActor)) : 0 - ); + std::string chance = std::to_string(int(MWMechanics::getSpellSuccessChance(spell, mActor))); newSpell.mCostColumn = cost + "/" + chance; } else diff --git a/apps/openmw/mwmechanics/spellcasting.cpp b/apps/openmw/mwmechanics/spellcasting.cpp index a09436d14..19afc11ec 100644 --- a/apps/openmw/mwmechanics/spellcasting.cpp +++ b/apps/openmw/mwmechanics/spellcasting.cpp @@ -126,7 +126,10 @@ namespace MWMechanics float castChance = calcSpellBaseSuccessChance(spell, actor, effectiveSchool) + castBonus; castChance *= stats.getFatigueTerm(); - if (stats.getMagicEffects().get(ESM::MagicEffect::Silence).getMagnitude()&& !godmode) + if (godmode) + return 100; + + if (stats.getMagicEffects().get(ESM::MagicEffect::Silence).getMagnitude()) return 0; if (spell->mData.mType == ESM::Spell::ST_Power) @@ -135,13 +138,11 @@ namespace MWMechanics if (spell->mData.mType != ESM::Spell::ST_Spell) return 100; - if (spell->mData.mFlags & ESM::Spell::F_Always) - return 100; + if (stats.getMagicka().getCurrent() < spell->mData.mCost) + return 0; - if (godmode) - { + if (spell->mData.mFlags & ESM::Spell::F_Always) return 100; - } if (!cap) return std::max(0.f, castChance); @@ -888,6 +889,11 @@ namespace MWMechanics MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicSkillFail}"); fail = true; } + + // Reduce mana + MWMechanics::DynamicStat magicka = stats.getMagicka(); + magicka.setCurrent(magicka.getCurrent() - spell->mData.mCost); + stats.setMagicka(magicka); } if (fail) diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 9c7fba9fa..83971eadf 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -2718,13 +2718,6 @@ namespace MWWorld message = "#{sPowerAlreadyUsed}"; fail = true; } - - // Reduce mana - if (!fail && !godmode) - { - magicka.setCurrent(magicka.getCurrent() - spell->mData.mCost); - stats.setMagicka(magicka); - } } if (isPlayer && fail)