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/AI | |
| 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/AI')
4 files changed, 8 insertions, 7 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 |
