From ef4564adfa61fe1801447054f88c2ea3cc901d6d Mon Sep 17 00:00:00 2001 From: Olion Date: Fri, 25 Sep 2015 12:48:44 +0300 Subject: [PATCH] [Spell] Minor refactoring Like HasSpellEffect method here, other now global-scoped methods from SpellMgr.h should be transfered into corresponding classes/structures (TODO). --- src/game/ChatCommands/Level3.cpp | 2 +- src/game/Object/Creature.cpp | 11 +---------- src/game/Object/CreatureEventAIMgr.cpp | 2 +- src/game/Object/ObjectMgr.cpp | 2 +- src/game/Object/PetAI.cpp | 2 +- src/game/Object/Player.cpp | 6 +++--- src/game/Object/SpellMgr.cpp | 14 +++++--------- src/game/Object/SpellMgr.h | 12 ++---------- src/game/Object/Unit.cpp | 6 +++--- src/game/Server/DBCStructure.h | 2 +- src/game/WorldHandlers/Spell.cpp | 6 +++--- src/game/WorldHandlers/UnitAuraProcHandler.cpp | 2 +- 12 files changed, 23 insertions(+), 44 deletions(-) diff --git a/src/game/ChatCommands/Level3.cpp b/src/game/ChatCommands/Level3.cpp index 26e2e29e..ee1ebf84 100644 --- a/src/game/ChatCommands/Level3.cpp +++ b/src/game/ChatCommands/Level3.cpp @@ -3522,7 +3522,7 @@ bool ChatHandler::HandleAuraCommand(char* args) { return false; } if (!IsSpellAppliesAura(spellInfo, (1 << EFFECT_INDEX_0) | (1 << EFFECT_INDEX_1) | (1 << EFFECT_INDEX_2)) && - !IsSpellHaveEffect(spellInfo, SPELL_EFFECT_PERSISTENT_AREA_AURA)) + !spellInfo->HasSpellEffect(SPELL_EFFECT_PERSISTENT_AREA_AURA)) { PSendSysMessage(LANG_SPELL_NO_HAVE_AURAS, spellID); SetSentErrorMessage(true); diff --git a/src/game/Object/Creature.cpp b/src/game/Object/Creature.cpp index e3c39585..cec4277e 100644 --- a/src/game/Object/Creature.cpp +++ b/src/game/Object/Creature.cpp @@ -1794,16 +1794,7 @@ SpellEntry const* Creature::ReachWithSpellCure(Unit* pVictim) continue; } - bool bcontinue = true; - for (int j = 0; j < MAX_EFFECT_INDEX; ++j) - { - if ((spellInfo->Effect[j] == SPELL_EFFECT_HEAL)) - { - bcontinue = false; - break; - } - } - if (bcontinue) + if (!spellInfo->HasSpellEffect(SPELL_EFFECT_HEAL)) { continue; } if (spellInfo->manaCost > GetPower(POWER_MANA)) diff --git a/src/game/Object/CreatureEventAIMgr.cpp b/src/game/Object/CreatureEventAIMgr.cpp index d54bbc46..6c2b5857 100644 --- a/src/game/Object/CreatureEventAIMgr.cpp +++ b/src/game/Object/CreatureEventAIMgr.cpp @@ -667,7 +667,7 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Scripts() // used TARGET_T_ACTION_INVOKER, but likely should be _INVOKER_OWNER instead if (action.cast.target == TARGET_T_ACTION_INVOKER && - (IsSpellHaveEffect(spell, SPELL_EFFECT_QUEST_COMPLETE) || IsSpellHaveEffect(spell, SPELL_EFFECT_DUMMY))) + (spell->HasSpellEffect(SPELL_EFFECT_QUEST_COMPLETE) || spell->HasSpellEffect(SPELL_EFFECT_DUMMY))) { sLog.outErrorEventAI("Event %u Action %u has TARGET_T_ACTION_INVOKER(%u) target type, but should have TARGET_T_ACTION_INVOKER_OWNER(%u).", i, j + 1, TARGET_T_ACTION_INVOKER, TARGET_T_ACTION_INVOKER_OWNER); } // Spell that should only target players, but could get any diff --git a/src/game/Object/ObjectMgr.cpp b/src/game/Object/ObjectMgr.cpp index 61ae4c42..3299e346 100644 --- a/src/game/Object/ObjectMgr.cpp +++ b/src/game/Object/ObjectMgr.cpp @@ -636,7 +636,7 @@ void ObjectMgr::ConvertCreatureAddonAuras(CreatureDataAddon* addon, char const* } // Must be Aura, but also allow dummy/script effect spells, as they are used sometimes to select a random aura or similar - if (!IsSpellAppliesAura(AdditionalSpellInfo) && !IsSpellHaveEffect(AdditionalSpellInfo, SPELL_EFFECT_DUMMY) && !IsSpellHaveEffect(AdditionalSpellInfo, SPELL_EFFECT_SCRIPT_EFFECT) && !IsSpellHaveEffect(AdditionalSpellInfo, SPELL_EFFECT_TRIGGER_SPELL)) + if (!IsSpellAppliesAura(AdditionalSpellInfo) && !AdditionalSpellInfo->HasSpellEffect(SPELL_EFFECT_DUMMY) && !AdditionalSpellInfo->HasSpellEffect(SPELL_EFFECT_SCRIPT_EFFECT) && !AdditionalSpellInfo->HasSpellEffect(SPELL_EFFECT_TRIGGER_SPELL)) { sLog.outErrorDb("Creature (%s: %u) has spell %u defined in `auras` field in `%s, but spell doesn't apply an aura`.", guidEntryStr, addon->guidOrEntry, cAura, table); continue; diff --git a/src/game/Object/PetAI.cpp b/src/game/Object/PetAI.cpp index 10550825..ae259f6f 100644 --- a/src/game/Object/PetAI.cpp +++ b/src/game/Object/PetAI.cpp @@ -235,7 +235,7 @@ void PetAI::UpdateAI(const uint32 diff) { continue; } // not allow instant kill autocasts as full health cost - if (IsSpellHaveEffect(spellInfo, SPELL_EFFECT_INSTAKILL)) + if (spellInfo->HasSpellEffect(SPELL_EFFECT_INSTAKILL)) { continue; } } } diff --git a/src/game/Object/Player.cpp b/src/game/Object/Player.cpp index 8b27372e..e3815e87 100644 --- a/src/game/Object/Player.cpp +++ b/src/game/Object/Player.cpp @@ -3008,7 +3008,7 @@ bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependen // cast talents with SPELL_EFFECT_LEARN_SPELL (other dependent spells will learned later as not auto-learned) // note: all spells with SPELL_EFFECT_LEARN_SPELL isn't passive - if (talentPos && IsSpellHaveEffect(spellInfo, SPELL_EFFECT_LEARN_SPELL)) + if (talentPos && spellInfo->HasSpellEffect(SPELL_EFFECT_LEARN_SPELL)) { // ignore stance requirement for talent learn spell (stance set for spell only for client spell description show) CastSpell(this, spell_id, true); @@ -3018,7 +3018,7 @@ bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependen { CastSpell(this, spell_id, true); } - else if (IsSpellHaveEffect(spellInfo, SPELL_EFFECT_SKILL_STEP)) + else if (spellInfo->HasSpellEffect(SPELL_EFFECT_SKILL_STEP)) { CastSpell(this, spell_id, true); return false; @@ -6956,7 +6956,7 @@ void Player::CastItemCombatSpell(Unit* Target, WeaponAttackType attType) } // not allow proc extra attack spell at extra attack - if (m_extraAttacks && IsSpellHaveEffect(spellInfo, SPELL_EFFECT_ADD_EXTRA_ATTACKS)) + if (m_extraAttacks && spellInfo->HasSpellEffect(SPELL_EFFECT_ADD_EXTRA_ATTACKS)) { return; } float chance = (float)spellInfo->procChance; diff --git a/src/game/Object/SpellMgr.cpp b/src/game/Object/SpellMgr.cpp index 3338962e..dd0939fe 100644 --- a/src/game/Object/SpellMgr.cpp +++ b/src/game/Object/SpellMgr.cpp @@ -513,13 +513,9 @@ SpellSpecific GetSpellSpecific(uint32 spellId) if ((spellInfo->IsFitToFamilyMask(UI64LIT(0x0000000020180400))) && spellInfo->baseLevel != 0) { return SPELL_JUDGEMENT; } - for (int i = 0; i < 3; ++i) - { + if (spellInfo->HasSpellEffect(SPELL_EFFECT_APPLY_AREA_AURA_PARTY)) // only paladin auras have this - if (spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AREA_AURA_PARTY) - { return SPELL_AURA; } - } - break; + { return SPELL_AURA; } } case SPELLFAMILY_SHAMAN: { @@ -3418,7 +3414,7 @@ void SpellMgr::LoadSpellLearnSpells() // talent or passive spells or skill-step spells auto-casted and not need dependent learning, // pet teaching spells don't must be dependent learning (casted) // other required explicit dependent learning - dbc_node.autoLearned = entry->EffectImplicitTargetA[i] == TARGET_PET || GetTalentSpellCost(spell) > 0 || IsPassiveSpell(entry) || IsSpellHaveEffect(entry, SPELL_EFFECT_SKILL_STEP); + dbc_node.autoLearned = entry->EffectImplicitTargetA[i] == TARGET_PET || GetTalentSpellCost(spell) > 0 || IsPassiveSpell(entry) || entry->HasSpellEffect(SPELL_EFFECT_SKILL_STEP); SpellLearnSpellMapBounds db_node_bounds = GetSpellLearnSpellMapBounds(spell); @@ -4191,7 +4187,7 @@ void SpellMgr::CheckUsedSpells(char const* table) } else { - if (effectType >= 0 && !IsSpellHaveEffect(spellEntry, SpellEffects(effectType))) + if (effectType >= 0 && !spellEntry->HasSpellEffect(SpellEffects(effectType))) { sLog.outError("Spell %u '%s' not have effect %u but used in %s.", spell, name.c_str(), effectType, code.c_str()); continue; @@ -4251,7 +4247,7 @@ void SpellMgr::CheckUsedSpells(char const* table) } else { - if (effectType >= 0 && !IsSpellHaveEffect(spellEntry, SpellEffects(effectType))) + if (effectType >= 0 && !spellEntry->HasSpellEffect(SpellEffects(effectType))) { continue; } if (auraType >= 0 && !IsSpellHaveAura(spellEntry, AuraType(auraType))) diff --git a/src/game/Object/SpellMgr.h b/src/game/Object/SpellMgr.h index 31a05b04..8ffe2598 100644 --- a/src/game/Object/SpellMgr.h +++ b/src/game/Object/SpellMgr.h @@ -98,14 +98,6 @@ uint16 GetSpellAuraMaxTicks(SpellEntry const* spellInfo); uint16 GetSpellAuraMaxTicks(uint32 spellId); WeaponAttackType GetWeaponAttackType(SpellEntry const* spellInfo); -inline bool IsSpellHaveEffect(SpellEntry const* spellInfo, SpellEffects effect) -{ - for (int i = 0; i < MAX_EFFECT_INDEX; ++i) - if (SpellEffects(spellInfo->Effect[i]) == effect) - { return true; } - return false; -} - inline bool IsAuraApplyEffect(SpellEntry const* spellInfo, SpellEffectIndex effecIdx) { switch (spellInfo->Effect[effecIdx]) @@ -202,7 +194,7 @@ inline bool IsPassiveSpellStackableWithRanks(SpellEntry const* spellProto) if (!IsPassiveSpell(spellProto)) { return false; } - return !IsSpellHaveEffect(spellProto, SPELL_EFFECT_APPLY_AURA); + return !spellProto->HasSpellEffect(SPELL_EFFECT_APPLY_AURA); } @@ -410,7 +402,7 @@ inline bool IsOnlySelfTargeting(SpellEntry const* spellInfo) inline bool IsDispelSpell(SpellEntry const* spellInfo) { - return IsSpellHaveEffect(spellInfo, SPELL_EFFECT_DISPEL); + return spellInfo->HasSpellEffect(SPELL_EFFECT_DISPEL); } inline bool isSpellBreakStealth(SpellEntry const* spellInfo) diff --git a/src/game/Object/Unit.cpp b/src/game/Object/Unit.cpp index c04fd888..4f2f0da6 100644 --- a/src/game/Object/Unit.cpp +++ b/src/game/Object/Unit.cpp @@ -6066,7 +6066,7 @@ uint32 Unit::MeleeDamageBonusDone(Unit* pVictim, uint32 pdamage, WeaponAttackTyp { return pdamage; } // differentiate for weapon damage based spells - bool isWeaponDamageBasedSpell = !(spellProto && (damagetype == DOT || IsSpellHaveEffect(spellProto, SPELL_EFFECT_SCHOOL_DAMAGE))); + bool isWeaponDamageBasedSpell = !(spellProto && (damagetype == DOT || spellProto->HasSpellEffect(SPELL_EFFECT_SCHOOL_DAMAGE))); Item* pWeapon = GetTypeId() == TYPEID_PLAYER ? ((Player*)this)->GetWeaponForAttack(attType, true, false) : NULL; uint32 creatureTypeMask = pVictim->GetCreatureTypeMask(); uint32 schoolMask = spellProto ? GetSpellSchoolMask(spellProto) : uint32(GetMeleeDamageSchoolMask()); @@ -6156,7 +6156,7 @@ uint32 Unit::MeleeDamageBonusDone(Unit* pVictim, uint32 pdamage, WeaponAttackTyp // weapon damage based spells else if (APbonus || DoneFlat) { - bool normalized = spellProto ? IsSpellHaveEffect(spellProto, SPELL_EFFECT_NORMALIZED_WEAPON_DMG) : false; + bool normalized = spellProto ? spellProto->HasSpellEffect(SPELL_EFFECT_NORMALIZED_WEAPON_DMG) : false; DoneTotal += int32(APbonus / 14.0f * GetAPMultiplier(attType, normalized)); // for weapon damage based spells we still have to apply damage done percent mods @@ -6206,7 +6206,7 @@ uint32 Unit::MeleeDamageBonusTaken(Unit* pCaster, uint32 pdamage, WeaponAttackTy { return pdamage; } // differentiate for weapon damage based spells - bool isWeaponDamageBasedSpell = !(spellProto && (damagetype == DOT || IsSpellHaveEffect(spellProto, SPELL_EFFECT_SCHOOL_DAMAGE))); + bool isWeaponDamageBasedSpell = !(spellProto && (damagetype == DOT || spellProto->HasSpellEffect(SPELL_EFFECT_SCHOOL_DAMAGE))); uint32 schoolMask = spellProto ? GetSpellSchoolMask(spellProto) : uint32(GetMeleeDamageSchoolMask()); // FLAT damage bonus auras diff --git a/src/game/Server/DBCStructure.h b/src/game/Server/DBCStructure.h index 11790f3b..47517735 100644 --- a/src/game/Server/DBCStructure.h +++ b/src/game/Server/DBCStructure.h @@ -921,7 +921,7 @@ struct SpellEntry */ inline bool HasAttribute(SpellAttributesEx4 attribute) const { return AttributesEx4 & attribute; } - inline bool HasSpellEffect(uint16 effect) const + inline bool HasSpellEffect(SpellEffects effect) const { for (uint8 i = EFFECT_INDEX_0; i <= EFFECT_INDEX_2; ++i) if (Effect[i] == effect) diff --git a/src/game/WorldHandlers/Spell.cpp b/src/game/WorldHandlers/Spell.cpp index 0492e9f1..976ee21f 100644 --- a/src/game/WorldHandlers/Spell.cpp +++ b/src/game/WorldHandlers/Spell.cpp @@ -4041,8 +4041,8 @@ SpellCastResult Spell::CheckCast(bool strict) case SPELLFAMILY_SHAMAN: case SPELLFAMILY_PALADIN: { - if (IsSpellHaveEffect(m_spellInfo, SPELL_EFFECT_HEAL) || IsSpellHaveAura(m_spellInfo, SPELL_AURA_PERIODIC_HEAL) || - IsSpellHaveEffect(m_spellInfo, SPELL_EFFECT_DISPEL)) + if (m_spellInfo->HasSpellEffect(SPELL_EFFECT_HEAL) || IsSpellHaveAura(m_spellInfo, SPELL_AURA_PERIODIC_HEAL) || + m_spellInfo->HasSpellEffect(SPELL_EFFECT_DISPEL)) { Unit::AuraList const& auraClassScripts = m_caster->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS); for (Unit::AuraList::const_iterator itr = auraClassScripts.begin(); itr != auraClassScripts.end();) @@ -4086,7 +4086,7 @@ SpellCastResult Spell::CheckCast(bool strict) } // give error message when applying lower hot rank to higher hot rank on target - if (!IsSpellHaveEffect(m_spellInfo, SPELL_EFFECT_HEAL) && IsSpellHaveAura(m_spellInfo, SPELL_AURA_PERIODIC_HEAL)) + if (!m_spellInfo->HasSpellEffect(SPELL_EFFECT_HEAL) && IsSpellHaveAura(m_spellInfo, SPELL_AURA_PERIODIC_HEAL)) { Unit::AuraList const& mPeriodicHeal = target->GetAurasByType(SPELL_AURA_PERIODIC_HEAL); for (Unit::AuraList::const_iterator i = mPeriodicHeal.begin(); i != mPeriodicHeal.end(); ++i) diff --git a/src/game/WorldHandlers/UnitAuraProcHandler.cpp b/src/game/WorldHandlers/UnitAuraProcHandler.cpp index 200964c7..bd9453c5 100644 --- a/src/game/WorldHandlers/UnitAuraProcHandler.cpp +++ b/src/game/WorldHandlers/UnitAuraProcHandler.cpp @@ -1161,7 +1161,7 @@ SpellAuraProcResult Unit::HandleProcTriggerSpellAuraProc(Unit* pVictim, uint32 d } // not allow proc extra attack spell at extra attack - if (m_extraAttacks && IsSpellHaveEffect(triggerEntry, SPELL_EFFECT_ADD_EXTRA_ATTACKS)) + if (m_extraAttacks && triggerEntry->HasSpellEffect(SPELL_EFFECT_ADD_EXTRA_ATTACKS)) { return SPELL_AURA_PROC_FAILED; } // Custom basepoints/target for exist spell