Skip to content

Commit

Permalink
[9035] Attempt make more fast and less hackish spell target checks
Browse files Browse the repository at this point in the history
* Enable server side recheck clear negative to friend or positive to enemy casts that already checks at client side
* Use more fast way check in similar cases for non-players, and fall back to old way in unclear (for while at least)

Please report if some spell stop propertly casted at friends/enemies.
  • Loading branch information
VladimirMangos committed Dec 20, 2009
1 parent 1c02808 commit 09d4805
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 7 deletions.
26 changes: 20 additions & 6 deletions src/game/Spell.cpp
Expand Up @@ -4079,21 +4079,35 @@ SpellCastResult Spell::CheckCast(bool strict)
}
}

// 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
if(non_caster_target && m_caster->GetTypeId() == TYPEID_UNIT && m_caster->GetCharmerOrOwnerGUID())
if(non_caster_target)
{
// check correctness positive/negative cast target (pet cast real check and cheating check)
if(IsPositiveSpell(m_spellInfo->Id))
// simple cases
if (IsExplicitPositiveTarget(m_spellInfo->EffectImplicitTargetA[0]))
{
if(m_caster->IsHostileTo(target))
return SPELL_FAILED_BAD_TARGETS;
}
else
else if (IsExplicitNegativeTarget(m_spellInfo->EffectImplicitTargetA[0]))
{
if(m_caster->IsFriendlyTo(target))
return SPELL_FAILED_BAD_TARGETS;
}
// 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())
{
// check correctness positive/negative cast target (pet cast real check and cheating check)
if(IsPositiveSpell(m_spellInfo->Id))
{
if(m_caster->IsHostileTo(target))
return SPELL_FAILED_BAD_TARGETS;
}
else
{
if(m_caster->IsFriendlyTo(target))
return SPELL_FAILED_BAD_TARGETS;
}
}
}

if(IsPositiveSpell(m_spellInfo->Id))
Expand Down
34 changes: 34 additions & 0 deletions src/game/SpellMgr.cpp
Expand Up @@ -426,6 +426,40 @@ bool IsPositiveTarget(uint32 targetA, uint32 targetB)
return true;
}

bool IsExplicitPositiveTarget(uint32 targetA)
{
// positive targets
switch(targetA)
{
case TARGET_SELF:
case TARGET_SINGLE_FRIEND:
case TARGET_SINGLE_PARTY:
case TARGET_CHAIN_HEAL:
case TARGET_SINGLE_FRIEND_2:
case TARGET_AREAEFFECT_PARTY_AND_CLASS:
case TARGET_SELF2:
return true;
default:
break;
}
return false;
}

bool IsExplicitNegativeTarget(uint32 targetA)
{
// non-positive targets
switch(targetA)
{
case TARGET_CHAIN_DAMAGE:
case TARGET_CURRENT_ENEMY_COORDINATES:
case TARGET_SINGLE_ENEMY:
return true;
default:
break;
}
return false;
}

bool IsPositiveEffect(uint32 spellId, uint32 effIndex)
{
SpellEntry const *spellproto = sSpellStore.LookupEntry(spellId);
Expand Down
3 changes: 3 additions & 0 deletions src/game/SpellMgr.h
Expand Up @@ -220,6 +220,9 @@ bool IsPositiveSpell(uint32 spellId);
bool IsPositiveEffect(uint32 spellId, uint32 effIndex);
bool IsPositiveTarget(uint32 targetA, uint32 targetB);

bool IsExplicitPositiveTarget(uint32 targetA);
bool IsExplicitNegativeTarget(uint32 targetA);

bool IsSingleTargetSpell(SpellEntry const *spellInfo);
bool IsSingleTargetSpells(SpellEntry const *spellInfo1, SpellEntry const *spellInfo2);

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 "9034"
#define REVISION_NR "9035"
#endif // __REVISION_NR_H__

3 comments on commit 09d4805

@NetSky
Copy link

@NetSky NetSky commented on 09d4805 Dec 20, 2009

Choose a reason for hiding this comment

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

spells like mind flay or shadowstep won't work @ hostile targets with this

@VladimirMangos
Copy link

Choose a reason for hiding this comment

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

first wprl for me, second confirmed, i will look

@VladimirMangos
Copy link

Choose a reason for hiding this comment

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

must be fixed for second and similar cases in [9044]

Please sign in to comment.