Core/Spell: added some helpers to SpellInfo to reduce code duplication

This commit is contained in:
ariel-
2016-12-30 23:50:28 -03:00
parent 90a330c910
commit 14c2b2d6cd
5 changed files with 69 additions and 62 deletions
+2 -9
View File
@@ -836,17 +836,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)
+2 -9
View File
@@ -1623,17 +1623,10 @@ uint32 Unit::CalcArmorReducedDamage(Unit* victim, const uint32 damage, SpellInfo
{
float arpPct = ToPlayer()->GetRatingBonusValue(CR_ARMOR_PENETRATION);
Item* weapon = ToPlayer()->GetWeaponForAttack(attackType, true);
Item const* weapon = ToPlayer()->GetWeaponForAttack(attackType, true);
arpPct += GetTotalAuraModifier(SPELL_AURA_MOD_ARMOR_PENETRATION_PCT, [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);
});
// no more than 100%
+21 -37
View File
@@ -529,25 +529,7 @@ m_caster((info->HasAttribute(SPELL_ATTR6_CAST_BY_CHARMER) && caster->GetCharmerO
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)
@@ -6567,12 +6549,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);
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;
}
Item const* item = m_caster->ToPlayer()->GetWeaponForAttack(m_attackType);
// skip spell if no weapon in slot or broken
if (!item || item->IsBroken())
@@ -6581,21 +6576,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;
}
}();
// offhand hand weapon required
if (m_spellInfo->HasAttribute(SPELL_ATTR3_REQ_OFFHAND))
{
Item* item = m_caster->ToPlayer()->GetWeaponForAttack(OFF_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;
}
if (itemRes != SPELL_CAST_OK)
return itemRes;
}
return SPELL_CAST_OK;
+40 -7
View File
@@ -1245,6 +1245,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, flag96 const& familyFlags) const
{
if (!familyName)
@@ -3093,13 +3132,7 @@ int32 SpellInfo::CalcPowerCost(Unit const* caster, SpellSchoolMask schoolMask) c
if (SpellShapeshiftEntry const* ss = sSpellShapeshiftStore.LookupEntry(caster->GetShapeshiftForm()))
speed = ss->attackSpeed;
else
{
WeaponAttackType slot = BASE_ATTACK;
if (HasAttribute(SPELL_ATTR3_REQ_OFFHAND))
slot = OFF_ATTACK;
speed = caster->GetAttackTime(slot);
}
speed = caster->GetAttackTime(GetAttackType());
powerCost += speed / 100;
}
+4
View File
@@ -452,6 +452,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, flag96 const& familyFlags) const;
bool IsAffectedBySpellMods() const;