[svn] * Added fleeing and call assistance in script until we move all AI functions to core

--HG--
branch : trunk
This commit is contained in:
Neo2003
2008-10-05 12:10:02 -05:00
parent 0c3db399c5
commit 843f789f58
4 changed files with 60 additions and 3 deletions

View File

@@ -72,6 +72,9 @@ struct MANGOS_DLL_DECL ScriptedAI : public CreatureAI
//Bool for if we are in combat or not
bool InCombat;
//For fleeing
bool IsFleeing;
//*************
//Pure virtual functions
//*************

View File

@@ -79,6 +79,7 @@ struct MANGOS_DLL_DECL Mob_EventAI : public ScriptedAI
bool MeleeEnabled; //If we allow melee auto attack
uint32 AttackDistance; //Distance to attack from
float AttackAngle; //Angle of attack
uint32 TimetoFleeLeft; //For fleeing
void AttackTarget(Unit* pTarget, bool Follow)
{
@@ -774,8 +775,9 @@ struct MANGOS_DLL_DECL Mob_EventAI : public ScriptedAI
break;
case ACTION_T_FLEE:
{
//TODO: Replace with Flee movement generator
m_creature->CastSpell(m_creature, SPELL_RUN_AWAY, true);
TimetoFleeLeft = 8000;
m_creature->DoFleeToGetAssistance();
IsFleeing = true;
}
break;
case ACTION_T_QUEST_EVENT_ALL:
@@ -954,6 +956,7 @@ struct MANGOS_DLL_DECL Mob_EventAI : public ScriptedAI
void JustRespawned()
{
InCombat = false;
IsFleeing = false;
Reset();
//Handle Spawned Events
@@ -1014,6 +1017,7 @@ struct MANGOS_DLL_DECL Mob_EventAI : public ScriptedAI
m_creature->SetLootRecipient(NULL);
InCombat = false;
IsFleeing = false;
Reset();
//Handle Evade events
@@ -1034,6 +1038,7 @@ struct MANGOS_DLL_DECL Mob_EventAI : public ScriptedAI
void JustDied(Unit* killer)
{
InCombat = false;
IsFleeing = false;
Reset();
//Handle Evade events
@@ -1131,7 +1136,7 @@ struct MANGOS_DLL_DECL Mob_EventAI : public ScriptedAI
if (!who)
return;
if (who->isTargetableForAttack())
if (who->isTargetableForAttack() && !IsFleeing)
{
//Begin melee attack if we are within range
if (CombatMovementEnabled)
@@ -1225,6 +1230,20 @@ struct MANGOS_DLL_DECL Mob_EventAI : public ScriptedAI
if (!m_creature->isAlive())
return;
if ((TimetoFleeLeft < diff || (m_creature->GetMotionMaster()->GetCurrentMovementGeneratorType() != POINT_MOTION_TYPE && m_creature->GetMotionMaster()->GetCurrentMovementGeneratorType() != FLEEING_MOTION_TYPE)) && IsFleeing)
{
m_creature->GetMotionMaster()->Clear(false);
m_creature->SetNoCallAssistence(false);
m_creature->CallAssistence();
m_creature->GetMotionMaster()->MoveChase(m_creature->getVictim());
IsFleeing = false;
}
else
TimetoFleeLeft -= diff;
if(IsFleeing)
return;
//Events are only updated once every EVENT_UPDATE_TIME ms to prevent lag with large amount of events
if (EventUpdateTime < diff)
{

View File

@@ -1644,6 +1644,40 @@ bool Creature::IsVisibleInGridForPlayer(Player* pl) const
return false;
}
void Creature::DoFleeToGetAssistance(float radius) // Optional parameter
{
if (!getVictim())
return;
Creature* pCreature = NULL;
CellPair p(MaNGOS::ComputeCellPair(GetPositionX(), GetPositionY()));
Cell cell(p);
cell.data.Part.reserved = ALL_DISTRICT;
cell.SetNoCreate();
MaNGOS::NearestAssistCreatureInCreatureRangeCheck u_check(this,getVictim(),radius);
MaNGOS::CreatureLastSearcher<MaNGOS::NearestAssistCreatureInCreatureRangeCheck> searcher(pCreature, u_check);
TypeContainerVisitor<MaNGOS::CreatureLastSearcher<MaNGOS::NearestAssistCreatureInCreatureRangeCheck>, GridTypeMapContainer > grid_creature_searcher(searcher);
CellLock<GridReadGuard> cell_lock(cell, p);
cell_lock->Visit(cell_lock, grid_creature_searcher, *(GetMap()));
if(!GetMotionMaster()->empty() && (GetMotionMaster()->GetCurrentMovementGeneratorType() != POINT_MOTION_TYPE))
GetMotionMaster()->Clear(false);
if(pCreature == NULL)
{
GetMotionMaster()->MoveIdle();
GetMotionMaster()->MoveFleeing(getVictim());
}
else
{
GetMotionMaster()->MoveIdle();
GetMotionMaster()->MovePoint(0,pCreature->GetPositionX(),pCreature->GetPositionY(),pCreature->GetPositionZ());
}
}
void Creature::CallAssistence()
{
if( !m_AlreadyCallAssistence && getVictim() && !isPet() && !isCharmed())

View File

@@ -510,6 +510,7 @@ class MANGOS_DLL_SPEC Creature : public Unit
void CallAssistence();
void SetNoCallAssistence(bool val) { m_AlreadyCallAssistence = val; }
void DoFleeToGetAssistance(float radius = 50);
MovementGeneratorType GetDefaultMovementType() const { return m_defaultMovementType; }
void SetDefaultMovementType(MovementGeneratorType mgt) { m_defaultMovementType = mgt; }