mirror of
https://github.com/mangosfour/server.git
synced 2025-12-15 01:37:00 +00:00
[10329] Improve target selection for spell_script_target creature targets
Fixes a problem where database has more than one entry for a spell and target is explicitly provided by script side. Signed-off-by: NoFantasy <nofantasy@nf.no>
This commit is contained in:
parent
1a1a541ecf
commit
b0a3ad5aa5
2 changed files with 15 additions and 9 deletions
|
|
@ -4545,6 +4545,7 @@ SpellCastResult Spell::CheckCast(bool strict)
|
||||||
SpellRangeEntry const* srange = sSpellRangeStore.LookupEntry(m_spellInfo->rangeIndex);
|
SpellRangeEntry const* srange = sSpellRangeStore.LookupEntry(m_spellInfo->rangeIndex);
|
||||||
float range = GetSpellMaxRange(srange);
|
float range = GetSpellMaxRange(srange);
|
||||||
|
|
||||||
|
Creature* targetExplicit = NULL; // used for cases where a target is provided (by script for example)
|
||||||
Creature* creatureScriptTarget = NULL;
|
Creature* creatureScriptTarget = NULL;
|
||||||
GameObject* goScriptTarget = NULL;
|
GameObject* goScriptTarget = NULL;
|
||||||
|
|
||||||
|
|
@ -4595,19 +4596,21 @@ SpellCastResult Spell::CheckCast(bool strict)
|
||||||
{
|
{
|
||||||
if (i_spellST->second.type == SPELL_TARGET_TYPE_DEAD && pTarget->isDead())
|
if (i_spellST->second.type == SPELL_TARGET_TYPE_DEAD && pTarget->isDead())
|
||||||
{
|
{
|
||||||
if (pTarget->IsWithinDistInMap(m_caster, range))
|
// always use spellMaxRange, in case GetLastRange returned different in a previous pass
|
||||||
p_Creature = (Creature*)pTarget;
|
if (pTarget->IsWithinDistInMap(m_caster, GetSpellMaxRange(srange)))
|
||||||
|
targetExplicit = (Creature*)pTarget;
|
||||||
}
|
}
|
||||||
else if (i_spellST->second.type == SPELL_TARGET_TYPE_CREATURE && pTarget->isAlive())
|
else if (i_spellST->second.type == SPELL_TARGET_TYPE_CREATURE && pTarget->isAlive())
|
||||||
{
|
{
|
||||||
if (pTarget->IsWithinDistInMap(m_caster, range))
|
// always use spellMaxRange, in case GetLastRange returned different in a previous pass
|
||||||
p_Creature = (Creature*)pTarget;
|
if (pTarget->IsWithinDistInMap(m_caster, GetSpellMaxRange(srange)))
|
||||||
|
targetExplicit = (Creature*)pTarget;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// no target provided or it was not valid, so use closest in range
|
// no target provided or it was not valid, so use closest in range
|
||||||
if (!p_Creature)
|
if (!targetExplicit)
|
||||||
{
|
{
|
||||||
MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck u_check(*m_caster, i_spellST->second.targetEntry, i_spellST->second.type != SPELL_TARGET_TYPE_DEAD, range);
|
MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck u_check(*m_caster, i_spellST->second.targetEntry, i_spellST->second.type != SPELL_TARGET_TYPE_DEAD, range);
|
||||||
MaNGOS::CreatureLastSearcher<MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck> searcher(m_caster, p_Creature, u_check);
|
MaNGOS::CreatureLastSearcher<MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck> searcher(m_caster, p_Creature, u_check);
|
||||||
|
|
@ -4618,11 +4621,14 @@ SpellCastResult Spell::CheckCast(bool strict)
|
||||||
range = u_check.GetLastRange();
|
range = u_check.GetLastRange();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p_Creature)
|
// always prefer provided target if it's valid
|
||||||
{
|
if (targetExplicit)
|
||||||
|
creatureScriptTarget = targetExplicit;
|
||||||
|
else if (p_Creature)
|
||||||
creatureScriptTarget = p_Creature;
|
creatureScriptTarget = p_Creature;
|
||||||
|
|
||||||
|
if (creatureScriptTarget)
|
||||||
goScriptTarget = NULL;
|
goScriptTarget = NULL;
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#ifndef __REVISION_NR_H__
|
#ifndef __REVISION_NR_H__
|
||||||
#define __REVISION_NR_H__
|
#define __REVISION_NR_H__
|
||||||
#define REVISION_NR "10328"
|
#define REVISION_NR "10329"
|
||||||
#endif // __REVISION_NR_H__
|
#endif // __REVISION_NR_H__
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue