TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ThreatManager Class Reference

#include <ThreatManager.h>

Public Member Functions

 ThreatManager (Unit *owner)
 
 ~ThreatManager ()
 
void clearReferences ()
 
void addThreat (Unit *victim, float threat, SpellSchoolMask schoolMask=SPELL_SCHOOL_MASK_NORMAL, SpellInfo const *threatSpell=NULL)
 
void doAddThreat (Unit *victim, float threat)
 
void modifyThreatPercent (Unit *victim, int32 percent)
 
float getThreat (Unit *victim, bool alsoSearchOfflineList=false)
 
bool isThreatListEmpty () const
 
void processThreatEvent (ThreatRefStatusChangeEvent *threatRefStatusChangeEvent)
 
bool isNeedUpdateToClient (uint32 time)
 
HostileReferencegetCurrentVictim () const
 
UnitGetOwner () const
 
UnitgetHostilTarget ()
 
void tauntApply (Unit *taunter)
 
void tauntFadeOut (Unit *taunter)
 
void setCurrentVictim (HostileReference *hostileRef)
 
void setDirty (bool isDirty)
 
void resetAllAggro ()
 
template<class PREDICATE >
void resetAggro (PREDICATE predicate)
 
ThreatContainer::StorageType
const
getThreatList () const
 
ThreatContainer::StorageType
const
getOfflineThreatList () const
 
ThreatContainergetOnlineContainer ()
 
ThreatContainergetOfflineContainer ()
 

Private Member Functions

void _addThreat (Unit *victim, float threat)
 

Private Attributes

HostileReferenceiCurrentVictim
 
UnitiOwner
 
uint32 iUpdateTimer
 
ThreatContainer iThreatContainer
 
ThreatContainer iThreatOfflineContainer
 

Friends

class HostileReference
 

Constructor & Destructor Documentation

ThreatManager::ThreatManager ( Unit owner)
explicit
arena_t NULL
Definition: jemalloc_internal.h:624
uint32 iUpdateTimer
Definition: ThreatManager.h:272
HostileReference * iCurrentVictim
Definition: ThreatManager.h:270
#define THREAT_UPDATE_INTERVAL
Definition: ThreatManager.h:37
Unit * iOwner
Definition: ThreatManager.h:271
ThreatManager::~ThreatManager ( )
inline
208 { clearReferences(); }
void clearReferences()
Definition: ThreatManager.cpp:396

Member Function Documentation

void ThreatManager::_addThreat ( Unit victim,
float  threat 
)
private
433 {
434  HostileReference* ref = iThreatContainer.addThreat(victim, threat);
435  // Ref is not in the online refs, search the offline refs next
436  if (!ref)
437  ref = iThreatOfflineContainer.addThreat(victim, threat);
438 
439  if (!ref) // there was no ref => create a new one
440  {
441  // threat has to be 0 here
442  HostileReference* hostileRef = new HostileReference(victim, this, 0);
443  iThreatContainer.addReference(hostileRef);
444  hostileRef->addThreat(threat); // now we add the real threat
445  if (victim->GetTypeId() == TYPEID_PLAYER && victim->ToPlayer()->IsGameMaster())
446  hostileRef->setOnlineOfflineState(false); // GM is always offline
447  }
448 }
void addThreat(float modThreat)
Definition: ThreatManager.cpp:136
void setOnlineOfflineState(bool isOnline)
Definition: ThreatManager.cpp:204
void addReference(HostileReference *hostileRef)
Definition: ThreatManager.h:185
Player * ToPlayer()
Definition: Object.h:191
TypeID GetTypeId() const
Definition: Object.h:113
ThreatContainer iThreatOfflineContainer
Definition: ThreatManager.h:274
ThreatContainer iThreatContainer
Definition: ThreatManager.h:273
Definition: ThreatManager.h:49
friend class HostileReference
Definition: ThreatManager.h:204
Definition: ObjectGuid.h:33
HostileReference * addThreat(Unit *victim, float threat)
Definition: ThreatManager.cpp:285

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ThreatManager::addThreat ( Unit victim,
float  threat,
SpellSchoolMask  schoolMask = SPELL_SCHOOL_MASK_NORMAL,
SpellInfo const threatSpell = NULL 
)
407 {
408  if (!ThreatCalcHelper::isValidProcess(victim, GetOwner(), threatSpell))
409  return;
410 
411  doAddThreat(victim, ThreatCalcHelper::calcThreat(victim, iOwner, threat, schoolMask, threatSpell));
412 }
static bool isValidProcess(Unit *hatedUnit, Unit *hatingUnit, SpellInfo const *threatSpell=NULL)
Definition: ThreatManager.cpp:54
static float calcThreat(Unit *hatedUnit, Unit *hatingUnit, float threat, SpellSchoolMask schoolMask=SPELL_SCHOOL_MASK_NORMAL, SpellInfo const *threatSpell=NULL)
Definition: ThreatManager.cpp:34
void doAddThreat(Unit *victim, float threat)
Definition: ThreatManager.cpp:414
Unit * GetOwner() const
Definition: ThreatManager.h:228
Unit * iOwner
Definition: ThreatManager.h:271

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ThreatManager::clearReferences ( )
397 {
402 }
void clearReferences()
Definition: ThreatManager.cpp:253
arena_t NULL
Definition: jemalloc_internal.h:624
uint32 iUpdateTimer
Definition: ThreatManager.h:272
ThreatContainer iThreatOfflineContainer
Definition: ThreatManager.h:274
ThreatContainer iThreatContainer
Definition: ThreatManager.h:273
HostileReference * iCurrentVictim
Definition: ThreatManager.h:270
#define THREAT_UPDATE_INTERVAL
Definition: ThreatManager.h:37

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ThreatManager::doAddThreat ( Unit victim,
float  threat 
)
415 {
416  uint32 redirectThreadPct = victim->GetRedirectThreatPercent();
417 
418  // must check > 0.0f, otherwise dead loop
419  if (threat > 0.0f && redirectThreadPct)
420  {
421  if (Unit* redirectTarget = victim->GetRedirectThreatTarget())
422  {
423  float redirectThreat = CalculatePct(threat, redirectThreadPct);
424  threat -= redirectThreat;
425  _addThreat(redirectTarget, redirectThreat);
426  }
427  }
428 
429  _addThreat(victim, threat);
430 }
Unit * GetRedirectThreatTarget()
Definition: Unit.cpp:14297
void _addThreat(Unit *victim, float threat)
Definition: ThreatManager.cpp:432
uint32 GetRedirectThreatPercent() const
Definition: Unit.h:2157
uint32_t uint32
Definition: Define.h:150
T CalculatePct(T base, U pct)
Definition: Util.h:92
Definition: Unit.h:1305

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

HostileReference* ThreatManager::getCurrentVictim ( ) const
inline
226 { return iCurrentVictim; }
HostileReference * iCurrentVictim
Definition: ThreatManager.h:270

+ Here is the caller graph for this function:

Unit * ThreatManager::getHostilTarget ( )
460 {
463  setCurrentVictim(nextVictim);
464  return getCurrentVictim() != NULL ? getCurrentVictim()->getTarget() : NULL;
465 }
HostileReference * getCurrentVictim() const
Definition: ThreatManager.h:226
void setCurrentVictim(HostileReference *hostileRef)
Definition: ThreatManager.cpp:503
arena_t NULL
Definition: jemalloc_internal.h:624
HostileReference * selectNextVictim(Creature *attacker, HostileReference *currentVictim) const
Definition: ThreatManager.cpp:316
ThreatContainer iThreatContainer
Definition: ThreatManager.h:273
Definition: ThreatManager.h:49
Unit * GetOwner() const
Definition: ThreatManager.h:228
TO * getTarget() const
Definition: Reference.h:94
void update()
Definition: ThreatManager.cpp:304

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ThreatContainer& ThreatManager::getOfflineContainer ( )
inline
266 { return iThreatOfflineContainer; }
ThreatContainer iThreatOfflineContainer
Definition: ThreatManager.h:274
ThreatContainer::StorageType const& ThreatManager::getOfflineThreatList ( ) const
inline
ThreatContainer iThreatOfflineContainer
Definition: ThreatManager.h:274
StorageType const & getThreatList() const
Definition: ThreatManager.h:177

+ Here is the caller graph for this function:

ThreatContainer& ThreatManager::getOnlineContainer ( )
inline
265 { return iThreatContainer; }
ThreatContainer iThreatContainer
Definition: ThreatManager.h:273

+ Here is the caller graph for this function:

Unit* ThreatManager::GetOwner ( ) const
inline
228 { return iOwner; }
Unit * iOwner
Definition: ThreatManager.h:271

+ Here is the caller graph for this function:

float ThreatManager::getThreat ( Unit victim,
bool  alsoSearchOfflineList = false 
)
470 {
471  float threat = 0.0f;
473  if (!ref && alsoSearchOfflineList)
475  if (ref)
476  threat = ref->getThreat();
477  return threat;
478 }
HostileReference * getReferenceByTarget(Unit *victim) const
Definition: ThreatManager.cpp:266
float getThreat() const
Definition: ThreatManager.h:61
ThreatContainer iThreatOfflineContainer
Definition: ThreatManager.h:274
ThreatContainer iThreatContainer
Definition: ThreatManager.h:273
Definition: ThreatManager.h:49

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ThreatContainer::StorageType const& ThreatManager::getThreatList ( ) const
inline
263 { return iThreatContainer.getThreatList(); }
ThreatContainer iThreatContainer
Definition: ThreatManager.h:273
StorageType const & getThreatList() const
Definition: ThreatManager.h:177
bool ThreatManager::isNeedUpdateToClient ( uint32  time)
565 {
566  if (isThreatListEmpty())
567  return false;
568 
569  if (time >= iUpdateTimer)
570  {
572  return true;
573  }
574  iUpdateTimer -= time;
575  return false;
576 }
bool isThreatListEmpty() const
Definition: ThreatManager.h:220
uint32 iUpdateTimer
Definition: ThreatManager.h:272
#define THREAT_UPDATE_INTERVAL
Definition: ThreatManager.h:37

+ Here is the call graph for this function:

bool ThreatManager::isThreatListEmpty ( ) const
inline
220 { return iThreatContainer.empty(); }
bool empty() const
Definition: ThreatManager.h:165
ThreatContainer iThreatContainer
Definition: ThreatManager.h:273

+ Here is the caller graph for this function:

void ThreatManager::modifyThreatPercent ( Unit victim,
int32  percent 
)
453 {
454  iThreatContainer.modifyThreatPercent(victim, percent);
455 }
ThreatContainer iThreatContainer
Definition: ThreatManager.h:273
void modifyThreatPercent(Unit *victim, int32 percent)
Definition: ThreatManager.cpp:295

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ThreatManager::processThreatEvent ( ThreatRefStatusChangeEvent threatRefStatusChangeEvent)
517 {
518  threatRefStatusChangeEvent->setThreatManager(this); // now we can set the threat manager
519 
520  HostileReference* hostilRef = threatRefStatusChangeEvent->getReference();
521 
522  switch (threatRefStatusChangeEvent->getType())
523  {
525  if ((getCurrentVictim() == hostilRef && threatRefStatusChangeEvent->getFValue()<0.0f) ||
526  (getCurrentVictim() != hostilRef && threatRefStatusChangeEvent->getFValue()>0.0f))
527  setDirty(true); // the order in the threat list might have changed
528  break;
530  if (!hostilRef->isOnline())
531  {
532  if (hostilRef == getCurrentVictim())
533  {
535  setDirty(true);
536  }
538  iThreatContainer.remove(hostilRef);
540  }
541  else
542  {
543  if (getCurrentVictim() && hostilRef->getThreat() > (1.1f * getCurrentVictim()->getThreat()))
544  setDirty(true);
545  iThreatContainer.addReference(hostilRef);
546  iThreatOfflineContainer.remove(hostilRef);
547  }
548  break;
550  if (hostilRef == getCurrentVictim())
551  {
553  setDirty(true);
554  }
556  if (hostilRef->isOnline())
557  iThreatContainer.remove(hostilRef);
558  else
559  iThreatOfflineContainer.remove(hostilRef);
560  break;
561  }
562 }
float getFValue() const
Definition: UnitEvents.h:106
bool isOnline() const
Definition: ThreatManager.h:63
HostileReference * getCurrentVictim() const
Definition: ThreatManager.h:226
void setThreatManager(ThreatManager *pThreatManager)
Definition: UnitEvents.h:114
uint32 getType() const
Definition: UnitEvents.h:76
float getThreat() const
Definition: ThreatManager.h:61
void SendRemoveFromThreatListOpcode(HostileReference *pHostileReference)
Definition: Unit.cpp:15557
void setCurrentVictim(HostileReference *hostileRef)
Definition: ThreatManager.cpp:503
arena_t NULL
Definition: jemalloc_internal.h:624
void setDirty(bool isDirty)
Definition: ThreatManager.h:237
Definition: UnitEvents.h:37
void addReference(HostileReference *hostileRef)
Definition: ThreatManager.h:185
Definition: UnitEvents.h:40
ThreatContainer iThreatOfflineContainer
Definition: ThreatManager.h:274
Definition: UnitEvents.h:34
ThreatContainer iThreatContainer
Definition: ThreatManager.h:273
Definition: ThreatManager.h:49
void remove(HostileReference *hostileRef)
Definition: ThreatManager.h:180
HostileReference * getReference() const
Definition: UnitEvents.h:112
Unit * iOwner
Definition: ThreatManager.h:271

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<class PREDICATE >
void ThreatManager::resetAggro ( PREDICATE  predicate)
inline
244  {
246  if (threatList.empty())
247  return;
248 
249  for (ThreatContainer::StorageType::iterator itr = threatList.begin(); itr != threatList.end(); ++itr)
250  {
251  HostileReference* ref = (*itr);
252 
253  if (predicate(ref->getTarget()))
254  {
255  ref->setThreat(0);
256  setDirty(true);
257  }
258  }
259  }
StorageType iThreatList
Definition: ThreatManager.h:195
void setDirty(bool isDirty)
Definition: ThreatManager.h:237
void setThreat(float threat)
Definition: ThreatManager.h:57
ThreatContainer iThreatContainer
Definition: ThreatManager.h:273
Definition: ThreatManager.h:49
std::list< HostileReference * > StorageType
Definition: ThreatManager.h:149
TO * getTarget() const
Definition: Reference.h:94

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ThreatManager::resetAllAggro ( )
580 {
582  if (threatList.empty())
583  return;
584 
585  for (ThreatContainer::StorageType::iterator itr = threatList.begin(); itr != threatList.end(); ++itr)
586  (*itr)->setThreat(0);
587 
588  setDirty(true);
589 }
StorageType iThreatList
Definition: ThreatManager.h:195
void setDirty(bool isDirty)
Definition: ThreatManager.h:237
ThreatContainer iThreatContainer
Definition: ThreatManager.h:273
std::list< HostileReference * > StorageType
Definition: ThreatManager.h:149

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ThreatManager::setCurrentVictim ( HostileReference hostileRef)
504 {
505  if (pHostileReference && pHostileReference != iCurrentVictim)
506  {
507  iOwner->SendChangeCurrentVictimOpcode(pHostileReference);
508  }
509  iCurrentVictim = pHostileReference;
510 }
HostileReference * iCurrentVictim
Definition: ThreatManager.h:270
void SendChangeCurrentVictimOpcode(HostileReference *pHostileReference)
Definition: Unit.cpp:15530
Unit * iOwner
Definition: ThreatManager.h:271

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ThreatManager::setDirty ( bool  isDirty)
inline
237 { iThreatContainer.setDirty(isDirty); }
ThreatContainer iThreatContainer
Definition: ThreatManager.h:273
void setDirty(bool isDirty)
Definition: ThreatManager.h:161

+ Here is the caller graph for this function:

void ThreatManager::tauntApply ( Unit taunter)
483 {
485  if (getCurrentVictim() && ref && (ref->getThreat() < getCurrentVictim()->getThreat()))
486  {
487  if (ref->getTempThreatModifier() == 0.0f) // Ok, temp threat is unused
489  }
490 }
HostileReference * getCurrentVictim() const
Definition: ThreatManager.h:226
HostileReference * getReferenceByTarget(Unit *victim) const
Definition: ThreatManager.cpp:266
float getThreat() const
Definition: ThreatManager.h:61
void setTempThreat(float threat)
Definition: ThreatManager.h:71
float getTempThreatModifier()
Definition: ThreatManager.h:92
ThreatContainer iThreatContainer
Definition: ThreatManager.h:273
Definition: ThreatManager.h:49
float getThreat(Unit *victim, bool alsoSearchOfflineList=false)
Definition: ThreatManager.cpp:469

+ Here is the call graph for this function:

void ThreatManager::tauntFadeOut ( Unit taunter)
495 {
497  if (ref)
498  ref->resetTempThreat();
499 }
HostileReference * getReferenceByTarget(Unit *victim) const
Definition: ThreatManager.cpp:266
ThreatContainer iThreatContainer
Definition: ThreatManager.h:273
Definition: ThreatManager.h:49
void resetTempThreat()
Definition: ThreatManager.h:83

+ Here is the call graph for this function:

Friends And Related Function Documentation

friend class HostileReference
friend

Member Data Documentation

HostileReference* ThreatManager::iCurrentVictim
private
Unit* ThreatManager::iOwner
private
ThreatContainer ThreatManager::iThreatContainer
private
ThreatContainer ThreatManager::iThreatOfflineContainer
private
uint32 ThreatManager::iUpdateTimer
private

The documentation for this class was generated from the following files: