Added spell failure sound

This commit is contained in:
scrawl 2013-11-09 07:59:17 +01:00
parent cbe96a2170
commit 1051611ffa

View file

@ -1996,24 +1996,47 @@ namespace MWWorld
const ESM::Spell* spell = getStore().get<ESM::Spell>().search(selectedSpell); const ESM::Spell* spell = getStore().get<ESM::Spell>().search(selectedSpell);
// Check mana // Check mana
bool fail = false;
MWMechanics::DynamicStat<float> magicka = stats.getMagicka(); MWMechanics::DynamicStat<float> magicka = stats.getMagicka();
if (magicka.getCurrent() < spell->mData.mCost) if (magicka.getCurrent() < spell->mData.mCost)
{ {
MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicInsufficientSP}"); MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicInsufficientSP}");
return; fail = true;
} }
// Reduce mana // Reduce mana
magicka.setCurrent(magicka.getCurrent() - spell->mData.mCost); if (!fail)
stats.setMagicka(magicka); {
magicka.setCurrent(magicka.getCurrent() - spell->mData.mCost);
stats.setMagicka(magicka);
}
// Check success // Check success
int successChance = MWMechanics::getSpellSuccessChance(selectedSpell, actor); int successChance = MWMechanics::getSpellSuccessChance(selectedSpell, actor);
int roll = std::rand()/ (static_cast<double> (RAND_MAX) + 1) * 100; // [0, 99] int roll = std::rand()/ (static_cast<double> (RAND_MAX) + 1) * 100; // [0, 99]
if (roll >= successChance) if (!fail && roll >= successChance)
{ {
MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicSkillFail}"); MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicSkillFail}");
// TODO sound: "Spell Failure <School>" fail = true;
}
if (fail)
{
// Failure sound
for (std::vector<ESM::ENAMstruct>::const_iterator iter (spell->mEffects.mList.begin());
iter!=spell->mEffects.mList.end(); ++iter)
{
const ESM::MagicEffect *magicEffect = getStore().get<ESM::MagicEffect>().find (
iter->mEffectID);
static const std::string schools[] = {
"alteration", "conjuration", "destruction", "illusion", "mysticism", "restoration"
};
MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager();
sndMgr->playSound3D(actor, "Spell Failure " + schools[magicEffect->mData.mSchool], 1.0f, 1.0f);
break;
}
return; return;
} }