Core/Spells: Use Unit::IsValidAttack/AssistTarget functions to validate spell explicit targets.
This commit is contained in:
@@ -4781,7 +4781,7 @@ SpellCastResult Spell::CheckCast(bool strict)
|
|||||||
// those spells may have incorrect target entries or not filled at all (for example 15332)
|
// those spells may have incorrect target entries or not filled at all (for example 15332)
|
||||||
// such spells when learned are not targeting anyone using targeting system, they should apply directly to caster instead
|
// such spells when learned are not targeting anyone using targeting system, they should apply directly to caster instead
|
||||||
// also, such casts shouldn't be sent to client
|
// also, such casts shouldn't be sent to client
|
||||||
if (!(((m_spellInfo->Attributes & SPELL_ATTR0_PASSIVE) && !m_targets.GetUnitTarget()) || m_targets.GetUnitTarget() == m_caster))
|
if (!((m_spellInfo->Attributes & SPELL_ATTR0_PASSIVE) && (!m_targets.GetUnitTarget() || m_targets.GetUnitTarget() == m_caster)))
|
||||||
{
|
{
|
||||||
// Check explicit target for m_originalCaster - todo: get rid of such workarounds
|
// Check explicit target for m_originalCaster - todo: get rid of such workarounds
|
||||||
SpellCastResult castResult = m_spellInfo->CheckExplicitTarget(m_originalCaster ? m_originalCaster : m_caster, m_targets.GetObjectTarget(), m_targets.GetItemTarget());
|
SpellCastResult castResult = m_spellInfo->CheckExplicitTarget(m_originalCaster ? m_originalCaster : m_caster, m_targets.GetObjectTarget(), m_targets.GetItemTarget());
|
||||||
@@ -4818,14 +4818,14 @@ SpellCastResult Spell::CheckCast(bool strict)
|
|||||||
return SPELL_FAILED_TARGET_AURASTATE;
|
return SPELL_FAILED_TARGET_AURASTATE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// check pet presence
|
// check pet presence
|
||||||
for (int j = 0; j < MAX_SPELL_EFFECTS; ++j)
|
for (int j = 0; j < MAX_SPELL_EFFECTS; ++j)
|
||||||
{
|
{
|
||||||
if (m_spellInfo->Effects[j].TargetA.GetTarget() == TARGET_UNIT_PET)
|
if (m_spellInfo->Effects[j].TargetA.GetTarget() == TARGET_UNIT_PET)
|
||||||
{
|
{
|
||||||
target = m_caster->GetGuardianPet();
|
if (!m_caster->GetGuardianPet())
|
||||||
if (!target)
|
|
||||||
{
|
{
|
||||||
if (m_triggeredByAuraSpell) // not report pet not existence for triggered spells
|
if (m_triggeredByAuraSpell) // not report pet not existence for triggered spells
|
||||||
return SPELL_FAILED_DONT_REPORT;
|
return SPELL_FAILED_DONT_REPORT;
|
||||||
@@ -4835,7 +4835,6 @@ SpellCastResult Spell::CheckCast(bool strict)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Spell casted only on battleground
|
// Spell casted only on battleground
|
||||||
if ((m_spellInfo->AttributesEx3 & SPELL_ATTR3_BATTLEGROUND) && m_caster->GetTypeId() == TYPEID_PLAYER)
|
if ((m_spellInfo->AttributesEx3 & SPELL_ATTR3_BATTLEGROUND) && m_caster->GetTypeId() == TYPEID_PLAYER)
|
||||||
|
|||||||
@@ -1634,7 +1634,7 @@ SpellCastResult SpellInfo::CheckTarget(Unit const* caster, Unit const* target, b
|
|||||||
if (!(AttributesEx6 & SPELL_ATTR6_CAN_TARGET_INVISIBLE) && !caster->canSeeOrDetect(target, implicit))
|
if (!(AttributesEx6 & SPELL_ATTR6_CAN_TARGET_INVISIBLE) && !caster->canSeeOrDetect(target, implicit))
|
||||||
return SPELL_FAILED_BAD_TARGETS;
|
return SPELL_FAILED_BAD_TARGETS;
|
||||||
|
|
||||||
// TODO: more research
|
// checked in Unit::IsValidAttack/AssistTarget, shouldn't be checked for ENTRY targets
|
||||||
//if (!(AttributesEx6 & SPELL_ATTR6_CAN_TARGET_UNTARGETABLE) && target->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE))
|
//if (!(AttributesEx6 & SPELL_ATTR6_CAN_TARGET_UNTARGETABLE) && target->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE))
|
||||||
// return SPELL_FAILED_BAD_TARGETS;
|
// return SPELL_FAILED_BAD_TARGETS;
|
||||||
|
|
||||||
@@ -1648,14 +1648,6 @@ SpellCastResult SpellInfo::CheckTarget(Unit const* caster, Unit const* target, b
|
|||||||
return SPELL_FAILED_BAD_TARGETS;
|
return SPELL_FAILED_BAD_TARGETS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check UNIT_FLAG_NON_ATTACKABLE flag - a player can cast spells on his pet (or other controlled unit) though in any state
|
|
||||||
if (!IsPositive() && target != caster && target->GetCharmerOrOwnerGUID() != caster->GetGUID())
|
|
||||||
{
|
|
||||||
// any unattackable target skipped
|
|
||||||
if (target->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE))
|
|
||||||
return SPELL_FAILED_BAD_TARGETS;
|
|
||||||
}
|
|
||||||
|
|
||||||
// check GM mode and GM invisibility - only for player casts (npc casts are controlled by AI) and negative spells
|
// check GM mode and GM invisibility - only for player casts (npc casts are controlled by AI) and negative spells
|
||||||
if (target != caster && (caster->IsControlledByPlayer() || !IsPositive()) && target->GetTypeId() == TYPEID_PLAYER)
|
if (target != caster && (caster->IsControlledByPlayer() || !IsPositive()) && target->GetTypeId() == TYPEID_PLAYER)
|
||||||
{
|
{
|
||||||
@@ -1738,16 +1730,12 @@ SpellCastResult SpellInfo::CheckExplicitTarget(Unit const* caster, WorldObject c
|
|||||||
if (neededTargets & (TARGET_FLAG_UNIT_ENEMY | TARGET_FLAG_UNIT_ALLY | TARGET_FLAG_UNIT_RAID | TARGET_FLAG_UNIT_PARTY | TARGET_FLAG_UNIT_MINIPET | TARGET_FLAG_UNIT_PASSENGER))
|
if (neededTargets & (TARGET_FLAG_UNIT_ENEMY | TARGET_FLAG_UNIT_ALLY | TARGET_FLAG_UNIT_RAID | TARGET_FLAG_UNIT_PARTY | TARGET_FLAG_UNIT_MINIPET | TARGET_FLAG_UNIT_PASSENGER))
|
||||||
{
|
{
|
||||||
if (neededTargets & TARGET_FLAG_UNIT_ENEMY)
|
if (neededTargets & TARGET_FLAG_UNIT_ENEMY)
|
||||||
if (!caster->IsFriendlyTo(unitTarget))
|
if (caster->_IsValidAttackTarget(unitTarget, this))
|
||||||
return SPELL_CAST_OK;
|
return SPELL_CAST_OK;
|
||||||
if (neededTargets & TARGET_FLAG_UNIT_ALLY)
|
if (neededTargets & TARGET_FLAG_UNIT_ALLY
|
||||||
if (caster->IsFriendlyTo(unitTarget))
|
|| (neededTargets & TARGET_FLAG_UNIT_PARTY && caster->IsInPartyWith(unitTarget))
|
||||||
return SPELL_CAST_OK;
|
|| (neededTargets & TARGET_FLAG_UNIT_RAID && caster->IsInRaidWith(unitTarget)))
|
||||||
if (neededTargets & TARGET_FLAG_UNIT_PARTY)
|
if (caster->_IsValidAssistTarget(unitTarget, this))
|
||||||
if (caster->IsInPartyWith(unitTarget))
|
|
||||||
return SPELL_CAST_OK;
|
|
||||||
if (neededTargets & TARGET_FLAG_UNIT_RAID)
|
|
||||||
if (caster->IsInRaidWith(unitTarget))
|
|
||||||
return SPELL_CAST_OK;
|
return SPELL_CAST_OK;
|
||||||
if (neededTargets & TARGET_FLAG_UNIT_MINIPET)
|
if (neededTargets & TARGET_FLAG_UNIT_MINIPET)
|
||||||
if (unitTarget->GetGUID() == caster->GetCritterGUID())
|
if (unitTarget->GetGUID() == caster->GetCritterGUID())
|
||||||
|
|||||||
Reference in New Issue
Block a user