diff options
author | megamage <none@none> | 2009-04-19 11:42:16 -0500 |
---|---|---|
committer | megamage <none@none> | 2009-04-19 11:42:16 -0500 |
commit | 2a875fb5e01b702a6984eb23b4f071e9ba3b5aa3 (patch) | |
tree | 486eef1d21d0b3e88d57ff412ab1793d4e4f7438 /src/game/Unit.cpp | |
parent | 0c27856ee4d26125b7e5cb2ca207449f218e1702 (diff) |
[7686] Implement aura SPELL_AURA_ADD_CASTER_HIT_TRIGGER (111). Author: Lightguard
--HG--
branch : trunk
Diffstat (limited to 'src/game/Unit.cpp')
-rw-r--r-- | src/game/Unit.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index 2dca6c45491..f9c5d5c4d6f 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -2266,6 +2266,9 @@ void Unit::AttackerStateUpdate (Unit *pVictim, WeaponAttackType attType, bool ex return; } + // attack can be redirected to another target + pVictim = SelectMagnetTarget(pVictim); + CalcDamageInfo damageInfo; CalculateMeleeDamage(pVictim, 0, &damageInfo, attType); // Send log damage message to client @@ -8175,6 +8178,40 @@ void Unit::SetCharm(Unit* charm, bool apply) } } +Unit* Unit::SelectMagnetTarget(Unit *victim, SpellEntry const *spellInfo) +{ + if(!victim) + return NULL; + + // Magic case + if(spellInfo && (spellInfo->DmgClass == SPELL_DAMAGE_CLASS_NONE || spellInfo->DmgClass == SPELL_DAMAGE_CLASS_MAGIC)) + { + //I am not sure if this should be redirected. + if(spellInfo->DmgClass == SPELL_DAMAGE_CLASS_NONE) + return victim; + + //if((*itr)->GetParentAura()->DropAuraCharge()) + + 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->isAlive()) + 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)) + return magnet; + } + + return victim; +} + Unit* Unit::GetFirstControlled() const { //Sequence: charmed, pet, other guardians |