From a7c953b3180e962af2c22458b2407800039faa80 Mon Sep 17 00:00:00 2001 From: Grigorii Latyshev Date: Fri, 24 Nov 2017 15:06:07 +0100 Subject: [PATCH 1/6] Display 0 chance for spell if player does not have enought magic energy --- apps/openmw/mwgui/spellmodel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/mwgui/spellmodel.cpp b/apps/openmw/mwgui/spellmodel.cpp index 6953d682b..c4112513a 100644 --- a/apps/openmw/mwgui/spellmodel.cpp +++ b/apps/openmw/mwgui/spellmodel.cpp @@ -60,7 +60,7 @@ namespace MWGui { newSpell.mType = Spell::Type_Spell; std::string cost = std::to_string(spell->mData.mCost); - std::string chance = std::to_string(int(MWMechanics::getSpellSuccessChance(spell, mActor))); + std::string chance = std::to_string((stats.getMagicka().getCurrent() >= spell->mData.mCost) ? int(MWMechanics::getSpellSuccessChance(spell, mActor)) : 0); newSpell.mCostColumn = cost + "/" + chance; } else From 32096ae0cc19f2b6c8eabd31a2732c49a337d567 Mon Sep 17 00:00:00 2001 From: Grigorii Latyshev Date: Sat, 25 Nov 2017 01:46:04 +0100 Subject: [PATCH 2/6] Fix displayed spell success chance in God Mode --- apps/openmw/mwgui/spellmodel.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwgui/spellmodel.cpp b/apps/openmw/mwgui/spellmodel.cpp index c4112513a..9d71d9247 100644 --- a/apps/openmw/mwgui/spellmodel.cpp +++ b/apps/openmw/mwgui/spellmodel.cpp @@ -8,6 +8,7 @@ #include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/spellcasting.hpp" +#include "../mwmechanics/actorutil.hpp" #include "../mwworld/esmstore.hpp" #include "../mwworld/inventorystore.hpp" @@ -60,7 +61,11 @@ 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) ? int(MWMechanics::getSpellSuccessChance(spell, mActor)) : 0); + 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 + ); newSpell.mCostColumn = cost + "/" + chance; } else From ce324623587bc261a8b6c6e81e63766fd80a0be2 Mon Sep 17 00:00:00 2001 From: Grigorii Latyshev Date: Sat, 25 Nov 2017 17:27:04 +0100 Subject: [PATCH 3/6] 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) From dab72b45db77e9fbbb6f51d64ac61f38c9f734bb Mon Sep 17 00:00:00 2001 From: Grigorii Latyshev Date: Tue, 28 Nov 2017 23:14:57 +0100 Subject: [PATCH 4/6] Move mana reducing code back --- apps/openmw/mwmechanics/spellcasting.cpp | 5 ----- apps/openmw/mwworld/worldimp.cpp | 7 +++++++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwmechanics/spellcasting.cpp b/apps/openmw/mwmechanics/spellcasting.cpp index 19afc11ec..5cab750db 100644 --- a/apps/openmw/mwmechanics/spellcasting.cpp +++ b/apps/openmw/mwmechanics/spellcasting.cpp @@ -889,11 +889,6 @@ 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 83971eadf..9c7fba9fa 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -2718,6 +2718,13 @@ namespace MWWorld message = "#{sPowerAlreadyUsed}"; fail = true; } + + // Reduce mana + if (!fail && !godmode) + { + magicka.setCurrent(magicka.getCurrent() - spell->mData.mCost); + stats.setMagicka(magicka); + } } if (isPlayer && fail) From 9fe5a4d236d5f3e5d3f3214be6beb2e400b9e43e Mon Sep 17 00:00:00 2001 From: Grigorii Latyshev Date: Tue, 28 Nov 2017 17:04:37 +0100 Subject: [PATCH 5/6] Revert condition changes --- apps/openmw/mwmechanics/spellcasting.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwmechanics/spellcasting.cpp b/apps/openmw/mwmechanics/spellcasting.cpp index 5cab750db..63fe3fa3c 100644 --- a/apps/openmw/mwmechanics/spellcasting.cpp +++ b/apps/openmw/mwmechanics/spellcasting.cpp @@ -126,10 +126,7 @@ namespace MWMechanics float castChance = calcSpellBaseSuccessChance(spell, actor, effectiveSchool) + castBonus; castChance *= stats.getFatigueTerm(); - if (godmode) - return 100; - - if (stats.getMagicEffects().get(ESM::MagicEffect::Silence).getMagnitude()) + if (stats.getMagicEffects().get(ESM::MagicEffect::Silence).getMagnitude()&& !godmode) return 0; if (spell->mData.mType == ESM::Spell::ST_Power) @@ -138,12 +135,17 @@ namespace MWMechanics if (spell->mData.mType != ESM::Spell::ST_Spell) return 100; - if (stats.getMagicka().getCurrent() < spell->mData.mCost) + if (stats.getMagicka().getCurrent() < spell->mData.mCost && !godmode) return 0; if (spell->mData.mFlags & ESM::Spell::F_Always) return 100; + if (godmode) + { + return 100; + } + if (!cap) return std::max(0.f, castChance); else From 2abb1a2ec27c35cbef25ae031a50e46dd5c0caea Mon Sep 17 00:00:00 2001 From: Grigorii Latyshev Date: Tue, 28 Nov 2017 23:10:07 +0100 Subject: [PATCH 6/6] Added checkMagicka parameter --- apps/openmw/mwgui/spellmodel.cpp | 2 +- apps/openmw/mwmechanics/spellcasting.cpp | 8 ++++---- apps/openmw/mwmechanics/spellcasting.hpp | 5 +++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwgui/spellmodel.cpp b/apps/openmw/mwgui/spellmodel.cpp index 6953d682b..f83b72096 100644 --- a/apps/openmw/mwgui/spellmodel.cpp +++ b/apps/openmw/mwgui/spellmodel.cpp @@ -60,7 +60,7 @@ namespace MWGui { newSpell.mType = Spell::Type_Spell; std::string cost = std::to_string(spell->mData.mCost); - std::string chance = std::to_string(int(MWMechanics::getSpellSuccessChance(spell, mActor))); + std::string chance = std::to_string(int(MWMechanics::getSpellSuccessChance(spell, mActor, NULL, true, true))); newSpell.mCostColumn = cost + "/" + chance; } else diff --git a/apps/openmw/mwmechanics/spellcasting.cpp b/apps/openmw/mwmechanics/spellcasting.cpp index 63fe3fa3c..8fbf67535 100644 --- a/apps/openmw/mwmechanics/spellcasting.cpp +++ b/apps/openmw/mwmechanics/spellcasting.cpp @@ -115,7 +115,7 @@ namespace MWMechanics return castChance; } - float getSpellSuccessChance (const ESM::Spell* spell, const MWWorld::Ptr& actor, int* effectiveSchool, bool cap) + float getSpellSuccessChance (const ESM::Spell* spell, const MWWorld::Ptr& actor, int* effectiveSchool, bool cap, bool checkMagicka) { bool godmode = actor == MWMechanics::getPlayer() && MWBase::Environment::get().getWorld()->getGodModeState(); @@ -135,7 +135,7 @@ namespace MWMechanics if (spell->mData.mType != ESM::Spell::ST_Spell) return 100; - if (stats.getMagicka().getCurrent() < spell->mData.mCost && !godmode) + if (checkMagicka && stats.getMagicka().getCurrent() < spell->mData.mCost && !godmode) return 0; if (spell->mData.mFlags & ESM::Spell::F_Always) @@ -152,11 +152,11 @@ namespace MWMechanics return std::max(0.f, std::min(100.f, castChance)); } - float getSpellSuccessChance (const std::string& spellId, const MWWorld::Ptr& actor, int* effectiveSchool, bool cap) + float getSpellSuccessChance (const std::string& spellId, const MWWorld::Ptr& actor, int* effectiveSchool, bool cap, bool checkMagicka) { const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get().find(spellId); - return getSpellSuccessChance(spell, actor, effectiveSchool, cap); + return getSpellSuccessChance(spell, actor, effectiveSchool, cap, checkMagicka); } diff --git a/apps/openmw/mwmechanics/spellcasting.hpp b/apps/openmw/mwmechanics/spellcasting.hpp index 2e368afcf..1f5ef45bd 100644 --- a/apps/openmw/mwmechanics/spellcasting.hpp +++ b/apps/openmw/mwmechanics/spellcasting.hpp @@ -31,11 +31,12 @@ namespace MWMechanics * @param actor calculate spell success chance for this actor (depends on actor's skills) * @param effectiveSchool the spell's effective school (relevant for skill progress) will be written here * @param cap cap the result to 100%? + * @param checkMagicka check magicka? * @note actor can be an NPC or a creature * @return success chance from 0 to 100 (in percent), if cap=false then chance above 100 may be returned. */ - float getSpellSuccessChance (const ESM::Spell* spell, const MWWorld::Ptr& actor, int* effectiveSchool = NULL, bool cap=true); - float getSpellSuccessChance (const std::string& spellId, const MWWorld::Ptr& actor, int* effectiveSchool = NULL, bool cap=true); + float getSpellSuccessChance (const ESM::Spell* spell, const MWWorld::Ptr& actor, int* effectiveSchool = NULL, bool cap=true, bool checkMagicka=false); + float getSpellSuccessChance (const std::string& spellId, const MWWorld::Ptr& actor, int* effectiveSchool = NULL, bool cap=true, bool checkMagicka=false); int getSpellSchool(const std::string& spellId, const MWWorld::Ptr& actor); int getSpellSchool(const ESM::Spell* spell, const MWWorld::Ptr& actor);