[10385] Remove Unit::GetUnit and update it callers.

This commit is contained in:
VladimirMangos 2010-08-20 16:51:52 +04:00
parent dcc9dc25ae
commit 77ae9a63b8
7 changed files with 40 additions and 50 deletions

View file

@ -84,12 +84,12 @@ VendorItem const* VendorItemData::FindItemCostPair(uint32 item_id, uint32 extend
bool AssistDelayEvent::Execute(uint64 /*e_time*/, uint32 /*p_time*/)
{
if(Unit* victim = Unit::GetUnit(m_owner, m_victim))
if (Unit* victim = m_owner.GetMap()->GetUnit(m_victimGuid))
{
while (!m_assistants.empty())
while (!m_assistantGuids.empty())
{
Creature* assistant = (Creature*)Unit::GetUnit(m_owner, *m_assistants.begin());
m_assistants.pop_front();
Creature* assistant = m_owner.GetMap()->GetAnyTypeCreature(*m_assistantGuids.rbegin());
m_assistantGuids.pop_back();
if (assistant && assistant->CanAssistTo(&m_owner, victim))
{
@ -102,6 +102,14 @@ bool AssistDelayEvent::Execute(uint64 /*e_time*/, uint32 /*p_time*/)
return true;
}
AssistDelayEvent::AssistDelayEvent( ObjectGuid victim, Unit& owner, std::list<Creature*> const& assistants ) : BasicEvent(), m_victimGuid(victim), m_owner(owner)
{
// Pushing guids because in delay can happen some creature gets despawned => invalid pointer
m_assistantGuids.reserve(assistants.size());
for (std::list<Creature*>::const_iterator itr = assistants.begin(); itr != assistants.end(); ++itr)
m_assistantGuids.push_back((*itr)->GetObjectGuid());
}
bool ForcedDespawnDelayEvent::Execute(uint64 /*e_time*/, uint32 /*p_time*/)
{
m_owner.ForcedDespawn();
@ -1663,13 +1671,7 @@ void Creature::CallAssistance()
if (!assistList.empty())
{
AssistDelayEvent *e = new AssistDelayEvent(getVictim()->GetGUID(), *this);
while (!assistList.empty())
{
// Pushing guids because in delay can happen some creature gets despawned => invalid pointer
e->AddAssistant((*assistList.begin())->GetGUID());
assistList.pop_front();
}
AssistDelayEvent *e = new AssistDelayEvent(getVictim()->GetObjectGuid(), *this, assistList);
m_Events.AddEvent(e, m_Events.CalculateTime(sWorld.getConfig(CONFIG_UINT32_CREATURE_FAMILY_ASSISTANCE_DELAY)));
}
}
@ -1945,17 +1947,17 @@ Unit* Creature::SelectAttackingTarget(AttackingTarget target, uint32 position) c
case ATTACKING_TARGET_RANDOM:
{
advance(i, position + (rand() % (threatlist.size() - position)));
return Unit::GetUnit(*this, (*i)->getUnitGuid());
return GetMap()->GetUnit((*i)->getUnitGuid());
}
case ATTACKING_TARGET_TOPAGGRO:
{
advance(i, position);
return Unit::GetUnit(*this, (*i)->getUnitGuid());
return GetMap()->GetUnit((*i)->getUnitGuid());
}
case ATTACKING_TARGET_BOTTOMAGGRO:
{
advance(r, position);
return Unit::GetUnit(*this, (*r)->getUnitGuid());
return GetMap()->GetUnit((*r)->getUnitGuid());
}
// TODO: implement these
//case ATTACKING_TARGET_RANDOM_PLAYER:

View file

@ -703,15 +703,14 @@ class MANGOS_DLL_SPEC Creature : public Unit
class AssistDelayEvent : public BasicEvent
{
public:
AssistDelayEvent(const uint64& victim, Unit& owner) : BasicEvent(), m_victim(victim), m_owner(owner) { }
AssistDelayEvent(ObjectGuid victim, Unit& owner, std::list<Creature*> const& assistants);
bool Execute(uint64 e_time, uint32 p_time);
void AddAssistant(const uint64& guid) { m_assistants.push_back(guid); }
private:
AssistDelayEvent();
uint64 m_victim;
std::list<uint64> m_assistants;
ObjectGuid m_victimGuid;
std::vector<ObjectGuid> m_assistantGuids;
Unit& m_owner;
};

View file

@ -551,7 +551,7 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
{
ThreatList const& threatList = m_creature->getThreatManager().getThreatList();
for (ThreatList::const_iterator i = threatList.begin(); i != threatList.end(); ++i)
if(Unit* Temp = Unit::GetUnit(*m_creature,(*i)->getUnitGuid()))
if(Unit* Temp = m_creature->GetMap()->GetUnit((*i)->getUnitGuid()))
m_creature->getThreatManager().modifyThreatPercent(Temp, action.threat_all_pct.percent);
break;
}
@ -652,19 +652,14 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
break;
case ACTION_T_QUEST_EVENT_ALL:
if (pActionInvoker && pActionInvoker->GetTypeId() == TYPEID_PLAYER)
{
if (Unit* Temp = Unit::GetUnit(*m_creature,pActionInvoker->GetGUID()))
if (Temp->GetTypeId() == TYPEID_PLAYER)
((Player*)Temp)->GroupEventHappens(action.quest_event_all.questId,m_creature);
}
((Player*)pActionInvoker)->GroupEventHappens(action.quest_event_all.questId,m_creature);
break;
case ACTION_T_CAST_EVENT_ALL:
{
ThreatList const& threatList = m_creature->getThreatManager().getThreatList();
for (ThreatList::const_iterator i = threatList.begin(); i != threatList.end(); ++i)
if (Unit* Temp = Unit::GetUnit(*m_creature,(*i)->getUnitGuid()))
if (Temp->GetTypeId() == TYPEID_PLAYER)
((Player*)Temp)->CastedCreatureOrGO(action.cast_event_all.creatureId, m_creature->GetObjectGuid(), action.cast_event_all.spellId);
if (Player* temp = m_creature->GetMap()->GetPlayer((*i)->getUnitGuid()))
temp->CastedCreatureOrGO(action.cast_event_all.creatureId, m_creature->GetObjectGuid(), action.cast_event_all.spellId);
break;
}
case ACTION_T_REMOVEAURASFROMSPELL:

View file

@ -4336,8 +4336,7 @@ SpellCastResult Spell::CheckCast(bool strict)
}
else if (m_caster == target)
{
if (m_caster->GetTypeId() == TYPEID_PLAYER) // Target - is player caster
if (m_caster->GetTypeId() == TYPEID_PLAYER && m_caster->IsInWorld())
{
// Additional check for some spells
// If 0 spell effect empty - client not send target data (need use selection)
@ -4345,7 +4344,7 @@ SpellCastResult Spell::CheckCast(bool strict)
if (m_targets.m_targetMask == TARGET_FLAG_SELF &&
m_spellInfo->EffectImplicitTargetA[EFFECT_INDEX_1] == TARGET_CHAIN_DAMAGE)
{
if (target = m_caster->GetUnit(*m_caster, ((Player *)m_caster)->GetSelection()))
if (target = m_caster->GetMap()->GetUnit(((Player *)m_caster)->GetSelection()))
m_targets.setUnitTarget(target);
else
return SPELL_FAILED_BAD_TARGETS;

View file

@ -8643,11 +8643,6 @@ void Unit::ApplyDiminishingAura( DiminishingGroup group, bool apply )
}
}
Unit* Unit::GetUnit(WorldObject const& object, uint64 guid)
{
return ObjectAccessor::GetUnit(object,guid);
}
bool Unit::isVisibleForInState( Player const* u, WorldObject const* viewPoint, bool inVisibleList ) const
{
return isVisibleForOrDetect(u, viewPoint, false, inVisibleList, false);
@ -9672,7 +9667,7 @@ void Unit::SetFeared(bool apply, uint64 const& casterGUID, uint32 spellID, uint3
GetMotionMaster()->MovementExpired(false);
CastStop(GetGUID() == casterGUID ? spellID : 0);
Unit* caster = ObjectAccessor::GetUnit(*this,casterGUID);
Unit* caster = IsInWorld() ? GetMap()->GetUnit(casterGUID) : NULL;
GetMotionMaster()->MoveFleeing(caster, time); // caster==NULL processed in MoveFleeing
}
@ -9684,6 +9679,7 @@ void Unit::SetFeared(bool apply, uint64 const& casterGUID, uint32 spellID, uint3
if (GetTypeId() != TYPEID_PLAYER && isAlive())
{
Creature* c = ((Creature*)this);
// restore appropriate movement generator
if (getVictim())
GetMotionMaster()->MoveChase(getVictim());
@ -9691,9 +9687,9 @@ void Unit::SetFeared(bool apply, uint64 const& casterGUID, uint32 spellID, uint3
GetMotionMaster()->Initialize();
// attack caster if can
Unit* caster = Unit::GetUnit(*this, casterGUID);
if(caster && ((Creature*)this)->AI())
((Creature*)this)->AI()->AttackedBy(caster);
if (Unit* caster = IsInWorld() ? GetMap()->GetUnit(casterGUID) : NULL)
if (c->AI())
c->AI()->AttackedBy(caster);
}
}

View file

@ -1848,7 +1848,6 @@ class MANGOS_DLL_SPEC Unit : public WorldObject
void addFollower(FollowerReference* pRef) { m_FollowingRefManager.insertFirst(pRef); }
void removeFollower(FollowerReference* /*pRef*/ ) { /* nothing to do yet */ }
static Unit* GetUnit(WorldObject const& object, uint64 guid);
MotionMaster* GetMotionMaster() { return &i_motionMaster; }
@ -1979,7 +1978,7 @@ void Unit::CallForAllControlledUnits(Func const& func, bool withTotems, bool wit
if (withGuardians)
{
for(GuardianPetList::const_iterator itr = m_guardianPets.begin(); itr != m_guardianPets.end(); ++itr)
if(Unit* guardian = Unit::GetUnit(*this,*itr))
if (Pet* guardian = GetMap()->GetPet(*itr))
func(guardian);
}
@ -2006,7 +2005,7 @@ bool Unit::CheckAllControlledUnits(Func const& func, bool withTotems, bool withG
if (withGuardians)
{
for(GuardianPetList::const_iterator itr = m_guardianPets.begin(); itr != m_guardianPets.end(); ++itr)
if (Unit const* guardian = Unit::GetUnit(*this,*itr))
if (Pet const* guardian = GetMap()->GetPet(*itr))
if (func(guardian))
return true;

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "10384"
#define REVISION_NR "10385"
#endif // __REVISION_NR_H__