1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-19 23:23:52 +00:00

Clean up CastSpell

This commit is contained in:
Capostrophic 2020-04-26 21:37:19 +03:00
parent 8d22e075e6
commit b1d857818d
2 changed files with 11 additions and 25 deletions

View file

@ -20,7 +20,7 @@
#include "../mwrender/animation.hpp" #include "../mwrender/animation.hpp"
#include "npcstats.hpp" #include "creaturestats.hpp"
#include "actorutil.hpp" #include "actorutil.hpp"
#include "aifollow.hpp" #include "aifollow.hpp"
#include "weapontype.hpp" #include "weapontype.hpp"
@ -515,16 +515,14 @@ namespace MWMechanics
bool CastSpell::cast(const std::string &id) bool CastSpell::cast(const std::string &id)
{ {
if (const ESM::Spell *spell = const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore();
MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().search (id)) if (const auto spell = store.get<ESM::Spell>().search(id))
return cast(spell); return cast(spell);
if (const ESM::Potion *potion = if (const auto potion = store.get<ESM::Potion>().search(id))
MWBase::Environment::get().getWorld()->getStore().get<ESM::Potion>().search (id))
return cast(potion); return cast(potion);
if (const ESM::Ingredient *ingredient = if (const auto ingredient = store.get<ESM::Ingredient>().search(id))
MWBase::Environment::get().getWorld()->getStore().get<ESM::Ingredient>().search (id))
return cast(ingredient); return cast(ingredient);
throw std::runtime_error("ID type cannot be casted"); throw std::runtime_error("ID type cannot be casted");
@ -687,10 +685,9 @@ namespace MWMechanics
stats.getSpells().usePower(spell); stats.getSpells().usePower(spell);
} }
if (mCaster == getPlayer() && spellIncreasesSkill()) if (!mManualSpell && mCaster == getPlayer() && spellIncreasesSkill(spell))
mCaster.getClass().skillUsageSucceeded(mCaster, mCaster.getClass().skillUsageSucceeded(mCaster, spellSchoolToSkill(school), 0);
spellSchoolToSkill(school), 0);
// A non-actor doesn't play its spell cast effects from a character controller, so play them here // A non-actor doesn't play its spell cast effects from a character controller, so play them here
if (!mCaster.getClass().isActor()) if (!mCaster.getClass().isActor())
playSpellCastingEffects(spell->mEffects.mList); playSpellCastingEffects(spell->mEffects.mList);
@ -718,10 +715,8 @@ namespace MWMechanics
effect.mRange = ESM::RT_Self; effect.mRange = ESM::RT_Self;
effect.mArea = 0; effect.mArea = 0;
const ESM::MagicEffect *magicEffect = const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore();
MWBase::Environment::get().getWorld()->getStore().get<ESM::MagicEffect>().find ( const auto magicEffect = store.get<ESM::MagicEffect>().find(effect.mEffectID);
effect.mEffectID);
const MWMechanics::CreatureStats& creatureStats = mCaster.getClass().getCreatureStats(mCaster); const MWMechanics::CreatureStats& creatureStats = mCaster.getClass().getCreatureStats(mCaster);
float x = (mCaster.getClass().getSkill(mCaster, ESM::Skill::Alchemy) + float x = (mCaster.getClass().getSkill(mCaster, ESM::Skill::Alchemy) +
@ -733,7 +728,7 @@ namespace MWMechanics
if (roll > x) if (roll > x)
{ {
// "X has no effect on you" // "X has no effect on you"
std::string message = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("sNotifyMessage50")->mValue.getString(); std::string message = store.get<ESM::GameSetting>().find("sNotifyMessage50")->mValue.getString();
message = Misc::StringUtils::format(message, ingredient->mName); message = Misc::StringUtils::format(message, ingredient->mName);
MWBase::Environment::get().getWindowManager()->messageBox(message); MWBase::Environment::get().getWindowManager()->messageBox(message);
return false; return false;
@ -834,9 +829,4 @@ namespace MWMechanics
sndMgr->playSound3D(mCaster, schools[effect->mData.mSchool]+" cast", 1.0f, 1.0f); sndMgr->playSound3D(mCaster, schools[effect->mData.mSchool]+" cast", 1.0f, 1.0f);
} }
} }
bool CastSpell::spellIncreasesSkill()
{
return !mManualSpell && MWMechanics::spellIncreasesSkill(mId);
}
} }

View file

@ -17,8 +17,6 @@ namespace ESM
namespace MWMechanics namespace MWMechanics
{ {
struct EffectKey; struct EffectKey;
class MagicEffects;
class CreatureStats;
class CastSpell class CastSpell
{ {
@ -56,8 +54,6 @@ namespace MWMechanics
void playSpellCastingEffects(const std::string &spellid, bool enchantment); void playSpellCastingEffects(const std::string &spellid, bool enchantment);
bool spellIncreasesSkill();
/// Launch a bolt with the given effects. /// Launch a bolt with the given effects.
void launchMagicBolt (); void launchMagicBolt ();