Restore used spell mods if spell cast fails.

--HG--
branch : trunk
This commit is contained in:
thenecromancer
2009-05-28 23:05:52 +02:00
parent 39dd09532b
commit bc55209b3e
3 changed files with 30 additions and 3 deletions
+22
View File
@@ -16706,6 +16706,28 @@ void Player::AddSpellMod(SpellModifier* mod, bool apply)
}
}
// Restore spellmods in case of failed cast
void Player::RestoreSpellMods(Spell const* spell)
{
if(!spell || (m_SpellModRemoveCount == 0))
return;
for(int i=0;i<MAX_SPELLMOD;++i)
{
for (SpellModList::iterator itr = m_spellMods[i].begin(); itr != m_spellMods[i].end();++itr)
{
SpellModifier *mod = *itr;
if (mod && mod->charges == -1 && mod->lastAffected == spell)
{
mod->lastAffected = NULL;
mod->charges = 1;
m_SpellModRemoveCount--;
}
}
}
}
void Player::RemoveSpellMods(Spell const* spell)
{
if(!spell || (m_SpellModRemoveCount == 0))
+1 -1
View File
@@ -1447,6 +1447,7 @@ class TRINITY_DLL_SPEC Player : public Unit
bool IsAffectedBySpellmod(SpellEntry const *spellInfo, SpellModifier *mod, Spell const* spell = NULL);
template <class T> T ApplySpellMod(uint32 spellId, SpellModOp op, T &basevalue, Spell const* spell = NULL);
void RemoveSpellMods(Spell const* spell);
void RestoreSpellMods(Spell const* spell);
bool HasSpellCooldown(uint32 spell_id) const
{
@@ -2396,4 +2397,3 @@ template <class T> T Player::ApplySpellMod(uint32 spellId, SpellModOp op, T &bas
return T(diff);
}
#endif
+6 -1
View File
@@ -2720,9 +2720,14 @@ void Spell::finish(bool ok)
if(!m_caster->IsNonMeleeSpellCasted(false, false, true))
m_caster->clearUnitState(UNIT_STAT_CASTING);
// other code related only to successfully finished spells
if(!ok)
{
//restore spell mods
if (m_caster->GetTypeId() == TYPEID_PLAYER)
((Player*)m_caster)->RestoreSpellMods(this);
return;
}
// other code related only to successfully finished spells
//remove spell mods
if (m_caster->GetTypeId() == TYPEID_PLAYER)