diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp index ae4293a36..666c7b87a 100644 --- a/src/game/Creature.cpp +++ b/src/game/Creature.cpp @@ -1793,6 +1793,45 @@ void Creature::SetInCombatWithZone() } } +Unit* Creature::SelectAttackingTarget(AttackingTarget target, uint32 position) const +{ + if (!CanHaveThreatList()) + return NULL; + + //ThreatList m_threatlist; + ThreatList const& threatlist = getThreatManager().getThreatList(); + ThreatList::const_iterator i = threatlist.begin(); + ThreatList::const_reverse_iterator r = threatlist.rbegin(); + + if (position >= threatlist.size() || !threatlist.size()) + return NULL; + + switch(target) + { + case ATTACKING_TARGET_RANDOM: + { + advance(i, position + (rand() % (threatlist.size() - position))); + return Unit::GetUnit(*this, (*i)->getUnitGuid()); + } + case ATTACKING_TARGET_TOPAGGRO: + { + advance(i, position); + return Unit::GetUnit(*this, (*i)->getUnitGuid()); + } + case ATTACKING_TARGET_BOTTOMAGGRO: + { + advance(r, position); + return Unit::GetUnit(*this, (*r)->getUnitGuid()); + } + // TODO: implement these + //case ATTACKING_TARGET_RANDOM_PLAYER: + //case ATTACKING_TARGET_TOPAGGRO_PLAYER: + //case ATTACKING_TARGET_BOTTOMAGGRO_PLAYER: + } + + return NULL; +} + void Creature::_AddCreatureSpellCooldown(uint32 spell_id, time_t end_time) { m_CreatureSpellCooldowns[spell_id] = end_time; diff --git a/src/game/Creature.h b/src/game/Creature.h index d4589563f..d8f74fbdf 100644 --- a/src/game/Creature.h +++ b/src/game/Creature.h @@ -252,7 +252,7 @@ enum ChatType CHAT_TYPE_ZONE_YELL = 6 }; -//Selection method used by SelectTarget (CreatureEventAI) +// Selection method used by SelectAttackingTarget enum AttackingTarget { ATTACKING_TARGET_RANDOM = 0, //Just selects a random target @@ -590,6 +590,8 @@ class MANGOS_DLL_SPEC Creature : public Unit void SetInCombatWithZone(); + Unit* SelectAttackingTarget(AttackingTarget target, uint32 position) const; + bool hasQuest(uint32 quest_id) const; bool hasInvolvedQuest(uint32 quest_id) const; diff --git a/src/game/CreatureEventAI.cpp b/src/game/CreatureEventAI.cpp index 8849b52d8..d6fdf66e0 100644 --- a/src/game/CreatureEventAI.cpp +++ b/src/game/CreatureEventAI.cpp @@ -1147,37 +1147,6 @@ bool CreatureEventAI::IsVisible(Unit *pl) const && pl->isVisibleForOrDetect(m_creature,m_creature,true); } -inline Unit* CreatureEventAI::SelectUnit(AttackingTarget target, uint32 position) const -{ - //ThreatList m_threatlist; - ThreatList const& threatlist = m_creature->getThreatManager().getThreatList(); - ThreatList::const_iterator i = threatlist.begin(); - ThreatList::const_reverse_iterator r = threatlist.rbegin(); - - if (position >= threatlist.size() || !threatlist.size()) - return NULL; - - switch (target) - { - case ATTACKING_TARGET_RANDOM: - { - advance ( i , position + (rand() % (threatlist.size() - position ) )); - return Unit::GetUnit(*m_creature,(*i)->getUnitGuid()); - } - case ATTACKING_TARGET_TOPAGGRO: - { - advance ( i , position); - return Unit::GetUnit(*m_creature,(*i)->getUnitGuid()); - } - case ATTACKING_TARGET_BOTTOMAGGRO: - { - advance ( r , position); - return Unit::GetUnit(*m_creature,(*r)->getUnitGuid()); - } - } - return NULL; -} - inline uint32 CreatureEventAI::GetRandActionParam(uint32 rnd, uint32 param1, uint32 param2, uint32 param3) { switch (rnd % 3) @@ -1209,13 +1178,13 @@ inline Unit* CreatureEventAI::GetTargetByType(uint32 Target, Unit* pActionInvoke case TARGET_T_HOSTILE: return m_creature->getVictim(); case TARGET_T_HOSTILE_SECOND_AGGRO: - return SelectUnit(ATTACKING_TARGET_TOPAGGRO,1); + return m_creature->SelectAttackingTarget(ATTACKING_TARGET_TOPAGGRO, 1); case TARGET_T_HOSTILE_LAST_AGGRO: - return SelectUnit(ATTACKING_TARGET_BOTTOMAGGRO,0); + return m_creature->SelectAttackingTarget(ATTACKING_TARGET_BOTTOMAGGRO, 0); case TARGET_T_HOSTILE_RANDOM: - return SelectUnit(ATTACKING_TARGET_RANDOM,0); + return m_creature->SelectAttackingTarget(ATTACKING_TARGET_RANDOM, 0); case TARGET_T_HOSTILE_RANDOM_NOT_TOP: - return SelectUnit(ATTACKING_TARGET_RANDOM,1); + return m_creature->SelectAttackingTarget(ATTACKING_TARGET_RANDOM, 1); case TARGET_T_ACTION_INVOKER: return pActionInvoker; default: diff --git a/src/game/CreatureEventAI.h b/src/game/CreatureEventAI.h index 715bf0a7b..1b07922d2 100644 --- a/src/game/CreatureEventAI.h +++ b/src/game/CreatureEventAI.h @@ -596,7 +596,6 @@ class MANGOS_DLL_SPEC CreatureEventAI : public CreatureAI inline uint32 GetRandActionParam(uint32 rnd, uint32 param1, uint32 param2, uint32 param3); inline int32 GetRandActionParam(uint32 rnd, int32 param1, int32 param2, int32 param3); inline Unit* GetTargetByType(uint32 Target, Unit* pActionInvoker); - inline Unit* SelectUnit(AttackingTarget target, uint32 position) const; void DoScriptText(int32 textEntry, WorldObject* pSource, Unit* target); void DoMeleeAttackIfReady(); diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index fae1e957d..9744907b8 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 "9831" + #define REVISION_NR "9832" #endif // __REVISION_NR_H__