Skip to content

Commit

Permalink
[9089] Check explicit target correctness by all effect target modes.
Browse files Browse the repository at this point in the history
All effect target modes start from client provided target data
so all its must be used for checking explicit target modes.
For example exist spells that have as first effect SELF non-explicit target mode.
but in same time negative to explicit target.

Signed-off-by: VladimirMangos <vladimir@getmangos.com>

Also add caching IsHostileTo/IsFriendlyTo for avoid recall this not fast functions.
  • Loading branch information
NetSky authored and VladimirMangos committed Dec 31, 2009
1 parent 09428eb commit d3581f7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 12 deletions.
58 changes: 47 additions & 11 deletions src/game/Spell.cpp
Expand Up @@ -4110,29 +4110,65 @@ SpellCastResult Spell::CheckCast(bool strict)
if(non_caster_target)
{
// simple cases
if (IsExplicitPositiveTarget(m_spellInfo->EffectImplicitTargetA[0]))
bool explicit_target_mode = false;
bool target_hostile = false;
bool target_hostile_checked = false;
bool target_friendly = false;
bool target_friendly_checked = false;
for(int k = 0; k < 3; ++k)
{
if(m_caster->IsHostileTo(target))
return SPELL_FAILED_BAD_TARGETS;
}
else if (IsExplicitNegativeTarget(m_spellInfo->EffectImplicitTargetA[0]))
{
if(m_caster->IsFriendlyTo(target))
return SPELL_FAILED_BAD_TARGETS;
if (IsExplicitPositiveTarget(m_spellInfo->EffectImplicitTargetA[k]))
{
if (!target_hostile_checked)
{
target_hostile_checked = true;
target_hostile = m_caster->IsHostileTo(target);
}

if(target_hostile)
return SPELL_FAILED_BAD_TARGETS;

explicit_target_mode = true;
}
else if (IsExplicitNegativeTarget(m_spellInfo->EffectImplicitTargetA[k]))
{
if (!target_friendly_checked)
{
target_friendly_checked = true;
target_friendly = m_caster->IsFriendlyTo(target);
}

if(target_friendly)
return SPELL_FAILED_BAD_TARGETS;

explicit_target_mode = true;
}
}
// TODO: this check can be applied and for player to prevent cheating when IsPositiveSpell will return always correct result.
// check target for pet/charmed casts (not self targeted), self targeted cast used for area effects and etc
else if (m_caster->GetTypeId() == TYPEID_UNIT && m_caster->GetCharmerOrOwnerGUID())
if (!explicit_target_mode && m_caster->GetTypeId() == TYPEID_UNIT && m_caster->GetCharmerOrOwnerGUID())
{
// check correctness positive/negative cast target (pet cast real check and cheating check)
if(IsPositiveSpell(m_spellInfo->Id))
{
if(m_caster->IsHostileTo(target))
if (!target_hostile_checked)
{
target_hostile_checked = true;
target_hostile = m_caster->IsHostileTo(target);
}

if(target_hostile)
return SPELL_FAILED_BAD_TARGETS;
}
else
{
if(m_caster->IsFriendlyTo(target))
if (!target_friendly_checked)
{
target_friendly_checked = true;
target_friendly = m_caster->IsFriendlyTo(target);
}

if(target_friendly)
return SPELL_FAILED_BAD_TARGETS;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/shared/revision_nr.h
@@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "9088"
#define REVISION_NR "9089"
#endif // __REVISION_NR_H__

4 comments on commit d3581f7

@insider42
Copy link
Contributor

Choose a reason for hiding this comment

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

it brokes spell http://www.wowhead.com/?spell=50842 . When i try to use it on hostile target (for example enemy player or mob) i get a error with bad target because result of SPELL_FAILED_BAD_TARGETS

@NetSky
Copy link

@NetSky NetSky commented on d3581f7 Dec 31, 2009

Choose a reason for hiding this comment

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

yes it also fixes casting some dmg spells @ friends

@VladimirMangos
Copy link

Choose a reason for hiding this comment

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

becuase i forgeo remove SELF2 when remove SELF target mode from explicit possitive targets

@VladimirMangos
Copy link

Choose a reason for hiding this comment

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

both problem must be fixed in [9098].

Please sign in to comment.