Skip to content

Commit

Permalink
Fix search for TARGET_SCRIPT if searcher DYN/GAMEOBJ
Browse files Browse the repository at this point in the history
bug after 6cd4c2b 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.
  • Loading branch information
boxa committed Feb 9, 2017
1 parent 71d6d4e commit e928ef6
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/game/Spell.cpp
Expand Up @@ -5464,13 +5464,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<MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck> 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();
}

Expand Down

5 comments on commit e928ef6

@xfurry
Copy link
Member

@xfurry xfurry commented on e928ef6 Feb 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a workaround 😄
Changing phases just to make the grid searcher happy is ugly. We should actually update the grid searcher to be able to pick up GOs or creatures from different phases.

Also we should mention this in the comments, so that we are aware of it for the future

@boxa
Copy link
Contributor Author

@boxa boxa commented on e928ef6 Feb 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok =)
maybe

CreatureLastSearcher(Creature*& result, Check& check, ___uint32 overridePhaseMask = 0___)  :
  i_phaseMask(___overridePhaseMask ? overridePhaseMask : check.GetFocusObject().GetPhaseMask()___),
  i_object(result), i_check(check) {}

?

or add param searcherForPhaseMask to
NearestCreatureEntryWithLiveStateInObjectRangeCheck

@VladimirMangos
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

current hack look very ugly (( search code don't must touch object states

@VladimirMangos
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding caster phasemask param look like clean solution

@boxa
Copy link
Contributor Author

@boxa boxa commented on e928ef6 Feb 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding caster phasemask param look like clean solution

done in next commit

Please sign in to comment.