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
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user