Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Toggle main menu visibility
Loading...
Searching...
No Matches
HostileRefManager.cpp
Go to the documentation of this file.
1
/*
2
* This file is part of Project SkyFire https://www.projectskyfire.org.
3
* See LICENSE.md file for Copyright information
4
*/
5
6
#include "
DBCStructure.h
"
7
#include "
HostileRefManager.h
"
8
#include "
SpellInfo.h
"
9
#include "
SpellMgr.h
"
10
#include "
ThreatManager.h
"
11
#include "
Unit.h
"
12
13
HostileRefManager::~HostileRefManager
()
14
{
15
deleteReferences
();
16
}
17
18
//=================================================
19
// send threat to all my hateres for the victim
20
// The victim is hated than by them as well
21
// use for buffs and healing threat functionality
22
23
void
HostileRefManager::threatAssist
(
Unit
* victim,
float
baseThreat,
SpellInfo
const
* threatSpell)
24
{
25
if
(
getSize
() == 0)
26
return
;
27
28
HostileReference
* ref =
getFirst
();
29
float
threat =
ThreatCalcHelper::calcThreat
(victim,
iOwner
, baseThreat, (threatSpell ? threatSpell->
GetSchoolMask
() :
SPELL_SCHOOL_MASK_NORMAL
), threatSpell);
30
threat /=
getSize
();
31
while
(ref)
32
{
33
if
(
ThreatCalcHelper::isValidProcess
(victim, ref->
GetSource
()->
GetOwner
(), threatSpell))
34
ref->
GetSource
()->
doAddThreat
(victim, threat);
35
36
ref = ref->
next
();
37
}
38
}
39
40
//=================================================
41
42
void
HostileRefManager::addTempThreat
(
float
threat,
bool
apply)
43
{
44
HostileReference
* ref =
getFirst
();
45
46
while
(ref)
47
{
48
if
(apply)
49
{
50
if
(ref->
getTempThreatModifier
() == 0.0f)
51
ref->
addTempThreat
(threat);
52
}
53
else
54
ref->
resetTempThreat
();
55
56
ref = ref->
next
();
57
}
58
}
59
60
//=================================================
61
62
void
HostileRefManager::addThreatPercent
(
int32
percent)
63
{
64
HostileReference
* ref =
getFirst
();
65
while
(ref)
66
{
67
ref->
addThreatPercent
(percent);
68
ref = ref->
next
();
69
}
70
}
71
72
//=================================================
73
// The online / offline status is given to the method. The calculation has to be done before
74
75
void
HostileRefManager::setOnlineOfflineState
(
bool
isOnline)
76
{
77
HostileReference
* ref =
getFirst
();
78
while
(ref)
79
{
80
ref->
setOnlineOfflineState
(isOnline);
81
ref = ref->
next
();
82
}
83
}
84
85
//=================================================
86
// The online / offline status is calculated and set
87
88
void
HostileRefManager::updateThreatTables
()
89
{
90
HostileReference
* ref =
getFirst
();
91
while
(ref)
92
{
93
ref->
updateOnlineStatus
();
94
ref = ref->
next
();
95
}
96
}
97
98
//=================================================
99
// The references are not needed anymore
100
// tell the source to remove them from the list and free the mem
101
102
void
HostileRefManager::deleteReferences
()
103
{
104
HostileReference
* ref =
getFirst
();
105
while
(ref)
106
{
107
HostileReference
* nextRef = ref->
next
();
108
ref->
removeReference
();
109
delete
ref;
110
ref = nextRef;
111
}
112
}
113
114
//=================================================
115
// delete one reference, defined by faction
116
117
void
HostileRefManager::deleteReferencesForFaction
(
uint32
faction)
118
{
119
HostileReference
* ref =
getFirst
();
120
while
(ref)
121
{
122
HostileReference
* nextRef = ref->
next
();
123
if
(ref->
GetSource
()->
GetOwner
()->
GetFactionTemplateEntry
()->
faction
== faction)
124
{
125
ref->
removeReference
();
126
delete
ref;
127
}
128
ref = nextRef;
129
}
130
}
131
132
//=================================================
133
// delete one reference, defined by Unit
134
135
void
HostileRefManager::deleteReference
(
Unit
* creature)
136
{
137
HostileReference
* ref =
getFirst
();
138
while
(ref)
139
{
140
HostileReference
* nextRef = ref->
next
();
141
if
(ref->
GetSource
()->
GetOwner
() == creature)
142
{
143
ref->
removeReference
();
144
delete
ref;
145
break
;
146
}
147
ref = nextRef;
148
}
149
}
150
151
//=================================================
152
// set state for one reference, defined by Unit
153
154
void
HostileRefManager::setOnlineOfflineState
(
Unit
* creature,
bool
isOnline)
155
{
156
HostileReference
* ref =
getFirst
();
157
while
(ref)
158
{
159
HostileReference
* nextRef = ref->
next
();
160
if
(ref->
GetSource
()->
GetOwner
() == creature)
161
{
162
ref->
setOnlineOfflineState
(isOnline);
163
break
;
164
}
165
ref = nextRef;
166
}
167
}
168
169
//=================================================
170
171
void
HostileRefManager::UpdateVisibility
()
172
{
173
HostileReference
* ref =
getFirst
();
174
while
(ref)
175
{
176
HostileReference
* nextRef = ref->
next
();
177
if
(!ref->
GetSource
()->
GetOwner
()->
CanSeeOrDetect
(
GetOwner
()))
178
{
179
nextRef = ref->
next
();
180
ref->
removeReference
();
181
delete
ref;
182
}
183
ref = nextRef;
184
}
185
}
DBCStructure.h
int32
std::int32_t int32
Definition
Define.h:73
uint32
std::uint32_t uint32
Definition
Define.h:77
HostileRefManager.h
SPELL_SCHOOL_MASK_NORMAL
@ SPELL_SCHOOL_MASK_NORMAL
Definition
SharedDefines.h:270
SpellInfo.h
SpellMgr.h
ThreatManager.h
Unit.h
HostileRefManager::getFirst
HostileReference * getFirst()
Definition
HostileRefManager.h:45
HostileRefManager::iOwner
Unit * iOwner
Definition
HostileRefManager.h:22
HostileRefManager::deleteReferencesForFaction
void deleteReferencesForFaction(uint32 faction)
Definition
HostileRefManager.cpp:117
HostileRefManager::threatAssist
void threatAssist(Unit *victim, float baseThreat, SpellInfo const *threatSpell=NULL)
Definition
HostileRefManager.cpp:23
HostileRefManager::~HostileRefManager
~HostileRefManager()
Definition
HostileRefManager.cpp:13
HostileRefManager::UpdateVisibility
void UpdateVisibility()
Definition
HostileRefManager.cpp:171
HostileRefManager::setOnlineOfflineState
void setOnlineOfflineState(bool isOnline)
Definition
HostileRefManager.cpp:75
HostileRefManager::deleteReference
void deleteReference(Unit *creature)
Definition
HostileRefManager.cpp:135
HostileRefManager::GetOwner
Unit * GetOwner()
Definition
HostileRefManager.h:27
HostileRefManager::addTempThreat
void addTempThreat(float threat, bool apply)
Definition
HostileRefManager.cpp:42
HostileRefManager::deleteReferences
void deleteReferences()
Definition
HostileRefManager.cpp:102
HostileRefManager::addThreatPercent
void addThreatPercent(int32 percent)
Definition
HostileRefManager.cpp:62
HostileRefManager::updateThreatTables
void updateThreatTables()
Definition
HostileRefManager.cpp:88
HostileReference
Definition
ThreatManager.h:28
HostileReference::updateOnlineStatus
void updateOnlineStatus()
Definition
ThreatManager.cpp:168
HostileReference::setOnlineOfflineState
void setOnlineOfflineState(bool isOnline)
Definition
ThreatManager.cpp:205
HostileReference::addTempThreat
void addTempThreat(float threat)
Definition
ThreatManager.h:54
HostileReference::next
HostileReference * next()
Definition
ThreatManager.h:94
HostileReference::removeReference
void removeReference()
Definition
ThreatManager.cpp:235
HostileReference::addThreatPercent
void addThreatPercent(int32 percent)
Definition
ThreatManager.cpp:158
HostileReference::getTempThreatModifier
float getTempThreatModifier() const
Definition
ThreatManager.h:70
HostileReference::resetTempThreat
void resetTempThreat()
Definition
ThreatManager.h:61
LinkedListHead::getSize
uint32 getSize() const
Definition
LinkedList.h:104
Reference::GetSource
FROM * GetSource() const
Definition
Reference.h:83
SpellInfo
Definition
SpellInfo.h:158
SpellInfo::GetSchoolMask
SpellSchoolMask GetSchoolMask() const
Definition
SpellInfo.cpp:1645
ThreatManager::GetOwner
Unit * GetOwner() const
Definition
ThreatManager.h:206
ThreatManager::doAddThreat
void doAddThreat(Unit *victim, float threat)
Definition
ThreatManager.cpp:415
Unit
Definition
Unit.h:1367
Unit::GetFactionTemplateEntry
FactionTemplateEntry const * GetFactionTemplateEntry() const
Definition
Unit.cpp:2117
WorldObject::CanSeeOrDetect
bool CanSeeOrDetect(WorldObject const *obj, bool ignoreStealth=false, bool distanceCheck=false) const
Definition
Object.cpp:2105
FactionTemplateEntry::faction
uint32 faction
Definition
DBCStructure.h:1494
ThreatCalcHelper::calcThreat
static float calcThreat(Unit *hatedUnit, Unit *hatingUnit, float threat, uint32 schoolMask=NormalSchoolMask, SpellInfo const *threatSpell=NULL)
Definition
ThreatManager.cpp:22
ThreatCalcHelper::isValidProcess
static bool isValidProcess(Unit *hatedUnit, Unit *hatingUnit, SpellInfo const *threatSpell=NULL)
Definition
ThreatManager.cpp:55
src
server
game
Combat
HostileRefManager.cpp
Generated on
for Project SkyFire Core by
1.17.0