*Update melee range calculation. By QAston.

--HG--
branch : trunk
This commit is contained in:
megamage
2008-12-05 18:39:31 -06:00
parent d36672cd7e
commit 3a1293ef18
34 changed files with 93 additions and 138 deletions
+3 -3
View File
@@ -130,7 +130,7 @@ void ScriptedAI::UpdateAI(const uint32 diff)
if (m_creature->isAttackReady() )
{
//If we are within range melee the target
if (m_creature->IsWithinCombatDist(m_creature->getVictim(), ATTACK_DISTANCE))
if (m_creature->IsWithinMeleeRange(m_creature->getVictim()))
{
m_creature->AttackerStateUpdate(m_creature->getVictim());
m_creature->resetAttackTimer();
@@ -193,7 +193,7 @@ void ScriptedAI::DoMeleeAttackIfReady()
if (m_creature->isAttackReady() && !m_creature->hasUnitState(UNIT_STAT_CASTING))
{
//If we are within range melee the target
if (m_creature->IsWithinCombatDist(m_creature->getVictim(), ATTACK_DISTANCE))
if (m_creature->IsWithinMeleeRange(m_creature->getVictim()))
{
m_creature->AttackerStateUpdate(m_creature->getVictim());
m_creature->resetAttackTimer();
@@ -202,7 +202,7 @@ void ScriptedAI::DoMeleeAttackIfReady()
if (m_creature->haveOffhandWeapon() && m_creature->isAttackReady(OFF_ATTACK) && !m_creature->hasUnitState(UNIT_STAT_CASTING))
{
//If we are within range melee the target
if (m_creature->IsWithinCombatDist(m_creature->getVictim(), ATTACK_DISTANCE))
if (m_creature->IsWithinMeleeRange(m_creature->getVictim()))
{
m_creature->AttackerStateUpdate(m_creature->getVictim(), OFF_ATTACK);
m_creature->resetAttackTimer(OFF_ATTACK);
@@ -42,10 +42,10 @@ struct TRINITY_DLL_DECL generic_creatureAI : public ScriptedAI
void Aggro(Unit *who)
{
if (!m_creature->IsWithinCombatDist(who, ATTACK_DISTANCE))
{
IsSelfRooted = true;
}
if (!m_creature->IsWithinMeleeRange(who))
{
IsSelfRooted = true;
}
}
void UpdateAI(const uint32 diff)
@@ -81,7 +81,7 @@ struct TRINITY_DLL_DECL generic_creatureAI : public ScriptedAI
return;
//If we are within range melee the target
if( m_creature->IsWithinCombatDist(m_creature->getVictim(), ATTACK_DISTANCE))
if( m_creature->IsWithinMeleeRange(m_creature->getVictim()))
{
//Make sure our attack is ready and we arn't currently casting
if( m_creature->isAttackReady() && !m_creature->IsNonMeleeSpellCasted(false))
@@ -126,7 +126,7 @@ struct TRINITY_DLL_DECL generic_creatureAI : public ScriptedAI
//No healing spell available, See if we can cast a ranged spell (Range must be greater than ATTACK_DISTANCE)
if (info) Healing = true;
else info = SelectSpell(m_creature->getVictim(), -1, -1, SELECT_TARGET_ANY_ENEMY, 0, 0, ATTACK_DISTANCE, 0, SELECT_EFFECT_DONTCARE);
else info = SelectSpell(m_creature->getVictim(), -1, -1, SELECT_TARGET_ANY_ENEMY, 0, 0, NOMINAL_MELEE_RANGE, 0, SELECT_EFFECT_DONTCARE);
//Found a spell, check if we arn't on cooldown
if (info && !GlobalCooldown)
@@ -86,7 +86,7 @@ void guardAI::UpdateAI(const uint32 diff)
if( m_creature->isAttackReady() && !m_creature->IsNonMeleeSpellCasted(false))
{
//If we are within range melee the target
if( m_creature->IsWithinCombatDist(m_creature->getVictim(), ATTACK_DISTANCE))
if( m_creature->IsWithinMeleeRange(m_creature->getVictim()))
{
bool Healing = false;
SpellEntry const *info = NULL;
@@ -128,7 +128,7 @@ void guardAI::UpdateAI(const uint32 diff)
//No healing spell available, See if we can cast a ranged spell (Range must be greater than ATTACK_DISTANCE)
if (info) Healing = true;
else info = SelectSpell(m_creature->getVictim(), -1, -1, SELECT_TARGET_ANY_ENEMY, 0, 0, ATTACK_DISTANCE, 0, SELECT_EFFECT_DONTCARE);
else info = SelectSpell(m_creature->getVictim(), -1, -1, SELECT_TARGET_ANY_ENEMY, 0, 0, NOMINAL_MELEE_RANGE, 0, SELECT_EFFECT_DONTCARE);
//Found a spell, check if we arn't on cooldown
if (info && !GlobalCooldown)
@@ -203,7 +203,7 @@ void npc_escortAI::UpdateAI(const uint32 diff)
if( m_creature->isAlive() && m_creature->SelectHostilTarget() && m_creature->getVictim())
{
//If we are within range melee the target
if( m_creature->IsWithinCombatDist(m_creature->getVictim(), ATTACK_DISTANCE))
if( m_creature->IsWithinMeleeRange(m_creature->getVictim()))
{
if( m_creature->isAttackReady() )
{
@@ -100,7 +100,7 @@ struct TRINITY_DLL_DECL boss_murmurAI : public Scripted_NoMovementAI
//Resonance_Timer
if (Resonance_Timer < diff)
{
if (!m_creature->IsWithinCombatDist(m_creature->getVictim(), ATTACK_DISTANCE))
if (!m_creature->IsWithinMeleeRange(m_creature->getVictim()))
DoCast(m_creature->getVictim(), SPELL_RESONANCE);
Resonance_Timer = 5000;
}else Resonance_Timer -= diff;
@@ -1741,7 +1741,7 @@ struct TRINITY_DLL_DECL mob_parasitic_shadowfiendAI : public ScriptedAI
void DoMeleeAttackIfReady()
{
if( m_creature->isAttackReady() && m_creature->IsWithinCombatDist(m_creature->getVictim(), ATTACK_DISTANCE))
if( m_creature->isAttackReady() && m_creature->IsWithinMeleeRange(m_creature->getVictim()))
{
if(!m_creature->getVictim()->HasAura(SPELL_PARASITIC_SHADOWFIEND, 0) && !m_creature->getVictim()->HasAura(SPELL_PARASITIC_SHADOWFIEND2, 0))
{
@@ -129,7 +129,7 @@ struct TRINITY_DLL_DECL boss_supremusAI : public ScriptedAI
for (i = m_threatlist.begin(); i!= m_threatlist.end();++i)
{
Unit* pUnit = Unit::GetUnit((*m_creature), (*i)->getUnitGuid());
if(pUnit && m_creature->IsWithinCombatDist(pUnit, ATTACK_DISTANCE))
if(pUnit && m_creature->IsWithinMeleeRange(pUnit))
{
if(pUnit->GetHealth() > health)
{
@@ -243,7 +243,7 @@ struct TRINITY_DLL_DECL boss_gruulAI : public ScriptedAI
Unit* target = NULL;
target = SelectUnit(SELECT_TARGET_TOPAGGRO,1);
if (target && m_creature->IsWithinCombatDist(m_creature->getVictim(), ATTACK_DISTANCE))
if (target && m_creature->IsWithinMeleeRange(m_creature->getVictim()))
DoCast(target,SPELL_HURTFUL_STRIKE);
else
DoCast(m_creature->getVictim(),SPELL_HURTFUL_STRIKE);
@@ -146,7 +146,7 @@ struct TRINITY_DLL_DECL boss_omor_the_unscarredAI : public Scripted_NoMovementAI
else if (OrbitalStrike_Timer < diff)
{
Unit* temp = NULL;
if (m_creature->IsWithinDistInMap(m_creature->getVictim(), ATTACK_DISTANCE))
if (m_creature->IsWithinMeleeRange(m_creature->getVictim()))
temp = m_creature->getVictim();
else temp = SelectUnit(SELECT_TARGET_RANDOM,0);
@@ -612,7 +612,7 @@ struct TRINITY_DLL_DECL boss_malchezaarAI : public ScriptedAI
void DoMeleeAttacksIfReady()
{
if( m_creature->IsWithinCombatDist(m_creature->getVictim(), ATTACK_DISTANCE) && !m_creature->IsNonMeleeSpellCasted(false))
if( m_creature->IsWithinMeleeRange(m_creature->getVictim()) && !m_creature->IsNonMeleeSpellCasted(false))
{
//Check for base attack
if( m_creature->isAttackReady() && m_creature->getVictim() )
@@ -274,7 +274,7 @@ struct TRINITY_DLL_DECL boss_ragnarosAI : public Scripted_NoMovementAI
}else Submerge_Timer -= diff;
//If we are within range melee the target
if( m_creature->IsWithinCombatDist(m_creature->getVictim(), ATTACK_DISTANCE))
if( m_creature->IsWithinMeleeRange(m_creature->getVictim()))
{
//Make sure our attack is ready and we arn't currently casting
if( m_creature->isAttackReady() && !m_creature->IsNonMeleeSpellCasted(false))
@@ -171,7 +171,7 @@ struct TRINITY_DLL_DECL boss_sapphironAI : public ScriptedAI
}else Beserk_Timer -= diff;
}
if( phase!=2 && m_creature->getVictim() && m_creature->IsWithinCombatDist(m_creature->getVictim(), ATTACK_DISTANCE))
if( phase!=2 && m_creature->getVictim() && m_creature->IsWithinMeleeRange(m_creature->getVictim()))
{
if( m_creature->isAttackReady() )
{
@@ -326,7 +326,7 @@ struct TRINITY_DLL_DECL boss_sacrolashAI : public ScriptedAI
if( m_creature->isAttackReady() && !m_creature->IsNonMeleeSpellCasted(false))
{
//If we are within range melee the target
if( m_creature->IsWithinCombatDist(m_creature->getVictim(), ATTACK_DISTANCE))
if( m_creature->IsWithinMeleeRange(m_creature->getVictim()))
{
HandleTouchedSpells(m_creature->getVictim(), SPELL_DARK_TOUCHED);
m_creature->AttackerStateUpdate(m_creature->getVictim());
@@ -736,7 +736,7 @@ struct TRINITY_DLL_DECL mob_shadow_imageAI : public ScriptedAI
if(!m_creature->IsNonMeleeSpellCasted(false))
{
//If we are within range melee the target
if( m_creature->IsWithinCombatDist(m_creature->getVictim(), ATTACK_DISTANCE))
if( m_creature->IsWithinMeleeRange(m_creature->getVictim()))
{
DoCast(m_creature->getVictim(),SPELL_DARK_STRIKE);
}
@@ -397,7 +397,7 @@ struct TRINITY_DLL_DECL boss_alarAI : public ScriptedAI
{
if(m_creature->isAttackReady() && !m_creature->IsNonMeleeSpellCasted(false))
{
if(m_creature->IsWithinCombatDist(m_creature->getVictim(), ATTACK_DISTANCE))
if(m_creature->IsWithinMeleeRange(m_creature->getVictim()))
{
m_creature->AttackerStateUpdate(m_creature->getVictim());
m_creature->resetAttackTimer();
@@ -1036,7 +1036,7 @@ struct TRINITY_DLL_DECL claw_tentacleAI : public Scripted_NoMovementAI
return;
//EvadeTimer
if (m_creature->GetDistance(m_creature->getVictim()) > ATTACK_DISTANCE)
if (!m_creature->IsWithinMeleeRange(m_creature->getVictim()))
if (EvadeTimer < diff)
{
Unit* p = Unit::GetUnit(*m_creature, Portal);
@@ -1133,7 +1133,7 @@ struct TRINITY_DLL_DECL giant_claw_tentacleAI : public Scripted_NoMovementAI
return;
//EvadeTimer
if (m_creature->GetDistance(m_creature->getVictim()) > ATTACK_DISTANCE)
if (!m_creature->IsWithinMeleeRange(m_creature->getVictim()))
if (EvadeTimer < diff)
{
Unit* p = Unit::GetUnit(*m_creature, Portal);
@@ -148,7 +148,7 @@ struct TRINITY_DLL_DECL boss_skeramAI : public ScriptedAI
}else ArcaneExplosion_Timer -= diff;
//If we are within range melee the target
if( m_creature->IsWithinCombatDist(m_creature->getVictim(), ATTACK_DISTANCE))
if( m_creature->IsWithinMeleeRange(m_creature->getVictim()))
{
//Make sure our attack is ready and we arn't currently casting
if( m_creature->isAttackReady() && !m_creature->IsNonMeleeSpellCasted(false))
@@ -206,55 +206,6 @@ struct TRINITY_DLL_DECL boss_twinemperorsAI : public ScriptedAI
} else Heal_Timer -= diff;
}
Unit *GetAnyoneCloseEnough(float dist, bool totallyRandom)
{
int cnt = 0;
std::list<HostilReference*>::iterator i;
std::list<HostilReference*> candidates;
for (i = m_creature->getThreatManager().getThreatList().begin();i != m_creature->getThreatManager().getThreatList().end(); ++i)
{
Unit* pUnit = Unit::GetUnit((*m_creature), (*i)->getUnitGuid());
if (m_creature->IsWithinDistInMap(pUnit, dist))
{
if (!totallyRandom)
return pUnit;
candidates.push_back((*i));
cnt ++;
}
}
if (!cnt)
return NULL;
for (int randomi = rand() % cnt; randomi > 0; randomi --)
candidates.pop_front();
i = candidates.begin();
Unit *ret = Unit::GetUnit((*m_creature), (*i)->getUnitGuid());
candidates.clear();
return ret;
}
Unit *PickNearestPlayer()
{
Unit *nearp = NULL;
float neardist = 0.0f;
std::list<HostilReference*>::iterator i;
for (i = m_creature->getThreatManager().getThreatList().begin();i != m_creature->getThreatManager().getThreatList().end(); ++i)
{
Unit* pUnit = NULL;
pUnit = Unit::GetUnit((*m_creature), (*i)->getUnitGuid());
if (!pUnit)
continue;
float pudist = pUnit->GetDistance((const Creature *)m_creature);
if (!nearp || (neardist > pudist))
{
nearp = pUnit;
neardist = pudist;
}
}
return nearp;
}
void TeleportToMyBrother()
{
if (!pInstance)
@@ -313,7 +264,7 @@ struct TRINITY_DLL_DECL boss_twinemperorsAI : public ScriptedAI
{
AfterTeleport = false;
m_creature->clearUnitState(UNIT_STAT_STUNNED);
Unit *nearu = PickNearestPlayer();
Unit *nearu = m_creature->SelectNearestTarget(100);
//DoYell(nearu->GetName(), LANG_UNIVERSAL, 0);
AttackStart(nearu);
m_creature->getThreatManager().addThreat(nearu, 10000);
@@ -520,7 +471,7 @@ struct TRINITY_DLL_DECL boss_veknilashAI : public boss_twinemperorsAI
if (UpperCut_Timer < diff)
{
Unit* randomMelee = GetAnyoneCloseEnough(ATTACK_DISTANCE, true);
Unit* randomMelee = SelectUnit(SELECT_TARGET_RANDOM, 0, NOMINAL_MELEE_RANGE, true);
if (randomMelee)
DoCast(randomMelee,SPELL_UPPERCUT);
UpperCut_Timer = 15000+rand()%15000;
@@ -616,7 +567,7 @@ struct TRINITY_DLL_DECL boss_veklorAI : public boss_twinemperorsAI
if (Blizzard_Timer < diff)
{
Unit* target = NULL;
target = GetAnyoneCloseEnough(45, true);
target = SelectUnit(SELECT_TARGET_RANDOM, 0, 45, true);
if (target)
DoCast(target,SPELL_BLIZZARD);
Blizzard_Timer = 15000+rand()%15000;
@@ -625,7 +576,7 @@ struct TRINITY_DLL_DECL boss_veklorAI : public boss_twinemperorsAI
if (ArcaneBurst_Timer < diff)
{
Unit *mvic;
if ((mvic=GetAnyoneCloseEnough(ATTACK_DISTANCE, false))!=NULL)
if ((mvic=SelectUnit(SELECT_TARGET_NEAREST, 0, NOMINAL_MELEE_RANGE, true))!=NULL)
{
DoCast(mvic,SPELL_ARCANEBURST);
ArcaneBurst_Timer = 5000;
@@ -268,7 +268,7 @@ struct TRINITY_DLL_DECL boss_zuljinAI : public ScriptedAI
{
if( !m_creature->IsNonMeleeSpellCasted(false))
{
if(m_creature->isAttackReady() && m_creature->IsWithinCombatDist(m_creature->getVictim(), ATTACK_DISTANCE))
if(m_creature->isAttackReady() && m_creature->IsWithinMeleeRange(m_creature->getVictim()))
{
if(Phase == 1 && !Overpower_Timer)
{
@@ -474,7 +474,7 @@ struct TRINITY_DLL_DECL boss_zuljinAI : public ScriptedAI
if(target)
{
AttackStart(target);
if(m_creature->IsWithinDistInMap(target, ATTACK_DISTANCE))
if(m_creature->IsWithinMeleeRange(target))
{
m_creature->CastSpell(target, SPELL_CLAW_RAGE_DAMAGE, true);
Claw_Counter++;
@@ -517,7 +517,7 @@ struct TRINITY_DLL_DECL boss_zuljinAI : public ScriptedAI
}
if(target)
{
if(m_creature->IsWithinDistInMap(target, ATTACK_DISTANCE))
if(m_creature->IsWithinMeleeRange(target))
{
m_creature->CastSpell(target, SPELL_LYNX_RUSH_DAMAGE, true);
Claw_Counter++;
@@ -613,7 +613,7 @@ struct TRINITY_DLL_DECL feather_vortexAI : public ScriptedAI
void UpdateAI(const uint32 diff)
{
//if the vortex reach the target, it change his target to another player
if( m_creature->IsWithinCombatDist(m_creature->getVictim(), ATTACK_DISTANCE))
if( m_creature->IsWithinMeleeRange(m_creature->getVictim()))
AttackStart(SelectUnit(SELECT_TARGET_RANDOM, 0));
}
};
@@ -134,7 +134,7 @@ struct TRINITY_DLL_DECL boss_mandokirAI : public ScriptedAI
targetZ != pUnit->GetPositionZ() ||
pUnit->isInCombat()))
{
if(m_creature->IsWithinDistInMap(pUnit, ATTACK_DISTANCE))
if(m_creature->IsWithinMeleeRange(pUnit))
{
DoCast(pUnit,24316);
}
@@ -200,7 +200,7 @@ struct TRINITY_DLL_DECL boss_mandokirAI : public ScriptedAI
for(; i != m_creature->getThreatManager().getThreatList().end(); ++i)
{
Unit* pUnit = Unit::GetUnit(*m_creature, (*i)->getUnitGuid());
if(pUnit && m_creature->IsWithinDistInMap(pUnit, ATTACK_DISTANCE))
if(pUnit && m_creature->IsWithinMeleeRange(pUnit))
TargetInRange++;
}
@@ -311,11 +311,11 @@ struct TRINITY_DLL_DECL mob_zealot_lorkhanAI : public ScriptedAI
switch(rand()%2)
{
case 0:
if(m_creature->IsWithinDistInMap(pThekal, ATTACK_DISTANCE))
if(m_creature->IsWithinMeleeRange(pThekal))
DoCast(pThekal, SPELL_GREATERHEAL);
break;
case 1:
if(m_creature->IsWithinDistInMap(pZath, ATTACK_DISTANCE))
if(m_creature->IsWithinMeleeRange(pZath))
DoCast(pZath, SPELL_GREATERHEAL);
break;
}
@@ -116,7 +116,7 @@ struct TRINITY_DLL_DECL boss_venoxisAI : public ScriptedAI
{
target = SelectUnit(SELECT_TARGET_TOPAGGRO,i);
if(target)
if(m_creature->IsWithinDistInMap(target, ATTACK_DISTANCE))
if(m_creature->IsWithinMeleeRange(target))
TargetInRange++;
}