Core/Spells: Changes in code related to spell explicit target redirection (cleanups, added target validation, prevent unexpected behaviour in some cases)
This commit is contained in:
1 parent
de823937b7
commit
9abc47736f
4 files changed
+64
-41
No files matched your search
@@ -1884,7 +1884,7 @@ void Unit::AttackerStateUpdate (Unit* victim, WeaponAttackType attType, bool ext
|
||||
else
|
||||
{
|
||||
// attack can be redirected to another target
|
||||
victim = SelectMagnetTarget(victim);
|
||||
victim = GetMeleeHitRedirectTarget(victim);
|
||||
|
||||
CalcDamageInfo damageInfo;
|
||||
CalculateMeleeDamage(victim, 0, &damageInfo, attType);
|
||||
@@ -9988,44 +9988,43 @@ int32 Unit::DealHeal(Unit* victim, uint32 addhealth)
|
||||
return gain;
|
||||
}
|
||||
|
||||
Unit* Unit::SelectMagnetTarget(Unit* victim, SpellInfo const* spellInfo)
|
||||
Unit* Unit::GetMagicHitRedirectTarget(Unit* victim, SpellInfo const* spellInfo)
|
||||
{
|
||||
if (!victim)
|
||||
return NULL;
|
||||
// Patch 1.2 notes: Spell Reflection no longer reflects abilities
|
||||
if (spellInfo->Attributes & SPELL_ATTR0_ABILITY || spellInfo->AttributesEx & SPELL_ATTR1_CANT_BE_REDIRECTED || spellInfo->Attributes & SPELL_ATTR0_UNAFFECTED_BY_INVULNERABILITY)
|
||||
return victim;
|
||||
|
||||
// Magic case
|
||||
if (spellInfo && (spellInfo->DmgClass == SPELL_DAMAGE_CLASS_NONE || spellInfo->DmgClass == SPELL_DAMAGE_CLASS_MAGIC))
|
||||
Unit::AuraEffectList const& magnetAuras = victim->GetAuraEffectsByType(SPELL_AURA_SPELL_MAGNET);
|
||||
for (Unit::AuraEffectList::const_iterator itr = magnetAuras.begin(); itr != magnetAuras.end(); ++itr)
|
||||
{
|
||||
// Patch 1.2 notes: Spell Reflection no longer reflects abilities
|
||||
if (spellInfo->Attributes & SPELL_ATTR0_ABILITY || spellInfo->AttributesEx & SPELL_ATTR1_CANT_BE_REDIRECTED || spellInfo->Attributes & SPELL_ATTR0_UNAFFECTED_BY_INVULNERABILITY)
|
||||
return victim;
|
||||
// I am not sure if this should be redirected.
|
||||
if (spellInfo->DmgClass == SPELL_DAMAGE_CLASS_NONE)
|
||||
return victim;
|
||||
if (Unit* magnet = (*itr)->GetBase()->GetUnitOwner())
|
||||
if (spellInfo->CheckExplicitTarget(this, magnet) == SPELL_CAST_OK
|
||||
&& spellInfo->CheckTarget(this, magnet, false) == SPELL_CAST_OK
|
||||
&& _IsValidAttackTarget(magnet, spellInfo)
|
||||
&& IsWithinLOSInMap(magnet))
|
||||
{
|
||||
(*itr)->GetBase()->DropCharge(AURA_REMOVE_BY_EXPIRE);
|
||||
return magnet;
|
||||
}
|
||||
}
|
||||
return victim;
|
||||
}
|
||||
|
||||
Unit::AuraEffectList const& magnetAuras = victim->GetAuraEffectsByType(SPELL_AURA_SPELL_MAGNET);
|
||||
for (Unit::AuraEffectList::const_iterator itr = magnetAuras.begin(); itr != magnetAuras.end(); ++itr)
|
||||
if (Unit* magnet = (*itr)->GetBase()->GetUnitOwner())
|
||||
if (magnet->isAlive() && IsWithinLOSInMap(magnet))
|
||||
Unit* Unit::GetMeleeHitRedirectTarget(Unit* victim, SpellInfo const* spellInfo)
|
||||
{
|
||||
AuraEffectList const& hitTriggerAuras = victim->GetAuraEffectsByType(SPELL_AURA_ADD_CASTER_HIT_TRIGGER);
|
||||
for (AuraEffectList::const_iterator i = hitTriggerAuras.begin(); i != hitTriggerAuras.end(); ++i)
|
||||
{
|
||||
if (Unit* magnet = (*i)->GetBase()->GetCaster())
|
||||
if (_IsValidAttackTarget(magnet, spellInfo) && magnet->IsWithinLOSInMap(this)
|
||||
&& (!spellInfo || (spellInfo->CheckExplicitTarget(this, magnet) == SPELL_CAST_OK
|
||||
&& spellInfo->CheckTarget(this, magnet, false) == SPELL_CAST_OK)))
|
||||
if (roll_chance_i((*i)->GetAmount()))
|
||||
{
|
||||
(*itr)->GetBase()->DropCharge(AURA_REMOVE_BY_EXPIRE);
|
||||
(*i)->GetBase()->DropCharge(AURA_REMOVE_BY_EXPIRE);
|
||||
return magnet;
|
||||
}
|
||||
}
|
||||
// Melee && ranged case
|
||||
else
|
||||
{
|
||||
AuraEffectList const& hitTriggerAuras = victim->GetAuraEffectsByType(SPELL_AURA_ADD_CASTER_HIT_TRIGGER);
|
||||
for (AuraEffectList::const_iterator i = hitTriggerAuras.begin(); i != hitTriggerAuras.end(); ++i)
|
||||
if (Unit* magnet = (*i)->GetBase()->GetCaster())
|
||||
if (magnet->isAlive() && magnet->IsWithinLOSInMap(this))
|
||||
if (roll_chance_i((*i)->GetAmount()))
|
||||
{
|
||||
(*i)->GetBase()->DropCharge(AURA_REMOVE_BY_EXPIRE);
|
||||
return magnet;
|
||||
}
|
||||
}
|
||||
|
||||
return victim;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user