From 6cd4c2b5031663a1b27c41b879c884d4ff1a8eca Mon Sep 17 00:00:00 2001 From: killerwife Date: Mon, 20 Jun 2016 19:41:48 +0200 Subject: [PATCH] Search for TARGET_SCRIPT around OriginalCaster if DYN/GAMEOBJ --- src/game/Spell.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/game/Spell.cpp b/src/game/Spell.cpp index 82ce16bab34..852c50b2254 100644 --- a/src/game/Spell.cpp +++ b/src/game/Spell.cpp @@ -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) { @@ -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; } } @@ -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 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(); }