Skip to content

Commit

Permalink
Search for TARGET_SCRIPT around OriginalCaster if DYN/GAMEOBJ
Browse files Browse the repository at this point in the history
  • Loading branch information
killerwife authored and cyberium committed Jan 10, 2017
1 parent f1a8aa6 commit 6cd4c2b
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/game/Spell.cpp
Expand Up @@ -5300,6 +5300,8 @@ SpellCastResult Spell::CheckCast(bool strict)
focusObject = ok; // game object found in range
}

WorldObject* worldObject = m_caster->GetMap()->GetWorldObject(m_originalCasterGUID); // will be maybe needed in more places where we calculate distance

// Database based targets from spell_target_script
if (m_UniqueTargetInfo.empty()) // skip second CheckCast apply (for delayed spells for example)
{
Expand Down Expand Up @@ -5385,16 +5387,14 @@ SpellCastResult Spell::CheckCast(bool strict)
{
if (pTarget->GetTypeId() == TYPEID_UNIT && pTarget->GetEntry() == i_spellST->targetEntry)
{
if (i_spellST->type == SPELL_TARGET_TYPE_DEAD && ((Creature*)pTarget)->IsCorpse())
if ((i_spellST->type == SPELL_TARGET_TYPE_DEAD && ((Creature*)pTarget)->IsCorpse())
|| (i_spellST->type == SPELL_TARGET_TYPE_CREATURE && pTarget->isAlive()))
{
// always use spellMaxRange, in case GetLastRange returned different in a previous pass
if (pTarget->IsWithinDistInMap(m_caster, GetSpellMaxRange(srange)))
if(worldObject && (worldObject->GetTypeId() == TYPEID_GAMEOBJECT || worldObject->GetTypeId() == TYPEID_DYNAMICOBJECT)
&& pTarget->IsWithinDistInMap(worldObject, GetSpellMaxRange(srange)))
targetExplicit = (Creature*)pTarget;
}
else if (i_spellST->type == SPELL_TARGET_TYPE_CREATURE && pTarget->isAlive())
{
// always use spellMaxRange, in case GetLastRange returned different in a previous pass
if (pTarget->IsWithinDistInMap(m_caster, GetSpellMaxRange(srange)))
else if (pTarget->IsWithinDistInMap(m_caster, GetSpellMaxRange(srange)))
targetExplicit = (Creature*)pTarget;
}
}
Expand All @@ -5403,11 +5403,12 @@ SpellCastResult Spell::CheckCast(bool strict)
// no target provided or it was not valid, so use closest in range
if (!targetExplicit)
{
MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck u_check(*m_caster, i_spellST->targetEntry, i_spellST->type != SPELL_TARGET_TYPE_DEAD, i_spellST->type == SPELL_TARGET_TYPE_DEAD, range);
WorldObject* objectForSearch = (worldObject && (worldObject->GetTypeId() == TYPEID_GAMEOBJECT || worldObject->GetTypeId() == TYPEID_DYNAMICOBJECT)) ? worldObject : m_caster;
MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck u_check(*objectForSearch, i_spellST->targetEntry, i_spellST->type != SPELL_TARGET_TYPE_DEAD, i_spellST->type == SPELL_TARGET_TYPE_DEAD, range);
MaNGOS::CreatureLastSearcher<MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck> searcher(p_Creature, u_check);

// Visit all, need to find also Pet* objects
Cell::VisitAllObjects(m_caster, searcher, range);
Cell::VisitAllObjects(objectForSearch, searcher, range);

range = u_check.GetLastRange();
}
Expand Down

0 comments on commit 6cd4c2b

Please sign in to comment.