Project SkyFire Core
SkyFire 5.4.8 server core API documentation
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
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
23void HostileRefManager::threatAssist(Unit* victim, float baseThreat, SpellInfo const* threatSpell)
24{
25 if (getSize() == 0)
26 return;
27
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
42void HostileRefManager::addTempThreat(float threat, bool apply)
43{
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
63{
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
76{
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
89{
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
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
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
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
154void 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
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}
std::int32_t int32
Definition Define.h:73
std::uint32_t uint32
Definition Define.h:77
@ SPELL_SCHOOL_MASK_NORMAL
HostileReference * getFirst()
void deleteReferencesForFaction(uint32 faction)
void threatAssist(Unit *victim, float baseThreat, SpellInfo const *threatSpell=NULL)
void setOnlineOfflineState(bool isOnline)
void deleteReference(Unit *creature)
void addTempThreat(float threat, bool apply)
void addThreatPercent(int32 percent)
void setOnlineOfflineState(bool isOnline)
void addTempThreat(float threat)
HostileReference * next()
void addThreatPercent(int32 percent)
float getTempThreatModifier() const
uint32 getSize() const
Definition LinkedList.h:104
FROM * GetSource() const
Definition Reference.h:83
SpellSchoolMask GetSchoolMask() const
Unit * GetOwner() const
void doAddThreat(Unit *victim, float threat)
Definition Unit.h:1367
FactionTemplateEntry const * GetFactionTemplateEntry() const
Definition Unit.cpp:2117
bool CanSeeOrDetect(WorldObject const *obj, bool ignoreStealth=false, bool distanceCheck=false) const
Definition Object.cpp:2105
uint32 faction
static float calcThreat(Unit *hatedUnit, Unit *hatingUnit, float threat, uint32 schoolMask=NormalSchoolMask, SpellInfo const *threatSpell=NULL)
static bool isValidProcess(Unit *hatedUnit, Unit *hatingUnit, SpellInfo const *threatSpell=NULL)