Core/GuardAI: General cleanup and removed some unnecessary code.

This commit is contained in:
kaelima
2012-05-23 16:40:44 +02:00
parent dbe8034ec2
commit 2ae0cfc8b6
2 changed files with 11 additions and 99 deletions
+7 -80
View File
@@ -23,7 +23,7 @@
#include "World.h" #include "World.h"
#include "CreatureAIImpl.h" #include "CreatureAIImpl.h"
int GuardAI::Permissible(const Creature* creature) int GuardAI::Permissible(Creature const* creature)
{ {
if (creature->isGuard()) if (creature->isGuard())
return PERMIT_BASE_SPECIAL; return PERMIT_BASE_SPECIAL;
@@ -31,7 +31,7 @@ int GuardAI::Permissible(const Creature* creature)
return PERMIT_BASE_NO; return PERMIT_BASE_NO;
} }
GuardAI::GuardAI(Creature* creature) : ScriptedAI(creature), i_victimGuid(0), i_state(STATE_NORMAL), i_tracker(TIME_INTERVAL_LOOK) GuardAI::GuardAI(Creature* creature) : ScriptedAI(creature)
{ {
} }
@@ -40,108 +40,35 @@ bool GuardAI::CanSeeAlways(WorldObject const* obj)
if (!obj->isType(TYPEMASK_UNIT)) if (!obj->isType(TYPEMASK_UNIT))
return false; return false;
std::list<HostileReference*> t_list = me->getThreatManager().getThreatList(); std::list<HostileReference*> threatList = me->getThreatManager().getThreatList();
for (std::list<HostileReference*>::const_iterator itr = t_list.begin(); itr!= t_list.end(); ++itr) for (std::list<HostileReference*>::const_iterator itr = threatList.begin(); itr != threatList.end(); ++itr)
{ if ((*itr)->getUnitGuid() == obj->GetGUID())
if (Unit* unit = Unit::GetUnit(*me, (*itr)->getUnitGuid())) return true;
if (unit == obj)
return true;
}
return false; return false;
} }
void GuardAI::MoveInLineOfSight(Unit* unit)
{
// Ignore Z for flying creatures
if (!me->CanFly() && me->GetDistanceZ(unit) > CREATURE_Z_ATTACK_RANGE)
return;
if (!me->getVictim() && me->IsValidAttackTarget(unit) &&
(unit->IsHostileToPlayers() || me->IsHostileTo(unit)) &&
unit->isInAccessiblePlaceFor(me))
{
float attackRadius = me->GetAttackDistance(unit);
if (me->IsWithinDistInMap(unit, attackRadius))
{
//Need add code to let guard support player
AttackStart(unit);
//u->RemoveAurasByType(SPELL_AURA_MOD_STEALTH);
}
}
}
void GuardAI::EnterEvadeMode() void GuardAI::EnterEvadeMode()
{ {
if (!me->isAlive()) if (!me->isAlive())
{ {
sLog->outStaticDebug("Creature stopped attacking because he is dead [guid=%u]", me->GetGUIDLow());
me->GetMotionMaster()->MoveIdle(); me->GetMotionMaster()->MoveIdle();
i_state = STATE_NORMAL;
i_victimGuid = 0;
me->CombatStop(true); me->CombatStop(true);
me->DeleteThreatList(); me->DeleteThreatList();
return; return;
} }
Unit* victim = ObjectAccessor::GetUnit(*me, i_victimGuid); sLog->outDebug(LOG_FILTER_UNITS, "Guard entry: %u enters evade mode.", me->GetEntry());
if (!victim)
{
sLog->outStaticDebug("Creature stopped attacking because victim does not exist [guid=%u]", me->GetGUIDLow());
}
else if (!victim->isAlive())
{
sLog->outStaticDebug("Creature stopped attacking because victim is dead [guid=%u]", me->GetGUIDLow());
}
else if (victim->HasStealthAura())
{
sLog->outStaticDebug("Creature stopped attacking because victim is using stealth [guid=%u]", me->GetGUIDLow());
}
else if (victim->isInFlight())
{
sLog->outStaticDebug("Creature stopped attacking because victim is flying away [guid=%u]", me->GetGUIDLow());
}
else
{
sLog->outStaticDebug("Creature stopped attacking because victim outran him [guid=%u]", me->GetGUIDLow());
}
me->RemoveAllAuras(); me->RemoveAllAuras();
me->DeleteThreatList(); me->DeleteThreatList();
i_victimGuid = 0;
me->CombatStop(true); me->CombatStop(true);
i_state = STATE_NORMAL;
// Remove ChaseMovementGenerator from MotionMaster stack list, and add HomeMovementGenerator instead // Remove ChaseMovementGenerator from MotionMaster stack list, and add HomeMovementGenerator instead
if (me->GetMotionMaster()->GetCurrentMovementGeneratorType() == CHASE_MOTION_TYPE) if (me->GetMotionMaster()->GetCurrentMovementGeneratorType() == CHASE_MOTION_TYPE)
me->GetMotionMaster()->MoveTargetedHome(); me->GetMotionMaster()->MoveTargetedHome();
} }
void GuardAI::UpdateAI(const uint32 /*diff*/)
{
// update i_victimGuid if me->getVictim() !=0 and changed
if (!UpdateVictim())
return;
Unit* const victim = me->getVictim();
if (!victim)
return;
i_victimGuid = victim->GetGUID();
if (me->isAttackReady())
{
if (me->IsWithinMeleeRange(victim))
{
me->AttackerStateUpdate(victim);
me->resetAttackTimer();
}
}
}
void GuardAI::JustDied(Unit* killer) void GuardAI::JustDied(Unit* killer)
{ {
if (Player* player = killer->GetCharmerOrOwnerPlayerOrPlayerItself()) if (Player* player = killer->GetCharmerOrOwnerPlayerOrPlayerItself())
+4 -19
View File
@@ -20,34 +20,19 @@
#define TRINITY_GUARDAI_H #define TRINITY_GUARDAI_H
#include "ScriptedCreature.h" #include "ScriptedCreature.h"
#include "Timer.h"
class Creature; class Creature;
class GuardAI : public ScriptedAI class GuardAI : public ScriptedAI
{ {
enum GuardState
{
STATE_NORMAL = 1,
STATE_LOOK_AT_VICTIM = 2
};
public: public:
explicit GuardAI(Creature* creature);
explicit GuardAI(Creature* c); static int Permissible(Creature const* creature);
void MoveInLineOfSight(Unit*);
void EnterEvadeMode();
void JustDied(Unit*);
bool CanSeeAlways(WorldObject const* obj); bool CanSeeAlways(WorldObject const* obj);
void UpdateAI(const uint32); void EnterEvadeMode();
static int Permissible(const Creature*); void JustDied(Unit* killer);
private:
uint64 i_victimGuid;
GuardState i_state;
TimeTracker i_tracker;
}; };
#endif #endif