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
36{
37 if (threatSpell)
38 {
39 if (SpellThreatEntry const* threatEntry = sSpellMgr->GetSpellThreatEntry(threatSpell->Id))
40 if (threatEntry->pctMod != 1.0f)
41 threat *= threatEntry->pctMod;
42
43 // Energize is not affected by Mods
44 for (uint8 i = 0; i < MAX_SPELL_EFFECTS; i++)
45 if (threatSpell->Effects[i].Effect == SPELL_EFFECT_ENERGIZE || threatSpell->Effects[i].ApplyAuraName == SPELL_AURA_PERIODIC_ENERGIZE)
46 return threat;
47
48 if (Player* modOwner = hatedUnit->GetSpellModOwner())
49 modOwner->ApplySpellMod(threatSpell->Id, SPELLMOD_THREAT, threat);
50 }
51
52 return hatedUnit->ApplyTotalThreatModifier(threat, schoolMask);
53}
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:818
#define MAX_SPELL_EFFECTS
Definition: DBCStructure.h:1610
@ SPELL_EFFECT_ENERGIZE
Definition: SharedDefines.h:780
Definition: Player.h:1046
Player * GetSpellModOwner() const
Definition: Unit.cpp:16751
float ApplyTotalThreatModifier(float fThreat, SpellSchoolMask schoolMask=SPELL_SCHOOL_MASK_NORMAL)
Definition: Unit.cpp:14536
Definition: SpellMgr.h:378

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
56{
57 //function deals with adding threat and adding players and pets into ThreatList
58 //mobs, NPCs, guards have ThreatList and HateOfflineList
59 //players and pets have only InHateListOf
60 //HateOfflineList is used co contain unattackable victims (in-flight, in-water, GM etc.)
61
62 if (!hatedUnit || !hatingUnit)
63 return false;
64
65 // not to self
66 if (hatedUnit == hatingUnit)
67 return false;
68
69 // not to GM
70 if (hatedUnit->GetTypeId() == TYPEID_PLAYER && hatedUnit->ToPlayer()->IsGameMaster())
71 return false;
72
73 // not to dead and not for dead
74 if (!hatedUnit->IsAlive() || !hatingUnit->IsAlive())
75 return false;
76
77 // not in same map or phase
78 if (!hatedUnit->IsInMap(hatingUnit) || !hatedUnit->InSamePhase(hatingUnit))
79 return false;
80
81 // spell not causing threat
82 if (threatSpell && threatSpell->HasAttribute(SPELL_ATTR1_NO_THREAT))
83 return false;
84
85 ASSERT(hatingUnit->GetTypeId() == TYPEID_UNIT);
86
87 return true;
88}
#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:401
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:1136
bool IsAlive() const
Definition: Unit.h:1808

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().