From 012d6fa865fb8083dcbeae9b04926527b3c19f4e Mon Sep 17 00:00:00 2001 From: megamage Date: Wed, 19 Aug 2009 16:52:51 -0500 Subject: [8381] Some refactoring work in Unit::m_currentSpells code. Author: VladimirMangos * Restrict access, use enum args, move some repeated code parts to function. * Make m_selfContainer set only part of Unit::SetCurrentCastedSpell --HG-- branch : trunk --- src/game/Unit.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'src/game/Unit.cpp') diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index d21e870a533..b2f0bda7ec8 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -873,7 +873,7 @@ void Unit::CastStop(uint32 except_spellid) { for (uint32 i = CURRENT_FIRST_NON_MELEE_SPELL; i < CURRENT_MAX_SPELL; i++) if (m_currentSpells[i] && m_currentSpells[i]->m_spellInfo->Id!=except_spellid) - InterruptSpell(i,false); + InterruptSpell(CurrentSpellTypes(i),false); } void Unit::CastSpell(Unit* Victim, uint32 spellId, bool triggered, Item *castItem, AuraEffect* triggeredByAura, uint64 originalCaster) @@ -2904,13 +2904,9 @@ SpellMissInfo Unit::SpellHitResult(Unit *pVictim, SpellEntry const *spell, bool } } if (isNormal || m_currentSpells[CURRENT_MELEE_SPELL]) - { misschance = 5.0f; - } else - { misschance = 24.0f; - } } // PvP : PvE melee misschances per leveldif > 2 @@ -3314,9 +3310,11 @@ void Unit::SetCurrentCastedSpell( Spell * pSpell ) // set new current spell m_currentSpells[CSpellType] = pSpell; pSpell->SetReferencedFromCurrent(true); + + pSpell->m_selfContainer = &(m_currentSpells[pSpell->GetCurrentContainer()]); } -void Unit::InterruptSpell(uint32 spellType, bool withDelayed, bool withInstant) +void Unit::InterruptSpell(CurrentSpellTypes spellType, bool withDelayed, bool withInstant) { assert(spellType < CURRENT_MAX_SPELL); @@ -3345,6 +3343,18 @@ void Unit::InterruptSpell(uint32 spellType, bool withDelayed, bool withInstant) } } +void Unit::FinishSpell(CurrentSpellTypes spellType, bool ok /*= true*/) +{ + Spell* spell = m_currentSpells[spellType]; + if (!spell) + return; + + if (spellType == CURRENT_CHANNELED_SPELL) + spell->SendChannelUpdate(0); + + spell->finish(ok); +} + bool Unit::IsNonMeleeSpellCasted(bool withDelayed, bool skipChanneled, bool skipAutorepeat, bool isAutoshoot) const { // We don't do loop here to explicitly show that melee spell is excluded. -- cgit v1.2.3