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

#include "ThreatMgr.h"

Public Types

typedef std::list< HostileReference * > StorageType
 

Public Member Functions

 ThreatContainer ()=default
 
 ~ThreatContainer ()
 
HostileReferenceAddThreat (Unit *victim, float threat)
 
void ModifyThreatByPercent (Unit *victim, int32 percent)
 
HostileReferenceSelectNextVictim (Creature *attacker, HostileReference *currentVictim) const
 
void setDirty (bool isDirty)
 
bool isDirty () const
 
bool empty () const
 
HostileReferencegetMostHated () const
 
HostileReferencegetReferenceByTarget (Unit const *victim) const
 
HostileReferencegetReferenceByTarget (ObjectGuid const &guid) const
 
StorageType const & GetThreatList () const
 

Private Member Functions

void remove (HostileReference *hostileRef)
 
void addReference (HostileReference *hostileRef)
 
void clearReferences ()
 
void update ()
 

Private Attributes

StorageType iThreatList
 
bool iDirty {false}
 

Friends

class ThreatMgr
 

Detailed Description

Member Typedef Documentation

◆ StorageType

Constructor & Destructor Documentation

◆ ThreatContainer()

ThreatContainer::ThreatContainer ( )
default

◆ ~ThreatContainer()

ThreatContainer::~ThreatContainer ( )
inline
151{ clearReferences(); }
void clearReferences()
Definition: ThreatMgr.cpp:248

References clearReferences().

Member Function Documentation

◆ addReference()

void ThreatContainer::addReference ( HostileReference hostileRef)
inlineprivate
185 {
186 iThreatList.push_back(hostileRef);
187 }
StorageType iThreatList
Definition: ThreatMgr.h:194

References iThreatList.

Referenced by ThreatMgr::_addThreat(), and ThreatMgr::processThreatEvent().

◆ AddThreat()

HostileReference * ThreatContainer::AddThreat ( Unit victim,
float  threat 
)
287{
289 if (ref)
290 ref->AddThreat(threat);
291 return ref;
292}
Definition: ThreatMgr.h:48
void AddThreat(float modThreat)
Definition: ThreatMgr.cpp:138
HostileReference * getReferenceByTarget(Unit const *victim) const
Definition: ThreatMgr.cpp:261

References HostileReference::AddThreat(), and getReferenceByTarget().

Referenced by ThreatMgr::_addThreat().

◆ clearReferences()

void ThreatContainer::clearReferences ( )
private
249{
250 for (ThreatContainer::StorageType::const_iterator i = iThreatList.begin(); i != iThreatList.end(); ++i)
251 {
252 (*i)->unlink();
253 delete (*i);
254 }
255
256 iThreatList.clear();
257}

References iThreatList.

Referenced by ThreatMgr::clearReferences(), and ~ThreatContainer().

◆ empty()

bool ThreatContainer::empty ( ) const
inline
164 {
165 return iThreatList.empty();
166 }

References iThreatList.

Referenced by ThreatMgr::areThreatListsEmpty(), Spell::EffectTaunt(), and ThreatMgr::isThreatListEmpty().

◆ getMostHated()

HostileReference * ThreatContainer::getMostHated ( ) const
inline
169 {
170 return iThreatList.empty() ? nullptr : iThreatList.front();
171 }

References iThreatList.

Referenced by Spell::EffectTaunt().

◆ getReferenceByTarget() [1/2]

HostileReference * ThreatContainer::getReferenceByTarget ( ObjectGuid const &  guid) const
270{
271 for (ThreatContainer::StorageType::const_iterator i = iThreatList.begin(); i != iThreatList.end(); ++i)
272 {
273 HostileReference* ref = (*i);
274 if (ref && ref->getUnitGuid() == guid)
275 {
276 return ref;
277 }
278 }
279
280 return nullptr;
281}
ObjectGuid getUnitGuid() const
Definition: ThreatMgr.h:106

References HostileReference::getUnitGuid(), and iThreatList.

◆ getReferenceByTarget() [2/2]

◆ GetThreatList()

◆ isDirty()

bool ThreatContainer::isDirty ( ) const
inline
161{ return iDirty; }
bool iDirty
Definition: ThreatMgr.h:195

References iDirty.

Referenced by setDirty().

◆ ModifyThreatByPercent()

void ThreatContainer::ModifyThreatByPercent ( Unit victim,
int32  percent 
)
297{
298 if (HostileReference* ref = getReferenceByTarget(victim))
299 ref->addThreatPercent(percent);
300}

References getReferenceByTarget().

Referenced by ThreatMgr::ModifyThreatByPercent().

◆ remove()

void ThreatContainer::remove ( HostileReference hostileRef)
inlineprivate
180 {
181 iThreatList.remove(hostileRef);
182 }

References iThreatList.

Referenced by ThreatMgr::processThreatEvent().

◆ SelectNextVictim()

HostileReference * ThreatContainer::SelectNextVictim ( Creature attacker,
HostileReference currentVictim 
) const
318{
319 // pussywizard: pretty much remade this whole function
320
321 HostileReference* currentRef = nullptr;
322 bool found = false;
323 bool noPriorityTargetFound = false;
324
325 // pussywizard: currentVictim is needed to compare if threat was exceeded by 10%/30% for melee/range targets (only then switching current target)
326 if (currentVictim)
327 {
328 Unit* cvUnit = currentVictim->getTarget();
329 if (!attacker->CanCreatureAttack(cvUnit)) // pussywizard: if currentVictim is not valid => don't compare the threat with it, just take the highest threat valid target
330 currentVictim = nullptr;
331 else if (cvUnit->IsImmunedToDamageOrSchool(attacker->GetMeleeDamageSchoolMask()) || cvUnit->HasNegativeAuraWithInterruptFlag(AURA_INTERRUPT_FLAG_TAKE_DAMAGE)) // pussywizard: no 10%/30% if currentVictim is immune to damage or has auras breakable by damage
332 currentVictim = nullptr;
333 }
334
335 ThreatContainer::StorageType::const_iterator lastRef = iThreatList.end();
336 --lastRef;
337
338 // pussywizard: iterate from highest to lowest threat
339 for (ThreatContainer::StorageType::const_iterator iter = iThreatList.begin(); iter != iThreatList.end() && !found;)
340 {
341 currentRef = (*iter);
342
343 Unit* target = currentRef->getTarget();
344 ASSERT(target); // if the ref has status online the target must be there !
345
346 // pussywizard: don't go to threat comparison if this ref is immune to damage or has aura breakable on damage (second choice target)
347 // pussywizard: if this is the last entry on the threat list, then all targets are second choice, set bool to true and loop threat list again, ignoring this section
349 {
350 if (iter != lastRef)
351 {
352 ++iter;
353 continue;
354 }
355 else
356 {
357 noPriorityTargetFound = true;
358 iter = iThreatList.begin();
359 continue;
360 }
361 }
362
363 // pussywizard: skip not valid targets
364 if (attacker->CanCreatureAttack(target))
365 {
366 if (currentVictim) // pussywizard: if not nullptr then target must have 10%/30% more threat
367 {
368 if (currentVictim == currentRef) // pussywizard: nothing found previously was good and enough, currentRef passed all necessary tests, so end now
369 {
370 found = true;
371 break;
372 }
373
374 // pussywizard: implement 110% threat rule for targets in melee range and 130% rule for targets in ranged distances
375 if (currentRef->GetThreat() > 1.3f * currentVictim->GetThreat()) // pussywizard: enough in all cases, end
376 {
377 found = true;
378 break;
379 }
380 else if (currentRef->GetThreat() > 1.1f * currentVictim->GetThreat()) // pussywizard: enought only if target in melee range
381 {
382 if (attacker->IsWithinMeleeRange(target))
383 {
384 found = true;
385 break;
386 }
387 }
388 else // pussywizard: nothing found previously was good and enough, this and next entries on the list have less than 110% threat, and currentVictim is present and valid as checked before the loop (otherwise it's nullptr), so end now
389 {
390 currentRef = currentVictim;
391 found = true;
392 break;
393 }
394 }
395 else // pussywizard: no currentVictim, first passing all checks is chosen (highest threat, list is sorted)
396 {
397 found = true;
398 break;
399 }
400 }
401 ++iter;
402 }
403 if (!found)
404 currentRef = nullptr;
405
406 return currentRef;
407}
#define ASSERT
Definition: Errors.h:68
@ AURA_INTERRUPT_FLAG_TAKE_DAMAGE
Definition: SpellDefines.h:44
@ SPELL_AURA_IGNORED
Definition: SpellAuraDefines.h:284
TO * getTarget() const
Definition: Reference.h:95
float GetThreat() const
Definition: ThreatMgr.h:62
bool CanCreatureAttack(Unit const *victim, bool skipDistCheck=false) const
Definition: Creature.cpp:2625
SpellSchoolMask GetMeleeDamageSchoolMask(WeaponAttackType=BASE_ATTACK, uint8=0) const override
Definition: Creature.h:164
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:112
Definition: Unit.h:630
bool HasNegativeAuraWithInterruptFlag(uint32 flag, ObjectGuid guid=ObjectGuid::Empty)
Definition: Unit.cpp:5769
bool HasAuraTypeWithCaster(AuraType auratype, ObjectGuid caster) const
Definition: Unit.cpp:5710
bool IsWithinMeleeRange(Unit const *obj, float dist=0.f) const
Definition: Unit.cpp:664
bool IsImmunedToDamageOrSchool(SpellSchoolMask meleeSchoolMask) const
Definition: Unit.cpp:12901

References ASSERT, AURA_INTERRUPT_FLAG_TAKE_DAMAGE, Creature::CanCreatureAttack(), Object::GetGUID(), Creature::GetMeleeDamageSchoolMask(), Reference< TO, FROM >::getTarget(), HostileReference::GetThreat(), Unit::HasAuraTypeWithCaster(), Unit::HasNegativeAuraWithInterruptFlag(), Unit::IsImmunedToDamageOrSchool(), Unit::IsWithinMeleeRange(), iThreatList, and SPELL_AURA_IGNORED.

Referenced by ThreatMgr::getHostileTarget().

◆ setDirty()

void ThreatContainer::setDirty ( bool  isDirty)
inline
159{ iDirty = isDirty; }
bool isDirty() const
Definition: ThreatMgr.h:161

References iDirty, and isDirty().

Referenced by ThreatMgr::setDirty().

◆ update()

void ThreatContainer::update ( )
private
306{
307 if (iDirty && iThreatList.size() > 1)
309
310 iDirty = false;
311}
Definition: ThreatMgr.h:320

References iDirty, and iThreatList.

Referenced by ThreatMgr::getHostileTarget().

Friends And Related Function Documentation

◆ ThreatMgr

friend class ThreatMgr
friend

Member Data Documentation

◆ iDirty

bool ThreatContainer::iDirty {false}
private

Referenced by isDirty(), setDirty(), and update().

◆ iThreatList