From 09d4805bacf56f1f3d6a02d0c2417caf9f08cdd5 Mon Sep 17 00:00:00 2001 From: VladimirMangos Date: Sun, 20 Dec 2009 03:26:39 +0300 Subject: [PATCH] [9035] Attempt make more fast and less hackish spell target checks * 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. --- src/game/Spell.cpp | 26 ++++++++++++++++++++------ src/game/SpellMgr.cpp | 34 ++++++++++++++++++++++++++++++++++ src/game/SpellMgr.h | 3 +++ src/shared/revision_nr.h | 2 +- 4 files changed, 58 insertions(+), 7 deletions(-) diff --git a/src/game/Spell.cpp b/src/game/Spell.cpp index 827152b421b..ce6814fc72c 100644 --- a/src/game/Spell.cpp +++ b/src/game/Spell.cpp @@ -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)) diff --git a/src/game/SpellMgr.cpp b/src/game/SpellMgr.cpp index bc981527e10..2f6621ee7f8 100644 --- a/src/game/SpellMgr.cpp +++ b/src/game/SpellMgr.cpp @@ -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); diff --git a/src/game/SpellMgr.h b/src/game/SpellMgr.h index fbe5621d331..0583f62baee 100644 --- a/src/game/SpellMgr.h +++ b/src/game/SpellMgr.h @@ -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); diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 87af3cab409..d85161e4681 100644 --- a/src/shared/revision_nr.h +++ b/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__