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 | |
| 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')
24 files changed, 422 insertions, 386 deletions
diff --git a/src/server/game/AuctionHouse/AuctionHouseMgr.cpp b/src/server/game/AuctionHouse/AuctionHouseMgr.cpp index 4c31527ac6a..b305421feb9 100644 --- a/src/server/game/AuctionHouse/AuctionHouseMgr.cpp +++ b/src/server/game/AuctionHouse/AuctionHouseMgr.cpp @@ -75,9 +75,9 @@ uint32 AuctionHouseMgr::GetAuctionDeposit(AuctionHouseEntry const* entry, uint32 if (MSV <= 0) return AH_MINIMUM_DEPOSIT; - uint32 timeHr = (((time / 60) / 60) /12); - float multiplier = (float)(entry->depositPercent * 3) / 100.0f; - uint32 deposit = ((uint32)((float)MSV * multiplier * (float)count)/3) * 3 * timeHr; + float multiplier = CalculatePctN(float(entry->depositPercent), 3); + uint32 timeHr = (((time / 60) / 60) / 12); + uint32 deposit = uint32(multiplier * MSV * count / 3) * timeHr * 3; sLog.outDebug("MSV: %u", MSV); sLog.outDebug("Items: %u", count); @@ -500,7 +500,7 @@ AuctionHouseEntry const* AuctionHouseMgr::GetAuctionHouseEntry(uint32 factionTem //FIXME: found way for proper auctionhouse selection by another way // AuctionHouse.dbc have faction field with _player_ factions associated with auction house races. // but no easy way convert creature faction to player race faction for specific city - switch(factionTemplateId) + switch (factionTemplateId) { case 12: houseid = 1; break; // human case 29: houseid = 6; break; // orc, and generic for horde @@ -762,27 +762,22 @@ bool AuctionEntry::BuildAuctionInfo(WorldPacket & data) const //minimal outbid data << uint32(buyout); //auction->buyout data << uint32((expire_time-time(NULL))*IN_MILLISECONDS);//time left - data << uint64(bidder) ; //auction->bidder current + data << uint64(bidder); //auction->bidder current data << uint32(bid); //current bid return true; } uint32 AuctionEntry::GetAuctionCut() const { - int32 cut = int32(((double)auctionHouseEntry->cutPercent / 100.0f) * (double)sWorld.getRate(RATE_AUCTION_CUT)) * bid; - if (cut > 0) - return cut; - else - return 0; + int32 cut = int32(CalculatePctU(sWorld.getRate(RATE_AUCTION_CUT), auctionHouseEntry->cutPercent)) * bid; + return std::max(cut, 0); } /// the sum of outbid is (1% from current bid)*5, if bid is very small, it is 1c uint32 AuctionEntry::GetAuctionOutBid() const { - uint32 outbid = (uint32)((double)bid / 100.0f) * 5; - if (!outbid) - outbid = 1; - return outbid; + uint32 outbid = CalculatePctN(bid, 5); + return outbid ? outbid : 1; } void AuctionEntry::DeleteFromDB(SQLTransaction& trans) const diff --git a/src/server/game/Battlegrounds/Battleground.cpp b/src/server/game/Battlegrounds/Battleground.cpp index bf2664929b5..797e615dede 100755 --- a/src/server/game/Battlegrounds/Battleground.cpp +++ b/src/server/game/Battlegrounds/Battleground.cpp @@ -896,8 +896,8 @@ void Battleground::EndBattleground(uint32 winner) uint32 Battleground::GetBonusHonorFromKill(uint32 kills) const { //variable kills means how many honorable kills you scored (so we need kills * honor_for_one_kill) - uint32 maxLevel = (GetMaxLevel() < 80) ? GetMaxLevel() : 80; - return Trinity::Honor::hk_honor_at_level(maxLevel, kills); + uint32 maxLevel = std::min(GetMaxLevel(), 80U); + return Trinity::Honor::hk_honor_at_level(maxLevel, float(kills)); } uint32 Battleground::GetBattlemasterEntry() const @@ -1985,16 +1985,16 @@ void Battleground::RewardXPAtKill(Player* plr, Player* victim) // XP updated only for alive group member if (pGroupGuy->isAlive() && not_gray_member_with_max_level && pGroupGuy->getLevel() <= not_gray_member_with_max_level->getLevel()) { - uint32 itr_xp = (member_with_max_level == not_gray_member_with_max_level) ? uint32(xp*rate) : uint32((xp*rate/2)+1); + uint32 itr_xp = (member_with_max_level == not_gray_member_with_max_level) ? uint32(xp * rate) : uint32((xp * rate / 2) + 1); // handle SPELL_AURA_MOD_XP_PCT auras Unit::AuraEffectList const& ModXPPctAuras = plr->GetAuraEffectsByType(SPELL_AURA_MOD_XP_PCT); for (Unit::AuraEffectList::const_iterator i = ModXPPctAuras.begin(); i != ModXPPctAuras.end(); ++i) - itr_xp = uint32(itr_xp*(1.0f + (*i)->GetAmount() / 100.0f)); + AddPctN(itr_xp, (*i)->GetAmount()); pGroupGuy->GiveXP(itr_xp, victim); if (Pet* pet = pGroupGuy->GetPet()) - pet->GivePetXP(itr_xp/2); + pet->GivePetXP(itr_xp / 2); } } } @@ -2009,7 +2009,7 @@ void Battleground::RewardXPAtKill(Player* plr, Player* victim) // handle SPELL_AURA_MOD_XP_PCT auras Unit::AuraEffectList const& ModXPPctAuras = plr->GetAuraEffectsByType(SPELL_AURA_MOD_XP_PCT); for (Unit::AuraEffectList::const_iterator i = ModXPPctAuras.begin(); i != ModXPPctAuras.end(); ++i) - xp = uint32(xp*(1.0f + (*i)->GetAmount() / 100.0f)); + AddPctN(xp, (*i)->GetAmount()); plr->GiveXP(xp, victim); diff --git a/src/server/game/Battlegrounds/BattlegroundMgr.cpp b/src/server/game/Battlegrounds/BattlegroundMgr.cpp index b7d82e8ac72..6103aabf694 100755 --- a/src/server/game/Battlegrounds/BattlegroundMgr.cpp +++ b/src/server/game/Battlegrounds/BattlegroundMgr.cpp @@ -865,8 +865,8 @@ void BattlegroundMgr::BuildBattlegroundListPacket(WorldPacket *data, const uint6 uint32 winner_arena = plr->GetRandomWinner() ? BG_REWARD_WINNER_ARENA_LAST : BG_REWARD_WINNER_ARENA_FIRST; uint32 loser_kills = plr->GetRandomWinner() ? BG_REWARD_LOSER_HONOR_LAST : BG_REWARD_LOSER_HONOR_FIRST; - winner_kills = Trinity::Honor::hk_honor_at_level(plr->getLevel(), winner_kills); - loser_kills = Trinity::Honor::hk_honor_at_level(plr->getLevel(), loser_kills); + winner_kills = Trinity::Honor::hk_honor_at_level(plr->getLevel(), float(winner_kills)); + loser_kills = Trinity::Honor::hk_honor_at_level(plr->getLevel(), float(loser_kills)); data->Initialize(SMSG_BATTLEFIELD_LIST); *data << uint64(guid); // battlemaster guid diff --git a/src/server/game/Combat/ThreatManager.h b/src/server/game/Combat/ThreatManager.h index 7aa8c905fee..8e2ed7fe7d3 100755 --- a/src/server/game/Combat/ThreatManager.h +++ b/src/server/game/Combat/ThreatManager.h @@ -58,8 +58,8 @@ class HostileReference : public Reference<Unit, ThreatManager> void addThreatPercent(int32 pPercent) { float tmpThreat = iThreat; - tmpThreat = tmpThreat * (pPercent+100.0f) / 100.0f; - addThreat(tmpThreat-iThreat); + AddPctN(tmpThreat, pPercent); + addThreat(tmpThreat - iThreat); } float getThreat() const { return iThreat; } diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index 4b5c8ae4223..c7b270a344d 100755 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -614,17 +614,17 @@ void Creature::RegenerateMana() float ManaIncreaseRate = sWorld.getRate(RATE_POWER_MANA); float Spirit = GetStat(STAT_SPIRIT); - addvalue = uint32((Spirit/5.0f + 17.0f) * ManaIncreaseRate); + addvalue = uint32((Spirit / 5.0f + 17.0f) * ManaIncreaseRate); } } else - addvalue = maxValue/3; + addvalue = maxValue / 3; // Apply modifiers (if any). AuraEffectList const& ModPowerRegenPCTAuras = GetAuraEffectsByType(SPELL_AURA_MOD_POWER_REGEN_PERCENT); for (AuraEffectList::const_iterator i = ModPowerRegenPCTAuras.begin(); i != ModPowerRegenPCTAuras.end(); ++i) if ((*i)->GetMiscValue() == POWER_MANA) - addvalue = uint32(addvalue * ((*i)->GetAmount() + 100) / 100.0f); + AddPctN(addvalue, (*i)->GetAmount()); addvalue += GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_POWER_REGEN, POWER_MANA) * CREATURE_REGEN_INTERVAL / (5 * IN_MILLISECONDS); @@ -661,7 +661,7 @@ void Creature::RegenerateHealth() // Apply modifiers (if any). AuraEffectList const& ModPowerRegenPCTAuras = GetAuraEffectsByType(SPELL_AURA_MOD_HEALTH_REGEN_PERCENT); for (AuraEffectList::const_iterator i = ModPowerRegenPCTAuras.begin(); i != ModPowerRegenPCTAuras.end(); ++i) - addvalue = uint32(addvalue * ((*i)->GetAmount() + 100) / 100.0f); + AddPctN(addvalue, (*i)->GetAmount()); addvalue += GetTotalAuraModifier(SPELL_AURA_MOD_REGEN) * CREATURE_REGEN_INTERVAL / (5 * IN_MILLISECONDS); diff --git a/src/server/game/Entities/Object/Object.h b/src/server/game/Entities/Object/Object.h index b9dd8ed44c0..08c5f716db8 100755 --- a/src/server/game/Entities/Object/Object.h +++ b/src/server/game/Entities/Object/Object.h @@ -229,8 +229,9 @@ class Object void ApplyPercentModFloatValue(uint16 index, float val, bool apply) { - val = val != -100.0f ? val : -99.9f ; - SetFloatValue(index, GetFloatValue(index) * (apply?(100.0f+val)/100.0f : 100.0f / (100.0f+val))); + float value = GetFloatValue(index); + ApplyPercentModFloatVar(value, val, apply); + SetFloatValue(index, value); } void SetFlag(uint16 index, uint32 newFlag); diff --git a/src/server/game/Entities/Pet/Pet.cpp b/src/server/game/Entities/Pet/Pet.cpp index 98cb9e66d85..5c53ca3cbb5 100755 --- a/src/server/game/Entities/Pet/Pet.cpp +++ b/src/server/game/Entities/Pet/Pet.cpp @@ -613,11 +613,11 @@ void Creature::Regenerate(Powers power) AuraEffectList const& ModPowerRegenPCTAuras = GetAuraEffectsByType(SPELL_AURA_MOD_POWER_REGEN_PERCENT); for (AuraEffectList::const_iterator i = ModPowerRegenPCTAuras.begin(); i != ModPowerRegenPCTAuras.end(); ++i) if (Powers((*i)->GetMiscValue()) == power) - addvalue *= ((*i)->GetAmount() + 100) / 100.0f; + AddPctN(addvalue, (*i)->GetAmount()); addvalue += GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_POWER_REGEN, power) * (isHunterPet()? PET_FOCUS_REGEN_INTERVAL : CREATURE_REGEN_INTERVAL) / (5 * IN_MILLISECONDS); - ModifyPower(power, (int32)addvalue); + ModifyPower(power, int32(addvalue)); } void Pet::LoseHappiness() @@ -1940,7 +1940,7 @@ void Pet::CastPetAura(PetAura const* aura) if (auraId == 35696) // Demonic Knowledge { - int32 basePoints = int32(aura->GetDamage() * (GetStat(STAT_STAMINA) + GetStat(STAT_INTELLECT)) / 100); + int32 basePoints = CalculatePctF(aura->GetDamage(), GetStat(STAT_STAMINA) + GetStat(STAT_INTELLECT)); CastCustomSpell(this, auraId, &basePoints, NULL, NULL, true); } else diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index 7e230be6533..0049c9ca702 100755 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -1045,22 +1045,22 @@ int32 Player::getMaxTimer(MirrorTimerType timer) switch (timer) { case FATIGUE_TIMER: - return MINUTE*IN_MILLISECONDS; + return MINUTE * IN_MILLISECONDS; case BREATH_TIMER: { if (!isAlive() || HasAuraType(SPELL_AURA_WATER_BREATHING) || GetSession()->GetSecurity() >= AccountTypes(sWorld.getIntConfig(CONFIG_DISABLE_BREATHING))) return DISABLED_MIRROR_TIMER; - int32 UnderWaterTime = 3*MINUTE*IN_MILLISECONDS; + int32 UnderWaterTime = 3 * MINUTE * IN_MILLISECONDS; AuraEffectList const& mModWaterBreathing = GetAuraEffectsByType(SPELL_AURA_MOD_WATER_BREATHING); for (AuraEffectList::const_iterator i = mModWaterBreathing.begin(); i != mModWaterBreathing.end(); ++i) - UnderWaterTime = uint32(UnderWaterTime * (100.0f + (*i)->GetAmount()) / 100.0f); + AddPctN(UnderWaterTime, (*i)->GetAmount()); return UnderWaterTime; } case FIRE_TIMER: { if (!isAlive()) return DISABLED_MIRROR_TIMER; - return 1*IN_MILLISECONDS; + return 1 * IN_MILLISECONDS; } default: return 0; @@ -2259,7 +2259,7 @@ void Player::Regenerate(Powers power) AuraEffectList const& ModPowerRegenPCTAuras = GetAuraEffectsByType(SPELL_AURA_MOD_POWER_REGEN_PERCENT); for (AuraEffectList::const_iterator i = ModPowerRegenPCTAuras.begin(); i != ModPowerRegenPCTAuras.end(); ++i) if (Powers((*i)->GetMiscValue()) == power) - addvalue *= ((*i)->GetAmount() + 100) / 100.0f; + AddPctN(addvalue, (*i)->GetAmount()); // Butchery requires combat for this effect if (power != POWER_RUNIC_POWER || isInCombat()) @@ -2339,12 +2339,12 @@ void Player::RegenerateHealth() { AuraEffectList const& mModHealthRegenPct = GetAuraEffectsByType(SPELL_AURA_MOD_HEALTH_REGEN_PERCENT); for (AuraEffectList::const_iterator i = mModHealthRegenPct.begin(); i != mModHealthRegenPct.end(); ++i) - addvalue *= (100.0f + (*i)->GetAmount()) / 100.0f; + AddPctN(addvalue, (*i)->GetAmount()); addvalue += GetTotalAuraModifier(SPELL_AURA_MOD_REGEN) * 2 * IN_MILLISECONDS / (5 * IN_MILLISECONDS); } else if (HasAuraType(SPELL_AURA_MOD_REGEN_DURING_COMBAT)) - addvalue *= GetTotalAuraModifier(SPELL_AURA_MOD_REGEN_DURING_COMBAT) / 100.0f; + ApplyPctN(addvalue, GetTotalAuraModifier(SPELL_AURA_MOD_REGEN_DURING_COMBAT)); if (!IsStandState()) addvalue *= 1.5; @@ -5357,7 +5357,7 @@ void Player::HandleBaseModValue(BaseModGroup modGroup, BaseModType modType, floa float val = 1.0f; - switch(modType) + switch (modType) { case FLAT_MOD: m_auraBaseMod[modGroup][modType] += apply ? amount : -amount; @@ -5365,9 +5365,7 @@ void Player::HandleBaseModValue(BaseModGroup modGroup, BaseModType modType, floa case PCT_MOD: if (amount <= -100.0f) amount = -200.0f; - - val = (100.0f + amount) / 100.0f; - m_auraBaseMod[modGroup][modType] *= apply ? val : (1.0f/val); + ApplyPercentModFloatVar(m_auraBaseMod[modGroup][modType], amount, apply); break; } @@ -5617,7 +5615,7 @@ void Player::UpdateRating(CombatRating cr) AuraEffectList const& modRatingFromStat = GetAuraEffectsByType(SPELL_AURA_MOD_RATING_FROM_STAT); for (AuraEffectList::const_iterator i = modRatingFromStat.begin(); i != modRatingFromStat.end(); ++i) if ((*i)->GetMiscValue() & (1<<cr)) - amount += int32(GetStat(Stats((*i)->GetMiscValueB())) * (*i)->GetAmount() / 100.0f); + amount += int32(CalculatePctN(GetStat(Stats((*i)->GetMiscValueB())), (*i)->GetAmount())); if (amount < 0) amount = 0; SetUInt32Value(PLAYER_FIELD_COMBAT_RATING_1 + cr, uint32(amount)); @@ -6893,7 +6891,7 @@ bool Player::RewardHonor(Unit *uVictim, uint32 groupsize, int32 honor, bool pvpt honor_f /= groupsize; // apply honor multiplier from aura (not stacking-get highest) - honor_f *= (GetMaxPositiveAuraModifier(SPELL_AURA_MOD_HONOR_GAIN_PCT) + 100) / 100.0f; + AddPctN(honor_f, GetMaxPositiveAuraModifier(SPELL_AURA_MOD_HONOR_GAIN_PCT)); } honor_f *= sWorld.getRate(RATE_HONOR); @@ -14525,7 +14523,7 @@ void Player::RewardQuest(Quest const *pQuest, uint32 reward, Object* questGiver, // handle SPELL_AURA_MOD_XP_QUEST_PCT auras Unit::AuraEffectList const& ModXPPctAuras = GetAuraEffectsByType(SPELL_AURA_MOD_XP_QUEST_PCT); for (Unit::AuraEffectList::const_iterator i = ModXPPctAuras.begin(); i != ModXPPctAuras.end(); ++i) - XP = uint32(XP*(1.0f + (*i)->GetAmount() / 100.0f)); + AddPctN(XP, (*i)->GetAmount()); int32 moneyRew = 0; if (getLevel() < sWorld.getIntConfig(CONFIG_MAX_PLAYER_LEVEL)) @@ -21860,16 +21858,16 @@ bool Player::RewardPlayerAndGroupAtKill(Unit* pVictim) if (pGroupGuy->isAlive() && not_gray_member_with_max_level && pGroupGuy->getLevel() <= not_gray_member_with_max_level->getLevel()) { - uint32 itr_xp = (member_with_max_level == not_gray_member_with_max_level) ? uint32(xp*rate) : uint32((xp*rate/2)+1); + uint32 itr_xp = (member_with_max_level == not_gray_member_with_max_level) ? uint32(xp * rate) : uint32((xp * rate / 2) + 1); // handle SPELL_AURA_MOD_XP_PCT auras Unit::AuraEffectList const& ModXPPctAuras = GetAuraEffectsByType(SPELL_AURA_MOD_XP_PCT); for (Unit::AuraEffectList::const_iterator i = ModXPPctAuras.begin(); i != ModXPPctAuras.end(); ++i) - itr_xp = uint32(itr_xp*(1.0f + (*i)->GetAmount() / 100.0f)); + AddPctN(itr_xp, (*i)->GetAmount()); pGroupGuy->GiveXP(itr_xp, pVictim, group_rate); if (Pet* pet = pGroupGuy->GetPet()) - pet->GivePetXP(itr_xp/2); + pet->GivePetXP(itr_xp / 2); } // quest objectives updated only for alive group member or dead but with not released body @@ -21899,7 +21897,7 @@ bool Player::RewardPlayerAndGroupAtKill(Unit* pVictim) // handle SPELL_AURA_MOD_XP_PCT auras Unit::AuraEffectList const& ModXPPctAuras = GetAuraEffectsByType(SPELL_AURA_MOD_XP_PCT); for (Unit::AuraEffectList::const_iterator i = ModXPPctAuras.begin(); i != ModXPPctAuras.end(); ++i) - xp = uint32(xp*(1.0f + (*i)->GetAmount() / 100.0f)); + AddPctN(xp, (*i)->GetAmount()); GiveXP(xp, pVictim); diff --git a/src/server/game/Entities/Player/Player.h b/src/server/game/Entities/Player/Player.h index 570e6c6e15f..0034222f31a 100755 --- a/src/server/game/Entities/Player/Player.h +++ b/src/server/game/Entities/Player/Player.h @@ -2753,7 +2753,7 @@ template <class T> T Player::ApplySpellMod(uint32 spellId, SpellModOp op, T &bas if (mod->op == SPELLMOD_CASTING_TIME && basevalue >= T(10000) && mod->value <= -100) continue; - totalmul *= 1.0f + (float)mod->value / 100.0f; + AddPctN(totalmul, mod->value); } DropModCharge(mod, spell); diff --git a/src/server/game/Entities/Unit/StatSystem.cpp b/src/server/game/Entities/Unit/StatSystem.cpp index 4ab3c25c747..20d751546c1 100755 --- a/src/server/game/Entities/Unit/StatSystem.cpp +++ b/src/server/game/Entities/Unit/StatSystem.cpp @@ -213,7 +213,7 @@ void Player::UpdateArmor() for (AuraEffectList::const_iterator i = mResbyIntellect.begin(); i != mResbyIntellect.end(); ++i) { if ((*i)->GetMiscValue() & SPELL_SCHOOL_MASK_NORMAL) - value += int32(GetStat(Stats((*i)->GetMiscValueB())) * (*i)->GetAmount() / 100.0f); + value += CalculatePctN(GetStat(Stats((*i)->GetMiscValueB())), (*i)->GetAmount()); } value *= GetModifierValue(unitMod, TOTAL_PCT); @@ -329,7 +329,7 @@ void Player::UpdateAttackPowerAndDamage(bool ranged) { ShapeshiftForm form = GetShapeshiftForm(); // Check if Predatory Strikes is skilled - float mLevelMult = 0.0; + float mLevelMult = 0.0f; switch (form) { case FORM_CAT: @@ -343,7 +343,7 @@ void Player::UpdateAttackPowerAndDamage(bool ranged) // Predatory Strikes (effect 0) if ((*itr)->GetEffIndex() == 0 && (*itr)->GetSpellProto()->SpellIconID == 1563) { - mLevelMult = (*itr)->GetAmount() / 100.0f; + mLevelMult = CalculatePctN(1.0f, (*itr)->GetAmount()); break; } } @@ -384,14 +384,14 @@ void Player::UpdateAttackPowerAndDamage(bool ranged) { AuraEffectList const& mRAPbyStat = GetAuraEffectsByType(SPELL_AURA_MOD_RANGED_ATTACK_POWER_OF_STAT_PERCENT); for (AuraEffectList::const_iterator i = mRAPbyStat.begin(); i != mRAPbyStat.end(); ++i) - attPowerMod += int32(GetStat(Stats((*i)->GetMiscValue())) * (*i)->GetAmount() / 100.0f); + attPowerMod += CalculatePctN(GetStat(Stats((*i)->GetMiscValue())), (*i)->GetAmount()); } } else { AuraEffectList const& mAPbyStat = GetAuraEffectsByType(SPELL_AURA_MOD_ATTACK_POWER_OF_STAT_PERCENT); for (AuraEffectList::const_iterator i = mAPbyStat.begin(); i != mAPbyStat.end(); ++i) - attPowerMod += int32(GetStat(Stats((*i)->GetMiscValue())) * (*i)->GetAmount() / 100.0f); + attPowerMod += CalculatePctN(GetStat(Stats((*i)->GetMiscValue())), (*i)->GetAmount()); AuraEffectList const& mAPbyArmor = GetAuraEffectsByType(SPELL_AURA_MOD_ATTACK_POWER_OF_ARMOR); for (AuraEffectList::const_iterator iter = mAPbyArmor.begin(); iter != mAPbyArmor.end(); ++iter) @@ -739,7 +739,7 @@ void Player::UpdateManaRegen() int32 modManaRegenInterrupt = GetTotalAuraModifier(SPELL_AURA_MOD_MANA_REGEN_INTERRUPT); if (modManaRegenInterrupt > 100) modManaRegenInterrupt = 100; - SetStatFloatValue(UNIT_FIELD_POWER_REGEN_INTERRUPTED_FLAT_MODIFIER, power_regen_mp5 + power_regen * modManaRegenInterrupt / 100.0f); + SetStatFloatValue(UNIT_FIELD_POWER_REGEN_INTERRUPTED_FLAT_MODIFIER, power_regen_mp5 + CalculatePctN(power_regen, modManaRegenInterrupt)); SetStatFloatValue(UNIT_FIELD_POWER_REGEN_FLAT_MODIFIER, power_regen_mp5 + power_regen); } @@ -958,13 +958,13 @@ bool Guardian::UpdateStats(Stats stat) aurEff = owner->GetAuraEffect(SPELL_AURA_MOD_TOTAL_STAT_PERCENTAGE, SPELLFAMILY_DEATHKNIGHT, 3010, 0); if (aurEff) { - SpellEntry const* sProto = aurEff->GetSpellProto(); // Then get the SpellProto and add the dummy effect value - mod += mod * (SpellMgr::CalculateSpellEffectAmount(sProto, 1) / 100.0f); // Ravenous Dead edits the original scale + SpellEntry const* sProto = aurEff->GetSpellProto(); // Then get the SpellProto and add the dummy effect value + AddPctN(mod, SpellMgr::CalculateSpellEffectAmount(sProto, 1)); // Ravenous Dead edits the original scale } // Glyph of the Ghoul aurEff = owner->GetAuraEffect(58686, 0); if (aurEff) - mod += (aurEff->GetAmount() / 100.0f); // Glyph of the Ghoul adds a flat value to the scale mod + mod += CalculatePctN(1.0f, aurEff->GetAmount()); // Glyph of the Ghoul adds a flat value to the scale mod ownersBonus = float(owner->GetStat(stat)) * mod; value += ownersBonus; } @@ -972,7 +972,7 @@ bool Guardian::UpdateStats(Stats stat) { if (owner->getClass() == CLASS_WARLOCK && isPet()) { - ownersBonus = float(owner->GetStat(STAT_STAMINA)) * 0.75f; + ownersBonus = CalculatePctN(owner->GetStat(STAT_STAMINA), 75); value += ownersBonus; } else @@ -987,7 +987,7 @@ bool Guardian::UpdateStats(Stats stat) if (itr != ToPet()->m_spells.end()) // If pet has Wild Hunt { SpellEntry const* sProto = sSpellStore.LookupEntry(itr->first); // Then get the SpellProto and add the dummy effect value - mod += mod * (SpellMgr::CalculateSpellEffectAmount(sProto, 0) / 100.0f); + AddPctN(mod, SpellMgr::CalculateSpellEffectAmount(sProto, 0)); } } ownersBonus = float(owner->GetStat(stat)) * mod; @@ -999,7 +999,7 @@ bool Guardian::UpdateStats(Stats stat) { if (owner->getClass() == CLASS_WARLOCK || owner->getClass() == CLASS_MAGE) { - ownersBonus = float(owner->GetStat(stat)) * 0.3f; + ownersBonus = CalculatePctN(owner->GetStat(stat), 30); value += ownersBonus; } } @@ -1051,7 +1051,7 @@ void Guardian::UpdateResistances(uint32 school) // hunter and warlock pets gain 40% of owner's resistance if (isPet()) - value += float(m_owner->GetResistance(SpellSchools(school))) * 0.4f; + value += float(CalculatePctN(m_owner->GetResistance(SpellSchools(school)), 40)); SetResistance(SpellSchools(school), int32(value)); } @@ -1067,7 +1067,7 @@ void Guardian::UpdateArmor() // hunter and warlock pets gain 35% of owner's armor value if (isPet()) - bonus_armor = 0.35f * float(m_owner->GetArmor()); + bonus_armor = float(CalculatePctN(m_owner->GetArmor(), 35)); value = GetModifierValue(unitMod, BASE_VALUE); value *= GetModifierValue(unitMod, BASE_PCT); @@ -1157,7 +1157,7 @@ void Guardian::UpdateAttackPowerAndDamage(bool ranged) if (itr != ToPet()->m_spells.end()) // If pet has Wild Hunt { SpellEntry const* sProto = sSpellStore.LookupEntry(itr->first); // Then get the SpellProto and add the dummy effect value - mod += (SpellMgr::CalculateSpellEffectAmount(sProto, 1) / 100.0f); + mod += CalculatePctN(1.0f, SpellMgr::CalculateSpellEffectAmount(sProto, 1)); } } @@ -1275,8 +1275,8 @@ void Guardian::UpdateDamagePhysical(WeaponAttackType attType) { case 61682: case 61683: - mindamage = mindamage * (100.0f-float((*itr)->GetAmount()))/100.0f; - maxdamage = maxdamage * (100.0f-float((*itr)->GetAmount()))/100.0f; + AddPctN(mindamage, -(*itr)->GetAmount()); + AddPctN(maxdamage, -(*itr)->GetAmount()); break; default: break; diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index f998555f7ef..317cdfaecfd 100755 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -566,7 +566,7 @@ uint32 Unit::DealDamage(Unit *pVictim, uint32 damage, CleanDamage const* cleanDa continue; SpellEntry const * spell = (*i)->GetSpellProto(); - uint32 share = uint32(damage * (float((*i)->GetAmount()) / 100.0f)); + uint32 share = CalculatePctN(damage, (*i)->GetAmount()); // TODO: check packets if damage is done by pVictim, or by attacker of pVictim DealDamageMods(shareDamageTarget, share, NULL); @@ -1002,7 +1002,7 @@ void Unit::CalculateSpellDamageTaken(SpellNonMeleeDamage *damageInfo, int32 dama critPctDamageMod += GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS, crTypeMask); if (critPctDamageMod != 0) - damage = int32(damage * float((100.0f + critPctDamageMod)/100.0f)); + AddPctN(damage, critPctDamageMod); } // Spell weapon based damage CAN BE crit & blocked at same time @@ -1204,7 +1204,7 @@ void Unit::CalculateMeleeDamage(Unit *pVictim, uint32 damage, CalcDamageInfo *da // Increase crit damage from SPELL_AURA_MOD_CRIT_PERCENT_VERSUS mod += GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS, crTypeMask); if (mod != 0) - damageInfo->damage = int32((damageInfo->damage) * float((100.0f + mod)/100.0f)); + AddPctN(damageInfo->damage, mod); } break; case MELEE_HIT_PARRY: @@ -1466,14 +1466,14 @@ uint32 Unit::CalcArmorReducedDamage(Unit* pVictim, const uint32 damage, SpellEnt { if ((*j)->GetMiscValue() & SPELL_SCHOOL_MASK_NORMAL && (*j)->IsAffectedOnSpell(spellInfo)) - armor = floor(float(armor) * (float(100 - (*j)->GetAmount()) / 100.0f)); + armor = floor(AddPctN(armor, -(*j)->GetAmount())); } AuraEffectList const& ResIgnoreAuras = GetAuraEffectsByType(SPELL_AURA_MOD_IGNORE_TARGET_RESIST); for (AuraEffectList::const_iterator j = ResIgnoreAuras.begin(); j != ResIgnoreAuras.end(); ++j) { if ((*j)->GetMiscValue() & SPELL_SCHOOL_MASK_NORMAL) - armor = floor(float(armor) * (float(100 - (*j)->GetAmount()) / 100.0f)); + armor = floor(AddPctN(armor, -(*j)->GetAmount())); } if (GetTypeId() == TYPEID_PLAYER) @@ -1484,7 +1484,7 @@ uint32 Unit::CalcArmorReducedDamage(Unit* pVictim, const uint32 damage, SpellEnt // item neutral spell if ((*itr)->GetSpellProto()->EquippedItemClass == -1) { - armor = floor(float(armor) * (float(100 - (*itr)->GetAmount()) / 100.0f)); + armor = floor(AddPctN(armor, -(*itr)->GetAmount())); continue; } @@ -1495,7 +1495,7 @@ uint32 Unit::CalcArmorReducedDamage(Unit* pVictim, const uint32 damage, SpellEnt if (weapon && weapon->IsFitToSpellRequirements((*itr)->GetSpellProto())) { - armor = floor(float(armor) * (float(100 - (*itr)->GetAmount()) / 100.0f)); + armor = floor(AddPctN(armor, -(*itr)->GetAmount())); break; } } @@ -1505,15 +1505,15 @@ uint32 Unit::CalcArmorReducedDamage(Unit* pVictim, const uint32 damage, SpellEnt // Apply Player CR_ARMOR_PENETRATION rating if (GetTypeId() == TYPEID_PLAYER) { - float maxArmorPen=0; + float maxArmorPen = 0; if (getLevel() < 60) maxArmorPen = float(400 + 85 * pVictim->getLevel()); else maxArmorPen = 400 + 85 * pVictim->getLevel() + 4.5f * 85 * (pVictim->getLevel() - 59); // Cap armor penetration to this number - maxArmorPen = std::min(((armor+maxArmorPen) / 3),armor); + maxArmorPen = std::min((armor + maxArmorPen) / 3, armor); // Figure out how much armor do we ignore - float armorPen = maxArmorPen * this->ToPlayer()->GetRatingBonusValue(CR_ARMOR_PENETRATION) / 100.0f; + float armorPen = CalculatePctF(maxArmorPen, ToPlayer()->GetRatingBonusValue(CR_ARMOR_PENETRATION)); // Got the value, apply it armor -= armorPen; } @@ -1523,10 +1523,10 @@ uint32 Unit::CalcArmorReducedDamage(Unit* pVictim, const uint32 damage, SpellEnt float levelModifier = getLevel(); if (levelModifier > 59) - levelModifier = levelModifier + (4.5f * (levelModifier-59)); + levelModifier = levelModifier + (4.5f * (levelModifier - 59)); float tmpvalue = 0.1f * armor / (8.5f * levelModifier + 40); - tmpvalue = tmpvalue/(1.0f + tmpvalue); + tmpvalue = tmpvalue / (1.0f + tmpvalue); if (tmpvalue < 0.0f) tmpvalue = 0.0f; @@ -1595,14 +1595,14 @@ void Unit::CalcAbsorbResist(Unit *pVictim, SpellSchoolMask schoolMask, DamageEff { if ((*j)->GetMiscValue() & schoolMask && (*j)->IsAffectedOnSpell(spellInfo)) - *resist= int32(float(*resist) * (float(100-(*j)->GetAmount())/100.0f)); + AddPctN(*resist, -(*j)->GetAmount()); } AuraEffectList const &ResIgnoreAuras = GetAuraEffectsByType(SPELL_AURA_MOD_IGNORE_TARGET_RESIST); for (AuraEffectList::const_iterator j = ResIgnoreAuras.begin(); j != ResIgnoreAuras.end(); ++j) { if ((*j)->GetMiscValue() & schoolMask) - *resist= int32(float(*resist) * (float(100-(*j)->GetAmount())/100.0f)); + AddPctN(*resist, -(*j)->GetAmount()); } } else @@ -1694,7 +1694,7 @@ void Unit::CalcAbsorbResist(Unit *pVictim, SpellSchoolMask schoolMask, DamageEff { //reduces all damage taken while stun, fear or silence if (unitflag & (UNIT_FLAG_STUNNED | UNIT_FLAG_FLEEING | UNIT_FLAG_SILENCED)) - RemainingDamage -= RemainingDamage * currentAbsorb / 100; + AddPctN(RemainingDamage, -currentAbsorb); continue; } // Nerves of Steel @@ -1702,7 +1702,7 @@ void Unit::CalcAbsorbResist(Unit *pVictim, SpellSchoolMask schoolMask, DamageEff { // while affected by Stun and Fear if (unitflag & (UNIT_FLAG_STUNNED | UNIT_FLAG_FLEEING)) - RemainingDamage -= RemainingDamage * currentAbsorb / 100; + AddPctN(RemainingDamage, -currentAbsorb); continue; } // Spell Deflection @@ -1710,7 +1710,7 @@ void Unit::CalcAbsorbResist(Unit *pVictim, SpellSchoolMask schoolMask, DamageEff { // You have a chance equal to your Parry chance if ((damagetype == DIRECT_DAMAGE) && roll_chance_f(pVictim->GetUnitParryChance())) - RemainingDamage -= RemainingDamage * currentAbsorb / 100; + AddPctN(RemainingDamage, -currentAbsorb); continue; } // Reflective Shield (Lady Malande boss) @@ -1739,7 +1739,7 @@ void Unit::CalcAbsorbResist(Unit *pVictim, SpellSchoolMask schoolMask, DamageEff { //reduces all damage taken while Stunned if ((pVictim->GetShapeshiftForm() == FORM_CAT) && (unitflag & UNIT_FLAG_STUNNED)) - RemainingDamage -= RemainingDamage * currentAbsorb / 100; + AddPctN(RemainingDamage, -currentAbsorb); continue; } // Savage Defense @@ -1759,7 +1759,7 @@ void Unit::CalcAbsorbResist(Unit *pVictim, SpellSchoolMask schoolMask, DamageEff { //reduces all damage taken while Stunned if (unitflag & UNIT_FLAG_STUNNED) - RemainingDamage -= RemainingDamage * currentAbsorb / 100; + AddPctN(RemainingDamage, -currentAbsorb); continue; } break; @@ -1802,7 +1802,7 @@ void Unit::CalcAbsorbResist(Unit *pVictim, SpellSchoolMask schoolMask, DamageEff case 5065: // Rank 1 case 5064: // Rank 2 triggeredSpells.push_back( - TriggeredSpellInfo(33619, pVictim, this, std::min(RemainingDamage, currentAbsorb) * aurEff->GetAmount() / 100, *itr) + TriggeredSpellInfo(33619, pVictim, this, CalculatePctN(std::min(RemainingDamage, currentAbsorb), aurEff->GetAmount()), *itr) ); break; default: @@ -1846,7 +1846,7 @@ void Unit::CalcAbsorbResist(Unit *pVictim, SpellSchoolMask schoolMask, DamageEff uint32 damageToReduce = (pVictim->GetHealth() < allowedHealth) ? RemainingDamage : allowedHealth - remainingHealth; - RemainingDamage -= damageToReduce * currentAbsorb / 100; + RemainingDamage -= CalculatePctN(damageToReduce, currentAbsorb); } continue; } @@ -1859,7 +1859,7 @@ void Unit::CalcAbsorbResist(Unit *pVictim, SpellSchoolMask schoolMask, DamageEff { //reduces all damage taken while stun, fear or silence if (unitflag & (UNIT_FLAG_STUNNED | UNIT_FLAG_FLEEING | UNIT_FLAG_SILENCED)) - RemainingDamage -= RemainingDamage * currentAbsorb / 100; + AddPctN(RemainingDamage, -currentAbsorb); continue; } break; @@ -1875,7 +1875,7 @@ void Unit::CalcAbsorbResist(Unit *pVictim, SpellSchoolMask schoolMask, DamageEff // Glyph of Unbreakable Armor if (AuraEffect const * aurEff = caster->GetAuraEffect(58635, 0)) - absorbed += uint32(absorbed * aurEff->GetAmount() / 100); + AddPctN(absorbed, aurEff->GetAmount()); RemainingDamage -= absorbed; } @@ -1903,18 +1903,18 @@ void Unit::CalcAbsorbResist(Unit *pVictim, SpellSchoolMask schoolMask, DamageEff { // damage absorbed by Anti-Magic Shell energizes the DK with additional runic power. // This, if I'm not mistaken, shows that we get back ~2% of the absorbed damage as runic power. - int32 absorbed = RemainingDamage * currentAbsorb / 100; + int32 absorbed = CalculatePctN(RemainingDamage, currentAbsorb); RemainingDamage -= absorbed; triggeredSpells.push_back(TriggeredSpellInfo(49088, pVictim, pVictim, absorbed * 2 / 10, *itr)); continue; } case 50462: // Anti-Magic Shell (on single party/raid member) - RemainingDamage -= RemainingDamage * currentAbsorb / 100; + AddPctN(RemainingDamage, -currentAbsorb); continue; case 50461: // Anti-Magic Zone if (Unit * caster = (*itr)->GetCaster()) { - int32 absorbed = RemainingDamage * currentAbsorb / 100; + int32 absorbed = CalculatePctN(RemainingDamage, currentAbsorb); int32 canabsorb = caster->GetHealth(); if (canabsorb < absorbed) absorbed = canabsorb; @@ -2091,8 +2091,8 @@ void Unit::CalcAbsorbResist(Unit *pVictim, SpellSchoolMask schoolMask, DamageEff if (!caster || (caster == pVictim) || !caster->IsInWorld() || !caster->isAlive()) continue; - uint32 splitted = uint32(RemainingDamage * (*itr)->GetAmount() / 100.0f); - splitted = (100 - auraAbsorbMod) * splitted / 100; + uint32 splitted = CalculatePctN(RemainingDamage, (*itr)->GetAmount()); + AddPctN(splitted, -auraAbsorbMod); RemainingDamage -= int32(splitted); @@ -2159,7 +2159,7 @@ void Unit::CalcAbsorbResist(Unit *pVictim, SpellSchoolMask schoolMask, DamageEff if (AuraEffect const * bonusEff = iter->second->GetBase()->GetEffect(0)) current_dmg += bonusEff->GetAmount(); - int32 new_dmg = int32(*absorb) * aurEff->GetAmount() / 100; + int32 new_dmg = CalculatePctN(int32(*absorb), aurEff->GetAmount()); if (new_dmg > 0) pVictim->CastCustomSpell(pVictim, 44413, &new_dmg, NULL, NULL, true); } @@ -2529,7 +2529,7 @@ float Unit::CalculateLevelPenalty(SpellEntry const* spellProto) const if (LvlFactor > 1.0f) LvlFactor = 1.0f; - return (100.0f - LvlPenalty) * LvlFactor / 100.0f; + return AddPctF(LvlFactor, -LvlPenalty); } void Unit::SendMeleeAttackStart(Unit* pVictim) @@ -4623,7 +4623,7 @@ float Unit::GetTotalAuraMultiplier(AuraType auratype) const AuraEffectList const& mTotalAuraList = GetAuraEffectsByType(auratype); for (AuraEffectList::const_iterator i = mTotalAuraList.begin(); i != mTotalAuraList.end(); ++i) - multiplier *= (100.0f + (*i)->GetAmount())/100.0f; + AddPctN(multiplier, (*i)->GetAmount()); return multiplier; } @@ -4675,7 +4675,7 @@ float Unit::GetTotalAuraMultiplierByMiscMask(AuraType auratype, uint32 misc_mask for (AuraEffectList::const_iterator i = mTotalAuraList.begin(); i != mTotalAuraList.end(); ++i) { if ((*i)->GetMiscValue()& misc_mask) - multiplier *= (100.0f + (*i)->GetAmount())/100.0f; + AddPctN(multiplier, (*i)->GetAmount()); } return multiplier; } @@ -4729,7 +4729,7 @@ float Unit::GetTotalAuraMultiplierByMiscValue(AuraType auratype, int32 misc_valu for (AuraEffectList::const_iterator i = mTotalAuraList.begin(); i != mTotalAuraList.end(); ++i) { if ((*i)->GetMiscValue() == misc_value) - multiplier *= (100.0f + (*i)->GetAmount())/100.0f; + AddPctN(multiplier, (*i)->GetAmount()); } return multiplier; } @@ -4783,7 +4783,7 @@ float Unit::GetTotalAuraMultiplierByAffectMask(AuraType auratype, SpellEntry con for (AuraEffectList::const_iterator i = mTotalAuraList.begin(); i != mTotalAuraList.end(); ++i) { if ((*i)->IsAffectedOnSpell(affectedSpell)) - multiplier *= (100.0f + (*i)->GetAmount())/100.0f; + AddPctN(multiplier, (*i)->GetAmount()); } return multiplier; } @@ -5326,11 +5326,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger case 25988: { // return damage % to attacker but < 50% own total health - basepoints0 = int32((triggerAmount * damage) /100); - - int32 halfMaxHealth = int32(CountPctFromMaxHealth(50)); - if (basepoints0 > halfMaxHealth) - basepoints0 = halfMaxHealth; + basepoints0 = int32(std::min(CalculatePctN(damage, triggerAmount), CountPctFromMaxHealth(50))); sLog.outDebug("DEBUG LINE: Data about Eye for an Eye ID %u, damage taken %u, unit max health %u, damage done %u", dummySpell->Id, damage, GetMaxHealth(), basepoints0); @@ -5840,7 +5836,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger { target = this; triggered_spell_id = 70872; - basepoints0 = int32(damage) * triggerAmount / 100; + basepoints0 = CalculatePctN(int32(damage), triggerAmount); break; } } @@ -5855,7 +5851,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger return false; // mana reward - basepoints0 = (triggerAmount * GetMaxPower(POWER_MANA) / 100); + basepoints0 = CalculatePctN(int32(GetMaxPower(POWER_MANA)), triggerAmount); target = this; triggered_spell_id = 29442; break; @@ -5867,8 +5863,8 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger return false; // mana cost save - int32 cost = procSpell->manaCost + procSpell->ManaCostPercentage * GetCreateMana() / 100; - basepoints0 = cost * triggerAmount/100; + int32 cost = int32(procSpell->manaCost + CalculatePctU(GetCreateMana(), procSpell->ManaCostPercentage)); + basepoints0 = CalculatePctN(cost, triggerAmount); if (basepoints0 <= 0) return false; @@ -5922,8 +5918,8 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger if (!procSpell) return false; - int32 cost = procSpell->manaCost + procSpell->ManaCostPercentage * GetCreateMana() / 100; - basepoints0 = cost * triggerAmount/100; + int32 cost = int32(procSpell->manaCost + CalculatePctU(GetCreateMana(), procSpell->ManaCostPercentage)); + basepoints0 = CalculatePctN(cost, triggerAmount); if (basepoints0 <= 0) return false; triggered_spell_id = 44450; @@ -6060,7 +6056,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger { triggered_spell_id = 59653; // % of amount blocked - basepoints0 = GetShieldBlockValue() * triggerAmount / 100; + basepoints0 = CalculatePctN(int32(GetShieldBlockValue()), triggerAmount); break; } // Glyph of Blocking @@ -6137,7 +6133,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger target = GetGuardianPet(); if (!target) return false; - basepoints0 = damage * triggerAmount / 100; + basepoints0 = CalculatePctN(int32(damage), triggerAmount); triggered_spell_id = 54181; break; } @@ -6151,7 +6147,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger triggerAmount += triggerAmount / 4; triggered_spell_id = 63106; target = this; - basepoints0 = int32(damage*triggerAmount/100); + basepoints0 = CalculatePctN(int32(damage), triggerAmount); break; } // Glyph of Shadowflame @@ -6205,7 +6201,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger } } // health - basepoints0 = int32(damage*triggerAmount/100); + basepoints0 = CalculatePctN(int32(damage), triggerAmount); target = this; triggered_spell_id = 30294; break; @@ -6224,7 +6220,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger return false; // heal amount - basepoints0 = damage * triggerAmount/100; + basepoints0 = CalculatePctN(int32(damage), triggerAmount); triggered_spell_id = 37382; break; } @@ -6264,7 +6260,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger if (AuraEffect *aurEff = target->GetAuraEffect(47753, 0)) bonus = aurEff->GetAmount(); - basepoints0 = damage * triggerAmount/100 + bonus; + basepoints0 = CalculatePctN(int32(damage), triggerAmount) + bonus; if (basepoints0 > target->getLevel() * 125) basepoints0 = target->getLevel() * 125; @@ -6281,7 +6277,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger target = this; break; } - switch(dummySpell->Id) + switch (dummySpell->Id) { // Vampiric Embrace case 15286: @@ -6290,9 +6286,10 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger return false; // heal amount - int32 team = triggerAmount*damage/500; - int32 self = triggerAmount*damage/100 - team; - CastCustomSpell(this,15290,&team,&self,NULL,true,castItem,triggeredByAura); + int32 total = CalculatePctN(int32(damage), triggerAmount); + int32 team = total / 5; + int32 self = total - team; + CastCustomSpell(this, 15290, &team, &self, NULL, true, castItem, triggeredByAura); return true; // no hidden cooldown } // Priest Tier 6 Trinket (Ashtongue Talisman of Acumen) @@ -6332,7 +6329,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger if (!tickcount) return false; - basepoints0 = damage * triggerAmount / tickcount / 100; + basepoints0 = CalculatePctN(int32(damage), triggerAmount) / tickcount; break; } // Improved Shadowform @@ -6362,7 +6359,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger case 26169: { // heal amount - basepoints0 = int32(damage * 10/100); + basepoints0 = int32(CalculatePctN(damage, 10)); target = this; triggered_spell_id = 26170; break; @@ -6374,7 +6371,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger return false; // heal amount - basepoints0 = damage * triggerAmount/100; + basepoints0 = CalculatePctN(int32(damage), triggerAmount); target = this; triggered_spell_id = 39373; break; @@ -6394,7 +6391,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger SpellEntry const* blessHealing = sSpellStore.LookupEntry(triggered_spell_id); if (!blessHealing) return false; - basepoints0 = int32(triggerAmount * damage / 100 / (GetSpellMaxDuration(blessHealing) / blessHealing->EffectAmplitude[0])); + basepoints0 = int32(CalculatePctN(damage, triggerAmount) / (GetSpellMaxDuration(blessHealing) / blessHealing->EffectAmplitude[0])); } break; } @@ -6411,7 +6408,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger return false; int32 mana_perc = SpellMgr::CalculateSpellEffectAmount(triggeredByAura->GetSpellProto(), triggeredByAura->GetEffIndex()); - basepoints0 = uint32((GetCreatePowers(POWER_MANA) * mana_perc / 100) / 10); + basepoints0 = int32(CalculatePctN(GetCreatePowers(POWER_MANA), mana_perc) / 10); triggered_spell_id = 54833; target = this; break; @@ -6485,7 +6482,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger case 28719: { // mana back - basepoints0 = int32(procSpell->manaCost * 30 / 100); + basepoints0 = int32(CalculatePctN(procSpell->manaCost, 30)); target = this; triggered_spell_id = 28742; break; @@ -6495,7 +6492,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger { if (!pVictim || !pVictim->HealthBelowPct(uint32(triggerAmount))) return false; - basepoints0 = int32(triggerAmount * damage / 100); + basepoints0 = CalculatePctN(int32(damage), triggerAmount); triggered_spell_id = 54755; break; } @@ -6563,7 +6560,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger SpellEntry const* triggeredSpell = sSpellStore.LookupEntry(triggered_spell_id); if (!triggeredSpell) return false; - basepoints0 = int32(triggerAmount * damage / 100 / (GetSpellMaxDuration(triggeredSpell) / triggeredSpell->EffectAmplitude[0])); + basepoints0 = CalculatePctN(int32(damage), triggerAmount) / (GetSpellMaxDuration(triggeredSpell) / triggeredSpell->EffectAmplitude[0]); } break; } @@ -6590,7 +6587,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger else if (dummySpell->SpellIconID == 2860) { triggered_spell_id = 48504; - basepoints0 = triggerAmount * damage / 100; + basepoints0 = CalculatePctN(int32(damage), triggerAmount); break; } // King of the Jungle @@ -6665,7 +6662,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger return false; // energy cost save - basepoints0 = procSpell->manaCost * triggerAmount/100; + basepoints0 = CalculatePctN(int32(procSpell->manaCost), triggerAmount); if (basepoints0 <= 0) return false; @@ -6766,7 +6763,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger float ap = GetTotalAttackPowerValue(BASE_ATTACK); int32 holy = SpellBaseDamageBonus(SPELL_SCHOOL_MASK_HOLY) + SpellBaseDamageBonusForVictim(SPELL_SCHOOL_MASK_HOLY, pVictim); - basepoints0 = (int32)GetAttackTime(BASE_ATTACK) * int32(ap*0.022f + 0.044f * holy) / 1000; + basepoints0 = (int32)GetAttackTime(BASE_ATTACK) * int32(ap * 0.022f + 0.044f * holy) / 1000; break; } // Light's Beacon - Beacon of Light @@ -6881,7 +6878,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger if (pVictim && pVictim->isAlive() && pVictim->getPowerType() == POWER_MANA) { // 2% of base mana - basepoints0 = int32(pVictim->GetCreateMana() * 2 / 100); + basepoints0 = int32(CalculatePctN(pVictim->GetCreateMana(), 2)); pVictim->CastCustomSpell(pVictim, 20268, &basepoints0, NULL, NULL, true, 0, triggeredByAura); } return true; @@ -6990,7 +6987,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger return false; // heal amount - basepoints0 = triggerAmount*(std::min(damage,GetMaxHealth() - GetHealth()))/100; + basepoints0 = int32(CalculatePctN(std::min(damage, GetMaxHealth() - GetHealth()), triggerAmount)); target = this; if (basepoints0) @@ -7042,14 +7039,14 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger case 54936: { triggered_spell_id = 54957; - basepoints0 = triggerAmount*damage/100; + basepoints0 = CalculatePctN(int32(damage), triggerAmount); break; } // Glyph of Holy Light case 54937: { triggered_spell_id = 54968; - basepoints0 = triggerAmount*damage/100; + basepoints0 = CalculatePctN(int32(damage), triggerAmount); break; } case 71406: // Tiny Abomination in a Jar @@ -7276,7 +7273,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger // Not proc from self heals if (this == pVictim) return false; - basepoints0 = triggerAmount * damage / 100; + basepoints0 = CalculatePctN(int32(damage), triggerAmount); target = this; triggered_spell_id = 55533; break; @@ -7288,14 +7285,14 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger target = GetOwner(); if (!target) return false; - basepoints0 = triggerAmount * damage / 100; + basepoints0 = CalculatePctN(int32(damage), triggerAmount); triggered_spell_id = 58879; break; } // Shaman T8 Elemental 4P Bonus case 64928: { - basepoints0 = int32(triggerAmount * damage / 100); + basepoints0 = CalculatePctN(int32(damage), triggerAmount); triggered_spell_id = 64930; // Electrified break; } @@ -7309,7 +7306,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger SpellEntry const* triggeredSpell = sSpellStore.LookupEntry(triggered_spell_id); if (!triggeredSpell) return false; - basepoints0 = int32(triggerAmount * damage / 100 / (GetSpellMaxDuration(triggeredSpell) / triggeredSpell->EffectAmplitude[0])); + basepoints0 = CalculatePctN(int32(damage), triggerAmount) / (GetSpellMaxDuration(triggeredSpell) / triggeredSpell->EffectAmplitude[0]); } break; } @@ -7323,7 +7320,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger SpellEntry const* triggeredSpell = sSpellStore.LookupEntry(triggered_spell_id); if (!triggeredSpell) return false; - basepoints0 = int32(triggerAmount * damage / 100 / (GetSpellMaxDuration(triggeredSpell) / triggeredSpell->EffectAmplitude[0])); + basepoints0 = CalculatePctN(int32(damage), triggerAmount) / (GetSpellMaxDuration(triggeredSpell) / triggeredSpell->EffectAmplitude[0]); } break; } @@ -7375,9 +7372,9 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger if (aurEffA) { int32 bp0 = 0, bp1 = 0; - bp0 = aurEffA->GetAmount() * triggerAmount / 100; + bp0 = CalculatePctN(triggerAmount, aurEffA->GetAmount()); if (AuraEffect * aurEffB = aurEffA->GetBase()->GetEffect(EFFECT_1)) - bp1 = aurEffB->GetAmount() * triggerAmount / 100; + bp1 = CalculatePctN(triggerAmount, aurEffB->GetAmount()); CastCustomSpell(this, 63283, &bp0, &bp1, NULL, true, NULL, triggeredByAura); return true; } @@ -7415,7 +7412,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger if (dummySpell->SpellIconID == 3065) { triggered_spell_id = 52759; - basepoints0 = triggerAmount * damage / 100; + basepoints0 = CalculatePctN(int32(damage), triggerAmount); target = this; break; } @@ -7429,10 +7426,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger // Glyph of Earth Shield if (AuraEffect* aur = GetAuraEffect(63279,0)) - { - int32 aur_mod = aur->GetAmount(); - basepoints0 = int32(basepoints0 * (aur_mod + 100.0f) / 100.0f); - } + AddPctN(basepoints0, aur->GetAmount()); triggered_spell_id = 379; break; } @@ -7442,13 +7436,13 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger if (GetTypeId() != TYPEID_PLAYER || !pVictim || !pVictim->isAlive() || !castItem || !castItem->IsEquipped()) return false; - float fire_onhit = (float)(SpellMgr::CalculateSpellEffectAmount(dummySpell, 0) / 100.0); + float fire_onhit = float(CalculatePctF(SpellMgr::CalculateSpellEffectAmount(dummySpell, 0), 1.0f)); float add_spellpower = (float)(SpellBaseDamageBonus(SPELL_SCHOOL_MASK_FIRE) + SpellBaseDamageBonusForVictim(SPELL_SCHOOL_MASK_FIRE, pVictim)); // 1.3speed = 5%, 2.6speed = 10%, 4.0 speed = 15%, so, 1.0speed = 3.84% - add_spellpower= add_spellpower / 100.0f * 3.84f; + ApplyPctF(add_spellpower, 3.84f); // Enchant on Off-Hand and ready? if (castItem->GetSlot() == EQUIPMENT_SLOT_OFFHAND && isAttackReady(OFF_ATTACK)) @@ -7602,7 +7596,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger { if (GetTypeId() != TYPEID_PLAYER) return false; - basepoints0 = triggerAmount * damage / 100; + basepoints0 = CalculatePctN(int32(damage), triggerAmount); break; } // Butchery @@ -7648,10 +7642,10 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger // Unholy Blight if (dummySpell->Id == 49194) { - basepoints0 = triggerAmount * damage / 100; + basepoints0 = CalculatePctN(int32(damage), triggerAmount); // Glyph of Unholy Blight if (AuraEffect *glyph=GetAuraEffect(63332,0)) - basepoints0 += basepoints0 * glyph->GetAmount() / 100; + AddPctN(basepoints0, glyph->GetAmount()); // Find replaced aura to use it's remaining amount AuraEffectList const& DoTAuras = target->GetAuraEffectsByType(SPELL_AURA_PERIODIC_DAMAGE); for (Unit::AuraEffectList::const_iterator i = DoTAuras.begin(); i != DoTAuras.end(); ++i) @@ -7676,7 +7670,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger // Necrosis if (dummySpell->SpellIconID == 2709) { - basepoints0 = triggerAmount * damage / 100; + basepoints0 = CalculatePctN(int32(damage), triggerAmount); triggered_spell_id = 51460; break; } @@ -7754,7 +7748,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger { if (!roll_chance_f(GetUnitCriticalChance(BASE_ATTACK, pVictim))) return false; - basepoints0 = triggerAmount * damage / 100; + basepoints0 = CalculatePctN(int32(damage), triggerAmount); triggered_spell_id = 50526; break; } @@ -7843,7 +7837,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger { triggered_spell_id = 54445; target = this; - float addThreat = SpellMgr::CalculateSpellEffectAmount(procSpell, 0, this) * triggerAmount / 100.0f; + float addThreat = float(CalculatePctN(SpellMgr::CalculateSpellEffectAmount(procSpell, 0, this), triggerAmount)); pVictim->AddThreat(this, addThreat); break; } @@ -7915,7 +7909,7 @@ bool Unit::HandleObsModEnergyAuraProc(Unit *pVictim, uint32 /*damage*/, AuraEffe if (dummySpell->SpellFamilyFlags[1] & 0x40000) { uint32 maxmana = GetMaxPower(POWER_MANA); - basepoints0 = uint32(maxmana* GetAttackTime(RANGED_ATTACK)/1000.0f/100.0f); + basepoints0 = CalculatePctF(maxmana, GetAttackTime(RANGED_ATTACK) / 1000.0f); target = this; triggered_spell_id = 34075; break; @@ -8047,7 +8041,7 @@ bool Unit::HandleAuraProc(Unit * pVictim, uint32 damage, Aura * triggeredByAura, *handled = true; if (pVictim->HasAura(53601)) { - int32 bp0 = (damage/12) * SpellMgr::CalculateSpellEffectAmount(dummySpell, 2)/100; + int32 bp0 = CalculatePctN(int32(damage / 12), SpellMgr::CalculateSpellEffectAmount(dummySpell, 2)); CastCustomSpell(pVictim, 66922, &bp0, NULL, NULL, true); return true; } @@ -8096,7 +8090,7 @@ bool Unit::HandleAuraProc(Unit * pVictim, uint32 damage, Aura * triggeredByAura, if (!spInfo) return false; - int32 bp0 = this->GetCreateMana() * SpellMgr::CalculateSpellEffectAmount(spInfo, 0) / 100; + int32 bp0 = int32(CalculatePctN(GetCreateMana(), SpellMgr::CalculateSpellEffectAmount(spInfo, 0))); this->CastCustomSpell(this, 67545, &bp0, NULL, NULL, true, NULL, triggeredByAura->GetEffect(0), this->GetGUID()); return true; } @@ -8288,7 +8282,7 @@ bool Unit::HandleProcTriggerSpell(Unit *pVictim, uint32 damage, AuraEffect* trig if ((*i)->GetMiscValue() == SPELLMOD_CHANCE_OF_SUCCESS && (*i)->GetSpellProto()->SpellIconID == 113) { int32 value2 = CalculateSpellDamage(this, (*i)->GetSpellProto(),2); - basepoints0 = value2 * GetMaxPower(POWER_MANA) / 100; + basepoints0 = int32(CalculatePctN(GetMaxPower(POWER_MANA), value2)); // Drain Soul CastCustomSpell(this, 18371, &basepoints0, NULL, NULL, true, castItem, triggeredByAura); break; @@ -8336,7 +8330,7 @@ bool Unit::HandleProcTriggerSpell(Unit *pVictim, uint32 damage, AuraEffect* trig sLog.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in BR", auraSpellInfo->Id); return false; } - basepoints0 = damage * triggerAmount / 100 / 3; + basepoints0 = CalculatePctN(int32(damage), triggerAmount) / 3; target = this; } break; @@ -8391,7 +8385,7 @@ bool Unit::HandleProcTriggerSpell(Unit *pVictim, uint32 damage, AuraEffect* trig if (!TriggerPS) return false; - basepoints0 = int32(damage * triggerAmount / 100 / (GetSpellMaxDuration(TriggerPS) / TriggerPS->EffectAmplitude[0])); + basepoints0 = CalculatePctN(int32(damage), triggerAmount) / (GetSpellMaxDuration(TriggerPS) / TriggerPS->EffectAmplitude[0]); basepoints0 += pVictim->GetRemainingDotDamage(GetGUID(), trigger_spell_id); break; } @@ -8520,8 +8514,8 @@ bool Unit::HandleProcTriggerSpell(Unit *pVictim, uint32 damage, AuraEffect* trig return false; } // percent stored in effect 1 (class scripts) base points - int32 cost = originalSpell->manaCost + originalSpell->ManaCostPercentage * GetCreateMana() / 100; - basepoints0 = cost*SpellMgr::CalculateSpellEffectAmount(auraSpellInfo, 1)/100; + int32 cost = int32(originalSpell->manaCost + CalculatePctU(GetCreateMana(), originalSpell->ManaCostPercentage)); + basepoints0 = CalculatePctN(cost, SpellMgr::CalculateSpellEffectAmount(auraSpellInfo, 1)); trigger_spell_id = 20272; target = this; } @@ -8551,7 +8545,7 @@ bool Unit::HandleProcTriggerSpell(Unit *pVictim, uint32 damage, AuraEffect* trig { if (!procSpell) return false; - basepoints0 = procSpell->manaCost * 35 / 100; + basepoints0 = int32(CalculatePctN(procSpell->manaCost, 35)); trigger_spell_id = 23571; target = this; break; @@ -8609,7 +8603,7 @@ bool Unit::HandleProcTriggerSpell(Unit *pVictim, uint32 damage, AuraEffect* trig return false; trigger_spell_id = 50475; - basepoints0 = damage * triggerAmount / 100; + basepoints0 = CalculatePctN(int32(damage), triggerAmount); } break; } @@ -8639,7 +8633,7 @@ bool Unit::HandleProcTriggerSpell(Unit *pVictim, uint32 damage, AuraEffect* trig // This spell originally trigger 13567 - Dummy Trigger (vs dummy efect) case 26467: { - basepoints0 = damage * 15 / 100; + basepoints0 = int32(CalculatePctN(damage, 15)); target = pVictim; trigger_spell_id = 26470; break; @@ -8703,7 +8697,7 @@ bool Unit::HandleProcTriggerSpell(Unit *pVictim, uint32 damage, AuraEffect* trig case 45057: { // reduce you below $s1% health - if (GetHealth() - damage > GetMaxHealth() * triggerAmount / 100) + if ((GetHealth() - damage) > CalculatePctN(GetMaxHealth(), triggerAmount)) return false; break; } @@ -8719,7 +8713,7 @@ bool Unit::HandleProcTriggerSpell(Unit *pVictim, uint32 damage, AuraEffect* trig // Blessing of Ancient Kings (Val'anyr, Hammer of Ancient Kings) case 64411: { - basepoints0 = damage * 15 / 100; + basepoints0 = int32(CalculatePctN(damage, 15)); target = pVictim; trigger_spell_id = 64413; break; @@ -8823,7 +8817,7 @@ bool Unit::HandleProcTriggerSpell(Unit *pVictim, uint32 damage, AuraEffect* trig // Shamanistic Rage triggered spell case 30824: { - basepoints0 = int32(GetTotalAttackPowerValue(BASE_ATTACK) * triggerAmount / 100); + basepoints0 = int32(CalculatePctN(GetTotalAttackPowerValue(BASE_ATTACK), triggerAmount)); break; } // Enlightenment (trigger only from mana cost spells) @@ -8842,8 +8836,8 @@ bool Unit::HandleProcTriggerSpell(Unit *pVictim, uint32 damage, AuraEffect* trig { if (AuraEffect * aurEff = owner->GetDummyAuraEffect(SPELLFAMILY_WARLOCK, 3220, 0)) { - basepoints0 = int32((aurEff->GetAmount() * owner->SpellBaseDamageBonus(SpellSchoolMask(SPELL_SCHOOL_MASK_MAGIC)) + 100.0f) / 100.0f); - CastCustomSpell(this,trigger_spell_id,&basepoints0,&basepoints0,NULL,true,castItem,triggeredByAura); + basepoints0 = int32((aurEff->GetAmount() * owner->SpellBaseDamageBonus(SpellSchoolMask(SPELL_SCHOOL_MASK_MAGIC)) + 100.0f) / 100.0f); // TODO: Is it right? + CastCustomSpell(this, trigger_spell_id, &basepoints0, &basepoints0, NULL, true, castItem, triggeredByAura); return true; } } @@ -8916,7 +8910,7 @@ bool Unit::HandleProcTriggerSpell(Unit *pVictim, uint32 damage, AuraEffect* trig // Savage Defense case 62606: { - basepoints0 = int32(GetTotalAttackPowerValue(BASE_ATTACK) * triggerAmount / 100.0f); + basepoints0 = CalculatePctF(triggerAmount, GetTotalAttackPowerValue(BASE_ATTACK)); break; } // Body and Soul @@ -10298,7 +10292,7 @@ uint32 Unit::SpellDamageBonus(Unit *pVictim, SpellEntry const *spellProto, uint3 if (((*i)->GetMiscValue() & GetSpellSchoolMask(spellProto)) && (*i)->GetSpellProto()->EquippedItemClass == -1 && // -1 == any item class (not wand) (*i)->GetSpellProto()->EquippedItemInventoryTypeMask == 0) // 0 == any inventory type (not wand) - DoneTotalMod *= ((*i)->GetAmount()+100.0f)/100.0f; + AddPctN(DoneTotalMod, (*i)->GetAmount()); uint32 creatureTypeMask = pVictim->GetCreatureTypeMask(); // Add flat bonus from spell damage versus @@ -10306,13 +10300,13 @@ uint32 Unit::SpellDamageBonus(Unit *pVictim, SpellEntry const *spellProto, uint3 AuraEffectList const &mDamageDoneVersus = GetAuraEffectsByType(SPELL_AURA_MOD_DAMAGE_DONE_VERSUS); for (AuraEffectList::const_iterator i = mDamageDoneVersus.begin(); i != mDamageDoneVersus.end(); ++i) if (creatureTypeMask & uint32((*i)->GetMiscValue())) - DoneTotalMod *= ((*i)->GetAmount()+100.0f)/100.0f; + AddPctN(DoneTotalMod, (*i)->GetAmount()); // bonus against aurastate AuraEffectList const &mDamageDoneVersusAurastate = GetAuraEffectsByType(SPELL_AURA_MOD_DAMAGE_DONE_VERSUS_AURASTATE); for (AuraEffectList::const_iterator i = mDamageDoneVersusAurastate.begin(); i != mDamageDoneVersusAurastate.end(); ++i) if (pVictim->HasAuraState(AuraState((*i)->GetMiscValue()))) - DoneTotalMod *= ((*i)->GetAmount() + 100.0f) / 100.0f; + AddPctN(DoneTotalMod, (*i)->GetAmount()); // done scripted mod (take it from owner) Unit * owner = GetOwner() ? GetOwner() : this; @@ -10331,7 +10325,7 @@ uint32 Unit::SpellDamageBonus(Unit *pVictim, SpellEntry const *spellProto, uint3 case 6928: { if (pVictim->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT, spellProto, this)) - DoneTotalMod *= (100.0f+(*i)->GetAmount())/100.0f; + AddPctN(DoneTotalMod, (*i)->GetAmount()); break; } // Soul Siphon @@ -10358,19 +10352,19 @@ uint32 Unit::SpellDamageBonus(Unit *pVictim, SpellEntry const *spellProto, uint3 break; } } - DoneTotalMod *= (modPercent+100.0f)/100.0f; + AddPctN(DoneTotalMod, modPercent); break; } case 6916: // Death's Embrace case 6925: case 6927: if (HasAuraState(AURA_STATE_HEALTHLESS_20_PERCENT, spellProto, this)) - DoneTotalMod *= (100.0f+(*i)->GetAmount())/100.0f; + AddPctN(DoneTotalMod, (*i)->GetAmount()); break; case 5481: // Starfire Bonus { if (pVictim->GetAuraEffect(SPELL_AURA_PERIODIC_DAMAGE, SPELLFAMILY_DRUID, 0x200002, 0, 0)) - DoneTotalMod *= ((*i)->GetAmount()+100.0f)/100.0f; + AddPctN(DoneTotalMod, (*i)->GetAmount()); break; } case 4418: // Increased Shock Damage @@ -10393,14 +10387,14 @@ uint32 Unit::SpellDamageBonus(Unit *pVictim, SpellEntry const *spellProto, uint3 if ((*i)->GetSpellProto()->SpellIconID == 2656) { if (!pVictim->HealthAbovePct(35)) - DoneTotalMod *= (100.0f+(*i)->GetAmount())/100.0f; + AddPctN(DoneTotalMod, (*i)->GetAmount()); } // Tundra Stalker else { // Frost Fever (target debuff) if (pVictim->HasAura(55095)) - DoneTotalMod *= ((*i)->GetAmount()+100.0f)/100.0f; + AddPctN(DoneTotalMod, (*i)->GetAmount()); break; } break; @@ -10411,7 +10405,7 @@ uint32 Unit::SpellDamageBonus(Unit *pVictim, SpellEntry const *spellProto, uint3 if (pVictim->GetAuraEffect(SPELL_AURA_PERIODIC_DAMAGE, SPELLFAMILY_DEATHKNIGHT, 0,0x02000000,0)) { if (SpellChainNode const *chain = sSpellMgr.GetSpellChainNode((*i)->GetId())) - DoneTotalMod *= (chain->rank * 2.0f + 100.0f)/100.0f; + AddPctF(DoneTotalMod, chain->rank * 2.0f); } break; } @@ -10419,7 +10413,7 @@ uint32 Unit::SpellDamageBonus(Unit *pVictim, SpellEntry const *spellProto, uint3 case 7377: { if (pVictim->GetAuraEffect(SPELL_AURA_PERIODIC_DAMAGE, SPELLFAMILY_PRIEST, 0x8000, 0,0, GetGUID())) - DoneTotalMod *= ((*i)->GetAmount()+100.0f)/100.0f; + AddPctN(DoneTotalMod, (*i)->GetAmount()); break; } // Marked for Death @@ -10430,7 +10424,7 @@ uint32 Unit::SpellDamageBonus(Unit *pVictim, SpellEntry const *spellProto, uint3 case 7602: { if (pVictim->GetAuraEffect(SPELL_AURA_MOD_STALKED, SPELLFAMILY_HUNTER, 0x400, 0, 0)) - DoneTotalMod *= ((*i)->GetAmount() + 100.0f) / 100.0f; + AddPctN(DoneTotalMod, (*i)->GetAmount()); break; } } @@ -10461,7 +10455,7 @@ uint32 Unit::SpellDamageBonus(Unit *pVictim, SpellEntry const *spellProto, uint3 for (AuraEffectList::const_iterator i = mDumyAuras.begin(); i != mDumyAuras.end(); ++i) if ((*i)->GetSpellProto()->SpellIconID == 3263) { - DoneTotalMod *= float((*i)->GetAmount() + 100.f) / 100.f; + AddPctN(DoneTotalMod, (*i)->GetAmount()); break; } } @@ -10473,13 +10467,13 @@ uint32 Unit::SpellDamageBonus(Unit *pVictim, SpellEntry const *spellProto, uint3 if (AuraEffect * aurEff = GetAuraEffect(55687, 0)) // Increase Mind Flay damage if Shadow Word: Pain present on target if (pVictim->GetAuraEffect(SPELL_AURA_PERIODIC_DAMAGE, SPELLFAMILY_PRIEST, 0x8000, 0,0, GetGUID())) - DoneTotalMod *= (aurEff->GetAmount() + 100.0f) / 100.f; + AddPctN(DoneTotalMod, aurEff->GetAmount()); // Twisted Faith - Mind Flay part if (AuraEffect * aurEff = GetAuraEffect(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS, SPELLFAMILY_PRIEST, 2848, 1)) // Increase Mind Flay damage if Shadow Word: Pain present on target if (pVictim->GetAuraEffect(SPELL_AURA_PERIODIC_DAMAGE, SPELLFAMILY_PRIEST, 0x8000, 0,0, GetGUID())) - DoneTotalMod *= (aurEff->GetAmount() + 100.0f) / 100.f; + AddPctN(DoneTotalMod, aurEff->GetAmount()); } break; case SPELLFAMILY_PALADIN: @@ -10497,7 +10491,7 @@ uint32 Unit::SpellDamageBonus(Unit *pVictim, SpellEntry const *spellProto, uint3 } // + 10% for each application of Holy Vengeance/Blood Corruption on the target if (stacks) - DoneTotalMod *= (10.0f + float(stacks)) / 10.0f; + AddPctU(DoneTotalMod, 10 * stacks); } break; case SPELLFAMILY_WARLOCK: @@ -10509,7 +10503,7 @@ uint32 Unit::SpellDamageBonus(Unit *pVictim, SpellEntry const *spellProto, uint3 for (AuraEffectList::const_iterator i = mDumyAuras.begin(); i != mDumyAuras.end(); ++i) if ((*i)->GetSpellProto()->SpellIconID == 3173) { - DoneTotalMod *= float((*i)->GetAmount() + 100.f) / 100.f; + AddPctN(DoneTotalMod, (*i)->GetAmount()); break; } } @@ -10522,13 +10516,13 @@ uint32 Unit::SpellDamageBonus(Unit *pVictim, SpellEntry const *spellProto, uint3 // Improved Icy Touch if (spellProto->SpellFamilyFlags[0] & 0x2) if (AuraEffect * aurEff = GetDummyAuraEffect(SPELLFAMILY_DEATHKNIGHT, 2721, 0)) - DoneTotalMod *= (100.0f + aurEff->GetAmount()) / 100.0f; + AddPctN(DoneTotalMod, aurEff->GetAmount()); // Glacier Rot if (spellProto->SpellFamilyFlags[0] & 0x2 || spellProto->SpellFamilyFlags[1] & 0x6) if (AuraEffect * aurEff = GetDummyAuraEffect(SPELLFAMILY_DEATHKNIGHT, 196, 0)) if (pVictim->GetDiseasesByCaster(owner->GetGUID()) > 0) - DoneTotalMod *= (100.0f + aurEff->GetAmount()) / 100.0f; + AddPctN(DoneTotalMod, aurEff->GetAmount()); // Impurity (dummy effect) if (GetTypeId() == TYPEID_PLAYER) @@ -10547,7 +10541,7 @@ uint32 Unit::SpellDamageBonus(Unit *pVictim, SpellEntry const *spellProto, uint3 case 49638: { if (const SpellEntry *proto=sSpellStore.LookupEntry(itr->first)) - ApCoeffMod *= (100.0f + SpellMgr::CalculateSpellEffectAmount(proto, 0)) / 100.0f; + AddPctN(ApCoeffMod, SpellMgr::CalculateSpellEffectAmount(proto, 0)); } break; } @@ -10616,7 +10610,7 @@ uint32 Unit::SpellDamageBonus(Unit *pVictim, SpellEntry const *spellProto, uint3 sumNegativeMod += (*i)->GetAmount(); } - float TakenTotalMod = (sumNegativeMod+maxPositiveMod+100.0f)/100.0f; + float TakenTotalMod = (sumNegativeMod + maxPositiveMod + 100.0f) / 100.0f; // Taken/Done fixed damage bonus auras int32 DoneAdvertisedBenefit = SpellBaseDamageBonus(GetSpellSchoolMask(spellProto)); @@ -10769,14 +10763,14 @@ int32 Unit::SpellBaseDamageBonus(SpellSchoolMask schoolMask) { // stat used stored in miscValueB for this aura Stats usedStat = Stats((*i)->GetMiscValueB()); - DoneAdvertisedBenefit += int32(GetStat(usedStat) * (*i)->GetAmount() / 100.0f); + DoneAdvertisedBenefit += int32(CalculatePctN(GetStat(usedStat), (*i)->GetAmount())); } } // ... and attack power AuraEffectList const& mDamageDonebyAP = GetAuraEffectsByType(SPELL_AURA_MOD_SPELL_DAMAGE_OF_ATTACK_POWER); for (AuraEffectList::const_iterator i =mDamageDonebyAP.begin(); i != mDamageDonebyAP.end(); ++i) if ((*i)->GetMiscValue() & schoolMask) - DoneAdvertisedBenefit += int32(GetTotalAttackPowerValue(BASE_ATTACK) * (*i)->GetAmount() / 100.0f); + DoneAdvertisedBenefit += int32(CalculatePctN(GetTotalAttackPowerValue(BASE_ATTACK), (*i)->GetAmount())); } return DoneAdvertisedBenefit > 0 ? DoneAdvertisedBenefit : 0; @@ -11058,7 +11052,7 @@ uint32 Unit::SpellHealingBonus(Unit *pVictim, SpellEntry const *spellProto, uint // Healing done percent AuraEffectList const& mHealingDonePct = GetAuraEffectsByType(SPELL_AURA_MOD_HEALING_DONE_PERCENT); for (AuraEffectList::const_iterator i = mHealingDonePct.begin(); i != mHealingDonePct.end(); ++i) - DoneTotalMod *= (100.0f + (*i)->GetAmount()) / 100.0f; + AddPctN(DoneTotalMod, (*i)->GetAmount()); // done scripted mod (take it from owner) Unit *owner = GetOwner() ? GetOwner() : this; @@ -11072,23 +11066,23 @@ uint32 Unit::SpellHealingBonus(Unit *pVictim, SpellEntry const *spellProto, uint case 4415: // Increased Rejuvenation Healing case 4953: case 3736: // Hateful Totem of the Third Wind / Increased Lesser Healing Wave / LK Arena (4/5/6) Totem of the Third Wind / Savage Totem of the Third Wind - DoneTotal+=(*i)->GetAmount(); + DoneTotal += (*i)->GetAmount(); break; case 7997: // Renewed Hope case 7998: if (pVictim->HasAura(6788)) - DoneTotalMod *=((*i)->GetAmount() + 100.0f)/100.0f; + AddPctN(DoneTotalMod, (*i)->GetAmount()); break; case 21: // Test of Faith case 6935: case 6918: if (pVictim->HealthBelowPct(50)) - DoneTotalMod *=((*i)->GetAmount() + 100.0f)/100.0f; + AddPctN(DoneTotalMod, (*i)->GetAmount()); break; case 7798: // Glyph of Regrowth { if (pVictim->GetAuraEffect(SPELL_AURA_PERIODIC_HEAL, SPELLFAMILY_DRUID, 0x40, 0, 0)) - DoneTotalMod *= ((*i)->GetAmount()+100.0f)/100.0f; + AddPctN(DoneTotalMod, (*i)->GetAmount()); break; } case 8477: // Nourish Heal Boost @@ -11107,13 +11101,13 @@ uint32 Unit::SpellHealingBonus(Unit *pVictim, SpellEntry const *spellProto, uint continue; modPercent += stepPercent * aura->GetStackAmount(); } - DoneTotalMod *= (modPercent+100.0f)/100.0f; + AddPctN(DoneTotalMod, modPercent); break; } case 7871: // Glyph of Lesser Healing Wave { if (pVictim->GetAuraEffect(SPELL_AURA_DUMMY, SPELLFAMILY_SHAMAN, 0 , 0x00000400, 0, GetGUID())) - DoneTotalMod *= ((*i)->GetAmount()+100.0f)/100.0f; + AddPctN(DoneTotalMod, (*i)->GetAmount()); break; } default: @@ -11271,39 +11265,39 @@ uint32 Unit::SpellHealingBonus(Unit *pVictim, SpellEntry const *spellProto, uint { // Search for Healing Way on Victim if (AuraEffect const* HealingWay = pVictim->GetAuraEffect(29203, 0)) - TakenTotalMod *= (HealingWay->GetAmount() + 100.0f) / 100.0f; + AddPctN(TakenTotalMod, HealingWay->GetAmount()); } // Tenacity increase healing % taken if (AuraEffect const* Tenacity = pVictim->GetAuraEffect(58549, 0)) - TakenTotalMod *= (Tenacity->GetAmount() + 100.0f) / 100.0f; + AddPctN(TakenTotalMod, Tenacity->GetAmount()); // Healing taken percent float minval = (float)pVictim->GetMaxNegativeAuraModifier(SPELL_AURA_MOD_HEALING_PCT); if (minval) - TakenTotalMod *= (100.0f + minval) / 100.0f; + AddPctF(TakenTotalMod, minval); float maxval = (float)pVictim->GetMaxPositiveAuraModifier(SPELL_AURA_MOD_HEALING_PCT); if (maxval) - TakenTotalMod *= (100.0f + maxval) / 100.0f; + AddPctF(TakenTotalMod, maxval); if (damagetype == DOT) { // Healing over time taken percent float minval_hot = (float)pVictim->GetMaxNegativeAuraModifier(SPELL_AURA_MOD_HOT_PCT); if (minval_hot) - TakenTotalMod *= (100.0f + minval_hot) / 100.0f; + AddPctF(TakenTotalMod, minval_hot); float maxval_hot = (float)pVictim->GetMaxPositiveAuraModifier(SPELL_AURA_MOD_HOT_PCT); if (maxval_hot) - TakenTotalMod *= (100.0f + maxval_hot) / 100.0f; + AddPctF(TakenTotalMod, maxval_hot); } AuraEffectList const& mHealingGet= pVictim->GetAuraEffectsByType(SPELL_AURA_MOD_HEALING_RECEIVED); for (AuraEffectList::const_iterator i = mHealingGet.begin(); i != mHealingGet.end(); ++i) if (GetGUID() == (*i)->GetCasterGUID() && (*i)->IsAffectedOnSpell(spellProto)) - TakenTotalMod *= ((*i)->GetAmount() + 100.0f) / 100.0f; + AddPctN(TakenTotalMod, (*i)->GetAmount()); heal = (int32(heal) + TakenTotal) * TakenTotalMod; @@ -11331,14 +11325,14 @@ int32 Unit::SpellBaseHealingBonus(SpellSchoolMask schoolMask) { // stat used dependent from misc value (stat index) Stats usedStat = Stats((*i)->GetSpellProto()->EffectMiscValue[(*i)->GetEffIndex()]); - AdvertisedBenefit += int32(GetStat(usedStat) * (*i)->GetAmount() / 100.0f); + AdvertisedBenefit += int32(CalculatePctN(GetStat(usedStat), (*i)->GetAmount())); } // ... and attack power AuraEffectList const& mHealingDonebyAP = GetAuraEffectsByType(SPELL_AURA_MOD_SPELL_HEALING_OF_ATTACK_POWER); for (AuraEffectList::const_iterator i = mHealingDonebyAP.begin(); i != mHealingDonebyAP.end(); ++i) if ((*i)->GetMiscValue() & schoolMask) - AdvertisedBenefit += int32(GetTotalAttackPowerValue(BASE_ATTACK) * (*i)->GetAmount() / 100.0f); + AdvertisedBenefit += int32(CalculatePctN(GetTotalAttackPowerValue(BASE_ATTACK), (*i)->GetAmount())); } return AdvertisedBenefit; } @@ -11593,19 +11587,19 @@ void Unit::MeleeDamageBonus(Unit *pVictim, uint32 *pdamage, WeaponAttackType att AuraEffectList const &mModDamagePercentDone = GetAuraEffectsByType(SPELL_AURA_MOD_DAMAGE_PERCENT_DONE); for (AuraEffectList::const_iterator i = mModDamagePercentDone.begin(); i != mModDamagePercentDone.end(); ++i) if (((*i)->GetMiscValue() & GetSpellSchoolMask(spellProto)) && !((*i)->GetMiscValue() & SPELL_SCHOOL_MASK_NORMAL)) - DoneTotalMod *= ((*i)->GetAmount()+100.0f)/100.0f; + AddPctN(DoneTotalMod, (*i)->GetAmount()); } AuraEffectList const &mDamageDoneVersus = GetAuraEffectsByType(SPELL_AURA_MOD_DAMAGE_DONE_VERSUS); for (AuraEffectList::const_iterator i = mDamageDoneVersus.begin(); i != mDamageDoneVersus.end(); ++i) if (creatureTypeMask & uint32((*i)->GetMiscValue())) - DoneTotalMod *= ((*i)->GetAmount()+100.0f)/100.0f; + AddPctN(DoneTotalMod, (*i)->GetAmount()); // bonus against aurastate AuraEffectList const &mDamageDoneVersusAurastate = GetAuraEffectsByType(SPELL_AURA_MOD_DAMAGE_DONE_VERSUS_AURASTATE); for (AuraEffectList::const_iterator i = mDamageDoneVersusAurastate.begin(); i != mDamageDoneVersusAurastate.end(); ++i) if (pVictim->HasAuraState(AuraState((*i)->GetMiscValue()))) - DoneTotalMod *= ((*i)->GetAmount() + 100.0f) / 100.0f; + AddPctN(DoneTotalMod, (*i)->GetAmount()); // done scripted mod (take it from owner) Unit * owner = GetOwner() ? GetOwner() : this; @@ -11625,14 +11619,14 @@ void Unit::MeleeDamageBonus(Unit *pVictim, uint32 *pdamage, WeaponAttackType att if ((*i)->GetSpellProto()->SpellIconID == 2656) { if (!pVictim->HealthAbovePct(35)) - DoneTotalMod *= (100.0f+(*i)->GetAmount())/100.0f; + AddPctN(DoneTotalMod, (*i)->GetAmount()); } // Tundra Stalker else { // Frost Fever (target debuff) if (pVictim->HasAura(55095)) - DoneTotalMod *= ((*i)->GetAmount()+100.0f)/100.0f; + AddPctN(DoneTotalMod, (*i)->GetAmount()); } break; } @@ -11641,7 +11635,7 @@ void Unit::MeleeDamageBonus(Unit *pVictim, uint32 *pdamage, WeaponAttackType att { if (pVictim->GetAuraEffect(SPELL_AURA_PERIODIC_DAMAGE, SPELLFAMILY_DEATHKNIGHT, 0,0x02000000,0)) if (SpellChainNode const *chain = sSpellMgr.GetSpellChainNode((*i)->GetId())) - DoneTotalMod *= (chain->rank * 2.0f + 100.0f)/100.0f; + AddPctF(DoneTotalMod, chain->rank * 2.0f); break; } // Marked for Death @@ -11652,7 +11646,7 @@ void Unit::MeleeDamageBonus(Unit *pVictim, uint32 *pdamage, WeaponAttackType att case 7602: { if (pVictim->GetAuraEffect(SPELL_AURA_MOD_STALKED, SPELLFAMILY_HUNTER, 0x400, 0, 0)) - DoneTotalMod *= ((*i)->GetAmount() + 100.0f) / 100.0f; + AddPctN(DoneTotalMod, (*i)->GetAmount()); break; } } @@ -11667,7 +11661,7 @@ void Unit::MeleeDamageBonus(Unit *pVictim, uint32 *pdamage, WeaponAttackType att if (spellProto->SpellFamilyFlags[0] & 0x2 || spellProto->SpellFamilyFlags[1] & 0x6) if (AuraEffect * aurEff = GetDummyAuraEffect(SPELLFAMILY_DEATHKNIGHT, 196, 0)) if (pVictim->GetDiseasesByCaster(owner->GetGUID()) > 0) - DoneTotalMod *= (100.0f + aurEff->GetAmount()) / 100.0f; + AddPctN(DoneTotalMod, aurEff->GetAmount()); break; } @@ -11675,13 +11669,13 @@ void Unit::MeleeDamageBonus(Unit *pVictim, uint32 *pdamage, WeaponAttackType att AuraEffectList const& mModDamagePercentTaken = pVictim->GetAuraEffectsByType(SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN); for (AuraEffectList::const_iterator i = mModDamagePercentTaken.begin(); i != mModDamagePercentTaken.end(); ++i) if ((*i)->GetMiscValue() & GetMeleeDamageSchoolMask()) - TakenTotalMod *= ((*i)->GetAmount()+100.0f)/100.0f; + AddPctN(TakenTotalMod, (*i)->GetAmount()); // From caster spells AuraEffectList const& mOwnerTaken = pVictim->GetAuraEffectsByType(SPELL_AURA_MOD_DAMAGE_FROM_CASTER); for (AuraEffectList::const_iterator i = mOwnerTaken.begin(); i != mOwnerTaken.end(); ++i) if ((*i)->GetCasterGUID() == GetGUID() && (*i)->IsAffectedOnSpell(spellProto)) - TakenTotalMod *= ((*i)->GetAmount() + 100.0f) / 100.0f; + AddPctN(TakenTotalMod, (*i)->GetAmount()); // .. taken pct (special attacks) if (spellProto) @@ -11698,7 +11692,7 @@ void Unit::MeleeDamageBonus(Unit *pVictim, uint32 *pdamage, WeaponAttackType att AuraEffectList const& mDamageDoneMechanic = pVictim->GetAuraEffectsByType(SPELL_AURA_MOD_MECHANIC_DAMAGE_TAKEN_PERCENT); for (AuraEffectList::const_iterator i = mDamageDoneMechanic.begin(); i != mDamageDoneMechanic.end(); ++i) if (mechanicMask & uint32(1<<((*i)->GetMiscValue()))) - TakenTotalMod *= ((*i)->GetAmount()+100.0f)/100.0f; + AddPctN(TakenTotalMod, (*i)->GetAmount()); } } @@ -11715,9 +11709,7 @@ void Unit::MeleeDamageBonus(Unit *pVictim, uint32 *pdamage, WeaponAttackType att if (pVictim->GetTypeId() != TYPEID_PLAYER) continue; float mod = pVictim->ToPlayer()->GetRatingBonusValue(CR_CRIT_TAKEN_MELEE)*(-8.0f); - if (mod < (*i)->GetAmount()) - mod = (float)(*i)->GetAmount(); - TakenTotalMod *= (mod+100.0f)/100.0f; + AddPctF(TakenTotalMod, std::max(mod, float((*i)->GetAmount()))); } break; // Blessing of Sanctuary @@ -11729,13 +11721,13 @@ void Unit::MeleeDamageBonus(Unit *pVictim, uint32 *pdamage, WeaponAttackType att continue; if ((*i)->GetMiscValue() & (spellProto ? GetSpellSchoolMask(spellProto) : 0)) - TakenTotalMod *= ((*i)->GetAmount() + 100.0f) / 100.0f; + AddPctN(TakenTotalMod, (*i)->GetAmount()); break; } // Ebon Plague case 1933: if ((*i)->GetMiscValue() & (spellProto ? GetSpellSchoolMask(spellProto) : 0)) - TakenTotalMod *= ((*i)->GetAmount()+100.0f)/100.0f; + AddPctN(TakenTotalMod, (*i)->GetAmount()); break; } } @@ -11757,7 +11749,7 @@ void Unit::MeleeDamageBonus(Unit *pVictim, uint32 *pdamage, WeaponAttackType att } // effect 0 have expected value but in negative state - TakenTotalMod *= (-eff0->GetAmount()+100.0f)/100.0f; + AddPctN(TakenTotalMod, -eff0->GetAmount()); } break; } @@ -11767,13 +11759,13 @@ void Unit::MeleeDamageBonus(Unit *pVictim, uint32 *pdamage, WeaponAttackType att { AuraEffectList const& mModMeleeDamageTakenPercent = pVictim->GetAuraEffectsByType(SPELL_AURA_MOD_MELEE_DAMAGE_TAKEN_PCT); for (AuraEffectList::const_iterator i = mModMeleeDamageTakenPercent.begin(); i != mModMeleeDamageTakenPercent.end(); ++i) - TakenTotalMod *= ((*i)->GetAmount()+100.0f)/100.0f; + AddPctN(TakenTotalMod, (*i)->GetAmount()); } else { AuraEffectList const& mModRangedDamageTakenPercent = pVictim->GetAuraEffectsByType(SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN_PCT); for (AuraEffectList::const_iterator i = mModRangedDamageTakenPercent.begin(); i != mModRangedDamageTakenPercent.end(); ++i) - TakenTotalMod *= ((*i)->GetAmount()+100.0f)/100.0f; + AddPctN(TakenTotalMod, (*i)->GetAmount()); } float tmpDamage = float(int32(*pdamage) + DoneFlatBenefit) * DoneTotalMod; @@ -11783,7 +11775,7 @@ void Unit::MeleeDamageBonus(Unit *pVictim, uint32 *pdamage, WeaponAttackType att if (Player* modOwner = GetSpellModOwner()) modOwner->ApplySpellMod(spellProto->Id, SPELLMOD_DAMAGE, tmpDamage); - tmpDamage = (tmpDamage + TakenFlatBenefit)*TakenTotalMod; + tmpDamage = (tmpDamage + TakenFlatBenefit) * TakenTotalMod; // bonus result can be negative *pdamage = uint32(std::max(tmpDamage, 0.0f)); @@ -12265,7 +12257,7 @@ void Unit::UpdateSpeed(UnitMoveType mtype, bool forced) float stack_bonus = 1.0f; float non_stack_bonus = 1.0f; - switch(mtype) + switch (mtype) { // Only apply debuffs case MOVE_FLIGHT_BACK: @@ -12280,13 +12272,13 @@ void Unit::UpdateSpeed(UnitMoveType mtype, bool forced) { main_speed_mod = GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_MOUNTED_SPEED); stack_bonus = GetTotalAuraMultiplier(SPELL_AURA_MOD_MOUNTED_SPEED_ALWAYS); - non_stack_bonus = (100.0f + GetMaxPositiveAuraModifier(SPELL_AURA_MOD_MOUNTED_SPEED_NOT_STACK))/100.0f; + non_stack_bonus += GetMaxPositiveAuraModifier(SPELL_AURA_MOD_MOUNTED_SPEED_NOT_STACK) / 100.0f; } else { main_speed_mod = GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_SPEED); stack_bonus = GetTotalAuraMultiplier(SPELL_AURA_MOD_SPEED_ALWAYS); - non_stack_bonus = (100.0f + GetMaxPositiveAuraModifier(SPELL_AURA_MOD_SPEED_NOT_STACK))/100.0f; + non_stack_bonus += GetMaxPositiveAuraModifier(SPELL_AURA_MOD_SPEED_NOT_STACK) / 100.0f; } break; } @@ -12318,7 +12310,7 @@ void Unit::UpdateSpeed(UnitMoveType mtype, bool forced) else // Use not mount (shapeshift for example) auras (should stack) main_speed_mod = GetTotalAuraModifier(SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED) + GetTotalAuraModifier(SPELL_AURA_MOD_INCREASE_VEHICLE_FLIGHT_SPEED); - non_stack_bonus = (100.0f + GetMaxPositiveAuraModifier(SPELL_AURA_MOD_FLIGHT_SPEED_NOT_STACK))/100.0f; + non_stack_bonus += GetMaxPositiveAuraModifier(SPELL_AURA_MOD_FLIGHT_SPEED_NOT_STACK) / 100.0f; // Update speed for vehicle if available if (GetTypeId() == TYPEID_PLAYER && GetVehicle()) @@ -12330,12 +12322,12 @@ void Unit::UpdateSpeed(UnitMoveType mtype, bool forced) return; } - float bonus = non_stack_bonus > stack_bonus ? non_stack_bonus : stack_bonus; - // now we ready for speed calculation - float speed = main_speed_mod ? bonus*(100.0f + main_speed_mod)/100.0f : bonus; + float speed = std::max(non_stack_bonus, stack_bonus); + if (main_speed_mod) + AddPctN(speed, main_speed_mod); - switch(mtype) + switch (mtype) { case MOVE_RUN: case MOVE_SWIM: @@ -12371,7 +12363,7 @@ void Unit::UpdateSpeed(UnitMoveType mtype, bool forced) int32 slow = GetMaxNegativeAuraModifier(SPELL_AURA_MOD_DECREASE_SPEED); if (slow) { - speed *=(100.0f + slow)/100.0f; + AddPctN(speed, slow); if (float minSpeedMod = (float)GetMaxPositiveAuraModifier(SPELL_AURA_MOD_MINIMUM_SPEED)) { float min_speed = minSpeedMod / 100.0f; @@ -12814,21 +12806,21 @@ Unit* Creature::SelectVictim() //====================================================================== //====================================================================== -int32 Unit::ApplyEffectModifiers(SpellEntry const* spellProto, uint8 effect_index, int32 value) const +float Unit::ApplyEffectModifiers(SpellEntry const* spellProto, uint8 effect_index, float value) const { if (Player* modOwner = GetSpellModOwner()) { - modOwner->ApplySpellMod(spellProto->Id,SPELLMOD_ALL_EFFECTS, value); + modOwner->ApplySpellMod(spellProto->Id, SPELLMOD_ALL_EFFECTS, value); switch (effect_index) { case 0: - modOwner->ApplySpellMod(spellProto->Id,SPELLMOD_EFFECT1, value); + modOwner->ApplySpellMod(spellProto->Id, SPELLMOD_EFFECT1, value); break; case 1: - modOwner->ApplySpellMod(spellProto->Id,SPELLMOD_EFFECT2, value); + modOwner->ApplySpellMod(spellProto->Id, SPELLMOD_EFFECT2, value); break; case 2: - modOwner->ApplySpellMod(spellProto->Id,SPELLMOD_EFFECT3, value); + modOwner->ApplySpellMod(spellProto->Id, SPELLMOD_EFFECT3, value); break; } } @@ -12895,7 +12887,7 @@ int32 Unit::ModSpellDuration(SpellEntry const* spellProto, Unit const* target, i durationMod = durationMod_always; if (durationMod != 0) - duration = int32(float(duration) * float(100.0f+durationMod) / 100.0f); + AddPctN(duration, durationMod); // there are only negative mods currently durationMod_always = target->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_AURA_DURATION_BY_DISPEL, spellProto->Dispel); @@ -12908,7 +12900,7 @@ int32 Unit::ModSpellDuration(SpellEntry const* spellProto, Unit const* target, i durationMod += durationMod_always; if (durationMod != 0) - duration = int32(float(duration) * float(100.0f+durationMod) / 100.0f); + AddPctN(duration, durationMod); } else { @@ -12957,7 +12949,7 @@ int32 Unit::ModSpellDuration(SpellEntry const* spellProto, Unit const* target, i break; } } - return duration > 0 ? duration : 0; + return std::max(duration, 0); } void Unit::ModSpellCastTime(SpellEntry const* spellProto, int32 & castTime, Spell * spell) @@ -16291,10 +16283,8 @@ float Unit::GetCombatRatingReduction(CombatRating cr) const uint32 Unit::GetCombatRatingDamageReduction(CombatRating cr, float rate, float cap, uint32 damage) const { - float percent = GetCombatRatingReduction(cr) * rate; - if (percent > cap) - percent = cap; - return uint32 (percent * damage / 100.0f); + float percent = std::min(GetCombatRatingReduction(cr) * rate, cap); + return CalculatePctF(damage, percent); } uint32 Unit::GetModelForForm(ShapeshiftForm form) @@ -16938,22 +16928,22 @@ void Unit::RewardRage(uint32 damage, uint32 weaponSpeedHitFactor, bool attacker) { float addRage; - float rageconversion = ((0.0091107836f * getLevel()*getLevel())+3.225598133f*getLevel())+4.2652911f; + float rageconversion = ((0.0091107836f * getLevel() * getLevel()) + 3.225598133f * getLevel()) + 4.2652911f; // Unknown if correct, but lineary adjust rage conversion above level 70 if (getLevel() > 70) - rageconversion += 13.27f*(getLevel()-70); + rageconversion += 13.27f * (getLevel() - 70); if (attacker) { - addRage = ((damage/rageconversion*7.5f + weaponSpeedHitFactor)/2); + addRage = (damage / rageconversion * 7.5f + weaponSpeedHitFactor) / 2; // talent who gave more rage on attack - addRage *= 1.0f + GetTotalAuraModifier(SPELL_AURA_MOD_RAGE_FROM_DAMAGE_DEALT) / 100.0f; + AddPctN(addRage, GetTotalAuraModifier(SPELL_AURA_MOD_RAGE_FROM_DAMAGE_DEALT)); } else { - addRage = damage/rageconversion*2.5f; + addRage = damage / rageconversion * 2.5f; // Berserker Rage effect if (HasAura(18499)) @@ -16962,7 +16952,7 @@ void Unit::RewardRage(uint32 damage, uint32 weaponSpeedHitFactor, bool attacker) addRage *= sWorld.getRate(RATE_POWER_RAGE_INCOME); - ModifyPower(POWER_RAGE, uint32(addRage*10)); + ModifyPower(POWER_RAGE, uint32(addRage * 10)); } void Unit::StopAttackFaction(uint32 faction_id) diff --git a/src/server/game/Entities/Unit/Unit.h b/src/server/game/Entities/Unit/Unit.h index 15fc7473251..2a5cdb36139 100755 --- a/src/server/game/Entities/Unit/Unit.h +++ b/src/server/game/Entities/Unit/Unit.h @@ -1211,8 +1211,8 @@ class Unit : public WorldObject inline bool HealthBelowPct(int32 pct) const { return GetHealth() * (uint64)100 < GetMaxHealth() * (uint64)pct; } inline bool HealthBelowPctDamaged(int32 pct, uint32 damage) const { return (int32(GetHealth()) - damage) * (int64)100 < GetMaxHealth() * (int64)pct; } inline bool HealthAbovePct(int32 pct) const { return GetHealth() * (uint64)100 > GetMaxHealth() * (uint64)pct; } - inline float GetHealthPct() const { return GetMaxHealth() ? 100.f * GetHealth() / GetMaxHealth() : 0.0f; } - inline uint32 CountPctFromMaxHealth(int32 pct) const { return uint32(float(pct) * GetMaxHealth() / 100.0f); } + inline float GetHealthPct() const { return GetMaxHealth() ? 100.f * GetHealth() / GetMaxHealth() : 0.0f; } + inline uint32 CountPctFromMaxHealth(int32 pct) const { return CalculatePctN(GetMaxHealth(), pct); } void SetHealth(uint32 val); void SetMaxHealth(uint32 val); @@ -1885,7 +1885,7 @@ class Unit : public WorldObject void SetHover(bool on); bool isHover() const { return HasAuraType(SPELL_AURA_HOVER); } - int32 ApplyEffectModifiers(SpellEntry const* spellProto, uint8 effect_index, int32 value) const; + float ApplyEffectModifiers(SpellEntry const* spellProto, uint8 effect_index, float value) const; int32 CalculateSpellDamage(Unit const* target, SpellEntry const* spellProto, uint8 effect_index, int32 const* basePoints = NULL) const; int32 CalcSpellDuration(SpellEntry const* spellProto); int32 ModSpellDuration(SpellEntry const* spellProto, Unit const* target, int32 duration, bool positive); diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp index d5b8786c280..11739172214 100755 --- a/src/server/game/Globals/ObjectMgr.cpp +++ b/src/server/game/Globals/ObjectMgr.cpp @@ -9011,7 +9011,7 @@ uint32 ObjectMgr::GetScriptId(const char *name) ScriptNameMap::const_iterator itr = std::lower_bound(m_scriptNames.begin(), m_scriptNames.end(), name); if (itr == m_scriptNames.end() || *itr != name) return 0; - return itr - m_scriptNames.begin(); + return uint32(itr - m_scriptNames.begin()); } void ObjectMgr::CheckScripts(ScriptsType type, std::set<int32>& ids) diff --git a/src/server/game/OutdoorPvP/OutdoorPvP.cpp b/src/server/game/OutdoorPvP/OutdoorPvP.cpp index af543c27ea8..06d3e37f7c2 100755 --- a/src/server/game/OutdoorPvP/OutdoorPvP.cpp +++ b/src/server/game/OutdoorPvP/OutdoorPvP.cpp @@ -135,7 +135,7 @@ bool OPvPCapturePoint::SetCapturePointData(uint32 entry, uint32 map, float x, fl m_maxValue = (float)goinfo->capturePoint.maxTime; m_maxSpeed = m_maxValue / (goinfo->capturePoint.minTime ? goinfo->capturePoint.minTime : 60); m_neutralValuePct = goinfo->capturePoint.neutralPercent; - m_minValue = m_maxValue * goinfo->capturePoint.neutralPercent / 100; + m_minValue = CalculatePctU(m_maxValue, m_neutralValuePct); return true; } diff --git a/src/server/game/Server/WorldSocket.cpp b/src/server/game/Server/WorldSocket.cpp index b4e77af2f09..f6df407279a 100755 --- a/src/server/game/Server/WorldSocket.cpp +++ b/src/server/game/Server/WorldSocket.cpp @@ -562,7 +562,7 @@ int WorldSocket::handle_input_missing_data (void) recv_size); if (n <= 0) - return n; + return int(n); message_block.wr_ptr (n); diff --git a/src/server/game/Spells/Auras/SpellAuraEffects.cpp b/src/server/game/Spells/Auras/SpellAuraEffects.cpp index 577deee44e1..03780375f00 100755 --- a/src/server/game/Spells/Auras/SpellAuraEffects.cpp +++ b/src/server/game/Spells/Auras/SpellAuraEffects.cpp @@ -472,7 +472,7 @@ int32 AuraEffect::CalculateAmount(Unit * caster) // Glyph of Fear, Glyph of Frost nova and similar auras if ((*itr)->GetMiscValue() == 7801) { - amount += (int32)(amount*(*itr)->GetAmount()/100.0f); + AddPctN(amount, (*itr)->GetAmount()); break; } } @@ -493,7 +493,7 @@ int32 AuraEffect::CalculateAmount(Unit * caster) DoneActualBenefit += caster->SpellBaseDamageBonus(GetSpellSchoolMask(m_spellProto)) * 0.8068f; // Glyph of Ice Barrier: its weird having a SPELLMOD_ALL_EFFECTS here but its blizzards doing :) // Glyph of Ice Barrier is only applied at the spell damage bonus because it was already applied to the base value in CalculateSpellDamage - DoneActualBenefit = caster->ApplyEffectModifiers(GetSpellProto(), m_effIndex, (int32)DoneActualBenefit); + DoneActualBenefit = caster->ApplyEffectModifiers(GetSpellProto(), m_effIndex, DoneActualBenefit); } // Fire Ward else if(GetSpellProto()->SpellFamilyFlags[0] & 0x8 && GetSpellProto()->SpellFamilyFlags[2] & 0x8) @@ -520,27 +520,27 @@ int32 AuraEffect::CalculateAmount(Unit * caster) // Power Word: Shield if (GetSpellProto()->SpellFamilyFlags[0] & 0x1 && GetSpellProto()->SpellFamilyFlags[2] & 0x400) { - //+80.68% from sp bonus + // +80.68% from sp bonus float bonus = 0.8068f; // Borrowed Time if (AuraEffect const* pAurEff = caster->GetAuraEffect(SPELL_AURA_DUMMY, SPELLFAMILY_PRIEST, 2899, 1)) - bonus += (float)pAurEff->GetAmount() / 100.0f; + bonus += CalculatePctN(1.0f, pAurEff->GetAmount()); DoneActualBenefit += caster->SpellBaseHealingBonus(GetSpellSchoolMask(m_spellProto)) * bonus; // Improved PW: Shield: its weird having a SPELLMOD_ALL_EFFECTS here but its blizzards doing :) // Improved PW: Shield is only applied at the spell healing bonus because it was already applied to the base value in CalculateSpellDamage - DoneActualBenefit = caster->ApplyEffectModifiers(GetSpellProto(), m_effIndex, (int32)DoneActualBenefit); + DoneActualBenefit = caster->ApplyEffectModifiers(GetSpellProto(), m_effIndex, DoneActualBenefit); DoneActualBenefit *= caster->CalculateLevelPenalty(GetSpellProto()); - amount += (int32)DoneActualBenefit; + amount += int32(DoneActualBenefit); // Twin Disciplines if (AuraEffect const* pAurEff = caster->GetAuraEffect(SPELL_AURA_ADD_PCT_MODIFIER, SPELLFAMILY_PRIEST, 0x400000, 0, 0, caster->GetGUID())) - amount *= (100.0f + pAurEff->GetAmount()) / 100.0f; + AddPctN(amount, pAurEff->GetAmount()); // Focused Power - amount *= caster->GetTotalAuraMultiplier(SPELL_AURA_MOD_HEALING_DONE_PERCENT); + amount *= int32(caster->GetTotalAuraMultiplier(SPELL_AURA_MOD_HEALING_DONE_PERCENT)); return amount; } @@ -554,17 +554,17 @@ int32 AuraEffect::CalculateAmount(Unit * caster) DoneActualBenefit += caster->SpellBaseHealingBonus(GetSpellSchoolMask(m_spellProto)) * bonus; // Divine Guardian is only applied at the spell healing bonus because it was already applied to the base value in CalculateSpellDamage - DoneActualBenefit = caster->ApplyEffectModifiers(GetSpellProto(), m_effIndex, (int32)DoneActualBenefit); + DoneActualBenefit = caster->ApplyEffectModifiers(GetSpellProto(), m_effIndex, DoneActualBenefit); DoneActualBenefit *= caster->CalculateLevelPenalty(GetSpellProto()); amount += (int32)DoneActualBenefit; // Arena - Dampening if (AuraEffect const* pAurEff = caster->GetAuraEffect(74410, 0)) - amount *= (100.0f + pAurEff->GetAmount()) / 100.0f; + AddPctN(amount, pAurEff->GetAmount()); // Battleground - Dampening else if (AuraEffect const* pAurEff = caster->GetAuraEffect(74411, 0)) - amount *= (100.0f + pAurEff->GetAmount()) / 100.0f; + AddPctN(amount, pAurEff->GetAmount()); return amount; } @@ -632,24 +632,25 @@ int32 AuraEffect::CalculateAmount(Unit * caster) if (AuraEffect const * aurEff = caster->GetAuraEffect(34241,0)) amount += cp * aurEff->GetAmount(); - amount += int32(caster->GetTotalAttackPowerValue(BASE_ATTACK) * cp / 100); + amount += CalculatePctF(cp, caster->GetTotalAttackPowerValue(BASE_ATTACK)); } // Rend else if (GetSpellProto()->SpellFamilyName == SPELLFAMILY_WARRIOR && GetSpellProto()->SpellFamilyFlags[0] & 0x20) { m_canBeRecalculated = false; - // $0.2*(($MWB+$mwb)/2+$AP/14*$MWS) bonus per tick + // $0.2 * (($MWB + $mwb) / 2 + $AP / 14 * $MWS) bonus per tick float ap = caster->GetTotalAttackPowerValue(BASE_ATTACK); int32 mws = caster->GetAttackTime(BASE_ATTACK); float mwb_min = caster->GetWeaponDamageRange(BASE_ATTACK,MINDAMAGE); float mwb_max = caster->GetWeaponDamageRange(BASE_ATTACK,MAXDAMAGE); - amount+=caster->ApplyEffectModifiers(m_spellProto,m_effIndex,int32(((mwb_min+mwb_max)/2+ap*mws/14000)*0.2f)); + float mwb = ((mwb_min + mwb_max) / 2 + ap * mws / 14000) * 0.2f; + amount += int32(caster->ApplyEffectModifiers(m_spellProto, m_effIndex, mwb)); // "If used while your target is above 75% health, Rend does 35% more damage." // as for 3.1.3 only ranks above 9 (wrong tooltip?) if (sSpellMgr.GetSpellRank(m_spellProto->Id) >= 9) { if (GetBase()->GetUnitOwner()->HasAuraState(AURA_STATE_HEALTH_ABOVE_75_PERCENT, m_spellProto, caster)) - amount += int32(amount * SpellMgr::CalculateSpellEffectAmount(m_spellProto, 2, caster) / 100.0f); + AddPctN(amount, SpellMgr::CalculateSpellEffectAmount(m_spellProto, 2, caster)); } } // Unholy Blight damage over time effect @@ -670,10 +671,10 @@ int32 AuraEffect::CalculateAmount(Unit * caster) } // Innervate else if (m_spellProto->Id == 29166) - amount = int32(GetBase()->GetUnitOwner()->GetCreatePowers(POWER_MANA) * amount / (GetTotalTicks() * 100.0f)); + ApplyPctF(amount, float(GetBase()->GetUnitOwner()->GetCreatePowers(POWER_MANA)) / GetTotalTicks()); // Owlkin Frenzy else if (m_spellProto->Id == 48391) - amount = GetBase()->GetUnitOwner()->GetCreatePowers(POWER_MANA) * amount / 100; + ApplyPctU(amount, GetBase()->GetUnitOwner()->GetCreatePowers(POWER_MANA)); break; case SPELL_AURA_PERIODIC_HEAL: if (!caster) @@ -684,7 +685,7 @@ int32 AuraEffect::CalculateAmount(Unit * caster) if (caster->GetTypeId() == TYPEID_PLAYER) // Bonus from Glyph of Lightwell if (AuraEffect* modHealing = caster->GetAuraEffect(55673, 0)) - amount = int32(amount * (100.0f + modHealing->GetAmount()) / 100.0f); + AddPctN(amount, modHealing->GetAmount()); } break; case SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN: @@ -749,7 +750,7 @@ int32 AuraEffect::CalculateAmount(Unit * caster) case SPELL_AURA_MOD_INCREASE_ENERGY: // Hymn of Hope if (GetId() == 64904) - amount = GetBase()->GetUnitOwner()->GetMaxPower(GetBase()->GetUnitOwner()->getPowerType()) * amount / 100; + ApplyPctU(amount, GetBase()->GetUnitOwner()->GetMaxPower(GetBase()->GetUnitOwner()->getPowerType())); break; case SPELL_AURA_MOD_INCREASE_SPEED: // Dash - do not set speed if not in cat form @@ -1550,27 +1551,27 @@ void AuraEffect::PeriodicTick(AuraApplication * aurApp, Unit * caster) const // Tenacity increase healing % taken if (AuraEffect const* Tenacity = target->GetAuraEffect(58549, 0)) - TakenTotalMod *= (Tenacity->GetAmount() + 100.0f) / 100.0f; + AddPctN(TakenTotalMod, Tenacity->GetAmount()); // Healing taken percent float minval = (float)target->GetMaxNegativeAuraModifier(SPELL_AURA_MOD_HEALING_PCT); if (minval) - TakenTotalMod *= (100.0f + minval) / 100.0f; + AddPctF(TakenTotalMod, minval); float maxval = (float)target->GetMaxPositiveAuraModifier(SPELL_AURA_MOD_HEALING_PCT); if (maxval) - TakenTotalMod *= (100.0f + maxval) / 100.0f; + AddPctF(TakenTotalMod, maxval); // Healing over time taken percent float minval_hot = (float)target->GetMaxNegativeAuraModifier(SPELL_AURA_MOD_HOT_PCT); if (minval_hot) - TakenTotalMod *= (100.0f + minval_hot) / 100.0f; + AddPctF(TakenTotalMod, minval_hot); float maxval_hot = (float)target->GetMaxPositiveAuraModifier(SPELL_AURA_MOD_HOT_PCT); if (maxval_hot) - TakenTotalMod *= (100.0f + maxval_hot) / 100.0f; + AddPctF(TakenTotalMod, maxval_hot); - TakenTotalMod = TakenTotalMod > 0.0f ? TakenTotalMod : 0.0f; + TakenTotalMod = std::max(TakenTotalMod, 0.0f); damage = uint32(target->CountPctFromMaxHealth(damage)); damage = uint32(damage * TakenTotalMod); @@ -1670,8 +1671,8 @@ void AuraEffect::PeriodicTick(AuraApplication * aurApp, Unit * caster) const if (m_spellProto->ManaCostPercentage) { // max value - uint32 maxmana = caster->GetMaxPower(power) * damage * 2 / 100; - damage = target->GetMaxPower(power) * damage / 100; + uint32 maxmana = CalculatePctF(caster->GetMaxPower(power), damage * 2.0f); + ApplyPctU(damage, target->GetMaxPower(power)); if (damage > maxmana) damage = maxmana; } @@ -1679,7 +1680,7 @@ void AuraEffect::PeriodicTick(AuraApplication * aurApp, Unit * caster) const sLog.outDetail("PeriodicTick: %u (TypeId: %u) power leech of %u (TypeId: %u) for %u dmg inflicted by %u", GUID_LOPART(GetCasterGUID()), GuidHigh2TypeId(GUID_HIPART(GetCasterGUID())), target->GetGUIDLow(), target->GetTypeId(), damage, GetId()); - int32 drain_amount = target->GetPower(power) > damage ? damage : target->GetPower(power); + int32 drain_amount = std::min(target->GetPower(power), damage); // resilience reduce mana draining effect at spell crit damage reduction (added in 2.4) if (power == POWER_MANA) @@ -1699,7 +1700,7 @@ void AuraEffect::PeriodicTick(AuraApplication * aurApp, Unit * caster) const if (gain_amount) { - int32 gain = caster->ModifyPower(power,gain_amount); + int32 gain = caster->ModifyPower(power, gain_amount); target->AddThreat(caster, float(gain) * 0.5f, GetSpellSchoolMask(GetSpellProto()), GetSpellProto()); } @@ -1735,7 +1736,7 @@ void AuraEffect::PeriodicTick(AuraApplication * aurApp, Unit * caster) const // Mana Feed - Drain Mana if (manaFeedVal > 0) { - manaFeedVal = manaFeedVal * gain_amount / 100; + ApplyPctN(manaFeedVal, gain_amount); caster->CastCustomSpell(caster, 32554, &manaFeedVal, NULL, NULL, true, NULL, this); } } @@ -5570,10 +5571,10 @@ void AuraEffect::HandleModPowerCostPCT(AuraApplication const * aurApp, uint8 mod Unit * target = aurApp->GetTarget(); - float amount = GetAmount() /100.0f; + float amount = CalculatePctN(1.0f, GetAmount()); for (int i = 0; i < MAX_SPELL_SCHOOL; ++i) - if (GetMiscValue() & (1<<i)) - target->ApplyModSignedFloatValue(UNIT_FIELD_POWER_COST_MULTIPLIER+i,amount,apply); + if (GetMiscValue() & (1 << i)) + target->ApplyModSignedFloatValue(UNIT_FIELD_POWER_COST_MULTIPLIER + i, amount, apply); } void AuraEffect::HandleModPowerCost(AuraApplication const * aurApp, uint8 mode, bool apply) const @@ -5930,7 +5931,7 @@ void AuraEffect::HandleAuraDummy(AuraApplication const * aurApp, uint8 mode, boo // restore mana if (caster) { - int32 returnmana = (GetSpellProto()->ManaCostPercentage * caster->GetCreateMana() / 100) * stack / 2; + int32 returnmana = CalculatePctU(caster->GetCreateMana(), GetSpellProto()->ManaCostPercentage) * stack / 2; caster->CastCustomSpell(caster, 64372, &returnmana, NULL, NULL, true, NULL, this, GetCasterGUID()); } } diff --git a/src/server/game/Spells/Auras/SpellAuras.cpp b/src/server/game/Spells/Auras/SpellAuras.cpp index 05e3b937ab0..21cad6bdd3f 100755 --- a/src/server/game/Spells/Auras/SpellAuras.cpp +++ b/src/server/game/Spells/Auras/SpellAuras.cpp @@ -988,10 +988,10 @@ void Aura::HandleAuraSpecificMods(AuraApplication const * aurApp, Unit * caster, case 48020: // Demonic Circle if (target->GetTypeId() == TYPEID_PLAYER) if (GameObject* obj = target->GetGameObject(48018)) - { - target->ToPlayer()->TeleportTo(obj->GetMapId(),obj->GetPositionX(),obj->GetPositionY(),obj->GetPositionZ(),obj->GetOrientation()); - target->ToPlayer()->RemoveMovementImpairingAuras(); - } + { + target->ToPlayer()->TeleportTo(obj->GetMapId(),obj->GetPositionX(),obj->GetPositionY(),obj->GetPositionZ(),obj->GetOrientation()); + target->ToPlayer()->RemoveMovementImpairingAuras(); + } break; } break; @@ -1271,7 +1271,7 @@ void Aura::HandleAuraSpecificMods(AuraApplication const * aurApp, Unit * caster, else if (aurEff->GetId() == 47537) multiplier += 0.5f; - int32 basepoints0 = int32(multiplier * caster->GetMaxPower(POWER_MANA) / 100); + int32 basepoints0 = int32(CalculatePctF(caster->GetMaxPower(POWER_MANA), multiplier)); caster->CastCustomSpell(caster, 47755, &basepoints0, NULL, NULL, true); } // effect on aura target @@ -1285,7 +1285,7 @@ void Aura::HandleAuraSpecificMods(AuraApplication const * aurApp, Unit * caster, { case POWER_MANA: { - int32 basepoints0 = 2 * (target->GetMaxPower(POWER_MANA) / 100); + int32 basepoints0 = int32(CalculatePctN(target->GetMaxPower(POWER_MANA), 2)); caster->CastCustomSpell(target, 63654, &basepoints0, NULL, NULL, true); break; } diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp index 3d04295988c..a0dee3630d1 100755 --- a/src/server/game/Spells/Spell.cpp +++ b/src/server/game/Spells/Spell.cpp @@ -1298,7 +1298,7 @@ void Spell::DoAllEffectOnTarget(TargetInfo *target) if (m_spellInfo->SpellFamilyName == SPELLFAMILY_WARLOCK && m_spellInfo->SpellFamilyFlags[1] & 0x40000 && m_spellAura && m_spellAura->GetEffect(1)) { AuraEffect * aurEff = m_spellAura->GetEffect(1); - aurEff->SetAmount(aurEff->GetAmount() * damageInfo.damage / 100); + aurEff->SetAmount(CalculatePctU(aurEff->GetAmount(), damageInfo.damage)); } } // Passive spell hits/misses or active spells only misses (only triggers) @@ -6450,7 +6450,7 @@ void Spell::Delayed() // only called in DealDamage() if (delayReduce >= 100) return; - delaytime = delaytime * (100 - delayReduce) / 100; + AddPctN(delaytime, -delayReduce); if (int32(m_timer) + delaytime > m_casttime) { @@ -6478,14 +6478,14 @@ void Spell::DelayedChannel() return; //check pushback reduce - int32 delaytime = GetSpellDuration(m_spellInfo) * 25 / 100; // channeling delay is normally 25% of its time per hit + int32 delaytime = CalculatePctN(GetSpellDuration(m_spellInfo), 25); // channeling delay is normally 25% of its time per hit int32 delayReduce = 100; // must be initialized to 100 for percent modifiers m_caster->ToPlayer()->ApplySpellMod(m_spellInfo->Id, SPELLMOD_NOT_LOSE_CASTING_TIME, delayReduce, this); delayReduce += m_caster->GetTotalAuraModifier(SPELL_AURA_REDUCE_PUSHBACK) - 100; if (delayReduce >= 100) return; - delaytime = delaytime * (100 - delayReduce) / 100; + AddPctN(delaytime, -delayReduce); if (int32(m_timer) <= delaytime) { diff --git a/src/server/game/Spells/SpellEffects.cpp b/src/server/game/Spells/SpellEffects.cpp index 23fe73ef738..8f4bf73c1a3 100755 --- a/src/server/game/Spells/SpellEffects.cpp +++ b/src/server/game/Spells/SpellEffects.cpp @@ -460,14 +460,14 @@ void Spell::SpellDamageSchoolDmg(SpellEffIndex effIndex) { // Bloodthirst if (m_spellInfo->SpellFamilyFlags[1] & 0x400) - damage = uint32(damage * (m_caster->GetTotalAttackPowerValue(BASE_ATTACK)) / 100); + ApplyPctF(damage, m_caster->GetTotalAttackPowerValue(BASE_ATTACK)); // Shield Slam else if (m_spellInfo->SpellFamilyFlags[1] & 0x200 && m_spellInfo->Category == 1209) - damage += m_caster->ApplyEffectModifiers(m_spellInfo,effIndex,int32(m_caster->GetShieldBlockValue())); + damage += int32(m_caster->ApplyEffectModifiers(m_spellInfo, effIndex, float(m_caster->GetShieldBlockValue()))); // Victory Rush else if (m_spellInfo->SpellFamilyFlags[1] & 0x100) { - damage = uint32(damage * m_caster->GetTotalAttackPowerValue(BASE_ATTACK) / 100); + ApplyPctF(damage, m_caster->GetTotalAttackPowerValue(BASE_ATTACK)); m_caster->ModifyAuraState(AURA_STATE_WARRIOR_VICTORY_RUSH, false); } // Shockwave @@ -475,7 +475,7 @@ void Spell::SpellDamageSchoolDmg(SpellEffIndex effIndex) { int32 pct = m_caster->CalculateSpellDamage(unitTarget, m_spellInfo, 2); if (pct > 0) - damage+= int32(m_caster->GetTotalAttackPowerValue(BASE_ATTACK) * pct / 100); + damage += int32(CalculatePctN(m_caster->GetTotalAttackPowerValue(BASE_ATTACK), pct)); break; } break; @@ -521,14 +521,14 @@ void Spell::SpellDamageSchoolDmg(SpellEffIndex effIndex) // found Immolate or Shadowflame if (aura) { - uint32 pdamage = aura->GetAmount() > 0 ? aura->GetAmount() : 0; + uint32 pdamage = uint32(std::max(aura->GetAmount(), 0)); pdamage = m_caster->SpellDamageBonus(unitTarget, aura->GetSpellProto(), pdamage, DOT, aura->GetBase()->GetStackAmount()); uint32 pct_dir = m_caster->CalculateSpellDamage(unitTarget, m_spellInfo, (effIndex + 1)); uint8 baseTotalTicks = uint8(m_caster->CalcSpellDuration(aura->GetSpellProto()) / aura->GetSpellProto()->EffectAmplitude[0]); - damage += pdamage * baseTotalTicks * pct_dir / 100; + damage += int32(CalculatePctU(pdamage * baseTotalTicks, pct_dir)); uint32 pct_dot = m_caster->CalculateSpellDamage(unitTarget, m_spellInfo, (effIndex + 2)) / 3; - m_spellValue->EffectBasePoints[1] = SpellMgr::CalculateSpellEffectBaseAmount(pdamage * baseTotalTicks * pct_dot / 100, m_spellInfo, 1); + m_spellValue->EffectBasePoints[1] = SpellMgr::CalculateSpellEffectBaseAmount(int32(CalculatePctU(pdamage * baseTotalTicks, pct_dot)), m_spellInfo, 1); apply_direct_bonus = false; // Glyph of Conflagrate @@ -542,10 +542,8 @@ void Spell::SpellDamageSchoolDmg(SpellEffIndex effIndex) else if (m_spellInfo->SpellFamilyFlags[1] & 0x400000) { if (m_caster->GetTypeId() == TYPEID_UNIT && m_caster->ToCreature()->isPet()) - { // Get DoTs on target by owner (5% increase by dot) - damage += 5 * unitTarget->GetDoTsByCaster(m_caster->GetOwnerGUID()) / 100; - } + damage += int32(CalculatePctN(unitTarget->GetDoTsByCaster(m_caster->GetOwnerGUID()), 5)); } break; } @@ -557,7 +555,7 @@ void Spell::SpellDamageSchoolDmg(SpellEffIndex effIndex) int32 back_damage = m_caster->SpellDamageBonus(unitTarget, m_spellInfo, (uint32)damage, SPELL_DIRECT_DAMAGE); // Pain and Suffering reduces damage if (AuraEffect * aurEff = m_caster->GetDummyAuraEffect(SPELLFAMILY_PRIEST, 2874, 0)) - back_damage -= aurEff->GetAmount() * back_damage / 100; + AddPctN(back_damage, -aurEff->GetAmount()); if (back_damage < int32(unitTarget->GetHealth())) m_caster->CastCustomSpell(m_caster, 32409, &back_damage, 0, 0, true); @@ -579,7 +577,7 @@ void Spell::SpellDamageSchoolDmg(SpellEffIndex effIndex) // Glyph of Smite if (AuraEffect * aurEff = m_caster->GetAuraEffect(55692, 0)) if (unitTarget->GetAuraEffect(SPELL_AURA_PERIODIC_DAMAGE, SPELLFAMILY_PRIEST, 0x100000, 0, 0, m_caster->GetGUID())) - damage += damage * aurEff->GetAmount() / 100; + AddPctN(damage, aurEff->GetAmount()); } // Improved Mind Blast (Mind Blast in shadow form bonus) else if (m_caster->GetShapeshiftForm() == FORM_SHADOW && (m_spellInfo->SpellFamilyFlags[0] & 0x00002000)) @@ -610,7 +608,7 @@ void Spell::SpellDamageSchoolDmg(SpellEffIndex effIndex) float multiple = ap / 410 + m_spellInfo->EffectDamageMultiplier[effIndex]; int32 energy = -(m_caster->ModifyPower(POWER_ENERGY, -30)); damage += int32(energy * multiple); - damage += int32(m_caster->ToPlayer()->GetComboPoints() * ap * 7 / 100); + damage += int32(CalculatePctN(m_caster->ToPlayer()->GetComboPoints() * ap, 7)); } // Wrath else if (m_spellInfo->SpellFamilyFlags[0] & 0x00000001) @@ -618,7 +616,7 @@ void Spell::SpellDamageSchoolDmg(SpellEffIndex effIndex) // Improved Insect Swarm if (AuraEffect const * aurEff = m_caster->GetDummyAuraEffect(SPELLFAMILY_DRUID, 1771, 0)) if (unitTarget->GetAuraEffect(SPELL_AURA_PERIODIC_DAMAGE, SPELLFAMILY_DRUID, 0x00200000, 0, 0)) - damage = int32(damage*(100.0f+aurEff->GetAmount())/100.0f); + AddPctN(damage, aurEff->GetAmount()); } break; } @@ -739,7 +737,7 @@ void Spell::SpellDamageSchoolDmg(SpellEffIndex effIndex) // Shield of Righteousness if (m_spellInfo->SpellFamilyFlags[EFFECT_1] & 0x100000) { - damage += m_caster->GetShieldBlockValue() * SpellMgr::CalculateSpellEffectAmount(m_spellInfo, EFFECT_1) / 100; + damage += CalculatePctN(m_caster->GetShieldBlockValue(), SpellMgr::CalculateSpellEffectAmount(m_spellInfo, EFFECT_1)); break; } break; @@ -1255,7 +1253,7 @@ void Spell::EffectDummy(SpellEffIndex effIndex) // Concussion Blow if (m_spellInfo->SpellFamilyFlags[0] & SPELLFAMILYFLAG_WARRIOR_CONCUSSION_BLOW) { - m_damage+= uint32(damage * m_caster->GetTotalAttackPowerValue(BASE_ATTACK) / 100); + m_damage += CalculatePctF(damage, m_caster->GetTotalAttackPowerValue(BASE_ATTACK)); return; } switch(m_spellInfo->Id) @@ -1289,7 +1287,7 @@ void Spell::EffectDummy(SpellEffIndex effIndex) // Improved Life Tap mod if (AuraEffect const * aurEff = m_caster->GetDummyAuraEffect(SPELLFAMILY_WARLOCK, 208, 0)) - mana = (aurEff->GetAmount() + 100)* mana / 100; + AddPctN(mana, aurEff->GetAmount()); m_caster->CastCustomSpell(unitTarget, 31818, &mana, NULL, NULL, true); @@ -1300,7 +1298,7 @@ void Spell::EffectDummy(SpellEffIndex effIndex) if (manaFeedVal > 0) { - manaFeedVal = manaFeedVal * mana / 100; + ApplyPctN(manaFeedVal, mana); m_caster->CastCustomSpell(m_caster, 32553, &manaFeedVal, NULL, NULL, true, NULL); } } @@ -1333,7 +1331,7 @@ void Spell::EffectDummy(SpellEffIndex effIndex) // Divine Storm if (m_spellInfo->SpellFamilyFlags[1] & SPELLFAMILYFLAG1_PALADIN_DIVINESTORM && effIndex == 1) { - int32 dmg = m_damage * damage / 100; + int32 dmg = CalculatePctN(m_damage, damage); if (!unitTarget) unitTarget = m_caster; m_caster->CastCustomSpell(unitTarget, 54171, &dmg, 0, 0, true); @@ -1383,7 +1381,7 @@ void Spell::EffectDummy(SpellEffIndex effIndex) // Restorative Totems if (Unit *owner = m_caster->GetOwner()) if (AuraEffect *dummy = owner->GetAuraEffect(SPELL_AURA_DUMMY, SPELLFAMILY_SHAMAN, 338, 1)) - damage += damage * dummy->GetAmount() / 100; + AddPctN(damage, dummy->GetAmount()); m_caster->CastCustomSpell(unitTarget, 52042, &damage, 0, 0, true, 0, 0, m_originalCasterGUID); return; @@ -1406,7 +1404,7 @@ void Spell::EffectDummy(SpellEffIndex effIndex) { // Damage is increased by 25% if your off-hand weapon is enchanted with Flametongue. if (m_caster->GetAuraEffect(SPELL_AURA_DUMMY, SPELLFAMILY_SHAMAN, 0x200000, 0, 0)) - m_damage += m_damage * damage / 100; + AddPctN(m_damage, damage); } return; } @@ -1419,7 +1417,7 @@ void Spell::EffectDummy(SpellEffIndex effIndex) int32 bp = int32(count * m_caster->CountPctFromMaxHealth(int32(m_spellInfo->EffectDamageMultiplier[0]))); // Improved Death Strike if (AuraEffect const * aurEff = m_caster->GetAuraEffect(SPELL_AURA_ADD_PCT_MODIFIER, SPELLFAMILY_DEATHKNIGHT, 2751, 0)) - bp = int32(bp * (m_caster->CalculateSpellDamage(m_caster, aurEff->GetSpellProto(), 2) + 100.0f) / 100.0f); + AddPctN(bp, m_caster->CalculateSpellDamage(m_caster, aurEff->GetSpellProto(), 2)); m_caster->CastCustomSpell(m_caster, 45470, &bp, NULL, NULL, false); return; } @@ -2115,8 +2113,8 @@ void Spell::EffectPowerBurn(SpellEffIndex effIndex) // burn x% of target's mana, up to maximum of 2x% of caster's mana (Mana Burn) if (m_spellInfo->ManaCostPercentage) { - int32 maxDamage = m_caster->GetMaxPower(powerType) * damage * 2 / 100; - damage = unitTarget->GetMaxPower(powerType) * damage / 100; + int32 maxDamage = int32(CalculatePctN(m_caster->GetMaxPower(powerType), damage * 2)); + damage = int32(CalculatePctN(unitTarget->GetMaxPower(powerType), damage)); damage = std::min(damage, maxDamage); } @@ -2224,7 +2222,7 @@ void Spell::SpellDamageHeal(SpellEffIndex /*effIndex*/) for (Unit::AuraEffectList::const_iterator i = Periodic.begin(); i != Periodic.end(); ++i) { if (m_caster->GetGUID() == (*i)->GetCasterGUID()) - addhealth += addhealth * aurEff->GetAmount() / 100; + AddPctN(addhealth, aurEff->GetAmount()); } } } @@ -2530,10 +2528,10 @@ void Spell::EffectEnergize(SpellEffIndex effIndex) case 31930: // Judgements of the Wise case 63375: // Improved Stormstrike case 68082: // Glyph of Seal of Command - damage = damage * unitTarget->GetCreateMana() / 100; + damage = int32(CalculatePctN(unitTarget->GetCreateMana(), damage)); break; case 48542: // Revitalize - damage = damage * unitTarget->GetMaxPower(power) / 100; + damage = int32(CalculatePctN(unitTarget->GetMaxPower(power), damage)); break; default: break; @@ -2616,7 +2614,7 @@ void Spell::EffectEnergizePct(SpellEffIndex effIndex) if (maxPower == 0) return; - uint32 gain = damage * maxPower / 100; + uint32 gain = CalculatePctN(maxPower, damage); m_caster->EnergizeBySpell(unitTarget, m_spellInfo->Id, gain, power); } @@ -3350,7 +3348,7 @@ void Spell::EffectAddHonor(SpellEffIndex /*effIndex*/) // do not allow to add too many honor for player (50 * 21) = 1040 at level 70, or (50 * 31) = 1550 at level 80 if (damage <= 50) { - uint32 honor_reward = Trinity::Honor::hk_honor_at_level(unitTarget->getLevel(), damage); + uint32 honor_reward = Trinity::Honor::hk_honor_at_level(unitTarget->getLevel(), float(damage)); unitTarget->ToPlayer()->RewardHonor(NULL, 1, honor_reward); sLog.outDebug("SpellEffect::AddHonor (spell_id %u) rewards %u honor points (scale) to player: %u", m_spellInfo->Id, honor_reward, unitTarget->ToPlayer()->GetGUIDLow()); } @@ -3938,14 +3936,14 @@ void Spell::SpellDamageWeaponDmg(SpellEffIndex effIndex) // Seal of Command - Increase damage by 36% on every swing if (m_spellInfo->SpellFamilyFlags[0] & 0x2000000) { - totalDamagePercentMod *= 1.36f; //136% damage + totalDamagePercentMod *= 1.36f; // 136% damage } // Seal of Command Unleashed else if (m_spellInfo->Id == 20467) { - spell_bonus += int32(0.08f*m_caster->GetTotalAttackPowerValue(BASE_ATTACK)); - spell_bonus += int32(0.13f*m_caster->SpellBaseDamageBonus(GetSpellSchoolMask(m_spellInfo))); + spell_bonus += int32(0.08f * m_caster->GetTotalAttackPowerValue(BASE_ATTACK)); + spell_bonus += int32(0.13f * m_caster->SpellBaseDamageBonus(GetSpellSchoolMask(m_spellInfo))); } break; } @@ -3963,15 +3961,13 @@ void Spell::SpellDamageWeaponDmg(SpellEffIndex effIndex) if (m_spellInfo->SpellFamilyFlags[1] & 0x400) { if (m_caster->GetTypeId() == TYPEID_PLAYER) - m_caster->ToPlayer()->AddComboPoints(unitTarget,1, this); + m_caster->ToPlayer()->AddComboPoints(unitTarget, 1, this); } // Shred, Maul - Rend and Tear else if (m_spellInfo->SpellFamilyFlags[0] & 0x00008800 && unitTarget->HasAuraState(AURA_STATE_BLEEDING)) { if (AuraEffect const* rendAndTear = m_caster->GetDummyAuraEffect(SPELLFAMILY_DRUID, 2859, 0)) - { - totalDamagePercentMod *= float((rendAndTear->GetAmount() + 100.0f) / 100.0f); - } + AddPctN(totalDamagePercentMod, rendAndTear->GetAmount()); } break; } @@ -3979,7 +3975,7 @@ void Spell::SpellDamageWeaponDmg(SpellEffIndex effIndex) { // Kill Shot - bonus damage from Ranged Attack Power if (m_spellInfo->SpellFamilyFlags[1] & 0x800000) - spell_bonus += int32(0.4f*m_caster->GetTotalAttackPowerValue(RANGED_ATTACK)); + spell_bonus += int32(0.4f * m_caster->GetTotalAttackPowerValue(RANGED_ATTACK)); break; } case SPELLFAMILY_DEATHKNIGHT: @@ -3989,18 +3985,18 @@ void Spell::SpellDamageWeaponDmg(SpellEffIndex effIndex) { // Glyph of Plague Strike if (AuraEffect const * aurEff = m_caster->GetAuraEffect(58657, EFFECT_0)) - totalDamagePercentMod *= (aurEff->GetAmount() + 100.0f) / 100.0f; + AddPctN(totalDamagePercentMod, aurEff->GetAmount()); break; } // Blood Strike if (m_spellInfo->SpellFamilyFlags[EFFECT_0] & 0x400000) { - totalDamagePercentMod *= ((SpellMgr::CalculateSpellEffectAmount(m_spellInfo, EFFECT_2) * unitTarget->GetDiseasesByCaster(m_caster->GetGUID()) / 2.0f) + 100.0f) / 100.0f; + AddPctF(totalDamagePercentMod, SpellMgr::CalculateSpellEffectAmount(m_spellInfo, EFFECT_2) * unitTarget->GetDiseasesByCaster(m_caster->GetGUID()) / 2.0f); // Glyph of Blood Strike if (m_caster->GetAuraEffect(59332, EFFECT_0)) if (unitTarget->HasAuraType(SPELL_AURA_MOD_DECREASE_SPEED)) - totalDamagePercentMod *= (20 + 100.0f) / 100.0f; + AddPctN(totalDamagePercentMod, 20); break; } // Death Strike @@ -4009,7 +4005,7 @@ void Spell::SpellDamageWeaponDmg(SpellEffIndex effIndex) // Glyph of Death Strike if (AuraEffect const * aurEff = m_caster->GetAuraEffect(59336, EFFECT_0)) if (uint32 runic = std::min<uint32>(m_caster->GetPower(POWER_RUNIC_POWER), SpellMgr::CalculateSpellEffectAmount(aurEff->GetSpellProto(), EFFECT_1))) - totalDamagePercentMod *= (runic + 100.0f) / 100.0f; + AddPctN(totalDamagePercentMod, runic); break; } // Obliterate (12.5% more damage per disease) @@ -4022,19 +4018,19 @@ void Spell::SpellDamageWeaponDmg(SpellEffIndex effIndex) if (roll_chance_i(aurEff->GetAmount())) consumeDiseases = false; - totalDamagePercentMod *= ((SpellMgr::CalculateSpellEffectAmount(m_spellInfo, EFFECT_2) * unitTarget->GetDiseasesByCaster(m_caster->GetGUID(), consumeDiseases) / 2.0f) + 100.0f) / 100.0f; + AddPctF(totalDamagePercentMod, SpellMgr::CalculateSpellEffectAmount(m_spellInfo, EFFECT_2) * unitTarget->GetDiseasesByCaster(m_caster->GetGUID(), consumeDiseases) / 2.0f); break; } // Blood-Caked Strike - Blood-Caked Blade if (m_spellInfo->SpellIconID == 1736) { - totalDamagePercentMod *= ((unitTarget->GetDiseasesByCaster(m_caster->GetGUID()) * 12.5f) + 100.0f) / 100.0f; + AddPctF(totalDamagePercentMod, unitTarget->GetDiseasesByCaster(m_caster->GetGUID()) * 12.5f); break; } // Heart Strike if (m_spellInfo->SpellFamilyFlags[EFFECT_0] & 0x1000000) { - totalDamagePercentMod *= ((SpellMgr::CalculateSpellEffectAmount(m_spellInfo, EFFECT_2) * unitTarget->GetDiseasesByCaster(m_caster->GetGUID())) + 100.0f) / 100.0f; + AddPctN(totalDamagePercentMod, SpellMgr::CalculateSpellEffectAmount(m_spellInfo, EFFECT_2) * unitTarget->GetDiseasesByCaster(m_caster->GetGUID())); break; } break; @@ -4042,10 +4038,10 @@ void Spell::SpellDamageWeaponDmg(SpellEffIndex effIndex) } bool normalized = false; - float weaponDamagePercentMod = 1.0; + float weaponDamagePercentMod = 1.0f; for (int j = 0; j < MAX_SPELL_EFFECTS; ++j) { - switch(m_spellInfo->Effect[j]) + switch (m_spellInfo->Effect[j]) { case SPELL_EFFECT_WEAPON_DAMAGE: case SPELL_EFFECT_WEAPON_DAMAGE_NOSCHOOL: @@ -4056,7 +4052,7 @@ void Spell::SpellDamageWeaponDmg(SpellEffIndex effIndex) normalized = true; break; case SPELL_EFFECT_WEAPON_PERCENT_DAMAGE: - weaponDamagePercentMod *= float(CalculateDamage(j,unitTarget)) / 100.0f; + ApplyPctN(weaponDamagePercentMod, CalculateDamage(j, unitTarget)); break; default: break; // not weapon damage effect, just skip @@ -4067,7 +4063,7 @@ void Spell::SpellDamageWeaponDmg(SpellEffIndex effIndex) if (fixed_bonus || spell_bonus) { UnitMods unitMod; - switch(m_attackType) + switch (m_attackType) { default: case BASE_ATTACK: unitMod = UNIT_MOD_DAMAGE_MAINHAND; break; @@ -4113,11 +4109,11 @@ void Spell::SpellDamageWeaponDmg(SpellEffIndex effIndex) weaponDamage = int32(weaponDamage * totalDamagePercentMod); // prevent negative damage - uint32 eff_damage = uint32(weaponDamage > 0 ? weaponDamage : 0); + uint32 eff_damage(std::max(weaponDamage, 0)); // Add melee damage bonuses (also check for negative) m_caster->MeleeDamageBonus(unitTarget, &eff_damage, m_attackType, m_spellInfo); - m_damage+= eff_damage; + m_damage += eff_damage; } void Spell::EffectThreat(SpellEffIndex /*effIndex*/) @@ -4154,7 +4150,7 @@ void Spell::EffectHealMaxHealth(SpellEffIndex /*effIndex*/) addhealth = unitTarget->GetMaxHealth() - unitTarget->GetHealth(); if (m_originalCaster) - m_healing += m_originalCaster->SpellHealingBonus(unitTarget,m_spellInfo, addhealth, HEAL); + m_healing += m_originalCaster->SpellHealingBonus(unitTarget, m_spellInfo, addhealth, HEAL); } void Spell::EffectInterruptCast(SpellEffIndex effIndex) @@ -5811,7 +5807,7 @@ void Spell::EffectResurrect(SpellEffIndex effIndex) return; uint32 health = pTarget->CountPctFromMaxHealth(damage); - uint32 mana = pTarget->GetMaxPower(POWER_MANA) * damage / 100; + uint32 mana = CalculatePctN(pTarget->GetMaxPower(POWER_MANA), damage); ExecuteLogEffectResurrect(effIndex, pTarget); @@ -5931,7 +5927,7 @@ void Spell::EffectSelfResurrect(SpellEffIndex effIndex) { health = unitTarget->CountPctFromMaxHealth(damage); if (unitTarget->GetMaxPower(POWER_MANA) > 0) - mana = uint32(damage/100.0f*unitTarget->GetMaxPower(POWER_MANA)); + mana = CalculatePctN(unitTarget->GetMaxPower(POWER_MANA), damage); } Player *plr = unitTarget->ToPlayer(); @@ -6206,13 +6202,12 @@ void Spell::EffectDestroyAllTotems(SpellEffIndex /*effIndex*/) if (spellInfo) { mana += spellInfo->manaCost; - mana += spellInfo->ManaCostPercentage * m_caster->GetCreateMana() / 100; + mana += int32(CalculatePctU(m_caster->GetCreateMana(), spellInfo->ManaCostPercentage)); } totem->ToTotem()->UnSummon(); } } - mana = mana * damage / 100; - + ApplyPctN(mana, damage); if (mana) m_caster->CastCustomSpell(m_caster, 39104, &mana, NULL, NULL, true); } @@ -6253,7 +6248,7 @@ void Spell::EffectDurabilityDamagePCT(SpellEffIndex effIndex) // Possibly its mean -1 all player equipped items and -2 all items if (slot < 0) { - unitTarget->ToPlayer()->DurabilityLossAll(double(damage)/100.0f, (slot < -1)); + unitTarget->ToPlayer()->DurabilityLossAll(float(damage) / 100.0f, (slot < -1)); return; } @@ -6265,7 +6260,7 @@ void Spell::EffectDurabilityDamagePCT(SpellEffIndex effIndex) return; if (Item* item = unitTarget->ToPlayer()->GetItemByPos(INVENTORY_SLOT_BAG_0, slot)) - unitTarget->ToPlayer()->DurabilityLoss(item, double(damage)/100.0f); + unitTarget->ToPlayer()->DurabilityLoss(item, float(damage) / 100.0f); } void Spell::EffectModifyThreatPercent(SpellEffIndex /*effIndex*/) 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) diff --git a/src/server/scripts/Spells/spell_dk.cpp b/src/server/scripts/Spells/spell_dk.cpp index 766ff5acb4f..907f1789d95 100644 --- a/src/server/scripts/Spells/spell_dk.cpp +++ b/src/server/scripts/Spells/spell_dk.cpp @@ -140,7 +140,7 @@ public: Unit* caster = GetCaster(); if (Unit* unitTarget = GetHitUnit()) { - int32 bp = (GetHitDamage() * GetEffectValue() * unitTarget->GetDiseasesByCaster(caster->GetGUID())) / 100; + int32 bp = CalculatePctN(GetHitDamage(), GetEffectValue() * unitTarget->GetDiseasesByCaster(caster->GetGUID())); caster->CastCustomSpell(unitTarget, DK_SPELL_SCOURGE_STRIKE_TRIGGERED, &bp, NULL, NULL, true); } } diff --git a/src/server/scripts/Spells/spell_hunter.cpp b/src/server/scripts/Spells/spell_hunter.cpp index 906bc87ef69..5c21563123f 100644 --- a/src/server/scripts/Spells/spell_hunter.cpp +++ b/src/server/scripts/Spells/spell_hunter.cpp @@ -88,7 +88,7 @@ public: int32 TickCount = aurEff->GetTotalTicks(); spellId = HUNTER_SPELL_CHIMERA_SHOT_SERPENT; basePoint = caster->SpellDamageBonus(unitTarget, aura->GetSpellProto(), aurEff->GetAmount(), DOT, aura->GetStackAmount()); - basePoint = basePoint * TickCount * 40 / 100; + ApplyPctN(basePoint, TickCount * 40); } // Viper Sting - Instantly restores mana to you equal to 60% of the total amount drained by your Viper Sting. else if (familyFlag[1] & 0x00000080) @@ -97,11 +97,11 @@ public: spellId = HUNTER_SPELL_CHIMERA_SHOT_VIPER; // Amount of one aura tick - basePoint = aurEff->GetAmount() * unitTarget->GetMaxPower(POWER_MANA) / 100 ; - int32 casterBasePoint = aurEff->GetAmount() * unitTarget->GetMaxPower(POWER_MANA) / 50 ; + basePoint = int32(CalculatePctN(unitTarget->GetMaxPower(POWER_MANA), aurEff->GetAmount())); + int32 casterBasePoint = aurEff->GetAmount() * unitTarget->GetMaxPower(POWER_MANA) / 50; // TODO: WTF? caster uses unitTarget? if (basePoint > casterBasePoint) basePoint = casterBasePoint; - basePoint = basePoint * TickCount * 60 / 100; + ApplyPctN(basePoint, TickCount * 60); } // Scorpid Sting - Attempts to Disarm the target for 10 sec. This effect cannot occur more than once per 1 minute. else if (familyFlag[0] & 0x00008000) diff --git a/src/server/scripts/Spells/spell_shaman.cpp b/src/server/scripts/Spells/spell_shaman.cpp index f39cd2b064c..cdd86ce2751 100644 --- a/src/server/scripts/Spells/spell_shaman.cpp +++ b/src/server/scripts/Spells/spell_shaman.cpp @@ -117,7 +117,7 @@ public: if (AuraEffect *dummy = owner->GetAuraEffect(SHAMAN_SPELL_GLYPH_OF_MANA_TIDE, 0)) effValue += dummy->GetAmount(); // Regenerate 6% of Total Mana Every 3 secs - int32 effBasePoints0 = unitTarget->GetMaxPower(POWER_MANA) * effValue / 100; + int32 effBasePoints0 = int32(CalculatePctN(unitTarget->GetMaxPower(POWER_MANA), effValue)); caster->CastCustomSpell(unitTarget, SHAMAN_SPELL_MANA_TIDE_TOTEM, &effBasePoints0, NULL, NULL, true, NULL, NULL, GetOriginalCaster()->GetGUID()); } } diff --git a/src/server/shared/Utilities/Util.h b/src/server/shared/Utilities/Util.h index 8a49d7d9681..f6b408f84c1 100755 --- a/src/server/shared/Utilities/Util.h +++ b/src/server/shared/Utilities/Util.h @@ -80,7 +80,7 @@ inline void ApplyModUInt32Var(uint32& var, int32 val, bool apply) { int32 cur = var; cur += (apply ? val : -val); - if(cur < 0) + if (cur < 0) cur = 0; var = cur; } @@ -88,7 +88,7 @@ inline void ApplyModUInt32Var(uint32& var, int32 val, bool apply) inline void ApplyModFloatVar(float& var, float val, bool apply) { var += (apply ? val : -val); - if(var < 0) + if (var < 0) var = 0; } @@ -96,9 +96,65 @@ inline void ApplyPercentModFloatVar(float& var, float val, bool apply) { if (val == -100.0f) // prevent set var to zero val = -99.99f; - var *= (apply?(100.0f+val)/100.0f : 100.0f / (100.0f+val)); + var *= (apply ? (100.0f + val) / 100.0f : 100.0f / (100.0f + val)); } +// Percentage calculation +template <class T> +inline T CalculatePctF(T base, float pct) +{ + return T(base * pct / 100.0f); +} + +template <class T> +inline T CalculatePctN(T base, int32 pct) +{ + return T(base * float(pct) / 100.0f); +} + +template <class T> +inline T CalculatePctU(T base, uint32 pct) +{ + return T(base * float(pct) / 100.0f); +} + +template <class T> +inline T AddPctF(T& base, float pct) +{ + return base += CalculatePctF(base, pct); +} + +template <class T> +inline T AddPctN(T& base, int32 pct) +{ + return base += CalculatePctN(base, pct); +} + +template <class T> +inline T AddPctU(T& base, uint32 pct) +{ + return base += CalculatePctU(base, pct); +} + +template <class T> +inline T ApplyPctF(T& base, float pct) +{ + return base = CalculatePctF(base, pct); +} + +template <class T> +inline T ApplyPctN(T& base, int32 pct) +{ + return base = CalculatePctN(base, pct); +} + +template <class T> +inline T ApplyPctU(T& base, uint32 pct) +{ + return base = CalculatePctU(base, pct); +} + +// UTF8 handling bool Utf8toWStr(const std::string& utf8str, std::wstring& wstr); // in wsize==max size of buffer, out wsize==real string size bool Utf8toWStr(char const* utf8str, size_t csize, wchar_t* wstr, size_t& wsize); |
