From 08b32d7d321cf3b8624145a8b00dd72dd05100c3 Mon Sep 17 00:00:00 2001 From: michalpolko Date: Wed, 8 Dec 2010 10:33:24 +0300 Subject: [PATCH] [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 --- src/game/Spell.cpp | 6 +++--- src/game/Unit.cpp | 36 +++++++++++++++++++++++++++++------- src/game/Unit.h | 2 +- src/shared/revision_nr.h | 2 +- 4 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/game/Spell.cpp b/src/game/Spell.cpp index 59a78eea6..fe281d6d4 100644 --- a/src/game/Spell.cpp +++ b/src/game/Spell.cpp @@ -1722,7 +1722,7 @@ void Spell::SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, UnitList& { if (EffectChainTarget <= 1) { - if(Unit* pUnitTarget = m_caster->SelectMagnetTarget(m_targets.getUnitTarget(), m_spellInfo)) + if(Unit* pUnitTarget = m_caster->SelectMagnetTarget(m_targets.getUnitTarget(), this, effIndex)) { m_targets.setUnitTarget(pUnitTarget); targetUnitMap.push_back(pUnitTarget); @@ -2077,7 +2077,7 @@ void Spell::SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, UnitList& } else { - if(Unit* pUnitTarget = m_caster->SelectMagnetTarget(m_targets.getUnitTarget(), m_spellInfo)) + if(Unit* pUnitTarget = m_caster->SelectMagnetTarget(m_targets.getUnitTarget(), this, effIndex)) { m_targets.setUnitTarget(pUnitTarget); targetUnitMap.push_back(pUnitTarget); @@ -2107,7 +2107,7 @@ void Spell::SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, UnitList& break; case TARGET_SINGLE_ENEMY: { - if(Unit* pUnitTarget = m_caster->SelectMagnetTarget(m_targets.getUnitTarget(), m_spellInfo)) + if(Unit* pUnitTarget = m_caster->SelectMagnetTarget(m_targets.getUnitTarget(), this, effIndex)) { m_targets.setUnitTarget(pUnitTarget); targetUnitMap.push_back(pUnitTarget); diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index d140289b9..43eddd51b 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -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; diff --git a/src/game/Unit.h b/src/game/Unit.h index aba2ce450..0c18d3753 100644 --- a/src/game/Unit.h +++ b/src/game/Unit.h @@ -1832,7 +1832,7 @@ class MANGOS_DLL_SPEC Unit : public WorldObject bool HasAuraState(AuraState flag) const { return HasFlag(UNIT_FIELD_AURASTATE, 1<<(flag-1)); } bool HasAuraStateForCaster(AuraState flag, uint64 caster) const; void UnsummonAllTotems(); - Unit* SelectMagnetTarget(Unit *victim, SpellEntry const *spellInfo = NULL); + Unit* SelectMagnetTarget(Unit *victim, Spell* spell = NULL, SpellEffectIndex eff = EFFECT_INDEX_0); int32 SpellBonusWithCoeffs(SpellEntry const *spellProto, int32 total, int32 benefit, int32 ap_benefit, DamageEffectType damagetype, bool donePart, float defCoeffMod = 1.0f); int32 SpellBaseDamageBonusDone(SpellSchoolMask schoolMask); diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 441abb8d6..f0467610b 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "10840" + #define REVISION_NR "10841" #endif // __REVISION_NR_H__