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
This commit is contained in:
ariel-
2017-04-10 04:50:09 -03:00
parent e478434146
commit e565b34f6d
3 changed files with 144 additions and 143 deletions
+75 -52
View File
@@ -651,7 +651,7 @@ void Player::UpdateAllCritPercentages()
UpdateCritPercentage(RANGED_ATTACK);
}
const float m_diminishing_k[MAX_CLASSES] =
float const m_diminishing_k[MAX_CLASSES] =
{
0.9560f, // Warrior
0.9560f, // Paladin
@@ -666,53 +666,75 @@ const float m_diminishing_k[MAX_CLASSES] =
0.9720f // Druid
};
// helper function
float CalculateDiminishingReturns(float const (&capArray)[MAX_CLASSES], uint8 playerClass, float nonDiminishValue, float diminishValue)
{
// 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 miss_cap[MAX_CLASSES] =
{
16.00f, // Warrior //correct
16.00f, // Paladin //correct
16.00f, // Hunter //?
16.00f, // Rogue //?
16.00f, // Priest //?
16.00f, // DK //correct
16.00f, // Shaman //?
16.00f, // Mage //?
16.00f, // Warlock //?
0.0f, // ??
16.00f // Druid //?
};
float Player::GetMissPercentageFromDefense() const
{
float const miss_cap[MAX_CLASSES] =
{
16.00f, // Warrior //correct
16.00f, // Paladin //correct
16.00f, // Hunter //?
16.00f, // Rogue //?
16.00f, // Priest //?
16.00f, // DK //correct
16.00f, // Shaman //?
16.00f, // Mage //?
16.00f, // Warlock //?
0.0f, // ??
16.00f // Druid //?
};
float diminishing = 0.0f, nondiminishing = 0.0f;
// Modify value from defense skill (only bonus from defense rating diminishes)
nondiminishing += (GetSkillValue(SKILL_DEFENSE) - GetMaxSkillValueForLevel()) * 0.04f;
diminishing += (int32(GetRatingBonusValue(CR_DEFENSE_SKILL))) * 0.04f;
// apply diminishing formula to diminishing miss chance
uint32 pclass = getClass()-1;
return nondiminishing + (diminishing * miss_cap[pclass] / (diminishing + miss_cap[pclass] * m_diminishing_k[pclass]));
return CalculateDiminishingReturns(miss_cap, getClass(), nondiminishing, diminishing);
}
float const parry_cap[MAX_CLASSES] =
{
47.003525f, // Warrior
47.003525f, // Paladin
145.560408f, // Hunter
145.560408f, // Rogue
0.0f, // Priest
47.003525f, // DK
145.560408f, // Shaman
0.0f, // Mage
0.0f, // Warlock
0.0f, // ??
0.0f // Druid
};
void Player::UpdateParryPercentage()
{
const float parry_cap[MAX_CLASSES] =
{
47.003525f, // Warrior
47.003525f, // Paladin
145.560408f, // Hunter
145.560408f, // Rogue
0.0f, // Priest
47.003525f, // DK
145.560408f, // Shaman
0.0f, // Mage
0.0f, // Warlock
0.0f, // ??
0.0f // Druid
};
// 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;
@@ -723,8 +745,9 @@ void Player::UpdateParryPercentage()
diminishing += (int32(GetRatingBonusValue(CR_DEFENSE_SKILL))) * 0.04f;
// 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;
@@ -734,23 +757,23 @@ void Player::UpdateParryPercentage()
SetStatFloatValue(PLAYER_PARRY_PERCENTAGE, value);
}
float const dodge_cap[MAX_CLASSES] =
{
88.129021f, // Warrior
88.129021f, // Paladin
145.560408f, // Hunter
145.560408f, // Rogue
150.375940f, // Priest
88.129021f, // DK
145.560408f, // Shaman
150.375940f, // Mage
150.375940f, // Warlock
0.0f, // ??
116.890707f // Druid
};
void Player::UpdateDodgePercentage()
{
const float dodge_cap[MAX_CLASSES] =
{
88.129021f, // Warrior
88.129021f, // Paladin
145.560408f, // Hunter
145.560408f, // Rogue
150.375940f, // Priest
88.129021f, // 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);
// Modify value from defense skill (only bonus from defense rating diminishes)
@@ -760,9 +783,9 @@ void Player::UpdateDodgePercentage()
nondiminishing += GetTotalAuraModifier(SPELL_AURA_MOD_DODGE_PERCENT);
// 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;