aboutsummaryrefslogtreecommitdiff
path: root/src/server/game
diff options
context:
space:
mode:
authorazazel <none@none>2010-08-26 01:20:57 +0600
committerazazel <none@none>2010-08-26 01:20:57 +0600
commit341e6303effccfdbfb6b67ae0d8fe6933f56ed3b (patch)
treeeff917fec707c7097a7b408ce15842ff24d8ddb4 /src/server/game
parentbb5f7b64927713911331f81f9c0a5abc33e0c3ab (diff)
Core:
* add helping methods for manipulating unit's health and use it where applicable * fix some conversion warnings and cleanup code (formatting, CRLF, tabs to spaces) --HG-- branch : trunk
Diffstat (limited to 'src/server/game')
-rw-r--r--src/server/game/AI/EventAI/CreatureEventAI.cpp6
-rw-r--r--src/server/game/AI/ScriptedAI/ScriptedCreature.h3
-rw-r--r--src/server/game/AI/ScriptedAI/ScriptedGuardAI.cpp4
-rw-r--r--src/server/game/AI/ScriptedAI/ScriptedSimpleAI.cpp2
-rw-r--r--src/server/game/Achievements/AchievementMgr.cpp12
-rw-r--r--src/server/game/Battlegrounds/Battleground.cpp4
-rw-r--r--src/server/game/Battlegrounds/Zones/BattlegroundSA.cpp2
-rw-r--r--src/server/game/Chat/Commands/Level2.cpp20
-rw-r--r--src/server/game/Conditions/ConditionMgr.cpp3
-rw-r--r--src/server/game/Entities/Creature/Creature.cpp6
-rw-r--r--src/server/game/Entities/Object/Object.cpp2
-rw-r--r--src/server/game/Entities/Pet/Pet.cpp4
-rw-r--r--src/server/game/Entities/Player/Player.cpp14
-rw-r--r--src/server/game/Entities/Unit/Unit.cpp64
-rw-r--r--src/server/game/Entities/Unit/Unit.h9
-rw-r--r--src/server/game/Maps/Map.cpp38
-rw-r--r--src/server/game/Spells/Auras/SpellAuraEffects.cpp36
-rw-r--r--src/server/game/Spells/Auras/SpellAuras.cpp2
-rw-r--r--src/server/game/Spells/Spell.cpp6
-rw-r--r--src/server/game/Spells/SpellEffects.cpp26
20 files changed, 136 insertions, 127 deletions
diff --git a/src/server/game/AI/EventAI/CreatureEventAI.cpp b/src/server/game/AI/EventAI/CreatureEventAI.cpp
index ec236890fa8..ec0b12a0b42 100644
--- a/src/server/game/AI/EventAI/CreatureEventAI.cpp
+++ b/src/server/game/AI/EventAI/CreatureEventAI.cpp
@@ -141,7 +141,7 @@ bool CreatureEventAI::ProcessEvent(CreatureEventAIHolder& pHolder, Unit* pAction
if (!me->isInCombat() || !me->GetMaxHealth())
return false;
- uint32 perc = (me->GetHealth()*100) / me->GetMaxHealth();
+ uint32 perc = uint32(me->GetHealthPct());
if (perc > event.percent_range.percentMax || perc < event.percent_range.percentMin)
return false;
@@ -195,7 +195,7 @@ bool CreatureEventAI::ProcessEvent(CreatureEventAIHolder& pHolder, Unit* pAction
if (!me->isInCombat() || !me->getVictim() || !me->getVictim()->GetMaxHealth())
return false;
- uint32 perc = (me->getVictim()->GetHealth()*100) / me->getVictim()->GetMaxHealth();
+ uint32 perc = uint32(me->getVictim()->GetHealthPct());
if (perc > event.percent_range.percentMax || perc < event.percent_range.percentMin)
return false;
@@ -821,7 +821,7 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
case ACTION_T_SET_INVINCIBILITY_HP_LEVEL:
{
if (action.invincibility_hp_level.is_percent)
- m_InvinceabilityHpLevel = me->GetMaxHealth()*action.invincibility_hp_level.hp_level/100;
+ m_InvinceabilityHpLevel = me->CountPctFromMaxHealth(action.invincibility_hp_level.hp_level);
else
m_InvinceabilityHpLevel = action.invincibility_hp_level.hp_level;
break;
diff --git a/src/server/game/AI/ScriptedAI/ScriptedCreature.h b/src/server/game/AI/ScriptedAI/ScriptedCreature.h
index bf24ead82ad..6c304ecd346 100644
--- a/src/server/game/AI/ScriptedAI/ScriptedCreature.h
+++ b/src/server/game/AI/ScriptedAI/ScriptedCreature.h
@@ -153,7 +153,8 @@ struct ScriptedAI : public CreatureAI
//Selects a unit from the creature's current aggro list
Unit* SelectUnit(SelectAggroTarget pTarget, uint32 uiPosition);
- bool HealthBelowPct(uint64 pct) const { return me->GetHealth() * 100 < me->GetMaxHealth() * pct; }
+ bool HealthBelowPct(uint32 pct) const { return me->HealthBelowPct(pct); }
+ bool HealthAbovePct(uint32 pct) const { return me->HealthAbovePct(pct); }
//Returns spells that meet the specified criteria from the creatures spell list
SpellEntry const* SelectSpell(Unit* Target, uint32 School, uint32 Mechanic, SelectTargetType Targets, uint32 PowerCostMin, uint32 PowerCostMax, float RangeMin, float RangeMax, SelectEffect Effect);
diff --git a/src/server/game/AI/ScriptedAI/ScriptedGuardAI.cpp b/src/server/game/AI/ScriptedAI/ScriptedGuardAI.cpp
index 8dbaa750701..81dd4fcdc27 100644
--- a/src/server/game/AI/ScriptedAI/ScriptedGuardAI.cpp
+++ b/src/server/game/AI/ScriptedAI/ScriptedGuardAI.cpp
@@ -103,7 +103,7 @@ void guardAI::UpdateAI(const uint32 diff)
SpellEntry const *info = NULL;
//Select a healing spell if less than 30% hp
- if (me->GetHealth()*100 / me->GetMaxHealth() < 30)
+ if (HealthBelowPct(30))
info = SelectSpell(me, 0, 0, SELECT_TARGET_ANY_FRIEND, 0, 0, 0, 0, SELECT_EFFECT_HEALING);
//No healing spell available, select a hostile spell
@@ -134,7 +134,7 @@ void guardAI::UpdateAI(const uint32 diff)
SpellEntry const *info = NULL;
//Select a healing spell if less than 30% hp ONLY 33% of the time
- if (me->GetHealth()*100 / me->GetMaxHealth() < 30 && rand() % 3 == 0)
+ if (HealthBelowPct(30) && rand() % 3 == 0)
info = SelectSpell(me, 0, 0, SELECT_TARGET_ANY_FRIEND, 0, 0, 0, 0, SELECT_EFFECT_HEALING);
//No healing spell available, See if we can cast a ranged spell (Range must be greater than ATTACK_DISTANCE)
diff --git a/src/server/game/AI/ScriptedAI/ScriptedSimpleAI.cpp b/src/server/game/AI/ScriptedAI/ScriptedSimpleAI.cpp
index 4ca55669245..864de9288a1 100644
--- a/src/server/game/AI/ScriptedAI/ScriptedSimpleAI.cpp
+++ b/src/server/game/AI/ScriptedAI/ScriptedSimpleAI.cpp
@@ -214,7 +214,7 @@ void SimpleAI::UpdateAI(const uint32 diff)
if (Spell_Timer[i] <= diff)
{
//Check if this is a percentage based
- if (Spell[i].First_Cast < 0 && Spell[i].First_Cast > -100 && me->GetHealth()*100 / me->GetMaxHealth() > uint32(-Spell[i].First_Cast))
+ if (Spell[i].First_Cast < 0 && Spell[i].First_Cast > -100 && HealthAbovePct(uint32(-Spell[i].First_Cast)))
continue;
//Check Current spell
diff --git a/src/server/game/Achievements/AchievementMgr.cpp b/src/server/game/Achievements/AchievementMgr.cpp
index c41b06ae752..d840283040e 100644
--- a/src/server/game/Achievements/AchievementMgr.cpp
+++ b/src/server/game/Achievements/AchievementMgr.cpp
@@ -286,12 +286,14 @@ bool AchievementCriteriaData::Meets(uint32 criteria_id, Player const* source, Un
case ACHIEVEMENT_CRITERIA_DATA_TYPE_T_PLAYER_LESS_HEALTH:
if (!target || target->GetTypeId() != TYPEID_PLAYER)
return false;
- return target->GetHealth()*100 <= health.percent*target->GetMaxHealth();
+ return !target->HealthAbovePct(health.percent);
case ACHIEVEMENT_CRITERIA_DATA_TYPE_T_PLAYER_DEAD:
- if (!target || target->GetTypeId() != TYPEID_PLAYER || target->isAlive() || target->ToPlayer()->GetDeathTimer() == 0)
- return false;
- // flag set == must be same team, not set == different team
- return (target->ToPlayer()->GetTeam() == source->GetTeam()) == (player_dead.own_team_flag != 0);
+ if (target && !target->isAlive())
+ if (const Player* player = target->ToPlayer())
+ if (player->GetDeathTimer() != 0)
+ // flag set == must be same team, not set == different team
+ return (player->GetTeam() == source->GetTeam()) == (player_dead.own_team_flag != 0);
+ return false;
case ACHIEVEMENT_CRITERIA_DATA_TYPE_S_AURA:
return source->HasAuraEffect(aura.spell_id,aura.effect_idx);
case ACHIEVEMENT_CRITERIA_DATA_TYPE_S_AREA:
diff --git a/src/server/game/Battlegrounds/Battleground.cpp b/src/server/game/Battlegrounds/Battleground.cpp
index aa654a8f55b..f7958287ecd 100644
--- a/src/server/game/Battlegrounds/Battleground.cpp
+++ b/src/server/game/Battlegrounds/Battleground.cpp
@@ -821,7 +821,7 @@ void Battleground::EndBattleground(uint32 winner)
}
- plr->SetHealth(plr->GetMaxHealth());
+ plr->SetFullHealth();
plr->SetPower(POWER_MANA, plr->GetMaxPower(POWER_MANA));
plr->CombatStopWithPets(true);
@@ -1113,7 +1113,7 @@ void Battleground::AddPlayer(Player *plr)
{
plr->CastSpell(plr, SPELL_ARENA_PREPARATION, true);
- plr->SetHealth(plr->GetMaxHealth());
+ plr->SetFullHealth();
plr->SetPower(POWER_MANA, plr->GetMaxPower(POWER_MANA));
}
}
diff --git a/src/server/game/Battlegrounds/Zones/BattlegroundSA.cpp b/src/server/game/Battlegrounds/Zones/BattlegroundSA.cpp
index aaea9f10db2..8ee0064a440 100644
--- a/src/server/game/Battlegrounds/Zones/BattlegroundSA.cpp
+++ b/src/server/game/Battlegrounds/Zones/BattlegroundSA.cpp
@@ -474,7 +474,7 @@ void BattlegroundSA::TeleportPlayers()
plr->SpawnCorpseBones();
}
- plr->SetHealth(plr->GetMaxHealth());
+ plr->SetFullHealth();
plr->SetPower(POWER_MANA, plr->GetMaxPower(POWER_MANA));
plr->CombatStopWithPets(true);
diff --git a/src/server/game/Chat/Commands/Level2.cpp b/src/server/game/Chat/Commands/Level2.cpp
index b77fe69d553..601c2ed240a 100644
--- a/src/server/game/Chat/Commands/Level2.cpp
+++ b/src/server/game/Chat/Commands/Level2.cpp
@@ -3978,19 +3978,19 @@ bool ChatHandler::HandleCreatePetCommand(const char* /*args*/)
// prepare visual effect for levelup
pet->SetUInt32Value(UNIT_FIELD_LEVEL,creatureTarget->getLevel()-1);
- pet->GetCharmInfo()->SetPetNumber(sObjectMgr.GeneratePetNumber(), true);
- // this enables pet details window (Shift+P)
- pet->InitPetCreateSpells();
- pet->SetHealth(pet->GetMaxHealth());
+ pet->GetCharmInfo()->SetPetNumber(sObjectMgr.GeneratePetNumber(), true);
+ // this enables pet details window (Shift+P)
+ pet->InitPetCreateSpells();
+ pet->SetFullHealth();
- pet->GetMap()->Add(pet->ToCreature());
+ pet->GetMap()->Add(pet->ToCreature());
- // visual effect for levelup
- pet->SetUInt32Value(UNIT_FIELD_LEVEL,creatureTarget->getLevel());
+ // visual effect for levelup
+ pet->SetUInt32Value(UNIT_FIELD_LEVEL,creatureTarget->getLevel());
- player->SetMinion(pet, true);
- pet->SavePetToDB(PET_SAVE_AS_CURRENT);
- player->PetSpellInitialize();
+ player->SetMinion(pet, true);
+ pet->SavePetToDB(PET_SAVE_AS_CURRENT);
+ player->PetSpellInitialize();
return true;
}
diff --git a/src/server/game/Conditions/ConditionMgr.cpp b/src/server/game/Conditions/ConditionMgr.cpp
index b63766bde6d..a3479bf417f 100644
--- a/src/server/game/Conditions/ConditionMgr.cpp
+++ b/src/server/game/Conditions/ConditionMgr.cpp
@@ -144,8 +144,7 @@ bool Condition::Meets(Player * player, Unit* targetOverride)
if (targetOverride)
target = targetOverride;
if (target)
- if ((target->GetHealth()*100 / target->GetMaxHealth()) <= mConditionValue1)
- condMeets = true;
+ condMeets = !target->HealthAbovePct(mConditionValue1);
break;
}
case CONDITION_TARGET_RANGE:
diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp
index b829e8bed05..40db0009ebe 100644
--- a/src/server/game/Entities/Creature/Creature.cpp
+++ b/src/server/game/Entities/Creature/Creature.cpp
@@ -1511,7 +1511,7 @@ void Creature::setDeathState(DeathState s)
{
//if (isPet())
// setActive(true);
- SetHealth(GetMaxHealth());
+ SetFullHealth();
SetLootRecipient(NULL);
ResetPlayerDamageReq();
CreatureInfo const *cinfo = GetCreatureInfo();
@@ -2276,12 +2276,12 @@ uint8 Creature::getLevelForTarget(Unit const* target) const
if (!isWorldBoss())
return Unit::getLevelForTarget(target);
- uint16 level = target->getLevel()+sWorld.getIntConfig(CONFIG_WORLD_BOSS_LEVEL_DIFF);
+ uint16 level = target->getLevel() + sWorld.getIntConfig(CONFIG_WORLD_BOSS_LEVEL_DIFF);
if (level < 1)
return 1;
if (level > 255)
return 255;
- return level;
+ return uint8(level);
}
std::string Creature::GetAIName() const
diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp
index 65638432277..9b5964bb4ff 100644
--- a/src/server/game/Entities/Object/Object.cpp
+++ b/src/server/game/Entities/Object/Object.cpp
@@ -1986,7 +1986,7 @@ Pet* Player::SummonPet(uint32 entry, float x, float y, float z, float ang, PetTy
pet->SetUInt32Value(UNIT_FIELD_BYTES_0, 2048);
pet->SetUInt32Value(UNIT_FIELD_PETEXPERIENCE, 0);
pet->SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, 1000);
- pet->SetHealth(pet->GetMaxHealth());
+ pet->SetFullHealth();
pet->SetPower(POWER_MANA, pet->GetMaxPower(POWER_MANA));
pet->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, time(NULL));
break;
diff --git a/src/server/game/Entities/Pet/Pet.cpp b/src/server/game/Entities/Pet/Pet.cpp
index 9fc41f63ff6..70e42e6266f 100644
--- a/src/server/game/Entities/Pet/Pet.cpp
+++ b/src/server/game/Entities/Pet/Pet.cpp
@@ -240,7 +240,7 @@ bool Pet::LoadPetFromDB(Player* owner, uint32 petentry, uint32 petnumber, bool c
if (getPetType() == SUMMON_PET && !current) //all (?) summon pets come with full health when called, but not when they are current
{
- SetHealth(GetMaxHealth());
+ SetFullHealth();
SetPower(POWER_MANA, GetMaxPower(POWER_MANA));
}
else
@@ -1056,7 +1056,7 @@ bool Guardian::InitStatsForLevel(uint8 petlevel)
UpdateAllStats();
- SetHealth(GetMaxHealth());
+ SetFullHealth();
SetPower(POWER_MANA, GetMaxPower(POWER_MANA));
return true;
}
diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp
index 8971f6be7b4..1375afe68b6 100644
--- a/src/server/game/Entities/Player/Player.cpp
+++ b/src/server/game/Entities/Player/Player.cpp
@@ -815,7 +815,7 @@ bool Player::Create(uint32 guidlow, const std::string& name, uint8 race, uint8 c
// apply original stats mods before spell loading or item equipment that call before equip _RemoveStatsMods()
UpdateMaxHealth(); // Update max Health (for add bonus from stamina)
- SetHealth(GetMaxHealth());
+ SetFullHealth();
if (getPowerType() == POWER_MANA)
{
UpdateMaxPower(POWER_MANA); // Update max Mana (for add bonus from intellect)
@@ -2047,7 +2047,7 @@ void Player::ProcessDelayedOperations()
if (GetMaxHealth() > m_resurrectHealth)
SetHealth(m_resurrectHealth);
else
- SetHealth(GetMaxHealth());
+ SetFullHealth();
if (GetMaxPower(POWER_MANA) > m_resurrectMana)
SetPower(POWER_MANA, m_resurrectMana);
@@ -2726,7 +2726,7 @@ void Player::GiveLevel(uint8 level)
UpdateSkillsToMaxSkillsForLevel();
// set current level health and mana/energy to maximum after applying all mods.
- SetHealth(GetMaxHealth());
+ SetFullHealth();
SetPower(POWER_MANA, GetMaxPower(POWER_MANA));
SetPower(POWER_ENERGY, GetMaxPower(POWER_ENERGY));
if (GetPower(POWER_RAGE) > GetMaxPower(POWER_RAGE))
@@ -2937,7 +2937,7 @@ void Player::InitStatsForLevel(bool reapplyMods)
_ApplyAllStatBonuses();
// set current level health and mana/energy to maximum after applying all mods.
- SetHealth(GetMaxHealth());
+ SetFullHealth();
SetPower(POWER_MANA, GetMaxPower(POWER_MANA));
SetPower(POWER_ENERGY, GetMaxPower(POWER_ENERGY));
if (GetPower(POWER_RAGE) > GetMaxPower(POWER_RAGE))
@@ -6206,7 +6206,7 @@ void Player::SendActionButtons(uint32 state) const
*/
if (state != 2)
{
- for (uint16 button = 0; button < MAX_ACTION_BUTTONS; ++button)
+ for (uint8 button = 0; button < MAX_ACTION_BUTTONS; ++button)
{
ActionButtonList::const_iterator itr = m_actionButtons.find(button);
if (itr != m_actionButtons.end() && itr->second.uState != ACTIONBUTTON_DELETED)
@@ -9601,7 +9601,7 @@ Item* Player::GetItemByPos(uint8 bag, uint8 slot) const
Item* Player::GetWeaponForAttack(WeaponAttackType attackType, bool useable /*= false*/) const
{
- uint16 slot;
+ uint8 slot;
switch (attackType)
{
case BASE_ATTACK: slot = EQUIPMENT_SLOT_MAINHAND; break;
@@ -21932,7 +21932,7 @@ void Player::ResurectUsingRequestData()
if (GetMaxHealth() > m_resurrectHealth)
SetHealth(m_resurrectHealth);
else
- SetHealth(GetMaxHealth());
+ SetFullHealth();
if (GetMaxPower(POWER_MANA) > m_resurrectMana)
SetPower(POWER_MANA, m_resurrectMana);
diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp
index 3f41f3f67c7..95beb3b34d6 100644
--- a/src/server/game/Entities/Unit/Unit.cpp
+++ b/src/server/game/Entities/Unit/Unit.cpp
@@ -273,9 +273,9 @@ void Unit::Update(uint32 p_time)
// update abilities available only for fraction of time
UpdateReactives(p_time);
- ModifyAuraState(AURA_STATE_HEALTHLESS_20_PERCENT, GetHealth() < GetMaxHealth()*0.20f);
- ModifyAuraState(AURA_STATE_HEALTHLESS_35_PERCENT, GetHealth() < GetMaxHealth()*0.35f);
- ModifyAuraState(AURA_STATE_HEALTH_ABOVE_75_PERCENT, GetHealth() > GetMaxHealth()*0.75f);
+ ModifyAuraState(AURA_STATE_HEALTHLESS_20_PERCENT, HealthBelowPct(20));
+ ModifyAuraState(AURA_STATE_HEALTHLESS_35_PERCENT, HealthBelowPct(35));
+ ModifyAuraState(AURA_STATE_HEALTH_ABOVE_75_PERCENT, HealthAbovePct(75));
i_motionMaster.UpdateMotion(p_time);
}
@@ -1922,7 +1922,7 @@ void Unit::CalcAbsorbResist(Unit *pVictim, SpellSchoolMask schoolMask, DamageEff
if (spellProto->SpellIconID == 2135 && pVictim->GetTypeId() == TYPEID_PLAYER)
{
int32 remainingHealth = pVictim->GetHealth() - RemainingDamage;
- uint32 allowedHealth = uint32(pVictim->GetMaxHealth() * 0.35f);
+ uint32 allowedHealth = pVictim->CountPctFromMaxHealth(35);
// If damage kills us
if (remainingHealth <= 0 && !pVictim->ToPlayer()->HasSpellCooldown(66235))
{
@@ -1937,7 +1937,7 @@ void Unit::CalcAbsorbResist(Unit *pVictim, SpellSchoolMask schoolMask, DamageEff
? 1.0f
: float(defenseSkillValue) / float(reqDefForMaxHeal);
- int32 healAmount = int32(pVictim->GetMaxHealth() * (*i)->GetAmount() / 100.0f * pctFromDefense);
+ int32 healAmount = int32(pVictim->CountPctFromMaxHealth(uint32((*i)->GetAmount() * pctFromDefense)));
pVictim->CastCustomSpell(pVictim, 66235, &healAmount, NULL, NULL, true);
pVictim->ToPlayer()->AddSpellCooldown(66235,0,time(NULL) + 120);
}
@@ -1992,7 +1992,7 @@ void Unit::CalcAbsorbResist(Unit *pVictim, SpellSchoolMask schoolMask, DamageEff
uint32 rank = sSpellMgr.GetSpellRank(spellProto->Id);
SpellEntry const * talentProto = sSpellStore.LookupEntry(sSpellMgr.GetSpellWithRank(49189, rank));
- int32 minHp = int32((float)pVictim->GetMaxHealth() * (float)SpellMgr::CalculateSpellEffectAmount(talentProto, 0, (*i)->GetCaster()) / 100.0f);
+ int32 minHp = int32(pVictim->CountPctFromMaxHealth(SpellMgr::CalculateSpellEffectAmount(talentProto, 0, (*i)->GetCaster())));
// Damage that would take you below [effect0] health or taken while you are at [effect0]
if (remainingHp < minHp)
{
@@ -2215,7 +2215,7 @@ void Unit::CalcAbsorbResist(Unit *pVictim, SpellSchoolMask schoolMask, DamageEff
pVictim->CastSpell(pVictim,31231,true);
pVictim->ToPlayer()->AddSpellCooldown(31231,0,time(NULL)+60);
// with health > 10% lost health until health == 10%, in other case no losses
- uint32 health10 = pVictim->GetMaxHealth()/10;
+ uint32 health10 = pVictim->CountPctFromMaxHealth(10);
RemainingDamage = pVictim->GetHealth() > health10 ? pVictim->GetHealth() - health10 : 0;
}
break;
@@ -2225,7 +2225,7 @@ void Unit::CalcAbsorbResist(Unit *pVictim, SpellSchoolMask schoolMask, DamageEff
// Guardian Spirit
if (preventDeathSpell->SpellIconID == 2873)
{
- int32 healAmount = pVictim->GetMaxHealth() * preventDeathAmount / 100;
+ int32 healAmount = int32(pVictim->CountPctFromMaxHealth(preventDeathAmount));
pVictim->RemoveAurasDueToSpell(preventDeathSpell->Id);
pVictim->CastCustomSpell(pVictim, 48153, &healAmount, NULL, NULL, true);
RemainingDamage = 0;
@@ -6441,7 +6441,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger
if (!target || !target->IsFriendlyTo(this))
return false;
- basepoints0 = int32(target->GetMaxHealth() * triggerAmount / 100);
+ basepoints0 = int32(target->CountPctFromMaxHealth(triggerAmount));
triggered_spell_id = 56131;
break;
}
@@ -6556,7 +6556,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger
{
if (triggerAmount <= 0)
return false;
- basepoints0 = triggerAmount * GetMaxHealth() / 100;
+ basepoints0 = int32(CountPctFromMaxHealth(triggerAmount));
target = this;
triggered_spell_id = 34299;
if (triggeredByAura->GetCasterGUID() != GetGUID())
@@ -6580,7 +6580,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger
// Glyph of Rejuvenation
case 54754:
{
- if (!pVictim || pVictim->GetHealth() >= triggerAmount * pVictim->GetMaxHealth()/100)
+ if (!pVictim || !pVictim->HealthBelowPct(uint32(triggerAmount)))
return false;
basepoints0 = int32(triggerAmount * damage / 100);
triggered_spell_id = 54755;
@@ -6939,7 +6939,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger
if (pVictim->getPowerType() == POWER_MANA)
{
// 2% of base mana
- basepoints0 = int32(pVictim->GetMaxHealth() * 2 / 100);
+ basepoints0 = int32(pVictim->CountPctFromMaxHealth(2));
pVictim->CastCustomSpell(pVictim, 20267, &basepoints0, 0, 0, true, 0, triggeredByAura);
}
return true;
@@ -7662,7 +7662,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger
// Vendetta
if (dummySpell->SpellFamilyFlags[0] & 0x10000)
{
- basepoints0 = triggerAmount * GetMaxHealth() / 100;
+ basepoints0 = int32(CountPctFromMaxHealth(triggerAmount));
triggered_spell_id = 50181;
target = this;
break;
@@ -8516,13 +8516,13 @@ bool Unit::HandleProcTriggerSpell(Unit *pVictim, uint32 damage, AuraEffect* trig
else if (auraSpellInfo->SpellIconID == 2013)
{
// Check health condition - should drop to less 30% (damage deal after this!)
- if (!(10*(int32(GetHealth() - damage)) < 3 * GetMaxHealth()))
+ if (!HealthBelowPctDamaged(30, damage))
return false;
if (pVictim && pVictim->isAlive())
pVictim->getThreatManager().modifyThreatPercent(this,-10);
- basepoints0 = triggerAmount * GetMaxHealth() / 100;
+ basepoints0 = int32(CountPctFromMaxHealth(triggerAmount));
trigger_spell_id = 31616;
target = this;
}
@@ -8603,8 +8603,8 @@ bool Unit::HandleProcTriggerSpell(Unit *pVictim, uint32 damage, AuraEffect* trig
// Deflection
case 52420:
{
- if (GetHealth()*100 / GetMaxHealth() >= 35)
- return false;
+ if (!HealthBelowPct(35))
+ return false;
break;
}
@@ -8612,7 +8612,7 @@ bool Unit::HandleProcTriggerSpell(Unit *pVictim, uint32 damage, AuraEffect* trig
case 28845:
{
// When your health drops below 20%
- if (GetHealth() - damage > GetMaxHealth() / 5 || GetHealth() < GetMaxHealth() / 5)
+ if (HealthBelowPctDamaged(20, damage) || HealthBelowPct(20))
return false;
break;
}
@@ -8620,7 +8620,7 @@ bool Unit::HandleProcTriggerSpell(Unit *pVictim, uint32 damage, AuraEffect* trig
case 31255:
{
// whenever you deal damage to a target who is below 20% health.
- if (!pVictim || !pVictim->isAlive() || (pVictim->GetHealth() > pVictim->GetMaxHealth() / 5))
+ if (!pVictim || !pVictim->isAlive() || pVictim->HealthAbovePct(20))
return false;
target = this;
@@ -8633,7 +8633,7 @@ bool Unit::HandleProcTriggerSpell(Unit *pVictim, uint32 damage, AuraEffect* trig
return false;
// Not give if target already have full health
- if (pVictim->GetHealth() == pVictim->GetMaxHealth())
+ if (pVictim->IsFullHealth())
return false;
// If your Greater Heal brings the target to full health, you gain $37595s1 mana.
if (pVictim->GetHealth() + damage < pVictim->GetMaxHealth())
@@ -8644,7 +8644,7 @@ bool Unit::HandleProcTriggerSpell(Unit *pVictim, uint32 damage, AuraEffect* trig
case 40971:
{
// If your target is below $s1% health
- if (!pVictim || !pVictim->isAlive() || (pVictim->GetHealth() > pVictim->GetMaxHealth() * triggerAmount / 100))
+ if (!pVictim || !pVictim->isAlive() || pVictim->HealthAbovePct(triggerAmount))
return false;
break;
}
@@ -8756,7 +8756,7 @@ bool Unit::HandleProcTriggerSpell(Unit *pVictim, uint32 damage, AuraEffect* trig
// Bloodthirst (($m/100)% of max health)
case 23880:
{
- basepoints0 = int32(GetMaxHealth() * triggerAmount / 100);
+ basepoints0 = int32(CountPctFromMaxHealth(triggerAmount));
break;
}
// Shamanistic Rage triggered spell
@@ -10276,7 +10276,7 @@ uint32 Unit::SpellDamageBonus(Unit *pVictim, SpellEntry const *spellProto, uint3
// Merciless Combat
if ((*i)->GetSpellProto()->SpellIconID == 2656)
{
- if ((pVictim->GetMaxHealth() * 35 / 100) >= pVictim->GetHealth())
+ if (!pVictim->HealthAbovePct(35))
DoneTotalMod *= (100.0f+(*i)->GetAmount())/100.0f;
}
// Tundra Stalker
@@ -10750,7 +10750,7 @@ bool Unit::isSpellCrit(Unit *pVictim, SpellEntry const *spellProto, SpellSchoolM
case 21: // Test of Faith
case 6935:
case 6918:
- if (pVictim->GetHealth() < pVictim->GetMaxHealth()/2)
+ if (pVictim->HealthBelowPct(50))
crit_chance+=(*i)->GetAmount();
break;
default:
@@ -10962,7 +10962,7 @@ uint32 Unit::SpellHealingBonus(Unit *pVictim, SpellEntry const *spellProto, uint
case 21: // Test of Faith
case 6935:
case 6918:
- if (pVictim->GetHealth() < pVictim->GetMaxHealth()/2)
+ if (pVictim->HealthBelowPct(50))
DoneTotalMod *=((*i)->GetAmount() + 100.0f)/100.0f;
break;
case 7798: // Glyph of Regrowth
@@ -11500,7 +11500,7 @@ void Unit::MeleeDamageBonus(Unit *pVictim, uint32 *pdamage, WeaponAttackType att
// Merciless Combat
if ((*i)->GetSpellProto()->SpellIconID == 2656)
{
- if ((pVictim->GetMaxHealth() * 35 / 100) >= pVictim->GetHealth())
+ if (!pVictim->HealthAbovePct(35))
DoneTotalMod *= (100.0f+(*i)->GetAmount())/100.0f;
}
// Tundra Stalker
@@ -13802,19 +13802,19 @@ void CharmInfo::LoadPetActionBar(const std::string& data)
for (iter = tokens.begin(), index = ACTION_BAR_INDEX_START; index < ACTION_BAR_INDEX_END; ++iter, ++index)
{
// use unsigned cast to avoid sign negative format use at long-> ActiveStates (int) conversion
- uint8 type = atol((*iter).c_str());
+ ActiveStates type = ActiveStates(atol(iter->c_str()));
++iter;
- uint32 action = atol((*iter).c_str());
+ uint32 action = uint32(atol(iter->c_str()));
- PetActionBar[index].SetActionAndType(action,ActiveStates(type));
+ PetActionBar[index].SetActionAndType(action, type);
// check correctness
if (PetActionBar[index].IsActionBarForSpell())
{
if (!sSpellStore.LookupEntry(PetActionBar[index].GetAction()))
- SetActionBar(index,0,ACT_PASSIVE);
+ SetActionBar(index, 0, ACT_PASSIVE);
else if (!IsAutocastableSpell(PetActionBar[index].GetAction()))
- SetActionBar(index,PetActionBar[index].GetAction(),ACT_PASSIVE);
+ SetActionBar(index, PetActionBar[index].GetAction(), ACT_PASSIVE);
}
}
}
@@ -14810,7 +14810,7 @@ bool Unit::InitTamedPet(Pet * pet, uint8 level, uint32 spell_id)
// this enables pet details window (Shift+P)
pet->InitPetCreateSpells();
//pet->InitLevelupSpellsForLevel();
- pet->SetHealth(pet->GetMaxHealth());
+ pet->SetFullHealth();
return true;
}
diff --git a/src/server/game/Entities/Unit/Unit.h b/src/server/game/Entities/Unit/Unit.h
index 596d7d15078..b451c56e4a1 100644
--- a/src/server/game/Entities/Unit/Unit.h
+++ b/src/server/game/Entities/Unit/Unit.h
@@ -1211,8 +1211,17 @@ class Unit : public WorldObject
uint32 GetHealth() const { return GetUInt32Value(UNIT_FIELD_HEALTH); }
uint32 GetMaxHealth() const { return GetUInt32Value(UNIT_FIELD_MAXHEALTH); }
+
+ inline bool IsFullHealth() const { return GetHealth() == GetMaxHealth(); }
+ inline bool HealthBelowPct(int32 pct) const { return GetHealth() * 100 < GetMaxHealth() * pct; }
+ inline bool HealthBelowPctDamaged(int32 pct, uint32 damage) const { return (int32(GetHealth()) - damage) * 100 < GetMaxHealth() * pct; }
+ inline bool HealthAbovePct(int32 pct) const { return GetHealth() * 100 > GetMaxHealth() * 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); }
+
void SetHealth(uint32 val);
void SetMaxHealth(uint32 val);
+ inline void SetFullHealth() { SetHealth(GetMaxHealth()); }
int32 ModifyHealth(int32 val);
int32 GetHealthGain(int32 dVal);
diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp
index 9fb6624193c..331257ca673 100644
--- a/src/server/game/Maps/Map.cpp
+++ b/src/server/game/Maps/Map.cpp
@@ -3247,25 +3247,25 @@ void Map::ScriptsProcess()
}
else
{
- pTarget = source->ToPlayer();
- if (pTarget)
- {
- if (target->GetTypeId() != TYPEID_UNIT && target->GetTypeId() != TYPEID_GAMEOBJECT && target->GetTypeId() != TYPEID_PLAYER)
- {
- sLog.outError("%s target is not unit, gameobject or player (TypeId: %u, Entry: %u, GUID: %u), skipping.",
- step.script->GetDebugInfo().c_str(), target->GetTypeId(), target->GetEntry(), target->GetGUIDLow());
- break;
- }
- worldObject = dynamic_cast<WorldObject*>(target);
- }
- else
- {
- sLog.outError("%s neither source nor target is player (source: TypeId: %u, Entry: %u, GUID: %u; target: TypeId: %u, Entry: %u, GUID: %u), skipping.",
- step.script->GetDebugInfo().c_str(),
- source ? source->GetTypeId() : 0, source ? source->GetEntry() : 0, source ? source->GetGUIDLow() : 0,
- target ? target->GetTypeId() : 0, target ? target->GetEntry() : 0, target ? target->GetGUIDLow() : 0);
- break;
- }
+ pTarget = source->ToPlayer();
+ if (pTarget)
+ {
+ if (target->GetTypeId() != TYPEID_UNIT && target->GetTypeId() != TYPEID_GAMEOBJECT && target->GetTypeId() != TYPEID_PLAYER)
+ {
+ sLog.outError("%s target is not unit, gameobject or player (TypeId: %u, Entry: %u, GUID: %u), skipping.",
+ step.script->GetDebugInfo().c_str(), target->GetTypeId(), target->GetEntry(), target->GetGUIDLow());
+ break;
+ }
+ worldObject = dynamic_cast<WorldObject*>(target);
+ }
+ else
+ {
+ sLog.outError("%s neither source nor target is player (source: TypeId: %u, Entry: %u, GUID: %u; target: TypeId: %u, Entry: %u, GUID: %u), skipping.",
+ step.script->GetDebugInfo().c_str(),
+ source ? source->GetTypeId() : 0, source ? source->GetEntry() : 0, source ? source->GetGUIDLow() : 0,
+ target ? target->GetTypeId() : 0, target ? target->GetEntry() : 0, target ? target->GetGUIDLow() : 0);
+ break;
+ }
}
// quest id and flags checked at script loading
diff --git a/src/server/game/Spells/Auras/SpellAuraEffects.cpp b/src/server/game/Spells/Auras/SpellAuraEffects.cpp
index 7dd8ad17957..7df7350f344 100644
--- a/src/server/game/Spells/Auras/SpellAuraEffects.cpp
+++ b/src/server/game/Spells/Auras/SpellAuraEffects.cpp
@@ -451,7 +451,7 @@ int32 AuraEffect::CalculateAmount(Unit * caster)
m_canBeRecalculated = false;
if (!m_spellProto->procFlags)
break;
- amount = int32(GetBase()->GetUnitOwner()->GetMaxHealth()*0.10f);
+ amount = int32(GetBase()->GetUnitOwner()->CountPctFromMaxHealth(10));
if (caster)
{
// Glyphs increasing damage cap
@@ -717,7 +717,7 @@ int32 AuraEffect::CalculateAmount(Unit * caster)
case SPELL_AURA_MOD_INCREASE_HEALTH:
// Vampiric Blood
if (GetId() == 55233)
- amount = GetBase()->GetUnitOwner()->GetMaxHealth() * amount / 100;
+ amount = GetBase()->GetUnitOwner()->CountPctFromMaxHealth(amount);
break;
case SPELL_AURA_MOD_INCREASE_ENERGY:
// Hymn of Hope
@@ -1288,7 +1288,7 @@ void AuraEffect::PeriodicTick(Unit * target, Unit * caster) const
{
case 43093: case 31956: case 38801: // Grievous Wound
case 35321: case 38363: case 39215: // Gushing Wound
- if (target->GetHealth() == target->GetMaxHealth())
+ if (target->IsFullHealth())
{
target->RemoveAurasDueToSpell(GetId());
return;
@@ -1300,7 +1300,7 @@ void AuraEffect::PeriodicTick(Unit * target, Unit * caster) const
GetEffIndex() < 2 && GetSpellProto()->Effect[GetEffIndex()] == SPELL_EFFECT_DUMMY ?
caster->CalculateSpellDamage(target, GetSpellProto(),GetEffIndex()+1) :
100;
- if (target->GetHealth()*100 >= target->GetMaxHealth()*percent)
+ if (!target->HealthBelowPct(percent))
{
target->RemoveAurasDueToSpell(GetId());
return;
@@ -1358,7 +1358,7 @@ void AuraEffect::PeriodicTick(Unit * target, Unit * caster) const
}
}
else
- damage = uint32(target->GetMaxHealth()*damage/100);
+ damage = uint32(target->CountPctFromMaxHealth(damage));
bool crit = IsPeriodicTickCrit(target, caster);
if (crit)
@@ -1523,7 +1523,7 @@ void AuraEffect::PeriodicTick(Unit * target, Unit * caster) const
if (target != caster && GetSpellProto()->AttributesEx2 & SPELL_ATTR_EX2_HEALTH_FUNNEL && !caster->isAlive())
break;
- if (GetBase()->GetDuration() == -1 && target->GetHealth() == target->GetMaxHealth())
+ if (GetBase()->GetDuration() == -1 && target->IsFullHealth())
break;
// ignore non positive values (can be result apply spellmods to aura damage
@@ -1558,7 +1558,7 @@ void AuraEffect::PeriodicTick(Unit * target, Unit * caster) const
TakenTotalMod = TakenTotalMod > 0.0f ? TakenTotalMod : 0.0f;
- damage = uint32(target->GetMaxHealth() * damage / 100);
+ damage = uint32(target->CountPctFromMaxHealth(damage));
damage = uint32(damage * TakenTotalMod);
}
else
@@ -1894,7 +1894,7 @@ void AuraEffect::PeriodicDummyTick(Unit * target, Unit * caster) const
case 51687:
case 51688:
case 51689:
- if (target->getVictim() && (target->GetHealth() * 100 / target->GetMaxHealth() > target->getVictim()->GetHealth() * 100 / target->getVictim()->GetMaxHealth())) {
+ if (target->getVictim() && (target->GetHealthPct() > target->getVictim()->GetHealthPct())) {
if (!target->HasAura(58670)) {
int32 basepoints = SpellMgr::CalculateSpellEffectAmount(GetSpellProto(), 0);
target->CastCustomSpell(target, 58670, &basepoints, 0, 0, true);
@@ -2052,12 +2052,12 @@ void AuraEffect::PeriodicDummyTick(Unit * target, Unit * caster) const
{
// Feeding Frenzy Rank 1
case 53511:
- if (target->getVictim() && target->getVictim()->GetHealth() * 100 < target->getVictim()->GetMaxHealth() * 35)
+ if (target->getVictim() && target->getVictim()->HealthBelowPct(35))
target->CastSpell(target, 60096, true, 0, this);
return;
// Feeding Frenzy Rank 2
case 53512:
- if (target->getVictim() && target->getVictim()->GetHealth() * 100 < target->getVictim()->GetMaxHealth() * 35)
+ if (target->getVictim() && target->getVictim()->HealthBelowPct(35))
target->CastSpell(target, 60097, true, 0, this);
return;
default:
@@ -2078,7 +2078,7 @@ void AuraEffect::PeriodicDummyTick(Unit * target, Unit * caster) const
switch (GetId())
{
case 49016: // Hysteria
- uint32 damage = uint32(target->GetMaxHealth()*0.01f);
+ uint32 damage = uint32(target->CountPctFromMaxHealth(1));
target->DealDamage(target, damage, NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
break;
}
@@ -2153,7 +2153,7 @@ void AuraEffect::TriggerSpell(Unit * target, Unit * caster) const
case 24379:
case 23493:
{
- int32 heal = caster->GetMaxHealth() / 10;
+ int32 heal = caster->CountPctFromMaxHealth(10);
caster->DealHeal(target, heal, auraSpellInfo);
int32 mana = caster->GetMaxPower(POWER_MANA);
@@ -2176,7 +2176,7 @@ void AuraEffect::TriggerSpell(Unit * target, Unit * caster) const
return;
// Frost Blast
case 27808:
- caster->CastCustomSpell(29879, SPELLVALUE_BASE_POINT0, int32((float)target->GetMaxHealth()*0.21f), target, true, NULL, this);
+ caster->CastCustomSpell(29879, SPELLVALUE_BASE_POINT0, int32(target->CountPctFromMaxHealth(21)), target, true, NULL, this);
return;
// Detonate Mana
case 27819:
@@ -4735,9 +4735,7 @@ void AuraEffect::HandleModTotalPercentStat(AuraApplication const * aurApp, uint8
//recalculate current HP/MP after applying aura modifications (only for spells with 0x10 flag)
if ((GetMiscValue() == STAT_STAMINA) && (maxHPValue > 0) && (m_spellProto->Attributes & 0x10))
{
- // hmm... why is newHPValue a uint64 here?
- // newHP = (curHP / maxHP) * newMaxHP = (newMaxHP * curHP) / maxHP -> which is better because no int -> double -> int conversion is needed
- uint64 newHPValue = (target->GetMaxHealth() * curHPValue) / maxHPValue;
+ uint32 newHPValue = target->CountPctFromMaxHealth(int32(100.0f * curHPValue / maxHPValue));
target->SetHealth(newHPValue);
}
}
@@ -4925,10 +4923,10 @@ void AuraEffect::HandleAuraModIncreaseHealthPercent(AuraApplication const * aurA
Unit * target = aurApp->GetTarget();
// Unit will keep hp% after MaxHealth being modified if unit is alive.
- float percent = ((float)target->GetHealth()) / target->GetMaxHealth();
+ float percent = target->GetHealthPct();
target->HandleStatModifier(UNIT_MOD_HEALTH, TOTAL_PCT, float(GetAmount()), apply);
if (target->isAlive())
- target->SetHealth(uint32(target->GetMaxHealth()*percent));
+ target->SetHealth(target->CountPctFromMaxHealth(percent));
}
void AuraEffect::HandleAuraIncreaseBaseHealthPercent(AuraApplication const * aurApp, uint8 mode, bool apply) const
@@ -6085,7 +6083,7 @@ void AuraEffect::HandleAuraDummy(AuraApplication const * aurApp, uint8 mode, boo
if (!target->IsInFeralForm())
break;
- int32 bp0 = int32(target->GetMaxHealth() * GetAmount() / 100);
+ int32 bp0 = int32(target->CountPctFromMaxHealth(GetAmount()));
target->CastCustomSpell(target, 50322, &bp0, NULL, NULL, true);
}
else
diff --git a/src/server/game/Spells/Auras/SpellAuras.cpp b/src/server/game/Spells/Auras/SpellAuras.cpp
index 2b929e5ba07..2831bbce8cd 100644
--- a/src/server/game/Spells/Auras/SpellAuras.cpp
+++ b/src/server/game/Spells/Auras/SpellAuras.cpp
@@ -1516,7 +1516,7 @@ void Aura::HandleAuraSpecificMods(AuraApplication const * aurApp, Unit * caster,
break;
if (apply)
{
- if (target != caster && target->GetHealth() <= target->GetMaxHealth() / 4)
+ if (target != caster && !target->HealthAbovePct(25))
caster->CastSpell(caster, 200000, true);
}
else
diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp
index 64694c502c6..f8128a632ea 100644
--- a/src/server/game/Spells/Spell.cpp
+++ b/src/server/game/Spells/Spell.cpp
@@ -1757,7 +1757,7 @@ struct ChainHealingOrder : public std::binary_function<const Unit*, const Unit*,
else*/ if (Target->GetTypeId() == TYPEID_PLAYER && MainTarget->GetTypeId() == TYPEID_PLAYER &&
Target->ToPlayer()->IsInSameRaidWith(MainTarget->ToPlayer()))
{
- if (Target->GetHealth() == Target->GetMaxHealth())
+ if (Target->IsFullHealth())
return 40000;
else
return 20000 - Target->GetMaxHealth() + Target->GetHealth();
@@ -1792,7 +1792,7 @@ void Spell::SearchChainTarget(std::list<Unit*> &TagUnitMap, float max_range, uin
{
SearchAreaTarget(tempUnitMap, max_range, PUSH_CHAIN, SPELL_TARGETS_ALLY);
tempUnitMap.sort(ChainHealingOrder(m_caster));
- //if (cur->GetHealth() == cur->GetMaxHealth() && tempUnitMap.size())
+ //if (cur->IsFullHealth() && tempUnitMap.size())
// cur = tempUnitMap.front();
}
else
@@ -6050,7 +6050,7 @@ SpellCastResult Spell::CheckItems()
if (m_spellInfo->Effect[i] == SPELL_EFFECT_HEAL)
{
- if (m_targets.getUnitTarget()->GetHealth() == m_targets.getUnitTarget()->GetMaxHealth())
+ if (m_targets.getUnitTarget()->IsFullHealth())
{
failReason = SPELL_FAILED_ALREADY_AT_FULL_HEALTH;
continue;
diff --git a/src/server/game/Spells/SpellEffects.cpp b/src/server/game/Spells/SpellEffects.cpp
index 3e870182e63..29a51df0caf 100644
--- a/src/server/game/Spells/SpellEffects.cpp
+++ b/src/server/game/Spells/SpellEffects.cpp
@@ -415,13 +415,13 @@ void Spell::SpellDamageSchoolDmg(uint32 effect_idx)
// Cataclysmic Bolt
case 38441:
{
- damage = unitTarget->GetMaxHealth() / 2;
+ damage = unitTarget->CountPctFromMaxHealth(50);
break;
}
// Tympanic Tantrum
case 62775:
{
- damage = unitTarget->GetMaxHealth() / 10;
+ damage = unitTarget->CountPctFromMaxHealth(10);
break;
}
// Gargoyle Strike
@@ -1264,11 +1264,11 @@ void Spell::EffectDummy(uint32 i)
}
case 47170: // Impale Leviroth
{
- if (!unitTarget && unitTarget->GetEntry() != 26452 && ((unitTarget->GetHealth() / unitTarget->GetMaxHealth()) * 100.0f) > 95.0f)
- return;
+ if (!unitTarget && unitTarget->GetEntry() != 26452 && unitTarget->HealthAbovePct(95))
+ return;
- m_caster->DealDamage(unitTarget, uint32(unitTarget->GetMaxHealth()*0.93f));
- return;
+ m_caster->DealDamage(unitTarget, unitTarget->CountPctFromMaxHealth(93));
+ return;
}
case 49357: // Brewfest Mount Transformation
if (m_caster->GetTypeId() != TYPEID_PLAYER)
@@ -1679,7 +1679,7 @@ void Spell::EffectDummy(uint32 i)
if (m_spellInfo->SpellFamilyFlags[0] & SPELLFAMILYFLAG_DK_DEATH_STRIKE)
{
uint32 count = unitTarget->GetDiseasesByCaster(m_caster->GetGUID());
- int32 bp = int32(count * m_caster->GetMaxHealth() * m_spellInfo->DmgMultiplier[0] / 100);
+ int32 bp = int32(count * m_caster->CountPctFromMaxHealth(m_spellInfo->DmgMultiplier[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);
@@ -2557,7 +2557,7 @@ void Spell::SpellDamageHeal(uint32 /*i*/)
}
// Death Pact - return pct of max health to caster
else if (m_spellInfo->SpellFamilyName == SPELLFAMILY_DEATHKNIGHT && m_spellInfo->SpellFamilyFlags[0] & 0x00080000)
- addhealth = caster->SpellHealingBonus(unitTarget, m_spellInfo, int32(caster->GetMaxHealth() * damage / 100.0f), HEAL);
+ addhealth = caster->SpellHealingBonus(unitTarget, m_spellInfo, int32(caster->CountPctFromMaxHealth(damage)), HEAL);
else
addhealth = caster->SpellHealingBonus(unitTarget, m_spellInfo, addhealth, HEAL);
@@ -2584,7 +2584,7 @@ void Spell::EffectHealPct(uint32 /*i*/)
if (m_spellInfo->Id == 59754 && unitTarget == m_caster)
return;
- uint32 addhealth = caster->SpellHealingBonus(unitTarget, m_spellInfo, uint32(unitTarget->GetMaxHealth() * damage / 100.0f), HEAL);
+ uint32 addhealth = caster->SpellHealingBonus(unitTarget, m_spellInfo, unitTarget->CountPctFromMaxHealth(damage), HEAL);
//if (Player *modOwner = m_caster->GetSpellModOwner())
// modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_DAMAGE, addhealth, this);
@@ -4733,7 +4733,7 @@ void Spell::EffectScriptEffect(uint32 effIndex)
case 54426:
if (unitTarget)
{
- int32 damage = int32((int32)unitTarget->GetHealth() - (int32)unitTarget->GetMaxHealth() * 0.05f);
+ int32 damage = int32(unitTarget->GetHealth()) - int32(unitTarget->CountPctFromMaxHealth(5));
if (damage > 0)
m_caster->CastCustomSpell(28375, SPELLVALUE_BASE_POINT0, damage, unitTarget);
}
@@ -6113,7 +6113,7 @@ void Spell::EffectResurrect(uint32 /*effIndex*/)
if (pTarget->isRessurectRequested()) // already have one active request
return;
- uint32 health = pTarget->GetMaxHealth() * damage / 100;
+ uint32 health = pTarget->CountPctFromMaxHealth(damage);
uint32 mana = pTarget->GetMaxPower(POWER_MANA) * damage / 100;
pTarget->setResurrectRequestData(m_caster->GetGUID(), m_caster->GetMapId(), m_caster->GetPositionX(), m_caster->GetPositionY(), m_caster->GetPositionZ(), health, mana);
@@ -6241,7 +6241,7 @@ void Spell::EffectSelfResurrect(uint32 i)
// percent case
else
{
- health = uint32(damage/100.0f*unitTarget->GetMaxHealth());
+ health = unitTarget->CountPctFromMaxHealth(damage);
if (unitTarget->GetMaxPower(POWER_MANA) > 0)
mana = uint32(damage/100.0f*unitTarget->GetMaxPower(POWER_MANA));
}
@@ -6495,7 +6495,7 @@ void Spell::EffectSummonDeadPet(uint32 /*i*/)
pet->RemoveFlag (UNIT_FIELD_FLAGS, UNIT_FLAG_SKINNABLE);
pet->setDeathState(ALIVE);
pet->clearUnitState(UNIT_STAT_ALL_STATE);
- pet->SetHealth(uint32(pet->GetMaxHealth()*(float(damage)/100)));
+ pet->SetHealth(pet->CountPctFromMaxHealth(damage));
//pet->AIM_Initialize();
//_player->PetSpellInitialize();