Skip to content

Commit

Permalink
[9144] Propertly update combat ratings fields.
Browse files Browse the repository at this point in the history
* Implemented proper combat rating fields update like other stats fields.
  This will prevent reset combat ratings at .reset stats for example.
* Skill loading moved after InitStatsForLevel for prevent reset fields setup
  as part of aura apply from skill set triggered spell casts.
  This fix for example talent 53125 work (combat rating set at skill loading)
  • Loading branch information
VladimirMangos committed Jan 11, 2010
1 parent 039310a commit 1846404
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 19 deletions.
58 changes: 41 additions & 17 deletions src/game/Player.cpp
Expand Up @@ -4925,7 +4925,36 @@ void Player::ApplyRatingMod(CombatRating cr, int32 value, bool apply)
{
m_baseRatingValue[cr]+=(apply ? value : -value);

int32 amount = uint32(m_baseRatingValue[cr]);
// explicit affected values
switch (cr)
{
case CR_HASTE_MELEE:
{
float RatingChange = value / GetRatingCoefficient(cr);
ApplyAttackTimePercentMod(BASE_ATTACK,RatingChange,apply);
ApplyAttackTimePercentMod(OFF_ATTACK,RatingChange,apply);
break;
}
case CR_HASTE_RANGED:
{
float RatingChange = value / GetRatingCoefficient(cr);
ApplyAttackTimePercentMod(RANGED_ATTACK, RatingChange, apply);
break;
}
case CR_HASTE_SPELL:
{
float RatingChange = value / GetRatingCoefficient(cr);
ApplyCastTimePercentMod(RatingChange,apply);
break;
}
}

UpdateRating(cr);
}

void Player::UpdateRating(CombatRating cr)
{
int32 amount = m_baseRatingValue[cr];
// Apply bonus from SPELL_AURA_MOD_RATING_FROM_STAT
// stat used stored in miscValueB for this aura
AuraList const& modRatingFromStat = GetAurasByType(SPELL_AURA_MOD_RATING_FROM_STAT);
Expand All @@ -4936,9 +4965,6 @@ void Player::ApplyRatingMod(CombatRating cr, int32 value, bool apply)
amount = 0;
SetUInt32Value(PLAYER_FIELD_COMBAT_RATING_1 + cr, uint32(amount));

float RatingCoeffecient = GetRatingCoefficient(cr);
float RatingChange = 0.0f;

bool affectStats = CanModifyStats();

switch (cr)
Expand Down Expand Up @@ -4990,18 +5016,9 @@ void Player::ApplyRatingMod(CombatRating cr, int32 value, bool apply)
break;
case CR_CRIT_TAKEN_SPELL: // Implemented in Unit::SpellCriticalBonus (only for chance to crit)
break;
case CR_HASTE_MELEE:
RatingChange = value / RatingCoeffecient;
ApplyAttackTimePercentMod(BASE_ATTACK,RatingChange,apply);
ApplyAttackTimePercentMod(OFF_ATTACK,RatingChange,apply);
break;
case CR_HASTE_MELEE: // Implemented in Player::ApplyRatingMod
case CR_HASTE_RANGED:
RatingChange = value / RatingCoeffecient;
ApplyAttackTimePercentMod(RANGED_ATTACK, RatingChange, apply);
break;
case CR_HASTE_SPELL:
RatingChange = value / RatingCoeffecient;
ApplyCastTimePercentMod(RatingChange,apply);
break;
case CR_WEAPON_SKILL_MAINHAND: // Implemented in Unit::RollMeleeOutcomeAgainst
case CR_WEAPON_SKILL_OFFHAND:
Expand All @@ -5021,6 +5038,12 @@ void Player::ApplyRatingMod(CombatRating cr, int32 value, bool apply)
}
}

void Player::UpdateAllRatings()
{
for(int cr = 0; cr < MAX_COMBAT_RATING; ++cr)
UpdateRating(CombatRating(cr));
}

void Player::SetRegularAttackTime()
{
for(int i = 0; i < MAX_ATTACK; ++i)
Expand Down Expand Up @@ -14900,8 +14923,6 @@ bool Player::LoadFromDB( uint32 guid, SqlQueryHolder *holder )
// cleanup aura list explicitly before skill load wher some spells can be applied
RemoveAllAuras();

_LoadSkills(holder->GetResult(PLAYER_LOGIN_QUERY_LOADSKILLS));

// make sure the unit is considered out of combat for proper loading
ClearInCombat();

Expand All @@ -14917,10 +14938,13 @@ bool Player::LoadFromDB( uint32 guid, SqlQueryHolder *holder )

// reset stats before loading any modifiers
InitStatsForLevel();
InitTaxiNodesForLevel();
InitGlyphsForLevel();
InitTaxiNodesForLevel();
InitRunes();

// load skills after InitStatsForLevel because it triggering aura apply also
_LoadSkills(holder->GetResult(PLAYER_LOGIN_QUERY_LOADSKILLS));

// apply original stats mods before spell loading or item equipment that call before equip _RemoveStatsMods()

// Mail
Expand Down
4 changes: 3 additions & 1 deletion src/game/Player.h
Expand Up @@ -1774,11 +1774,13 @@ class MANGOS_DLL_SPEC Player : public Unit
void UpdateDamagePhysical(WeaponAttackType attType);
void ApplySpellPowerBonus(int32 amount, bool apply);
void UpdateSpellDamageAndHealingBonus();
void ApplyRatingMod(CombatRating cr, int32 value, bool apply);
void UpdateRating(CombatRating cr);
void UpdateAllRatings();

void CalculateMinMaxDamage(WeaponAttackType attType, bool normalized, float& min_damage, float& max_damage);

void UpdateDefenseBonusesMod();
void ApplyRatingMod(CombatRating cr, int32 value, bool apply);
float GetMeleeCritFromAgility();
float GetDodgeFromAgility();
float GetSpellCritFromIntellect();
Expand Down
1 change: 1 addition & 0 deletions src/game/StatSystem.cpp
Expand Up @@ -128,6 +128,7 @@ bool Player::UpdateAllStats()
for(int i = POWER_MANA; i < MAX_POWERS; ++i)
UpdateMaxPower(Powers(i));

UpdateAllRatings();
UpdateAllCritPercentages();
UpdateAllSpellCritChances();
UpdateDefenseBonusesMod();
Expand Down
2 changes: 1 addition & 1 deletion src/shared/revision_nr.h
@@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "9143"
#define REVISION_NR "9144"
#endif // __REVISION_NR_H__

0 comments on commit 1846404

Please sign in to comment.