Remove redundant store lookups

crashfix_debugdraw
Evil Eye 2 years ago
parent 325081dc07
commit 06d6de50e6

@ -1426,30 +1426,31 @@ bool CharacterController::updateWeaponState()
else if (!spellid.empty() && spellCastResult != MWWorld::SpellCastState::PowerAlreadyUsed)
{
world->breakInvisibility(mPtr);
MWMechanics::CastSpell cast(mPtr, nullptr, false, mCastingManualSpell);
cast.playSpellCastingEffects(spellid, isMagicItem);
MWMechanics::CastSpell cast(mPtr, {}, false, mCastingManualSpell);
std::vector<ESM::ENAMstruct> effects;
const std::vector<ESM::ENAMstruct>* effects{nullptr};
const MWWorld::ESMStore &store = world->getStore();
if (isMagicItem)
{
const ESM::Enchantment *enchantment = store.get<ESM::Enchantment>().find(spellid);
effects = enchantment->mEffects.mList;
effects = &enchantment->mEffects.mList;
cast.playSpellCastingEffects(enchantment);
}
else
{
const ESM::Spell *spell = store.get<ESM::Spell>().find(spellid);
effects = spell->mEffects.mList;
effects = &spell->mEffects.mList;
cast.playSpellCastingEffects(spell);
}
if (mCanCast)
{
const ESM::MagicEffect *effect = store.get<ESM::MagicEffect>().find(effects.back().mEffectID); // use last effect of list for color of VFX_Hands
const ESM::MagicEffect *effect = store.get<ESM::MagicEffect>().find(effects->back().mEffectID); // use last effect of list for color of VFX_Hands
const ESM::Static* castStatic = world->getStore().get<ESM::Static>().find ("VFX_Hands");
const VFS::Manager* const vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
for (size_t iter = 0; iter < effects.size(); ++iter) // play hands vfx for each effect
if (!effects->empty())
{
if (mAnimation->getNode("Bip01 L Hand"))
mAnimation->addEffect(
@ -1463,7 +1464,7 @@ bool CharacterController::updateWeaponState()
}
}
const ESM::ENAMstruct &firstEffect = effects.at(0); // first effect used for casting animation
const ESM::ENAMstruct& firstEffect = effects->at(0); // first effect used for casting animation
std::string startKey;
std::string stopKey;

@ -169,24 +169,6 @@ namespace MWMechanics
if (!found)
return;
const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().search (mId);
if (spell && targetIsActor && (spell->mData.mType == ESM::Spell::ST_Disease || spell->mData.mType == ESM::Spell::ST_Blight))
{
int requiredResistance = (spell->mData.mType == ESM::Spell::ST_Disease) ?
ESM::MagicEffect::ResistCommonDisease
: ESM::MagicEffect::ResistBlightDisease;
float x = target.getClass().getCreatureStats(target).getMagicEffects().get(requiredResistance).getMagnitude();
auto& prng = MWBase::Environment::get().getWorld()->getPrng();
if (Misc::Rng::roll0to99(prng) <= x)
{
// Fully resisted, show message
if (target == getPlayer())
MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicPCResisted}");
return;
}
}
ActiveSpells::ActiveSpellParams params(*this, mCaster);
bool castByPlayer = (!mCaster.isEmpty() && mCaster == getPlayer());
@ -522,19 +504,14 @@ namespace MWMechanics
return true;
}
void CastSpell::playSpellCastingEffects(std::string_view spellid, bool enchantment) const
void CastSpell::playSpellCastingEffects(const ESM::Enchantment* enchantment) const
{
const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore();
if (enchantment)
{
if (const auto spell = store.get<ESM::Enchantment>().search(spellid))
playSpellCastingEffects(spell->mEffects.mList);
}
else
{
if (const auto spell = store.get<ESM::Spell>().search(spellid))
playSpellCastingEffects(spell->mEffects.mList);
}
playSpellCastingEffects(enchantment->mEffects.mList);
}
void CastSpell::playSpellCastingEffects(const ESM::Spell* spell) const
{
playSpellCastingEffects(spell->mEffects.mList);
}
void CastSpell::playSpellCastingEffects(const std::vector<ESM::ENAMstruct>& effects) const

@ -12,6 +12,7 @@ namespace ESM
struct Ingredient;
struct Potion;
struct EffectList;
struct Enchantment;
struct MagicEffect;
}
@ -58,7 +59,9 @@ namespace MWMechanics
/// @note Auto detects if spell, ingredient or potion
bool cast (const std::string& id);
void playSpellCastingEffects(std::string_view spellid, bool enchantment) const;
void playSpellCastingEffects(const ESM::Enchantment* enchantment) const;
void playSpellCastingEffects(const ESM::Spell* spell) const;
/// @note \a target can be any type of object, not just actors.
void inflict(const MWWorld::Ptr& target, const ESM::EffectList& effects, ESM::RangeType range, bool exploded = false) const;

@ -1263,7 +1263,7 @@ namespace MWScript
return;
MWMechanics::CastSpell cast(ptr, target, false, true);
cast.playSpellCastingEffects(spell->mId, false);
cast.playSpellCastingEffects(spell);
cast.mHitPosition = target.getRefData().getPosition().asVec3();
cast.mAlwaysSucceed = true;
cast.cast(spell);

Loading…
Cancel
Save