Core/Unit: cleanup and minor fixes of miss and resist calculations

- Removed Unit::GetUnitMeleeSkill as it was basically a copy of GetMaxSkillValueForLevel
- Removed static from GetEffectiveResistChance, as this was passed anyways, changed name to CalculateAverageResistReduction, which better reflects what it does
- Fix melee miss chances calculated from attacker maxskill instead of victim maxskill
- Do actual checks if spell can be resisted/missed in MagicSpellHitResult (ie chances > 0)
- Fixed SPELLMOD_RESIST_MISS_CHANCE calculation in MeleeSpellMissChance
- Minor codestyle and cleanup of diminishing returns calcs

(cherry picked from commit e565b34f6d24411e210151d0d03e524f94cdff85)
This commit is contained in:
ariel- authored and funjoker committed 2022-02-16 04:49:24 +01:00
1 parent 0e8422c30a
commit d441e864c4
3 files changed
+105 -91

No files matched your search

+56 -35
View File
@@ -575,7 +575,7 @@ void Player::UpdateMastery()
}
}
const float m_diminishing_k[MAX_CLASSES] =
float const m_diminishing_k[MAX_CLASSES] =
{
0.9560f, // Warrior
0.9560f, // Paladin
@@ -590,26 +590,48 @@ const float m_diminishing_k[MAX_CLASSES] =
0.9720f // Druid
};
void Player::UpdateParryPercentage()
float CalculateDiminishingReturns(float const (&capArray)[MAX_CLASSES], uint8 playerClass, float nonDiminishValue, float diminishValue)
{
const float parry_cap[MAX_CLASSES] =
{
65.631440f, // Warrior
65.631440f, // Paladin
145.560408f, // Hunter
145.560408f, // Rogue
0.0f, // Priest
65.631440f, // DK
145.560408f, // Shaman
0.0f, // Mage
0.0f, // Warlock
0.0f, // ??
0.0f // Druid
};
// 1 1 k cx
// --- = --- + --- <=> x' = --------
// x' c x x + ck
// where:
// k is m_diminishing_k for that class
// c is capArray for that class
// x is chance before DR (diminishValue)
// x' is chance after DR (our result)
uint32 const classIdx = playerClass - 1;
float const k = m_diminishing_k[classIdx];
float const c = capArray[classIdx];
float result = c * diminishValue / (diminishValue + c * k);
result += nonDiminishValue;
return result;
}
float const parry_cap[MAX_CLASSES] =
{
65.631440f, // Warrior
65.631440f, // Paladin
145.560408f, // Hunter
145.560408f, // Rogue
0.0f, // Priest
65.631440f, // DK
145.560408f, // Shaman
0.0f, // Mage
0.0f, // Warlock
0.0f, // ??
0.0f // Druid
};
void Player::UpdateParryPercentage()
{
// No parry
float value = 0.0f;
uint32 pclass = getClass()-1;
uint32 pclass = getClass() - 1;
if (CanParry() && parry_cap[pclass] > 0.0f)
{
float nondiminishing = 5.0f;
@@ -618,7 +640,7 @@ void Player::UpdateParryPercentage()
// Parry from SPELL_AURA_MOD_PARRY_PERCENT aura
nondiminishing += GetTotalAuraModifier(SPELL_AURA_MOD_PARRY_PERCENT);
// apply diminishing formula to diminishing parry chance
value = nondiminishing + diminishing * parry_cap[pclass] / (diminishing + parry_cap[pclass] * m_diminishing_k[pclass]);
value = CalculateDiminishingReturns(parry_cap, getClass(), nondiminishing, diminishing);
if (sWorld->getBoolConfig(CONFIG_STATS_LIMITS_ENABLE))
value = value > sWorld->getFloatConfig(CONFIG_STATS_LIMITS_PARRY) ? sWorld->getFloatConfig(CONFIG_STATS_LIMITS_PARRY) : value;
@@ -628,23 +650,23 @@ void Player::UpdateParryPercentage()
SetStatFloatValue(PLAYER_PARRY_PERCENTAGE, value);
}
float const dodge_cap[MAX_CLASSES] =
{
65.631440f, // Warrior
65.631440f, // Paladin
145.560408f, // Hunter
145.560408f, // Rogue
150.375940f, // Priest
65.631440f, // DK
145.560408f, // Shaman
150.375940f, // Mage
150.375940f, // Warlock
0.0f, // ??
116.890707f // Druid
};
void Player::UpdateDodgePercentage()
{
const float dodge_cap[MAX_CLASSES] =
{
65.631440f, // Warrior
65.631440f, // Paladin
145.560408f, // Hunter
145.560408f, // Rogue
150.375940f, // Priest
65.631440f, // DK
145.560408f, // Shaman
150.375940f, // Mage
150.375940f, // Warlock
0.0f, // ??
116.890707f // Druid
};
float diminishing = 0.0f, nondiminishing = 0.0f;
GetDodgeFromAgility(diminishing, nondiminishing);
// Dodge from SPELL_AURA_MOD_DODGE_PERCENT aura
@@ -652,8 +674,7 @@ void Player::UpdateDodgePercentage()
// Dodge from rating
diminishing += GetRatingBonusValue(CR_DODGE);
// apply diminishing formula to diminishing dodge chance
uint32 pclass = getClass()-1;
float value = nondiminishing + (diminishing * dodge_cap[pclass] / (diminishing + dodge_cap[pclass] * m_diminishing_k[pclass]));
float value = CalculateDiminishingReturns(dodge_cap, getClass(), nondiminishing, diminishing);
if (sWorld->getBoolConfig(CONFIG_STATS_LIMITS_ENABLE))
value = value > sWorld->getFloatConfig(CONFIG_STATS_LIMITS_DODGE) ? sWorld->getFloatConfig(CONFIG_STATS_LIMITS_DODGE) : value;