From bcff80e095eb5169757e05dc73195481eee60f6b Mon Sep 17 00:00:00 2001 From: boxa Date: Sun, 10 Dec 2017 14:16:49 +0100 Subject: [PATCH] Fix search for TARGET_SCRIPT if searcher DYN/GAMEOBJ bug after https://github.com/cmangos/mangos-wotlk/commit/6cd4c2b5031663a1b27c41b879c884d4ff1a8eca commit. when caster (player) and GO have different phase mask, we don't find targets. example: Q24507 GO 201969 (Ball and chain) have phase mask 1 NPC 36770... (Horde Slave) have phase mask 64 player have phase mask 65 so player see GO and NPC, but if search target from GO we don't find NPC. (based on cmangos/mangos-wotlk@e928ef66f) Signed-off-by: Xfurry --- src/game/Spell.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/game/Spell.cpp b/src/game/Spell.cpp index 0164103c18..b3647e049a 100644 --- a/src/game/Spell.cpp +++ b/src/game/Spell.cpp @@ -5768,13 +5768,25 @@ SpellCastResult Spell::CheckCast(bool strict) // no target provided or it was not valid, so use closest in range if (!targetExplicit) { - WorldObject* objectForSearch = (worldObject && (worldObject->GetTypeId() == TYPEID_GAMEOBJECT || worldObject->GetTypeId() == TYPEID_DYNAMICOBJECT)) ? worldObject : m_caster; + WorldObject* objectForSearch = m_caster; + uint32 savePhaseMask = 0; + + if (worldObject && (worldObject->GetTypeId() == TYPEID_GAMEOBJECT || worldObject->GetTypeId() == TYPEID_DYNAMICOBJECT)) + { + objectForSearch = worldObject; + savePhaseMask = worldObject->GetPhaseMask(); + objectForSearch->SetPhaseMask(m_caster->GetPhaseMask(), false); + } + 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(objectForSearch, searcher, range); + if (savePhaseMask) + objectForSearch->SetPhaseMask(savePhaseMask, false); + range = u_check.GetLastRange(); }