AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
ThreatReference Class Reference

#include "ThreatManager.h"

Inheritance diagram for ThreatReference:
ThreatReferenceImpl

Public Types

enum  TauntState : uint32 {
  TAUNT_STATE_DETAUNT = 0 ,
  TAUNT_STATE_NONE = 1 ,
  TAUNT_STATE_TAUNT = 2
}
 
enum  OnlineState {
  ONLINE_STATE_ONLINE = 2 ,
  ONLINE_STATE_SUPPRESSED = 1 ,
  ONLINE_STATE_OFFLINE = 0
}
 

Public Member Functions

CreatureGetOwner () const
 
UnitGetVictim () const
 
float GetThreat () const
 
OnlineState GetOnlineState () const
 
bool IsOnline () const
 
bool IsAvailable () const
 
bool IsSuppressed () const
 
bool IsOffline () const
 
TauntState GetTauntState () const
 
bool IsTaunting () const
 
bool IsDetaunted () const
 
void AddThreat (float amount)
 
void ScaleThreat (float factor)
 
void ModifyThreatByPercent (int32 percent)
 
void UpdateOffline ()
 
void ClearThreat ()
 
 ThreatReference (ThreatReference const &)=delete
 
ThreatReferenceoperator= (ThreatReference const &)=delete
 

Protected Member Functions

 ThreatReference (ThreatManager *mgr, Unit *victim)
 
virtual ~ThreatReference ()=default
 
void UnregisterAndFree ()
 
bool ShouldBeOffline () const
 
bool ShouldBeSuppressed () const
 
void UpdateTauntState (TauntState state=TAUNT_STATE_NONE)
 
void HeapNotifyIncreased ()
 
void HeapNotifyDecreased ()
 

Static Protected Member Functions

static bool FlagsAllowFighting (Unit const *a, Unit const *b)
 

Protected Attributes

Creature *const _owner
 
ThreatManager_mgr
 
Unit *const _victim
 
OnlineState _online
 
float _baseAmount
 
int32 _tempModifier
 
TauntState _taunted
 

Friends

class ThreatManager
 
struct CompareThreatLessThan
 

Detailed Description

Member Enumeration Documentation

◆ OnlineState

Enumerator
ONLINE_STATE_ONLINE 
ONLINE_STATE_SUPPRESSED 
ONLINE_STATE_OFFLINE 
@ ONLINE_STATE_ONLINE
Definition ThreatManager.h:268
@ ONLINE_STATE_OFFLINE
Definition ThreatManager.h:268
@ ONLINE_STATE_SUPPRESSED
Definition ThreatManager.h:268

◆ TauntState

Enumerator
TAUNT_STATE_DETAUNT 
TAUNT_STATE_NONE 
TAUNT_STATE_TAUNT 
std::uint32_t uint32
Definition Define.h:107
@ TAUNT_STATE_DETAUNT
Definition ThreatManager.h:267
@ TAUNT_STATE_TAUNT
Definition ThreatManager.h:267
@ TAUNT_STATE_NONE
Definition ThreatManager.h:267

Constructor & Destructor Documentation

◆ ThreatReference() [1/2]

ThreatReference::ThreatReference ( ThreatManager mgr,
Unit victim 
)
inlineexplicitprotected
292 :
293 _owner(reinterpret_cast<Creature*>(mgr->_owner)), _mgr(*mgr), _victim(victim),
295 {
297 }
Definition Creature.h:47
Unit *const _owner
Definition ThreatManager.h:194
int32 _tempModifier
Definition ThreatManager.h:313
float _baseAmount
Definition ThreatManager.h:312
ThreatManager & _mgr
Definition ThreatManager.h:307
Creature *const _owner
Definition ThreatManager.h:306
Unit *const _victim
Definition ThreatManager.h:310
TauntState _taunted
Definition ThreatManager.h:314
OnlineState _online
Definition ThreatManager.h:311

◆ ~ThreatReference()

virtual ThreatReference::~ThreatReference ( )
protectedvirtualdefault

◆ ThreatReference() [2/2]

ThreatReference::ThreatReference ( ThreatReference const &  )
delete

Member Function Documentation

◆ AddThreat()

void ThreatReference::AddThreat ( float  amount)
52{
53 if (amount == 0.0f)
54 return;
55 _baseAmount = std::max<float>(_baseAmount + amount, 0.0f);
56 if (amount > 0.0f)
58 else
61}
bool _needClientUpdate
Definition ThreatManager.h:209
void HeapNotifyDecreased()
Definition ThreatManager.cpp:184
void HeapNotifyIncreased()
Definition ThreatManager.cpp:179

References _baseAmount, _mgr, ThreatManager::_needClientUpdate, HeapNotifyDecreased(), and HeapNotifyIncreased().

Referenced by ThreatManager::AddThreat().

◆ ClearThreat()

void ThreatReference::ClearThreat ( )
156{
157 _mgr.ClearThreat(this);
158}
void ClearThreat(Unit *target)
Definition ThreatManager.cpp:560

References _mgr, and ThreatManager::ClearThreat().

◆ FlagsAllowFighting()

bool ThreatReference::FlagsAllowFighting ( Unit const *  a,
Unit const *  b 
)
staticprotected
96{
97 if (a->IsCreature() && a->ToCreature()->IsTrigger())
98 return false;
99 if (a->HasUnitFlag(UNIT_FLAG_PLAYER_CONTROLLED))
100 {
101 if (b->HasUnitFlag(UNIT_FLAG_IMMUNE_TO_PC))
102 return false;
103 }
104 else
105 {
106 if (b->HasUnitFlag(UNIT_FLAG_IMMUNE_TO_NPC))
107 return false;
108 }
109 return true;
110}
@ UNIT_FLAG_IMMUNE_TO_NPC
Definition UnitDefines.h:266
@ UNIT_FLAG_IMMUNE_TO_PC
Definition UnitDefines.h:265
@ UNIT_FLAG_PLAYER_CONTROLLED
Definition UnitDefines.h:260

References Unit::HasUnitFlag(), Object::IsCreature(), Creature::IsTrigger(), Object::ToCreature(), UNIT_FLAG_IMMUNE_TO_NPC, UNIT_FLAG_IMMUNE_TO_PC, and UNIT_FLAG_PLAYER_CONTROLLED.

Referenced by ShouldBeOffline().

◆ GetOnlineState()

OnlineState ThreatReference::GetOnlineState ( ) const
inline
273{ return _online; }

Referenced by ThreatManager::AddThreat().

◆ GetOwner()

Creature * ThreatReference::GetOwner ( ) const
inline

◆ GetTauntState()

TauntState ThreatReference::GetTauntState ( ) const
inline
278{ return IsTaunting() ? TAUNT_STATE_TAUNT : _taunted; }
bool IsTaunting() const
Definition ThreatManager.h:279

◆ GetThreat()

float ThreatReference::GetThreat ( ) const
inline

◆ GetVictim()

◆ HeapNotifyDecreased()

void ThreatReference::HeapNotifyDecreased ( )
protected
185{
186 _mgr._sortedThreatList->decrease(static_cast<ThreatReferenceImpl*>(this)->_handle);
187}
std::unique_ptr< Heap > _sortedThreatList
Definition ThreatManager.h:211
Definition ThreatManager.cpp:168

References _mgr, and ThreatManager::_sortedThreatList.

Referenced by AddThreat(), ScaleThreat(), UpdateOffline(), and UpdateTauntState().

◆ HeapNotifyIncreased()

void ThreatReference::HeapNotifyIncreased ( )
protected
180{
181 _mgr._sortedThreatList->increase(static_cast<ThreatReferenceImpl*>(this)->_handle);
182}

References _mgr, and ThreatManager::_sortedThreatList.

Referenced by AddThreat(), ThreatManager::AddThreat(), ScaleThreat(), UpdateOffline(), and UpdateTauntState().

◆ IsAvailable()

bool ThreatReference::IsAvailable ( ) const
inline

◆ IsDetaunted()

bool ThreatReference::IsDetaunted ( ) const
inline
280{ return _taunted == TAUNT_STATE_DETAUNT; }

◆ IsOffline()

bool ThreatReference::IsOffline ( ) const
inline

◆ IsOnline()

bool ThreatReference::IsOnline ( ) const
inline
274{ return (_online >= ONLINE_STATE_ONLINE); }

Referenced by ThreatManager::AddThreat().

◆ IsSuppressed()

bool ThreatReference::IsSuppressed ( ) const
inline

◆ IsTaunting()

bool ThreatReference::IsTaunting ( ) const
inline

◆ ModifyThreatByPercent()

void ThreatReference::ModifyThreatByPercent ( int32  percent)
inline
284{ if (percent) ScaleThreat(0.01f * float(100 + percent)); }
void ScaleThreat(float factor)
Definition ThreatManager.cpp:63

◆ operator=()

ThreatReference & ThreatReference::operator= ( ThreatReference const &  )
delete

◆ ScaleThreat()

void ThreatReference::ScaleThreat ( float  factor)
64{
65 if (factor == 1.0f)
66 return;
67 _baseAmount *= factor;
68 if (factor > 1.0f)
70 else
73}

References _baseAmount, _mgr, ThreatManager::_needClientUpdate, HeapNotifyDecreased(), and HeapNotifyIncreased().

◆ ShouldBeOffline()

bool ThreatReference::ShouldBeOffline ( ) const
protected
113{
115 return true;
117 return true;
119 return true;
120 return false;
121}
bool _IsTargetAcceptable(Unit const *target) const
Definition Creature.cpp:2489
bool CanCreatureAttack(Unit const *victim, bool skipDistCheck=false) const
Definition Creature.cpp:2557
static bool FlagsAllowFighting(Unit const *a, Unit const *b)
Definition ThreatManager.cpp:95
bool CanSeeOrDetect(WorldObject const *obj, bool ignoreStealth=false, bool distanceCheck=false, bool checkAlert=false) const
Definition Object.cpp:1750

References Creature::_IsTargetAcceptable(), _owner, _victim, Creature::CanCreatureAttack(), WorldObject::CanSeeOrDetect(), and FlagsAllowFighting().

Referenced by ThreatManager::GetCurrentVictim(), ThreatManager::GetLastVictim(), and UpdateOffline().

◆ ShouldBeSuppressed()

bool ThreatReference::ShouldBeSuppressed ( ) const
protected
124{
125 if (IsTaunting()) // a taunting victim can never be suppressed
126 return false;
128 return true;
130 return true;
132 return true;
133 return false;
134}
@ SPELL_AURA_MOD_CONFUSE
Definition SpellAuraDefines.h:68
@ SPELL_AURA_MOD_STUN
Definition SpellAuraDefines.h:75
SpellSchoolMask GetMeleeDamageSchoolMask(WeaponAttackType=BASE_ATTACK, uint8=0) const override
Definition Creature.h:163
bool HasAuraType(AuraType auraType) const
Definition Unit.cpp:5938
bool IsImmunedToDamage(SpellSchoolMask meleeSchoolMask) const
Definition Unit.cpp:9737
bool HasBreakableByDamageAuraType(AuraType type, uint32 excludeAura=0) const
Definition Unit.cpp:894

References _owner, _victim, Creature::GetMeleeDamageSchoolMask(), Unit::HasAuraType(), Unit::HasBreakableByDamageAuraType(), Unit::IsImmunedToDamage(), IsTaunting(), SPELL_AURA_MOD_CONFUSE, and SPELL_AURA_MOD_STUN.

Referenced by ThreatManager::AddThreat(), and UpdateOffline().

◆ UnregisterAndFree()

void ThreatReference::UnregisterAndFree ( )
protected
161{
164 delete this;
165}
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:114
void PurgeThreatListRef(ObjectGuid const &guid)
Definition ThreatManager.cpp:901
void PurgeThreatenedByMeRef(ObjectGuid const &guid)
Definition ThreatManager.cpp:923
ThreatManager & GetThreatMgr()
Definition Unit.h:951

References _owner, _victim, Object::GetGUID(), Unit::GetThreatMgr(), ThreatManager::PurgeThreatenedByMeRef(), and ThreatManager::PurgeThreatListRef().

Referenced by ThreatManager::ClearThreat().

◆ UpdateOffline()

void ThreatReference::UpdateOffline ( )
76{
77 bool const shouldBeOffline = ShouldBeOffline();
78 if (shouldBeOffline == IsOffline())
79 return;
80
81 if (shouldBeOffline)
82 {
86 }
87 else
88 {
92 }
93}
void RegisterForAIUpdate(ObjectGuid const &guid)
Definition ThreatManager.h:215
void SendRemoveToClients(Unit const *victim) const
Definition ThreatManager.cpp:863
bool ShouldBeSuppressed() const
Definition ThreatManager.cpp:123
bool ShouldBeOffline() const
Definition ThreatManager.cpp:112
bool IsOffline() const
Definition ThreatManager.h:277
Unit * GetVictim() const
Definition ThreatManager.h:271

References _mgr, _online, _victim, GetVictim(), HeapNotifyDecreased(), HeapNotifyIncreased(), IsOffline(), ONLINE_STATE_OFFLINE, ONLINE_STATE_ONLINE, ONLINE_STATE_SUPPRESSED, ThreatManager::RegisterForAIUpdate(), ThreatManager::SendRemoveToClients(), ShouldBeOffline(), and ShouldBeSuppressed().

Referenced by ThreatManager::AddThreat(), and ThreatManager::ReselectVictim().

◆ UpdateTauntState()

void ThreatReference::UpdateTauntState ( TauntState  state = TAUNT_STATE_NONE)
protected
137{
138 // Check for SPELL_AURA_MOD_DETAUNT (applied from owner to victim)
139 if (state < TAUNT_STATE_TAUNT && _victim->HasAuraTypeWithCaster(SPELL_AURA_MOD_DETAUNT, _owner->GetGUID()))
140 state = TAUNT_STATE_DETAUNT;
141
142 if (state == _taunted)
143 return;
144
145 std::swap(state, _taunted);
146
147 if (_taunted < state)
149 else
151
152 _mgr._needClientUpdate = true;
153}
@ SPELL_AURA_MOD_DETAUNT
Definition SpellAuraDefines.h:284

References _mgr, ThreatManager::_needClientUpdate, _owner, _taunted, Object::GetGUID(), HeapNotifyDecreased(), HeapNotifyIncreased(), SPELL_AURA_MOD_DETAUNT, and TAUNT_STATE_DETAUNT.

Friends And Related Symbol Documentation

◆ CompareThreatLessThan

friend struct CompareThreatLessThan
friend

◆ ThreatManager

friend class ThreatManager
friend

Member Data Documentation

◆ _baseAmount

float ThreatReference::_baseAmount
protected

Referenced by AddThreat(), and ScaleThreat().

◆ _mgr

◆ _online

OnlineState ThreatReference::_online
protected

◆ _owner

Creature* const ThreatReference::_owner
protected

◆ _taunted

TauntState ThreatReference::_taunted
protected

◆ _tempModifier

int32 ThreatReference::_tempModifier
protected

◆ _victim


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