diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp index ab588a8fa..62f268188 100644 --- a/src/game/Creature.cpp +++ b/src/game/Creature.cpp @@ -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 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::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: diff --git a/src/game/Creature.h b/src/game/Creature.h index a822c7300..69d57e4db 100644 --- a/src/game/Creature.h +++ b/src/game/Creature.h @@ -703,16 +703,15 @@ 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 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 m_assistants; - Unit& m_owner; + ObjectGuid m_victimGuid; + std::vector m_assistantGuids; + Unit& m_owner; }; class ForcedDespawnDelayEvent : public BasicEvent diff --git a/src/game/CreatureEventAI.cpp b/src/game/CreatureEventAI.cpp index 79b779c55..c8f261dea 100644 --- a/src/game/CreatureEventAI.cpp +++ b/src/game/CreatureEventAI.cpp @@ -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: diff --git a/src/game/Spell.cpp b/src/game/Spell.cpp index 93f5c63c8..d2da586c9 100644 --- a/src/game/Spell.cpp +++ b/src/game/Spell.cpp @@ -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; diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index 318f3d73d..fa88df47c 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -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); @@ -9664,7 +9659,7 @@ void Unit::SetFeared(bool apply, uint64 const& casterGUID, uint32 spellID, uint3 { if( apply ) { - if(HasAuraType(SPELL_AURA_PREVENTS_FLEEING)) + if (HasAuraType(SPELL_AURA_PREVENTS_FLEEING)) return; SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_FLEEING); @@ -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 } @@ -9682,18 +9677,19 @@ void Unit::SetFeared(bool apply, uint64 const& casterGUID, uint32 spellID, uint3 GetMotionMaster()->MovementExpired(false); - if( GetTypeId() != TYPEID_PLAYER && isAlive() ) + if (GetTypeId() != TYPEID_PLAYER && isAlive()) { + Creature* c = ((Creature*)this); // restore appropriate movement generator - if(getVictim()) + if (getVictim()) GetMotionMaster()->MoveChase(getVictim()); else 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); } } diff --git a/src/game/Unit.h b/src/game/Unit.h index 5af1b5eea..53bfd319a 100644 --- a/src/game/Unit.h +++ b/src/game/Unit.h @@ -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; } @@ -1973,13 +1972,13 @@ class MANGOS_DLL_SPEC Unit : public WorldObject template void Unit::CallForAllControlledUnits(Func const& func, bool withTotems, bool withGuardians, bool withCharms) { - if(Pet* pet = GetPet()) + if (Pet* pet = GetPet()) func(pet); 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); } @@ -1991,7 +1990,7 @@ void Unit::CallForAllControlledUnits(Func const& func, bool withTotems, bool wit } if (withCharms) - if(Unit* charm = GetCharm()) + if (Unit* charm = GetCharm()) func(charm); } @@ -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; @@ -2021,7 +2020,7 @@ bool Unit::CheckAllControlledUnits(Func const& func, bool withTotems, bool withG } if (withCharms) - if(Unit const* charm = GetCharm()) + if (Unit const* charm = GetCharm()) if (func(charm)) return true; diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 213d79dab..1b2c29217 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "10384" + #define REVISION_NR "10385" #endif // __REVISION_NR_H__