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:110
@ SPELL_AURA_PERIODIC_ENERGIZE
Definition: SpellAuraDefines.h:87
@ SPELLMOD_THREAT
Definition: SpellDefines.h:79
#define sSpellMgr
Definition: SpellMgr.h:825
#define MAX_SPELL_EFFECTS
Definition: DBCStructure.h:1635
@ SPELL_EFFECT_ENERGIZE
Definition: SharedDefines.h:808
Definition: Player.h:1056
Player * GetSpellModOwner() const
Definition: Unit.cpp:16845
float ApplyTotalThreatModifier(float fThreat, SpellSchoolMask schoolMask=SPELL_SCHOOL_MASK_NORMAL)
Definition: Unit.cpp:14627
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->GetTypeId() == TYPEID_PLAYER && 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->GetTypeId() == TYPEID_UNIT);
85
86 return true;
87}
#define ASSERT
Definition: Errors.h:68
@ TYPEID_UNIT
Definition: ObjectGuid.h:37
@ TYPEID_PLAYER
Definition: ObjectGuid.h:38
@ SPELL_ATTR1_NO_THREAT
Definition: SharedDefines.h:429
Player * ToPlayer()
Definition: Object.h:195
TypeID GetTypeId() const
Definition: Object.h:121
bool InSamePhase(WorldObject const *obj) const
Definition: Object.h:435
bool IsInMap(WorldObject const *obj) const
Definition: Object.cpp:1285
bool IsGameMaster() const
Definition: Player.h:1148
bool IsAlive() const
Definition: Unit.h:1822

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

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