AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
ThreatCalcHelper Struct Reference

#include "ThreatMgr.h"

Static Public Member Functions

static float calcThreat (Unit *hatedUnit, float threat, SpellSchoolMask schoolMask=SPELL_SCHOOL_MASK_NORMAL, SpellInfo const *threatSpell=nullptr)
 
static bool isValidProcess (Unit *hatedUnit, Unit *hatingUnit, SpellInfo const *threatSpell=nullptr)
 

Detailed Description

Member Function Documentation

◆ calcThreat()

float ThreatCalcHelper::calcThreat ( Unit hatedUnit,
float  threat,
SpellSchoolMask  schoolMask = SPELL_SCHOOL_MASK_NORMAL,
SpellInfo const *  threatSpell = nullptr 
)
static
35{
36 if (threatSpell)
37 {
38 if (SpellThreatEntry const* threatEntry = sSpellMgr->GetSpellThreatEntry(threatSpell->Id))
39 if (threatEntry->pctMod != 1.0f)
40 threat *= threatEntry->pctMod;
41
42 // Energize is not affected by Mods
43 for (uint8 i = 0; i < MAX_SPELL_EFFECTS; i++)
44 if (threatSpell->Effects[i].Effect == SPELL_EFFECT_ENERGIZE || threatSpell->Effects[i].ApplyAuraName == SPELL_AURA_PERIODIC_ENERGIZE)
45 return threat;
46
47 if (Player* modOwner = hatedUnit->GetSpellModOwner())
48 modOwner->ApplySpellMod(threatSpell->Id, SPELLMOD_THREAT, threat);
49 }
50
51 return hatedUnit->ApplyTotalThreatModifier(threat, schoolMask);
52}
std::uint8_t uint8
Definition: Define.h:109
@ SPELL_AURA_PERIODIC_ENERGIZE
Definition: SpellAuraDefines.h:87
@ SPELLMOD_THREAT
Definition: SpellDefines.h:79
#define sSpellMgr
Definition: SpellMgr.h:825
@ SPELL_EFFECT_ENERGIZE
Definition: SharedDefines.h:808
#define MAX_SPELL_EFFECTS
Definition: DBCStructure.h:1637
Definition: Player.h:1064
Player * GetSpellModOwner() const
Definition: Unit.cpp:16533
float ApplyTotalThreatModifier(float fThreat, SpellSchoolMask schoolMask=SPELL_SCHOOL_MASK_NORMAL)
Definition: Unit.cpp:14596
Definition: SpellMgr.h:385

References Unit::ApplyTotalThreatModifier(), SpellInfo::Effects, Unit::GetSpellModOwner(), SpellInfo::Id, MAX_SPELL_EFFECTS, SPELL_AURA_PERIODIC_ENERGIZE, SPELL_EFFECT_ENERGIZE, SPELLMOD_THREAT, and sSpellMgr.

Referenced by ThreatMgr::AddThreat(), and HostileRefMgr::threatAssist().

◆ isValidProcess()

bool ThreatCalcHelper::isValidProcess ( Unit hatedUnit,
Unit hatingUnit,
SpellInfo const *  threatSpell = nullptr 
)
static
55{
56 //function deals with adding threat and adding players and pets into ThreatList
57 //mobs, NPCs, guards have ThreatList and HateOfflineList
58 //players and pets have only InHateListOf
59 //HateOfflineList is used co contain unattackable victims (in-flight, in-water, GM etc.)
60
61 if (!hatedUnit || !hatingUnit)
62 return false;
63
64 // not to self
65 if (hatedUnit == hatingUnit)
66 return false;
67
68 // not to GM
69 if (hatedUnit->IsPlayer() && hatedUnit->ToPlayer()->IsGameMaster())
70 return false;
71
72 // not to dead and not for dead
73 if (!hatedUnit->IsAlive() || !hatingUnit->IsAlive())
74 return false;
75
76 // not in same map or phase
77 if (!hatedUnit->IsInMap(hatingUnit) || !hatedUnit->InSamePhase(hatingUnit))
78 return false;
79
80 // spell not causing threat
81 if (threatSpell && threatSpell->HasAttribute(SPELL_ATTR1_NO_THREAT))
82 return false;
83
84 ASSERT(hatingUnit->IsCreature());
85
86 return true;
87}
#define ASSERT
Definition: Errors.h:68
@ SPELL_ATTR1_NO_THREAT
Definition: SharedDefines.h:429
bool IsPlayer() const
Definition: Object.h:197
Player * ToPlayer()
Definition: Object.h:198
bool IsCreature() const
Definition: Object.h:201
bool InSamePhase(WorldObject const *obj) const
Definition: Object.h:447
bool IsInMap(WorldObject const *obj) const
Definition: Object.cpp:1285
bool IsGameMaster() const
Definition: Player.h:1158
bool IsAlive() const
Definition: Unit.h:1204

References ASSERT, SpellInfo::HasAttribute(), WorldObject::InSamePhase(), Unit::IsAlive(), Object::IsCreature(), Player::IsGameMaster(), WorldObject::IsInMap(), Object::IsPlayer(), SPELL_ATTR1_NO_THREAT, and Object::ToPlayer().

Referenced by ThreatMgr::AddThreat(), ThreatMgr::DoAddThreat(), and HostileRefMgr::threatAssist().