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