diff options
| author | azazel <none@none> | 2010-12-11 20:37:38 +0600 |
|---|---|---|
| committer | azazel <none@none> | 2010-12-11 20:37:38 +0600 |
| commit | d2d62eab50fc03bdba66676e508354521e385631 (patch) | |
| tree | f4278268481ec42649142a4027aaacae0ee5ee9e /src/server/game/Spells/SpellMgr.cpp | |
| parent | 81db111ffd70338de973fa8b1969367d8ca9624e (diff) | |
Cleanup: implemented helper methods for manipulating percentage calculation and used it where appropriate (plus fixed some other warnings).
NOTE: Initially I just wanted to fix some warnings, but noticed that there is no common method for percentage calculation and various formulas are used many time in the code making it difficult to read and understand what the code actually does. So, I introduced several template methods for calculating percent values and adding those values to the original base. I replaced all the raw calculations throughout the code where found, but I could have missed something or could have made a mistake. So, please report any strange behaviour after this commit.
If you ask me why I did it: for the sake of consistency and exact understanding what code means. If you see CalculatePct method, you clearly understand, that it find the value of x percent of y. And you can easily express, for example, spell behviour "reduces smth by x%" by the means of a method instead of recalling school maths.
--HG--
branch : trunk
Diffstat (limited to 'src/server/game/Spells/SpellMgr.cpp')
| -rwxr-xr-x | src/server/game/Spells/SpellMgr.cpp | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/server/game/Spells/SpellMgr.cpp b/src/server/game/Spells/SpellMgr.cpp index 6bde370cd70..f7b0d92a7e2 100755 --- a/src/server/game/Spells/SpellMgr.cpp +++ b/src/server/game/Spells/SpellMgr.cpp @@ -392,16 +392,16 @@ uint32 CalculatePowerCost(SpellEntry const * spellInfo, Unit const * caster, Spe { // health as power used case POWER_HEALTH: - powerCost += spellInfo->ManaCostPercentage * caster->GetCreateHealth() / 100; + powerCost += int32(CalculatePctU(caster->GetCreateHealth(), spellInfo->ManaCostPercentage)); break; case POWER_MANA: - powerCost += spellInfo->ManaCostPercentage * caster->GetCreateMana() / 100; + powerCost += int32(CalculatePctU(caster->GetCreateMana(), spellInfo->ManaCostPercentage)); break; case POWER_RAGE: case POWER_FOCUS: case POWER_ENERGY: case POWER_HAPPINESS: - powerCost += spellInfo->ManaCostPercentage * caster->GetMaxPower(Powers(spellInfo->powerType)) / 100; + powerCost += int32(CalculatePctU(caster->GetMaxPower(Powers(spellInfo->powerType)), spellInfo->ManaCostPercentage)); break; case POWER_RUNE: case POWER_RUNIC_POWER: @@ -1862,7 +1862,7 @@ int32 SpellMgr::CalculateSpellEffectAmount(SpellEntry const * spellEntry, uint8 break; } - int32 value = basePoints; + float value = float(basePoints); // random damage if (caster) @@ -1871,7 +1871,7 @@ int32 SpellMgr::CalculateSpellEffectAmount(SpellEntry const * spellEntry, uint8 if (caster->m_movedPlayer) if (uint8 comboPoints = caster->m_movedPlayer->GetComboPoints()) if (float comboDamage = spellEntry->EffectPointsPerComboPoint[effIndex]) - value += int32(comboDamage * comboPoints); + value += comboDamage * comboPoints; value = caster->ApplyEffectModifiers(spellEntry, effIndex, value); @@ -1884,11 +1884,11 @@ int32 SpellMgr::CalculateSpellEffectAmount(SpellEntry const * spellEntry, uint8 spellEntry->EffectApplyAuraName[effIndex] != SPELL_AURA_MOD_INCREASE_SPEED && spellEntry->EffectApplyAuraName[effIndex] != SPELL_AURA_MOD_DECREASE_SPEED) //there are many more: slow speed, -healing pct - value = int32(value*0.25f*exp(caster->getLevel()*(70-spellEntry->spellLevel)/1000.0f)); + value *= 0.25f * exp(caster->getLevel() * (70 - spellEntry->spellLevel) / 1000.0f); //value = int32(value * (int32)getLevel() / (int32)(spellProto->spellLevel ? spellProto->spellLevel : 1)); } - return value; + return int32(value); } int32 SpellMgr::CalculateSpellEffectBaseAmount(int32 value, SpellEntry const * spellEntry, uint8 effIndex) |
