[8381] Some refactoring work in Unit::m_currentSpells code.

* Restrict access, use enum args, move some repeated code parts to function.
* Make m_selfContainer set only part of Unit::SetCurrentCastedSpell
This commit is contained in:
VladimirMangos 2009-08-18 02:07:39 +04:00
parent 1b1d013623
commit 74d27294aa
10 changed files with 70 additions and 69 deletions

View file

@ -816,14 +816,16 @@ uint32 Unit::DealDamage(Unit *pVictim, uint32 damage, CleanDamage const* cleanDa
if (i == CURRENT_CHANNELED_SPELL)
continue;
if(Spell* spell = pVictim->m_currentSpells[i])
if(Spell* spell = pVictim->GetCurrentSpell(CurrentSpellTypes(i)))
{
if(spell->getState() == SPELL_STATE_PREPARING)
{
if(spell->m_spellInfo->InterruptFlags & SPELL_INTERRUPT_FLAG_ABORT_ON_DMG)
pVictim->InterruptSpell(i);
pVictim->InterruptSpell(CurrentSpellTypes(i));
else
spell->Delayed();
}
}
}
}
@ -879,7 +881,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, Aura* triggeredByAura, uint64 originalCaster)
@ -2705,13 +2707,9 @@ float Unit::MeleeMissChanceCalc(const Unit *pVictim, WeaponAttackType attType) c
}
}
if (isNormal || m_currentSpells[CURRENT_MELEE_SPELL])
{
misschance = 5.0f;
}
else
{
misschance = 24.0f;
}
}
// PvP : PvE melee misschances per leveldif > 2
@ -3107,9 +3105,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)
void Unit::InterruptSpell(CurrentSpellTypes spellType, bool withDelayed)
{
assert(spellType < CURRENT_MAX_SPELL);
@ -3134,6 +3134,19 @@ void Unit::InterruptSpell(uint32 spellType, bool withDelayed)
}
}
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) const
{
// We don't do loop here to explicitly show that melee spell is excluded.