From df1ffbc8ee376d3681a20d163f765351debef042 Mon Sep 17 00:00:00 2001 From: ratkosrb Date: Thu, 21 Mar 2019 20:33:31 +0200 Subject: [PATCH] Refactor resistance and armor calculation. Credit to cmangos. https://github.com/cmangos/mangos-classic/commit/40f242421633f1789cd820129547bc38faed598d https://github.com/cmangos/mangos-classic/commit/7e090ea19f62869012a9e22826c7a6ca68a03a75 --- src/game/Objects/Creature.cpp | 21 ++--- src/game/Objects/Pet.cpp | 18 ++--- src/game/Objects/Unit.cpp | 46 +++++++---- src/game/Objects/Unit.h | 4 + src/game/Spells/SpellAuras.cpp | 138 +++++++++++++++++++++------------ src/game/Spells/SpellAuras.h | 2 +- src/game/StatSystem.cpp | 64 +++++++-------- 7 files changed, 170 insertions(+), 123 deletions(-) diff --git a/src/game/Objects/Creature.cpp b/src/game/Objects/Creature.cpp index fb6c02e22..acc0dfc34 100644 --- a/src/game/Objects/Creature.cpp +++ b/src/game/Objects/Creature.cpp @@ -507,21 +507,14 @@ bool Creature::UpdateEntry(uint32 Entry, Team team, const CreatureData *data /*= // preserve all current dynamic flags if exist uint32 dynFlags = GetUInt32Value(UNIT_DYNAMIC_FLAGS); SetUInt32Value(UNIT_DYNAMIC_FLAGS, dynFlags ? dynFlags : GetCreatureInfo()->dynamic_flags); - SetModifierValue(UNIT_MOD_ARMOR, BASE_VALUE, float(GetCreatureInfo()->armor)); - float resistances[] = { - float(GetCreatureInfo()->holy_res), - float(GetCreatureInfo()->fire_res), - float(GetCreatureInfo()->nature_res), - float(GetCreatureInfo()->frost_res), - float(GetCreatureInfo()->shadow_res), - float(GetCreatureInfo()->arcane_res) - }; - - for (int i = 0; i < 6; ++i) - { - SetModifierValue(UnitMods(UNIT_MOD_RESISTANCE_HOLY + i), BASE_VALUE, resistances[i]); - } + SetModifierValue(UNIT_MOD_ARMOR, BASE_VALUE, float(GetCreatureInfo()->armor)); + SetCreateResistance(SPELL_SCHOOL_HOLY, GetCreatureInfo()->holy_res); + SetCreateResistance(SPELL_SCHOOL_FIRE, GetCreatureInfo()->fire_res); + SetCreateResistance(SPELL_SCHOOL_NATURE, GetCreatureInfo()->nature_res); + SetCreateResistance(SPELL_SCHOOL_FROST, GetCreatureInfo()->frost_res); + SetCreateResistance(SPELL_SCHOOL_SHADOW, GetCreatureInfo()->shadow_res); + SetCreateResistance(SPELL_SCHOOL_ARCANE, GetCreatureInfo()->arcane_res); SetFly(CanFly()); SetMeleeDamageSchool(SpellSchools(GetCreatureInfo()->dmg_school)); diff --git a/src/game/Objects/Pet.cpp b/src/game/Objects/Pet.cpp index d0be91120..9d4cb0150 100644 --- a/src/game/Objects/Pet.cpp +++ b/src/game/Objects/Pet.cpp @@ -1304,7 +1304,7 @@ bool Pet::InitStatsForLevel(uint32 petlevel, Unit* owner) else SetMeleeDamageSchool(SPELL_SCHOOL_NORMAL); - SetModifierValue(UNIT_MOD_ARMOR, BASE_VALUE, float(petlevel * 50)); + SetCreateResistance(SPELL_SCHOOL_NORMAL, int32(petlevel * 50)); // Nostalrius: pre-2.0: normalisation de la vitesse d'attaque des pets. SetAttackTime(BASE_ATTACK, cinfo->base_attack_time); //BASE_ATTACK_TIME); @@ -1338,12 +1338,12 @@ bool Pet::InitStatsForLevel(uint32 petlevel, Unit* owner) // TODO: Do we keep it or remove it? if (getPetType() != HUNTER_PET || (sWorld.GetWowPatch() < WOW_PATCH_103 && sWorld.getConfig(CONFIG_BOOL_ACCURATE_PETS))) { - createResistance[SPELL_SCHOOL_HOLY] = cinfo->holy_res; - createResistance[SPELL_SCHOOL_FIRE] = cinfo->fire_res; - createResistance[SPELL_SCHOOL_NATURE] = cinfo->nature_res; - createResistance[SPELL_SCHOOL_FROST] = cinfo->frost_res; - createResistance[SPELL_SCHOOL_SHADOW] = cinfo->shadow_res; - createResistance[SPELL_SCHOOL_ARCANE] = cinfo->arcane_res; + SetCreateResistance(SPELL_SCHOOL_HOLY, cinfo->holy_res); + SetCreateResistance(SPELL_SCHOOL_FIRE, cinfo->fire_res); + SetCreateResistance(SPELL_SCHOOL_NATURE, cinfo->nature_res); + SetCreateResistance(SPELL_SCHOOL_FROST, cinfo->frost_res); + SetCreateResistance(SPELL_SCHOOL_SHADOW, cinfo->shadow_res); + SetCreateResistance(SPELL_SCHOOL_ARCANE, cinfo->arcane_res); } switch (getPetType()) @@ -1363,7 +1363,7 @@ bool Pet::InitStatsForLevel(uint32 petlevel, Unit* owner) SetCreateMana(pInfo->mana); if (pInfo->armor > 0) - SetModifierValue(UNIT_MOD_ARMOR, BASE_VALUE, float(pInfo->armor)); + SetCreateResistance(SPELL_SCHOOL_NORMAL, int32(pInfo->armor)); for (int stat = 0; stat < MAX_STATS; ++stat) SetCreateStat(Stats(stat), float(pInfo->stats[stat])); @@ -1398,7 +1398,7 @@ bool Pet::InitStatsForLevel(uint32 petlevel, Unit* owner) if (pInfo) // exist in DB { SetCreateHealth(pInfo->health); - SetModifierValue(UNIT_MOD_ARMOR, BASE_VALUE, float(pInfo->armor)); + SetCreateResistance(SPELL_SCHOOL_NORMAL, int32(pInfo->armor)); //SetModifierValue(UNIT_MOD_ATTACK_POWER, BASE_VALUE, float(cinfo->attack_power)); for (int i = STAT_STRENGTH; i < MAX_STATS; ++i) diff --git a/src/game/Objects/Unit.cpp b/src/game/Objects/Unit.cpp index 7ccfa9069..46d2ce156 100644 --- a/src/game/Objects/Unit.cpp +++ b/src/game/Objects/Unit.cpp @@ -176,6 +176,9 @@ Unit::Unit() for (int i = 0; i < MAX_STATS; ++i) m_createStats[i] = 0.0f; + for (auto& m_createResistance : m_createResistances) + m_createResistance = 0; + m_attacking = nullptr; m_modMeleeHitChance = 0.0f; m_modRangedHitChance = 0.0f; @@ -8945,6 +8948,36 @@ float Unit::GetTotalStatValue(Stats stat) const return value; } +int32 Unit::GetTotalResistanceValue(SpellSchools school) const +{ + UnitMods unitMod = UnitMods(UNIT_MOD_RESISTANCE_START + school); + + if (m_auraModifiersGroup[unitMod][TOTAL_PCT] <= 0.0f) + return 0.0f; + + // value = ((base_value * base_pct) + total_value) * total_pct + float value = GetCreateResistance(school); + + const bool vulnerability = (value < 0); + + value += m_auraModifiersGroup[unitMod][BASE_VALUE]; + value *= m_auraModifiersGroup[unitMod][BASE_PCT]; + value += m_auraModifiersGroup[unitMod][TOTAL_VALUE]; + value *= m_auraModifiersGroup[unitMod][TOTAL_PCT]; + + // World of Warcraft Client Patch 1.9.0 (2006-01-03) + // - Curse of Shadow and Curse of the Elements - These curses can no + // longer cause resistance to become negative. +#if SUPPORTED_CLIENT_BUILD > CLIENT_BUILD_1_8_4 + // Auras can't cause resistances to dip below 0 since early vanilla + // PS: Actually, they can, but only visually advertised in the fields, calculations ignore it, we limit both + if (value < 0 && !vulnerability) + value = 0; +#endif + + return int32(value); +} + float Unit::GetTotalAuraModValue(UnitMods unitMod) const { if (unitMod >= UNIT_MOD_END) @@ -8961,19 +8994,6 @@ float Unit::GetTotalAuraModValue(UnitMods unitMod) const value += m_auraModifiersGroup[unitMod][TOTAL_VALUE]; value *= m_auraModifiersGroup[unitMod][TOTAL_PCT]; - // World of Warcraft Client Patch 1.9.0 (2006-01-03) - // - Curse of Shadow and Curse of the Elements - These curses can no - // longer cause resistance to become negative. -#if SUPPORTED_CLIENT_BUILD > CLIENT_BUILD_1_8_4 - // Auras can't cause resistances to dip below 0 since early vanilla - // PS: Actually, they can, but only visually advertised in the fields, calculations ignore it, we limit both - if ((unitMod >= UNIT_MOD_RESISTANCE_START) && (unitMod < UNIT_MOD_RESISTANCE_END) && - (value < 0.0f) && (m_auraModifiersGroup[unitMod][BASE_VALUE] >= 0.0f)) - { - value = 0.0f; - } -#endif - return value; } diff --git a/src/game/Objects/Unit.h b/src/game/Objects/Unit.h index fbd259609..da335621b 100644 --- a/src/game/Objects/Unit.h +++ b/src/game/Objects/Unit.h @@ -1649,6 +1649,8 @@ class MANGOS_DLL_SPEC Unit : public WorldObject uint32 GetCreateMana() const { return GetUInt32Value(UNIT_FIELD_BASE_MANA); } uint32 GetCreatePowers(Powers power) const; float GetCreateStat(Stats stat) const { return m_createStats[stat]; } + void SetCreateResistance(SpellSchools school, int32 val) { m_createResistances[school] = val; } + int32 GetCreateResistance(SpellSchools school) const { return m_createResistances[school]; } void SetCurrentCastedSpell(Spell * pSpell); bool IsSpellProhibited(SpellEntry const* pSpell); @@ -1710,6 +1712,7 @@ class MANGOS_DLL_SPEC Unit : public WorldObject void SetModifierValue(UnitMods unitMod, UnitModifierType modifierType, float value) { m_auraModifiersGroup[unitMod][modifierType] = value; } float GetModifierValue(UnitMods unitMod, UnitModifierType modifierType) const; float GetTotalStatValue(Stats stat) const; + int32 GetTotalResistanceValue(SpellSchools school) const; float GetTotalAuraModValue(UnitMods unitMod) const; SpellSchools GetSpellSchoolByAuraGroup(UnitMods unitMod) const; Stats GetStatByAuraGroup(UnitMods unitMod) const; @@ -2098,6 +2101,7 @@ class MANGOS_DLL_SPEC Unit : public WorldObject uint32 m_attackTimer[MAX_ATTACK]; float m_createStats[MAX_STATS]; + int32 m_createResistances[MAX_SPELL_SCHOOL]; AttackerSet m_attackers; Unit* m_attacking; diff --git a/src/game/Spells/SpellAuras.cpp b/src/game/Spells/SpellAuras.cpp index 96d93a3db..696b97df3 100644 --- a/src/game/Spells/SpellAuras.cpp +++ b/src/game/Spells/SpellAuras.cpp @@ -204,7 +204,7 @@ pAuraHandler AuraHandler[TOTAL_AURAS] = &Aura::HandleForceReaction, //139 SPELL_AURA_FORCE_REACTION &Aura::HandleAuraModRangedHaste, //140 SPELL_AURA_MOD_RANGED_HASTE &Aura::HandleRangedAmmoHaste, //141 SPELL_AURA_MOD_RANGED_AMMO_HASTE - &Aura::HandleAuraModBaseResistancePCT, //142 SPELL_AURA_MOD_BASE_RESISTANCE_PCT + &Aura::HandleAuraModBaseResistancePercent, //142 SPELL_AURA_MOD_BASE_RESISTANCE_PCT &Aura::HandleAuraModResistanceExclusive, //143 SPELL_AURA_MOD_RESISTANCE_EXCLUSIVE &Aura::HandleAuraSafeFall, //144 SPELL_AURA_SAFE_FALL implemented in WorldSession::HandleMovementOpcodes &Aura::HandleUnused, //145 SPELL_AURA_CHARISMA obsolete? @@ -4199,44 +4199,79 @@ void Aura::HandlePeriodicHealthFunnel(bool apply, bool /*Real*/) void Aura::HandleAuraModResistanceExclusive(bool apply, bool /*Real*/) { - Unit *target = GetTarget(); - SpellEntry const* spellProto = GetSpellProto(); - // Calcul du montant des autres buffs similaires. - int32 maxModifiersOthers[MAX_SPELL_SCHOOL] = {0}; - Unit::AuraList const& mModResistanceExcl = target->GetAurasByType(SPELL_AURA_MOD_RESISTANCE_EXCLUSIVE); - for (Unit::AuraList::const_iterator i = mModResistanceExcl.begin(); i != mModResistanceExcl.end(); ++i) - for (int8 x = SPELL_SCHOOL_NORMAL; x < MAX_SPELL_SCHOOL; ++x) - if ((*i)->GetSpellProto()->Id != spellProto->Id && (*i)->GetModifier()->m_miscvalue & int32(1 << x)) - if (maxModifiersOthers[x] < (*i)->GetModifier()->m_amount) - maxModifiersOthers[x] = (*i)->GetModifier()->m_amount; - // Application des effets. - for (int8 x = SPELL_SCHOOL_NORMAL; x < MAX_SPELL_SCHOOL; x++) + if (!m_modifier.m_amount) + return; + + Unit* target = GetTarget(); + + for (uint32 i = SPELL_SCHOOL_NORMAL; i < MAX_SPELL_SCHOOL; ++i) { - GetTarget()->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + x), BASE_VALUE, float(maxModifiersOthers[x]), !apply); - if (GetTarget()->GetTypeId() == TYPEID_PLAYER) - ((Player*)GetTarget())->ApplyResistanceBuffModsMod(SpellSchools(x), m_positive, float(maxModifiersOthers[x]), !apply); - GetTarget()->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + x), BASE_VALUE, float(std::max(maxModifiersOthers[x], m_modifier.m_miscvalue & int32(1 << x) ? m_modifier.m_amount : 0)), apply); - if (GetTarget()->GetTypeId() == TYPEID_PLAYER) - ((Player*)GetTarget())->ApplyResistanceBuffModsMod(SpellSchools(x), m_positive, float(std::max(maxModifiersOthers[x], m_modifier.m_miscvalue & int32(1 << x) ? m_modifier.m_amount : 0)), apply); + if (m_modifier.m_miscvalue & (1 << i)) + { + // Apply the value exclusively for each school + const int32 amount = m_modifier.m_amount; + int32 bonusMax = 0; + int32 malusMax = 0; + + for (Aura* aura : target->GetAurasByType(m_modifier.m_auraname)) + { + if (aura == this || !(aura->GetMiscValue() & (1 << i))) + continue; + + const int32 mod = aura->GetModifier()->m_amount; + + if (mod > bonusMax) + bonusMax = mod; + else if (mod < malusMax) + malusMax = mod; + } + + if (amount > bonusMax) + { + target->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + i), TOTAL_VALUE, float(apply ? bonusMax : amount), false); + target->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + i), TOTAL_VALUE, float(apply ? amount : bonusMax), true); + // UI bonus info: + if (target->GetTypeId() == TYPEID_PLAYER) + { + static_cast(target)->ApplyResistanceBuffModsMod(SpellSchools(i), true, float(apply ? bonusMax : amount), false); + static_cast(target)->ApplyResistanceBuffModsMod(SpellSchools(i), true, float(apply ? amount : bonusMax), true); + } + } + else if (amount < malusMax) + { + target->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + i), TOTAL_VALUE, float(apply ? malusMax : amount), false); + target->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + i), TOTAL_VALUE, float(apply ? amount : malusMax), true); + // UI malus info: + if (target->GetTypeId() == TYPEID_PLAYER) + { + static_cast(target)->ApplyResistanceBuffModsMod(SpellSchools(i), false, float(apply ? malusMax : amount), false); + static_cast(target)->ApplyResistanceBuffModsMod(SpellSchools(i), false, float(apply ? amount : malusMax), true); + } + } + } } } void Aura::HandleAuraModResistance(bool apply, bool /*Real*/) { - Unit *target = GetTarget(); - SpellEntry const* spellProto = GetSpellProto(); + if (!m_modifier.m_amount) + return; - for (int8 x = SPELL_SCHOOL_NORMAL; x < MAX_SPELL_SCHOOL; x++) + Unit* target = GetTarget(); + + for (uint32 i = SPELL_SCHOOL_NORMAL; i < MAX_SPELL_SCHOOL; ++i) { - if (m_modifier.m_miscvalue & int32(1 << x)) + if (m_modifier.m_miscvalue & (1 << i)) { - target->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + x), TOTAL_VALUE, float(m_modifier.m_amount), apply); + target->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + i), TOTAL_VALUE, float(m_modifier.m_amount), apply); + // UI bonus/malus info: if (target->GetTypeId() == TYPEID_PLAYER) - ((Player*)target)->ApplyResistanceBuffModsMod(SpellSchools(x), m_positive, float(m_modifier.m_amount), apply); + static_cast(target)->ApplyResistanceBuffModsMod(SpellSchools(i), (m_modifier.m_amount > 0), float(m_modifier.m_amount), apply); } - } +} // Faerie Fire (druid versions) + SpellEntry const* spellProto = GetSpellProto(); if (spellProto->SpellIconID == 109 && spellProto->IsFitToFamily()) { target->ApplySpellDispelImmunity(spellProto, DISPEL_STEALTH, apply); @@ -4244,14 +4279,6 @@ void Aura::HandleAuraModResistance(bool apply, bool /*Real*/) } } -void Aura::HandleAuraModBaseResistancePCT(bool apply, bool /*Real*/) -{ - for (int8 x = SPELL_SCHOOL_NORMAL; x < MAX_SPELL_SCHOOL; x++) - { - if (m_modifier.m_miscvalue & int32(1 << x)) - GetTarget()->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + x), BASE_PCT, float(m_modifier.m_amount), apply); - } -} void Aura::HandleAurasVisible(bool apply, bool /*Real*/) { @@ -4260,17 +4287,21 @@ void Aura::HandleAurasVisible(bool apply, bool /*Real*/) void Aura::HandleModResistancePercent(bool apply, bool /*Real*/) { - Unit *target = GetTarget(); + if (!m_modifier.m_amount) + return; - for (int8 i = SPELL_SCHOOL_NORMAL; i < MAX_SPELL_SCHOOL; i++) + Unit* target = GetTarget(); + + for (uint32 i = SPELL_SCHOOL_NORMAL; i < MAX_SPELL_SCHOOL; ++i) { - if (m_modifier.m_miscvalue & int32(1 << i)) + if (m_modifier.m_miscvalue & (1 << i)) { target->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + i), TOTAL_PCT, float(m_modifier.m_amount), apply); + // UI bonus/malus info: if (target->GetTypeId() == TYPEID_PLAYER) { - ((Player*)target)->ApplyResistanceBuffModsPercentMod(SpellSchools(i), true, float(m_modifier.m_amount), apply); - ((Player*)target)->ApplyResistanceBuffModsPercentMod(SpellSchools(i), false, float(m_modifier.m_amount), apply); + static_cast(target)->ApplyResistanceBuffModsPercentMod(SpellSchools(i), true, float(m_modifier.m_amount), apply); + static_cast(target)->ApplyResistanceBuffModsPercentMod(SpellSchools(i), false, float(m_modifier.m_amount), apply); } } } @@ -4278,18 +4309,29 @@ void Aura::HandleModResistancePercent(bool apply, bool /*Real*/) void Aura::HandleModBaseResistance(bool apply, bool /*Real*/) { - // only players have base stats - if (GetTarget()->GetTypeId() != TYPEID_PLAYER) + if (!m_modifier.m_amount) + return; + + Unit* target = GetTarget(); + + for (uint32 i = SPELL_SCHOOL_NORMAL; i < MAX_SPELL_SCHOOL; ++i) { - //only pets have base stats - if (((Creature*)GetTarget())->IsPet() && (m_modifier.m_miscvalue & SPELL_SCHOOL_MASK_NORMAL)) - GetTarget()->HandleStatModifier(UNIT_MOD_ARMOR, TOTAL_VALUE, float(m_modifier.m_amount), apply); + if (m_modifier.m_miscvalue & (1 << i)) + target->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + i), BASE_VALUE, float(m_modifier.m_amount), apply); } - else +} + +void Aura::HandleAuraModBaseResistancePercent(bool apply, bool /*Real*/) +{ + if (!m_modifier.m_amount) + return; + + Unit* target = GetTarget(); + + for (uint32 i = SPELL_SCHOOL_NORMAL; i < MAX_SPELL_SCHOOL; ++i) { - for (int i = SPELL_SCHOOL_NORMAL; i < MAX_SPELL_SCHOOL; i++) - if (m_modifier.m_miscvalue & (1 << i)) - GetTarget()->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + i), TOTAL_VALUE, float(m_modifier.m_amount), apply); + if (m_modifier.m_miscvalue & (1 << i)) + target->HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + i), BASE_PCT, float(m_modifier.m_amount), apply); } } diff --git a/src/game/Spells/SpellAuras.h b/src/game/Spells/SpellAuras.h index 0d98611d4..7fd693911 100644 --- a/src/game/Spells/SpellAuras.h +++ b/src/game/Spells/SpellAuras.h @@ -392,7 +392,7 @@ class MANGOS_DLL_SPEC Aura void HandleModPercentStat(bool Apply, bool Real); void HandleAurasVisible(bool Apply, bool Real); void HandleModResistancePercent(bool Apply, bool Real); - void HandleAuraModBaseResistancePCT(bool Apply, bool Real); + void HandleAuraModBaseResistancePercent(bool Apply, bool Real); void HandleModShieldBlockPCT(bool Apply, bool Real); void HandleAuraTrackStealthed(bool Apply, bool Real); void HandleModShieldBlock(bool Apply, bool Real); diff --git a/src/game/StatSystem.cpp b/src/game/StatSystem.cpp index 6e7ebc2d0..445417167 100644 --- a/src/game/StatSystem.cpp +++ b/src/game/StatSystem.cpp @@ -119,8 +119,8 @@ void Player::UpdateResistances(uint32 school) { if (school > SPELL_SCHOOL_NORMAL) { - float value = school == SPELL_SCHOOL_HOLY ? 0.0f : GetTotalAuraModValue(UnitMods(UNIT_MOD_RESISTANCE_START + school)); - SetResistance(SpellSchools(school), int32(value)); + int32 value = school == SPELL_SCHOOL_HOLY ? 0 : GetTotalResistanceValue(SpellSchools(school)); + SetResistance(SpellSchools(school), value); } else UpdateArmor(); @@ -128,24 +128,22 @@ void Player::UpdateResistances(uint32 school) void Player::UpdateArmor() { - float value = 0.0f; - UnitMods unitMod = UNIT_MOD_ARMOR; + float dynamic = (GetStat(STAT_AGILITY) * 2.0f); - value = GetModifierValue(unitMod, BASE_VALUE); // base armor (from items) - value *= GetModifierValue(unitMod, BASE_PCT); // armor percent from items - value += GetStat(STAT_AGILITY) * 2.0f; // armor bonus from stats - value += GetModifierValue(unitMod, TOTAL_VALUE); - - //add dynamic flat mods - AuraList const& mResbyIntellect = GetAurasByType(SPELL_AURA_MOD_RESISTANCE_OF_STAT_PERCENT); - for (AuraList::const_iterator i = mResbyIntellect.begin(); i != mResbyIntellect.end(); ++i) + // Add dynamic flat mods + for (auto& i : GetAurasByType(SPELL_AURA_MOD_RESISTANCE_OF_STAT_PERCENT)) { - Modifier* mod = (*i)->GetModifier(); - if (mod->m_miscvalue & SPELL_SCHOOL_MASK_NORMAL) - value += int32(GetStat(STAT_INTELLECT) * mod->m_amount / 100.0f); + if (Modifier* mod = i->GetModifier()) + { + if (mod->m_miscvalue & SPELL_SCHOOL_MASK_NORMAL) + dynamic += (GetStat(STAT_INTELLECT) * (mod->m_amount * 0.01f)); + } } - // add dummy effects from spells (check class and other conditions first for optimization) + m_auraModifiersGroup[UNIT_MOD_ARMOR][TOTAL_VALUE] += dynamic; + int32 value = GetTotalResistanceValue(SPELL_SCHOOL_NORMAL); + + // Add dummy effects from spells (check class and other conditions first for optimization) if (getClass() == CLASS_DRUID) { ShapeshiftForm form = GetShapeshiftForm(); @@ -158,7 +156,7 @@ void Player::UpdateArmor() if ((*itr)->GetId() == 5229) { float enrageModifier = 0.0f; - enrageModifier = GetModifierValue(unitMod, BASE_VALUE); + enrageModifier = GetModifierValue(UNIT_MOD_ARMOR, BASE_VALUE); enrageModifier *= (*itr)->GetModifier()->m_amount / 100.0f; value += enrageModifier; break; @@ -167,9 +165,8 @@ void Player::UpdateArmor() } } - value *= GetModifierValue(unitMod, TOTAL_PCT); - - SetArmor(int32(value)); + SetArmor(value); + m_auraModifiersGroup[UNIT_MOD_ARMOR][TOTAL_VALUE] -= dynamic; } float Player::GetHealthBonusFromStamina(float stamina) @@ -709,8 +706,8 @@ void Creature::UpdateResistances(uint32 school) { if (school > SPELL_SCHOOL_NORMAL) { - float value = school == SPELL_SCHOOL_HOLY ? 0.0f : GetTotalAuraModValue(UnitMods(UNIT_MOD_RESISTANCE_START + school)); - SetResistance(SpellSchools(school), int32(value)); + int32 value = school == SPELL_SCHOOL_HOLY ? 0 : GetTotalResistanceValue(SpellSchools(school)); + SetResistance(SpellSchools(school), value); } else UpdateArmor(); @@ -718,8 +715,8 @@ void Creature::UpdateResistances(uint32 school) void Creature::UpdateArmor() { - float value = GetTotalAuraModValue(UNIT_MOD_ARMOR); - SetArmor(int32(value)); + int32 value = GetTotalResistanceValue(SPELL_SCHOOL_NORMAL); + SetArmor(value); } void Creature::UpdateMaxHealth() @@ -888,27 +885,18 @@ bool Pet::UpdateAllStats() void Pet::UpdateResistances(uint32 school) { if (school > SPELL_SCHOOL_NORMAL) - { - float value = school == SPELL_SCHOOL_HOLY ? 0.0f : GetTotalAuraModValue(UnitMods(UNIT_MOD_RESISTANCE_START + school)); - SetResistance(SpellSchools(school), int32(value)); - } + return Creature::UpdateResistances(school); else UpdateArmor(); } void Pet::UpdateArmor() { - float value = 0.0f; - float bonus_armor = 0.0f; - UnitMods unitMod = UNIT_MOD_ARMOR; + float amount = (GetStat(STAT_AGILITY) * 2.0f); - value = GetModifierValue(unitMod, BASE_VALUE); - value *= GetModifierValue(unitMod, BASE_PCT); - value += GetStat(STAT_AGILITY) * 2.0f; - value += GetModifierValue(unitMod, TOTAL_VALUE) + bonus_armor; - value *= GetModifierValue(unitMod, TOTAL_PCT); - - SetArmor(int32(value)); + m_auraModifiersGroup[UNIT_MOD_ARMOR][TOTAL_VALUE] += amount; + Creature::UpdateArmor(); + m_auraModifiersGroup[UNIT_MOD_ARMOR][TOTAL_VALUE] -= amount; } void Pet::UpdateMaxHealth()