mirror of
https://github.com/mangosfour/server.git
synced 2025-12-12 19:37:03 +00:00
[9832] Move function to select an attacking target from EventAi to Creature class
Also rename function to a more descriptive name, SelectAttackingTarget Signed-off-by: NoFantasy <nofantasy@nf.no>
This commit is contained in:
parent
0cc946e91e
commit
92ab082fc6
5 changed files with 47 additions and 38 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#ifndef __REVISION_NR_H__
|
||||
#define __REVISION_NR_H__
|
||||
#define REVISION_NR "9831"
|
||||
#define REVISION_NR "9832"
|
||||
#endif // __REVISION_NR_H__
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue