diff options
| author | azazel <none@none> | 2010-08-26 01:20:57 +0600 |
|---|---|---|
| committer | azazel <none@none> | 2010-08-26 01:20:57 +0600 |
| commit | 341e6303effccfdbfb6b67ae0d8fe6933f56ed3b (patch) | |
| tree | eff917fec707c7097a7b408ce15842ff24d8ddb4 /src/server/game/Entities | |
| parent | bb5f7b64927713911331f81f9c0a5abc33e0c3ab (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/Entities')
| -rw-r--r-- | src/server/game/Entities/Creature/Creature.cpp | 6 | ||||
| -rw-r--r-- | src/server/game/Entities/Object/Object.cpp | 2 | ||||
| -rw-r--r-- | src/server/game/Entities/Pet/Pet.cpp | 4 | ||||
| -rw-r--r-- | src/server/game/Entities/Player/Player.cpp | 14 | ||||
| -rw-r--r-- | src/server/game/Entities/Unit/Unit.cpp | 64 | ||||
| -rw-r--r-- | src/server/game/Entities/Unit/Unit.h | 9 |
6 files changed, 54 insertions, 45 deletions
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); |
