Skip to content

Commit

Permalink
Refactor SPELL_RANGE_IDX_COMBAT in CheckRange
Browse files Browse the repository at this point in the history
These spells will no longer bypass additional logic down the line. This
means Melee Leeway when moving will work as intended and there is much
less code as well. Downside is doing one SQRT computation but that is
something that shouldn't be too big of a deal.
  • Loading branch information
killerwife committed Jun 20, 2017
1 parent c5841b0 commit 7699a66
Showing 1 changed file with 5 additions and 19 deletions.
24 changes: 5 additions & 19 deletions src/game/Spells/Spell.cpp
Expand Up @@ -6606,6 +6606,9 @@ SpellCastResult Spell::CheckRange(bool strict) const
{
Unit* target = m_targets.getUnitTarget();

// add radius of caster and ~5 yds "give" for non stricred (landing) check
float range_mod = strict ? 1.25f : 6.25;

// special range cases
switch (m_spellInfo->rangeIndex)
{
Expand All @@ -6617,28 +6620,11 @@ SpellCastResult Spell::CheckRange(bool strict) const
// combat range spells are treated differently
case SPELL_RANGE_IDX_COMBAT:
{
if (target)
{
if (target == m_caster)
return SPELL_CAST_OK;

float range_mod = strict ? 0.0f : 5.0f;
if (Player* modOwner = m_caster->GetSpellModOwner())
{
float base = ATTACK_DISTANCE;
range_mod += modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_RANGE, base);
}

// with additional 5 dist for non stricted case (some melee spells have delay in apply
return m_caster->CanReachWithMeleeAttack(target, range_mod) ? SPELL_CAST_OK : SPELL_FAILED_OUT_OF_RANGE;
}
break; // let continue in generic way for no target
range_mod = 0.0f; // These spells do not have any leeway like ranged ones do
break;
}
}

// add radius of caster and ~5 yds "give" for non stricred (landing) check
float range_mod = strict ? 1.25f : 6.25;

// leeway for moving
if (target && m_caster->IsMoving() && target->IsMoving() && !m_caster->IsWalking() && !target->IsWalking() &&
(m_spellInfo->rangeIndex == SPELL_RANGE_IDX_COMBAT || target->GetTypeId() == TYPEID_PLAYER))
Expand Down

0 comments on commit 7699a66

Please sign in to comment.