[11460] Use ObjectGuids in last missing cases in AI classes.

This commit is contained in:
VladimirMangos 2011-05-10 11:03:54 +04:00
parent 44f2c26389
commit b4f2e3d1a0
13 changed files with 38 additions and 34 deletions

View file

@ -37,7 +37,7 @@ AggressorAI::Permissible(const Creature *creature)
return PERMIT_BASE_NO;
}
AggressorAI::AggressorAI(Creature *c) : CreatureAI(c), i_victimGuid(0), i_state(STATE_NORMAL), i_tracker(TIME_INTERVAL_LOOK)
AggressorAI::AggressorAI(Creature *c) : CreatureAI(c), i_state(STATE_NORMAL), i_tracker(TIME_INTERVAL_LOOK)
{
}
@ -73,7 +73,7 @@ void AggressorAI::EnterEvadeMode()
if (!m_creature->isAlive())
{
DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "Creature stopped attacking, he is dead [guid=%u]", m_creature->GetGUIDLow());
i_victimGuid = 0;
i_victimGuid.Clear();
m_creature->CombatStop(true);
m_creature->DeleteThreatList();
return;
@ -114,7 +114,7 @@ void AggressorAI::EnterEvadeMode()
}
m_creature->DeleteThreatList();
i_victimGuid = 0;
i_victimGuid.Clear();
m_creature->CombatStop(true);
m_creature->SetLootRecipient(NULL);
}
@ -126,7 +126,7 @@ AggressorAI::UpdateAI(const uint32 /*diff*/)
if(!m_creature->SelectHostileTarget() || !m_creature->getVictim())
return;
i_victimGuid = m_creature->getVictim()->GetGUID();
i_victimGuid = m_creature->getVictim()->GetObjectGuid();
DoMeleeAttackIfReady();
}
@ -146,7 +146,7 @@ AggressorAI::AttackStart(Unit *u)
if(m_creature->Attack(u,true))
{
i_victimGuid = u->GetGUID();
i_victimGuid = u->GetObjectGuid();
m_creature->AddThreat(u);
m_creature->SetInCombatWith(u);

View file

@ -21,6 +21,7 @@
#include "CreatureAI.h"
#include "Timer.h"
#include "ObjectGuid.h"
class Creature;
@ -45,8 +46,9 @@ class MANGOS_DLL_DECL AggressorAI : public CreatureAI
static int Permissible(const Creature *);
private:
uint64 i_victimGuid;
ObjectGuid i_victimGuid;
AggressorState i_state;
TimeTracker i_tracker;
};
#endif

View file

@ -73,7 +73,7 @@ CanCastResult CreatureAI::CanCastSpell(Unit* pTarget, const SpellEntry *pSpell,
return CAST_FAIL_OTHER;
}
CanCastResult CreatureAI::DoCastSpellIfCan(Unit* pTarget, uint32 uiSpell, uint32 uiCastFlags, uint64 uiOriginalCasterGUID)
CanCastResult CreatureAI::DoCastSpellIfCan(Unit* pTarget, uint32 uiSpell, uint32 uiCastFlags, ObjectGuid uiOriginalCasterGUID)
{
Unit* pCaster = m_creature;

View file

@ -24,6 +24,7 @@
#include "Policies/Singleton.h"
#include "Dynamic/ObjectRegistry.h"
#include "Dynamic/FactoryHolder.h"
#include "ObjectGuid.h"
class WorldObject;
class GameObject;
@ -156,7 +157,7 @@ class MANGOS_DLL_SPEC CreatureAI
///== Helper functions =============================
bool DoMeleeAttackIfReady();
CanCastResult DoCastSpellIfCan(Unit* pTarget, uint32 uiSpell, uint32 uiCastFlags = 0, uint64 uiOriginalCasterGUID = 0);
CanCastResult DoCastSpellIfCan(Unit* pTarget, uint32 uiSpell, uint32 uiCastFlags = 0, ObjectGuid uiOriginalCasterGUID = ObjectGuid());
///== Fields =======================================

View file

@ -189,9 +189,9 @@ FleeingMovementGenerator<T>::_setMoveData(T &owner)
{
float cur_dist_xyz = owner.GetDistance(i_caster_x, i_caster_y, i_caster_z);
if(i_to_distance_from_caster > 0.0f)
if (i_to_distance_from_caster > 0.0f)
{
if((i_last_distance_from_caster > i_to_distance_from_caster && cur_dist_xyz < i_to_distance_from_caster) ||
if ((i_last_distance_from_caster > i_to_distance_from_caster && cur_dist_xyz < i_to_distance_from_caster) ||
// if we reach lower distance
(i_last_distance_from_caster > i_to_distance_from_caster && cur_dist_xyz > i_last_distance_from_caster) ||
// if we can't be close
@ -217,12 +217,10 @@ FleeingMovementGenerator<T>::_setMoveData(T &owner)
float cur_dist;
float angle_to_caster;
Unit * fright = ObjectAccessor::GetUnit(owner, i_frightGUID);
if(fright)
if (Unit* fright = owner.GetMap()->GetUnit(i_frightGuid))
{
cur_dist = fright->GetDistance(&owner);
if(cur_dist < cur_dist_xyz)
if (cur_dist < cur_dist_xyz)
{
i_caster_x = fright->GetPositionX();
i_caster_y = fright->GetPositionY();
@ -286,7 +284,7 @@ FleeingMovementGenerator<T>::Initialize(T &owner)
_Init(owner);
if(Unit * fright = ObjectAccessor::GetUnit(owner, i_frightGUID))
if (Unit * fright = owner.GetMap()->GetUnit(i_frightGuid))
{
i_caster_x = fright->GetPositionX();
i_caster_y = fright->GetPositionY();

View file

@ -22,13 +22,14 @@
#include "MovementGenerator.h"
#include "DestinationHolder.h"
#include "Traveller.h"
#include "ObjectGuid.h"
template<class T>
class MANGOS_DLL_SPEC FleeingMovementGenerator
: public MovementGeneratorMedium< T, FleeingMovementGenerator<T> >
{
public:
FleeingMovementGenerator(uint64 fright) : i_frightGUID(fright), i_nextCheckTime(0) {}
FleeingMovementGenerator(ObjectGuid fright) : i_frightGuid(fright), i_nextCheckTime(0) {}
void Initialize(T &);
void Finalize(T &);
@ -54,7 +55,7 @@ class MANGOS_DLL_SPEC FleeingMovementGenerator
float i_last_distance_from_caster;
float i_to_distance_from_caster;
float i_cur_angle;
uint64 i_frightGUID;
ObjectGuid i_frightGuid;
TimeTracker i_nextCheckTime;
DestinationHolder< Traveller<T> > i_destinationHolder;
@ -64,7 +65,7 @@ class MANGOS_DLL_SPEC TimedFleeingMovementGenerator
: public FleeingMovementGenerator<Creature>
{
public:
TimedFleeingMovementGenerator(uint64 fright, uint32 time) :
TimedFleeingMovementGenerator(ObjectGuid fright, uint32 time) :
FleeingMovementGenerator<Creature>(fright),
i_totalFleeTime(time) {}

View file

@ -345,13 +345,13 @@ void MotionMaster::MoveFleeing(Unit* enemy, uint32 time)
DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "%s flee from %s", m_owner->GetGuidStr().c_str(), enemy->GetGuidStr().c_str());
if (m_owner->GetTypeId() == TYPEID_PLAYER)
Mutate(new FleeingMovementGenerator<Player>(enemy->GetGUID()));
Mutate(new FleeingMovementGenerator<Player>(enemy->GetObjectGuid()));
else
{
if (time)
Mutate(new TimedFleeingMovementGenerator(enemy->GetGUID(), time));
Mutate(new TimedFleeingMovementGenerator(enemy->GetObjectGuid(), time));
else
Mutate(new FleeingMovementGenerator<Creature>(enemy->GetGUID()));
Mutate(new FleeingMovementGenerator<Creature>(enemy->GetObjectGuid()));
}
}

View file

@ -252,7 +252,7 @@ void PetAI::UpdateAI(const uint32 diff)
bool spellUsed = false;
for (AllySet::const_iterator tar = m_AllySet.begin(); tar != m_AllySet.end(); ++tar)
{
Unit* Target = ObjectAccessor::GetUnit(*m_creature,*tar);
Unit* Target = m_creature->GetMap()->GetUnit(*tar);
//only buff targets that are in combat, unless the spell can only be cast while out of combat
if (!Target)

View file

@ -48,7 +48,7 @@ ReactorAI::AttackStart(Unit *p)
if(m_creature->Attack(p,true))
{
DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "Tag unit GUID: %u (TypeId: %u) as a victim", p->GetGUIDLow(), p->GetTypeId());
i_victimGuid = p->GetGUID();
i_victimGuid = p->GetObjectGuid();
m_creature->AddThreat(p);
m_creature->SetInCombatWith(p);
@ -71,7 +71,7 @@ ReactorAI::UpdateAI(const uint32 /*time_diff*/)
if (!m_creature->SelectHostileTarget() || !m_creature->getVictim())
return;
i_victimGuid = m_creature->getVictim()->GetGUID();
i_victimGuid = m_creature->getVictim()->GetObjectGuid();
DoMeleeAttackIfReady();
}
@ -84,7 +84,7 @@ ReactorAI::EnterEvadeMode()
DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "Creature stopped attacking, he is dead [guid=%u]", m_creature->GetGUIDLow());
m_creature->GetMotionMaster()->MovementExpired();
m_creature->GetMotionMaster()->MoveIdle();
i_victimGuid = 0;
i_victimGuid.Clear();
m_creature->CombatStop(true);
m_creature->DeleteThreatList();
return;
@ -111,7 +111,7 @@ ReactorAI::EnterEvadeMode()
m_creature->RemoveAllAuras();
m_creature->DeleteThreatList();
i_victimGuid = 0;
i_victimGuid.Clear();
m_creature->CombatStop(true);
m_creature->SetLootRecipient(NULL);

View file

@ -20,6 +20,7 @@
#define MANGOS_REACTORAI_H
#include "CreatureAI.h"
#include "ObjectGuid.h"
class Unit;
@ -27,7 +28,7 @@ class MANGOS_DLL_DECL ReactorAI : public CreatureAI
{
public:
explicit ReactorAI(Creature *c) : CreatureAI(c), i_victimGuid(0) {}
explicit ReactorAI(Creature *c) : CreatureAI(c) {}
void MoveInLineOfSight(Unit *);
void AttackStart(Unit *);
@ -38,6 +39,6 @@ class MANGOS_DLL_DECL ReactorAI : public CreatureAI
static int Permissible(const Creature *);
private:
uint64 i_victimGuid;
ObjectGuid i_victimGuid;
};
#endif

View file

@ -35,7 +35,7 @@ TotemAI::Permissible(const Creature *creature)
return PERMIT_BASE_NO;
}
TotemAI::TotemAI(Creature *c) : CreatureAI(c), i_victimGuid(0)
TotemAI::TotemAI(Creature *c) : CreatureAI(c)
{
}
@ -70,7 +70,7 @@ TotemAI::UpdateAI(const uint32 /*diff*/)
// SPELLMOD_RANGE not applied in this place just because nonexistent range mods for attacking totems
// pointer to appropriate target if found any
Unit* victim = i_victimGuid ? m_creature->GetMap()->GetUnit(i_victimGuid) : NULL;
Unit* victim = m_creature->GetMap()->GetUnit(i_victimGuid);
// Search victim if no, not attackable, or out of range, or friendly (possible in case duel end)
if( !victim ||
@ -88,14 +88,14 @@ TotemAI::UpdateAI(const uint32 /*diff*/)
if (victim)
{
// remember
i_victimGuid = victim->GetGUID();
i_victimGuid = victim->GetObjectGuid();
// attack
m_creature->SetInFront(victim); // client change orientation by self
m_creature->CastSpell(victim, getTotem().GetSpell(), false);
}
else
i_victimGuid = 0;
i_victimGuid.Clear();
}
bool

View file

@ -20,6 +20,7 @@
#define MANGOS_TOTEMAI_H
#include "CreatureAI.h"
#include "ObjectGuid.h"
#include "Timer.h"
class Creature;
@ -42,6 +43,6 @@ class MANGOS_DLL_DECL TotemAI : public CreatureAI
Totem& getTotem();
private:
uint64 i_victimGuid;
ObjectGuid i_victimGuid;
};
#endif

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "11459"
#define REVISION_NR "11460"
#endif // __REVISION_NR_H__