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

#include "HostileRefMgr.h"

Inheritance diagram for HostileRefMgr:
RefMgr< Unit, ThreatMgr > LinkedListHead

Public Member Functions

 HostileRefMgr (Unit *owner)
 
 ~HostileRefMgr () override
 
UnitGetOwner ()
 
void threatAssist (Unit *victim, float baseThreat, SpellInfo const *threatSpell=nullptr)
 
void addTempThreat (float threat, bool apply)
 
void addThreatPercent (int32 percent)
 
void deleteReferences (bool removeFromMap=false)
 
void deleteReferencesForFaction (uint32 faction)
 
void deleteReferencesOutOfRange (float range)
 
HostileReferencegetFirst ()
 
void updateThreatTables ()
 
void setOnlineOfflineState (bool isOnline)
 
void setOnlineOfflineState (Unit *creature, bool isOnline)
 
void deleteReference (Unit *creature)
 
void UpdateVisibility (bool checkThreat)
 
- Public Member Functions inherited from RefMgr< Unit, ThreatMgr >
 RefMgr ()=default
 
virtual ~RefMgr ()
 
Reference< Unit, ThreatMgr > * getFirst ()
 
Reference< Unit, ThreatMgr > const * getFirst () const
 
Reference< Unit, ThreatMgr > * getLast ()
 
Reference< Unit, ThreatMgr > const * getLast () const
 
iterator begin ()
 
iterator end ()
 
iterator rbegin ()
 
iterator rend ()
 
void clearReferences ()
 
- Public Member Functions inherited from LinkedListHead
 LinkedListHead ()
 
bool IsEmpty () const
 
LinkedListElementgetFirst ()
 
LinkedListElement const * getFirst () const
 
LinkedListElementgetLast ()
 
LinkedListElement const * getLast () const
 
void insertFirst (LinkedListElement *pElem)
 
void insertLast (LinkedListElement *pElem)
 
uint32 getSize () const
 
void incSize ()
 
void decSize ()
 

Private Attributes

UnitiOwner
 

Additional Inherited Members

- Public Types inherited from RefMgr< Unit, ThreatMgr >
typedef LinkedListHead::Iterator< Reference< Unit, ThreatMgr > > iterator
 
- Public Types inherited from LinkedListHead
typedef Iterator< LinkedListElementiterator
 

Detailed Description

Constructor & Destructor Documentation

◆ HostileRefMgr()

HostileRefMgr::HostileRefMgr ( Unit owner)
inlineexplicit
36{ iOwner = owner; }
Unit * iOwner
Definition: HostileRefMgr.h:34

References iOwner.

◆ ~HostileRefMgr()

HostileRefMgr::~HostileRefMgr ( )
override
26{
28}
void deleteReferences(bool removeFromMap=false)
Definition: HostileRefMgr.cpp:125

References deleteReferences().

Member Function Documentation

◆ addTempThreat()

void HostileRefMgr::addTempThreat ( float  threat,
bool  apply 
)
66{
68
69 while (ref)
70 {
71 if (apply)
72 {
73 if (ref->getTempThreatModifier() == 0.0f)
74 ref->addTempThreat(threat);
75 }
76 else
77 ref->resetTempThreat();
78
79 ref = ref->next();
80 }
81}
HostileReference * getFirst()
Definition: HostileRefMgr.h:60
Definition: ThreatMgr.h:49
float getTempThreatModifier()
Definition: ThreatMgr.h:94
void addTempThreat(float threat)
Definition: ThreatMgr.h:78
HostileReference * next()
Definition: ThreatMgr.h:116
void resetTempThreat()
Definition: ThreatMgr.h:85

References HostileReference::addTempThreat(), getFirst(), HostileReference::getTempThreatModifier(), HostileReference::next(), and HostileReference::resetTempThreat().

Referenced by AuraEffect::HandleAuraModTotalThreat().

◆ addThreatPercent()

void HostileRefMgr::addThreatPercent ( int32  percent)
86{
88 while (ref)
89 {
90 ref->addThreatPercent(percent);
91 ref = ref->next();
92 }
93}
void addThreatPercent(int32 percent)
Definition: ThreatMgr.cpp:165

References HostileReference::addThreatPercent(), getFirst(), and HostileReference::next().

Referenced by Spell::EffectSanctuary(), and AuraEffect::HandleFeignDeath().

◆ deleteReference()

void HostileRefMgr::deleteReference ( Unit creature)
181{
182 HostileReference* ref = getFirst();
183 while (ref)
184 {
185 HostileReference* nextRef = ref->next();
186 if (ref->GetSource()->GetOwner() == creature)
187 {
188 ref->removeReference();
189 delete ref;
190 break;
191 }
192 ref = nextRef;
193 }
194}
FROM * GetSource() const
Definition: Reference.h:97
void removeReference()
Definition: ThreatMgr.cpp:229
Unit * GetOwner() const
Definition: ThreatMgr.h:237

References getFirst(), ThreatMgr::GetOwner(), Reference< TO, FROM >::GetSource(), HostileReference::next(), and HostileReference::removeReference().

◆ deleteReferences()

void HostileRefMgr::deleteReferences ( bool  removeFromMap = false)
126{
127 std::vector<Creature*> creaturesToEvade;
128
129 HostileReference* ref = getFirst();
130 while (ref)
131 {
132 HostileReference* nextRef = ref->next();
133 ref->removeReference();
134
135 if (removeFromMap)
136 {
137 if (ThreatMgr const* threatMgr = ref->GetSource())
138 {
139 if (threatMgr->areThreatListsEmpty())
140 {
141 if (Creature* creature = threatMgr->GetOwner()->ToCreature())
142 {
143 creaturesToEvade.push_back(creature);
144 }
145 }
146 }
147 }
148
149 delete ref;
150 ref = nextRef;
151 }
152
153 for (Creature* creature : creaturesToEvade)
154 {
155 creature->AI()->EnterEvadeMode();
156 }
157}
Definition: ThreatMgr.h:204
Definition: Creature.h:46
Creature * ToCreature()
Definition: Object.h:202
Unit * GetOwner() const
Definition: Unit.cpp:10562

References getFirst(), Unit::GetOwner(), Reference< TO, FROM >::GetSource(), HostileReference::next(), HostileReference::removeReference(), and Object::ToCreature().

Referenced by PetAI::_stopAttack(), Unit::CleanupBeforeRemoveFromMap(), misc_commandscript::HandleCombatStopCommand(), AuraEffect::HandleFeignDeath(), WorldSession::HandleMoveWorldportAck(), Unit::Kill(), WorldSession::LogoutPlayer(), Map::RemovePlayerFromMap(), Unit::setDeathState(), and ~HostileRefMgr().

◆ deleteReferencesForFaction()

void HostileRefMgr::deleteReferencesForFaction ( uint32  faction)
163{
164 HostileReference* ref = getFirst();
165 while (ref)
166 {
167 HostileReference* nextRef = ref->next();
168 if (ref->GetSource()->GetOwner()->GetFactionTemplateEntry()->faction == faction)
169 {
170 ref->removeReference();
171 delete ref;
172 }
173 ref = nextRef;
174 }
175}
FactionTemplateEntry const * GetFactionTemplateEntry() const
Definition: Unit.cpp:9996
uint32 faction
Definition: DBCStructure.h:941

References FactionTemplateEntry::faction, Unit::GetFactionTemplateEntry(), getFirst(), ThreatMgr::GetOwner(), Reference< TO, FROM >::GetSource(), HostileReference::next(), and HostileReference::removeReference().

Referenced by Unit::StopAttackFaction().

◆ deleteReferencesOutOfRange()

void HostileRefMgr::deleteReferencesOutOfRange ( float  range)
200{
201 HostileReference* ref = getFirst();
202 range = range * range;
203 while (ref)
204 {
205 HostileReference* nextRef = ref->next();
206 Unit* owner = ref->GetSource()->GetOwner();
207 if (!owner->isActiveObject() && owner->GetExactDist2dSq(GetOwner()) > range)
208 {
209 ref->removeReference();
210 delete ref;
211 }
212 ref = nextRef;
213 }
214}
Unit * GetOwner()
Definition: HostileRefMgr.h:39
bool isActiveObject() const
Definition: Object.h:574
float GetExactDist2dSq(const float x, const float y) const
Definition: Position.h:157
Definition: Unit.h:630

References Position::GetExactDist2dSq(), getFirst(), GetOwner(), ThreatMgr::GetOwner(), Reference< TO, FROM >::GetSource(), WorldObject::isActiveObject(), HostileReference::next(), and HostileReference::removeReference().

Referenced by Player::Update().

◆ getFirst()

◆ GetOwner()

Unit * HostileRefMgr::GetOwner ( )
inline
39{ return iOwner; }

References iOwner.

Referenced by deleteReferencesOutOfRange().

◆ setOnlineOfflineState() [1/2]

void HostileRefMgr::setOnlineOfflineState ( bool  isOnline)

◆ setOnlineOfflineState() [2/2]

void HostileRefMgr::setOnlineOfflineState ( Unit creature,
bool  isOnline 
)
220{
221 HostileReference* ref = getFirst();
222 while (ref)
223 {
224 HostileReference* nextRef = ref->next();
225 if (ref->GetSource()->GetOwner() == creature)
226 {
227 ref->setOnlineOfflineState(isOnline);
228 break;
229 }
230 ref = nextRef;
231 }
232}

References getFirst(), ThreatMgr::GetOwner(), Reference< TO, FROM >::GetSource(), HostileReference::next(), and HostileReference::setOnlineOfflineState().

◆ threatAssist()

void HostileRefMgr::threatAssist ( Unit victim,
float  baseThreat,
SpellInfo const *  threatSpell = nullptr 
)
36{
37 if (getSize() == 0)
38 return;
39
41 float threat = ThreatCalcHelper::calcThreat(victim, baseThreat, (threatSpell ? threatSpell->GetSchoolMask() : SPELL_SCHOOL_MASK_NORMAL), threatSpell);
42 threat /= getSize();
43 while (ref)
44 {
45 Unit* refOwner = ref->GetSource()->GetOwner();
46 if (ThreatCalcHelper::isValidProcess(victim, refOwner, threatSpell))
47 {
48 if (Creature* hatingCreature = refOwner->ToCreature())
49 {
50 if (hatingCreature->IsAIEnabled)
51 {
52 hatingCreature->AI()->CalculateThreat(victim, threat, threatSpell);
53 }
54 }
55
56 ref->GetSource()->DoAddThreat(victim, threat);
57 }
58
59 ref = ref->next();
60 }
61}
@ SPELL_SCHOOL_MASK_NORMAL
Definition: SharedDefines.h:297
uint32 getSize() const
Definition: LinkedList.h:115
static float calcThreat(Unit *hatedUnit, float threat, SpellSchoolMask schoolMask=SPELL_SCHOOL_MASK_NORMAL, SpellInfo const *threatSpell=nullptr)
Definition: ThreatMgr.cpp:34
static bool isValidProcess(Unit *hatedUnit, Unit *hatingUnit, SpellInfo const *threatSpell=nullptr)
Definition: ThreatMgr.cpp:54
void DoAddThreat(Unit *victim, float threat)
Definition: ThreatMgr.cpp:453

References ThreatCalcHelper::calcThreat(), ThreatMgr::DoAddThreat(), getFirst(), ThreatMgr::GetOwner(), SpellInfo::GetSchoolMask(), LinkedListHead::getSize(), Reference< TO, FROM >::GetSource(), ThreatCalcHelper::isValidProcess(), HostileReference::next(), SPELL_SCHOOL_MASK_NORMAL, and Object::ToCreature().

Referenced by Spell::DoAllEffectOnTarget(), Spell::DoSpellHitOnUnit(), Spell::EffectDispel(), Spell::EffectDispelMechanic(), Unit::EnergizeBySpell(), AuraEffect::HandleObsModPowerAuraTick(), AuraEffect::HandlePeriodicEnergizeAuraTick(), AuraEffect::HandlePeriodicHealAurasTick(), AuraEffect::HandlePeriodicHealthLeechAuraTick(), and Spell::HandleThreatSpells().

◆ updateThreatTables()

void HostileRefMgr::updateThreatTables ( )
112{
113 HostileReference* ref = getFirst();
114 while (ref)
115 {
116 ref->updateOnlineStatus();
117 ref = ref->next();
118 }
119}
void updateOnlineStatus()
Definition: ThreatMgr.cpp:180

References getFirst(), HostileReference::next(), and HostileReference::updateOnlineStatus().

Referenced by Player::SetInWater().

◆ UpdateVisibility()

void HostileRefMgr::UpdateVisibility ( bool  checkThreat)
237{
238 HostileReference* ref = getFirst();
239 while (ref)
240 {
241 HostileReference* nextRef = ref->next();
242 if ((!checkThreat || ref->GetSource()->GetThreatListSize() <= 1))
243 {
244 nextRef = ref->next();
245 ref->removeReference();
246 delete ref;
247 }
248 ref = nextRef;
249 }
250}
float GetThreatListSize() const
Definition: ThreatMgr.h:222

References getFirst(), Reference< TO, FROM >::GetSource(), ThreatMgr::GetThreatListSize(), HostileReference::next(), and HostileReference::removeReference().

Referenced by Spell::EffectSanctuary().

Member Data Documentation

◆ iOwner

Unit* HostileRefMgr::iOwner
private

Referenced by GetOwner(), and HostileRefMgr().