[10841] Implement charges counting for magnet target auras.

Also implement skip spell effects redirecting if magnet target can't be
targeted by this spell effect base at spell effect target data requirements.

Signed-off-by: VladimirMangos <vladimir@getmangos.com>
This commit is contained in:
michalpolko 2010-12-08 10:33:24 +03:00 committed by VladimirMangos
parent 1b4210e38c
commit 08b32d7d32
4 changed files with 34 additions and 12 deletions

View file

@ -6063,29 +6063,51 @@ int32 Unit::DealHeal(Unit *pVictim, uint32 addhealth, SpellEntry const *spellPro
return gain;
}
Unit* Unit::SelectMagnetTarget(Unit *victim, SpellEntry const *spellInfo)
Unit* Unit::SelectMagnetTarget(Unit *victim, Spell* spell, SpellEffectIndex eff)
{
if(!victim)
return NULL;
// Magic case
if(spellInfo && (spellInfo->DmgClass == SPELL_DAMAGE_CLASS_NONE || spellInfo->DmgClass == SPELL_DAMAGE_CLASS_MAGIC))
if (spell && (spell->m_spellInfo->DmgClass == SPELL_DAMAGE_CLASS_NONE || spell->m_spellInfo->DmgClass == SPELL_DAMAGE_CLASS_MAGIC))
{
Unit::AuraList const& magnetAuras = victim->GetAurasByType(SPELL_AURA_SPELL_MAGNET);
for(Unit::AuraList::const_iterator itr = magnetAuras.begin(); itr != magnetAuras.end(); ++itr)
if(Unit* magnet = (*itr)->GetCaster())
if(magnet->IsWithinLOSInMap(this) && magnet->isAlive())
{
if (Unit* magnet = (*itr)->GetCaster())
{
if (magnet->isAlive() && magnet->IsWithinLOSInMap(this) && spell->CheckTarget(magnet, eff))
{
if (SpellAuraHolder *holder = (*itr)->GetHolder())
if (holder->GetAuraCharges())
if (holder->DropAuraCharge())
victim->RemoveSpellAuraHolder(holder);
return magnet;
}
}
}
}
// Melee && ranged case
else
{
AuraList const& hitTriggerAuras = victim->GetAurasByType(SPELL_AURA_ADD_CASTER_HIT_TRIGGER);
for(AuraList::const_iterator i = hitTriggerAuras.begin(); i != hitTriggerAuras.end(); ++i)
if(Unit* magnet = (*i)->GetCaster())
if(magnet->isAlive() && magnet->IsWithinLOSInMap(this))
if(roll_chance_i((*i)->GetModifier()->m_amount))
{
if (Unit* magnet = (*i)->GetCaster())
{
if (magnet->isAlive() && magnet->IsWithinLOSInMap(this) && (!spell || spell->CheckTarget(magnet, eff)))
{
if (roll_chance_i((*i)->GetModifier()->m_amount))
{
if (SpellAuraHolder *holder = (*i)->GetHolder())
if (holder->GetAuraCharges())
if (holder->DropAuraCharge())
victim->RemoveSpellAuraHolder(holder);
return magnet;
}
}
}
}
}
return victim;