From bc55209b3e2723ef39935d6c4ff3f8b442b98f1c Mon Sep 17 00:00:00 2001 From: thenecromancer Date: Thu, 28 May 2009 23:05:52 +0200 Subject: Restore used spell mods if spell cast fails. --HG-- branch : trunk --- src/game/Player.cpp | 22 ++++++++++++++++++++++ src/game/Player.h | 2 +- src/game/Spell.cpp | 9 +++++++-- 3 files changed, 30 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/game/Player.cpp b/src/game/Player.cpp index e11b7e168ef..b036fd1118e 100644 --- a/src/game/Player.cpp +++ b/src/game/Player.cpp @@ -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;icharges == -1 && mod->lastAffected == spell) + { + mod->lastAffected = NULL; + mod->charges = 1; + m_SpellModRemoveCount--; + } + } + } +} + void Player::RemoveSpellMods(Spell const* spell) { if(!spell || (m_SpellModRemoveCount == 0)) diff --git a/src/game/Player.h b/src/game/Player.h index 27e088f5131..aff836b33c4 100644 --- a/src/game/Player.h +++ b/src/game/Player.h @@ -1447,6 +1447,7 @@ class TRINITY_DLL_SPEC Player : public Unit bool IsAffectedBySpellmod(SpellEntry const *spellInfo, SpellModifier *mod, Spell const* spell = NULL); template 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 T Player::ApplySpellMod(uint32 spellId, SpellModOp op, T &bas return T(diff); } #endif - diff --git a/src/game/Spell.cpp b/src/game/Spell.cpp index 66a237d9198..e9ab64f87d4 100644 --- a/src/game/Spell.cpp +++ b/src/game/Spell.cpp @@ -2720,9 +2720,14 @@ void Spell::finish(bool ok) if(!m_caster->IsNonMeleeSpellCasted(false, false, true)) m_caster->clearUnitState(UNIT_STAT_CASTING); + 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 - if(!ok) - return; //remove spell mods if (m_caster->GetTypeId() == TYPEID_PLAYER) -- cgit v1.2.3