diff options
author | ariel- <ariel-@users.noreply.github.com> | 2016-12-30 23:50:28 -0300 |
---|---|---|
committer | DoctorKraft <DoctorKraft@users.noreply.github.com> | 2018-03-18 00:19:46 +0100 |
commit | be4670250d769829e6210df540bbe79f2ead258a (patch) | |
tree | fc3cfbb8bc85b8efb9308536547bc09c198e8699 /src | |
parent | 15b22590beb99fd1ac7f06564d5aa37a29ab127c (diff) |
Core/Spell: added some helpers to SpellInfo to reduce code duplication
(cherry picked from commit 14c2b2d6cd2303609f1a1859e727ace7b8ea649c)
Diffstat (limited to 'src')
-rw-r--r-- | src/server/game/Entities/Unit/StatSystem.cpp | 11 | ||||
-rw-r--r-- | src/server/game/Spells/Spell.cpp | 58 | ||||
-rw-r--r-- | src/server/game/Spells/SpellInfo.cpp | 40 | ||||
-rw-r--r-- | src/server/game/Spells/SpellInfo.h | 4 |
4 files changed, 67 insertions, 46 deletions
diff --git a/src/server/game/Entities/Unit/StatSystem.cpp b/src/server/game/Entities/Unit/StatSystem.cpp index 14037920628..3c93d8404a0 100644 --- a/src/server/game/Entities/Unit/StatSystem.cpp +++ b/src/server/game/Entities/Unit/StatSystem.cpp @@ -706,17 +706,10 @@ void Player::UpdateExpertise(WeaponAttackType attack) int32 expertise = int32(GetRatingBonusValue(CR_EXPERTISE)); - Item* weapon = GetWeaponForAttack(attack, true); + Item const* weapon = GetWeaponForAttack(attack, true); expertise += GetTotalAuraModifier(SPELL_AURA_MOD_EXPERTISE, [weapon](AuraEffect const* aurEff) -> bool { - // item neutral spell - if (aurEff->GetSpellInfo()->EquippedItemClass == -1) - return true; - // item dependent spell - else if (weapon && weapon->IsFitToSpellRequirements(aurEff->GetSpellInfo())) - return true; - - return false; + return aurEff->GetSpellInfo()->IsItemFitToSpellRequirements(weapon); }); if (expertise < 0) diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp index 104d1901a7f..56c81a0bd4c 100644 --- a/src/server/game/Spells/Spell.cpp +++ b/src/server/game/Spells/Spell.cpp @@ -541,25 +541,7 @@ m_spellValue(new SpellValue(caster->GetMap()->GetDifficultyID(), m_spellInfo)) memset(m_damageMultipliers, 0, sizeof(m_damageMultipliers)); // Get data for type of attack - switch (m_spellInfo->DmgClass) - { - case SPELL_DAMAGE_CLASS_MELEE: - if (m_spellInfo->HasAttribute(SPELL_ATTR3_REQ_OFFHAND)) - m_attackType = OFF_ATTACK; - else - m_attackType = BASE_ATTACK; - break; - case SPELL_DAMAGE_CLASS_RANGED: - m_attackType = m_spellInfo->IsRangedWeaponSpell() ? RANGED_ATTACK : BASE_ATTACK; - break; - default: - // Wands - if (m_spellInfo->HasAttribute(SPELL_ATTR2_AUTOREPEAT_FLAG)) - m_attackType = RANGED_ATTACK; - else - m_attackType = BASE_ATTACK; - break; - } + m_attackType = info->GetAttackType(); m_spellSchoolMask = info->GetSchoolMask(); // Can be override for some spell (wand shoot for example) @@ -6709,26 +6691,25 @@ SpellCastResult Spell::CheckItems(uint32* param1 /*= nullptr*/, uint32* param2 / } // check weapon presence in slots for main/offhand weapons - if (!(_triggeredCastFlags & TRIGGERED_IGNORE_EQUIPPED_ITEM_REQUIREMENT) && m_spellInfo->EquippedItemClass >=0) + if (!(_triggeredCastFlags & TRIGGERED_IGNORE_EQUIPPED_ITEM_REQUIREMENT) && m_spellInfo->EquippedItemClass >= 0) { - // main hand weapon required - if (m_spellInfo->HasAttribute(SPELL_ATTR3_MAIN_HAND)) + SpellCastResult itemRes = [this]() -> SpellCastResult { - Item* item = m_caster->ToPlayer()->GetWeaponForAttack(BASE_ATTACK); - - // skip spell if no weapon in slot or broken - if (!item || item->IsBroken()) - return SPELL_FAILED_EQUIPPED_ITEM_CLASS; - - // skip spell if weapon not fit to triggered spell - if (!item->IsFitToSpellRequirements(m_spellInfo)) - return SPELL_FAILED_EQUIPPED_ITEM_CLASS; - } + switch (m_attackType) + { + case BASE_ATTACK: + // main hand weapon required + if (!m_spellInfo->HasAttribute(SPELL_ATTR3_MAIN_HAND)) + return SPELL_CAST_OK; + case OFF_ATTACK: + // offhand hand weapon required + if (!m_spellInfo->HasAttribute(SPELL_ATTR3_REQ_OFFHAND)) + return SPELL_CAST_OK; + default: + return SPELL_CAST_OK; + } - // offhand hand weapon required - if (m_spellInfo->HasAttribute(SPELL_ATTR3_REQ_OFFHAND)) - { - Item* item = m_caster->ToPlayer()->GetWeaponForAttack(OFF_ATTACK); + Item const* item = m_caster->ToPlayer()->GetWeaponForAttack(m_attackType); // skip spell if no weapon in slot or broken if (!item || item->IsBroken()) @@ -6737,7 +6718,10 @@ SpellCastResult Spell::CheckItems(uint32* param1 /*= nullptr*/, uint32* param2 / // skip spell if weapon not fit to triggered spell if (!item->IsFitToSpellRequirements(m_spellInfo)) return SPELL_FAILED_EQUIPPED_ITEM_CLASS; - } + }(); + + if (itemRes != SPELL_CAST_OK) + return itemRes; } return SPELL_CAST_OK; diff --git a/src/server/game/Spells/SpellInfo.cpp b/src/server/game/Spells/SpellInfo.cpp index b900c670968..958bcc82f16 100644 --- a/src/server/game/Spells/SpellInfo.cpp +++ b/src/server/game/Spells/SpellInfo.cpp @@ -22,6 +22,7 @@ #include "DB2Stores.h" #include "GameTables.h" #include "InstanceScript.h" +#include "Item.h" #include "ItemTemplate.h" #include "Log.h" #include "Map.h" @@ -1574,6 +1575,45 @@ bool SpellInfo::HasInitialAggro() const return !(HasAttribute(SPELL_ATTR1_NO_THREAT) || HasAttribute(SPELL_ATTR3_NO_INITIAL_AGGRO)); } +WeaponAttackType SpellInfo::GetAttackType() const +{ + WeaponAttackType result; + switch (DmgClass) + { + case SPELL_DAMAGE_CLASS_MELEE: + if (HasAttribute(SPELL_ATTR3_REQ_OFFHAND)) + result = OFF_ATTACK; + else + result = BASE_ATTACK; + break; + case SPELL_DAMAGE_CLASS_RANGED: + result = IsRangedWeaponSpell() ? RANGED_ATTACK : BASE_ATTACK; + break; + default: + // Wands + if (IsAutoRepeatRangedSpell()) + result = RANGED_ATTACK; + else + result = BASE_ATTACK; + break; + } + + return result; +} + +bool SpellInfo::IsItemFitToSpellRequirements(Item const* item) const +{ + // item neutral spell + if (EquippedItemClass == -1) + return true; + + // item dependent spell + if (item && item->IsFitToSpellRequirements(this)) + return true; + + return false; +} + bool SpellInfo::IsAffected(uint32 familyName, flag128 const& familyFlags) const { if (!familyName) diff --git a/src/server/game/Spells/SpellInfo.h b/src/server/game/Spells/SpellInfo.h index 9f3722302af..32e952a62c5 100644 --- a/src/server/game/Spells/SpellInfo.h +++ b/src/server/game/Spells/SpellInfo.h @@ -586,6 +586,10 @@ class TC_GAME_API SpellInfo bool IsAutoRepeatRangedSpell() const; bool HasInitialAggro() const; + WeaponAttackType GetAttackType() const; + + bool IsItemFitToSpellRequirements(Item const* item) const; + bool IsAffected(uint32 familyName, flag128 const& familyFlags) const; bool IsAffectedBySpellMods() const; |