TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
HostileReference Class Reference

#include <ThreatManager.h>

Public Member Functions

 HostileReference (Unit *refUnit, ThreatManager *threatManager, float threat)
 
void addThreat (float modThreat)
 
void setThreat (float threat)
 
void addThreatPercent (int32 percent)
 
float getThreat () const
 
bool isOnline () const
 
bool isAccessible () const
 
void setTempThreat (float threat)
 
void addTempThreat (float threat)
 
void resetTempThreat ()
 
float getTempThreatModifier ()
 
void updateOnlineStatus ()
 
void setOnlineOfflineState (bool isOnline)
 
void setAccessibleState (bool isAccessible)
 
bool operator== (const HostileReference &hostileRef) const
 
ObjectGuid getUnitGuid () const
 
void removeReference ()
 
HostileReferencenext ()
 
void targetObjectBuildLink () override
 
void targetObjectDestroyLink () override
 
void sourceObjectDestroyLink () override
 
- Public Member Functions inherited from Reference< Unit, ThreatManager >
 Reference ()
 
virtual ~Reference ()
 
void link (Unit *toObj, ThreatManager *fromObj)
 
void unlink ()
 
void invalidate ()
 
bool isValid () const
 
Reference< Unit, ThreatManager > * next ()
 
Reference< Unit, ThreatManager >
const
next () const
 
Reference< Unit, ThreatManager > * prev ()
 
Reference< Unit, ThreatManager >
const
prev () const
 
Reference< Unit, ThreatManager > * nocheck_next ()
 
Reference< Unit, ThreatManager >
const
nocheck_next () const
 
Reference< Unit, ThreatManager > * nocheck_prev ()
 
Reference< Unit, ThreatManager >
const
nocheck_prev () const
 
Unitoperator-> () const
 
UnitgetTarget () const
 
ThreatManagerGetSource () const
 
- Public Member Functions inherited from LinkedListElement
 LinkedListElement ()
 
virtual ~LinkedListElement ()
 
bool hasNext () const
 
bool hasPrev () const
 
bool isInList () const
 
LinkedListElementnext ()
 
LinkedListElement constnext () const
 
LinkedListElementprev ()
 
LinkedListElement constprev () const
 
LinkedListElementnocheck_next ()
 
LinkedListElement constnocheck_next () const
 
LinkedListElementnocheck_prev ()
 
LinkedListElement constnocheck_prev () const
 
void delink ()
 
void insertBefore (LinkedListElement *pElem)
 
void insertAfter (LinkedListElement *pElem)
 

Private Member Functions

void fireStatusChanged (ThreatRefStatusChangeEvent &threatRefStatusChangeEvent)
 
UnitGetSourceUnit ()
 

Private Attributes

float iThreat
 
float iTempThreatModifier
 
ObjectGuid iUnitGuid
 
bool iOnline
 
bool iAccessible
 

Additional Inherited Members

Constructor & Destructor Documentation

HostileReference::HostileReference ( Unit refUnit,
ThreatManager threatManager,
float  threat 
)
94 {
95  iThreat = threat;
96  iTempThreatModifier = 0.0f;
97  link(refUnit, threatManager);
98  iUnitGuid = refUnit->GetGUID();
99  iOnline = true;
100  iAccessible = true;
101 }
float iThreat
Definition: ThreatManager.h:134
float iTempThreatModifier
Definition: ThreatManager.h:135
bool iAccessible
Definition: ThreatManager.h:138
ObjectGuid iUnitGuid
Definition: ThreatManager.h:136
void link(Unit *toObj, ThreatManager *fromObj)
Definition: Reference.h:46
ObjectGuid const & GetGUID() const
Definition: Object.h:105
bool iOnline
Definition: ThreatManager.h:137

+ Here is the call graph for this function:

Member Function Documentation

void HostileReference::addTempThreat ( float  threat)
inline
77  {
78  iTempThreatModifier = threat;
79  if (iTempThreatModifier != 0.0f)
81  }
void addThreat(float modThreat)
Definition: ThreatManager.cpp:136
float iTempThreatModifier
Definition: ThreatManager.h:135

+ Here is the caller graph for this function:

void HostileReference::addThreat ( float  modThreat)
137 {
138  iThreat += modThreat;
139  // the threat is changed. Source and target unit have to be available
140  // if the link was cut before relink it again
141  if (!isOnline())
143  if (modThreat != 0.0f)
144  {
146  fireStatusChanged(event);
147  }
148 
149  if (isValid() && modThreat >= 0.0f)
150  {
151  Unit* victimOwner = getTarget()->GetCharmerOrOwner();
152  if (victimOwner && victimOwner->IsAlive())
153  GetSource()->addThreat(victimOwner, 0.0f); // create a threat to the owner of a pet, if the pet attacks
154  }
155 }
bool isOnline() const
Definition: ThreatManager.h:63
void addThreat(Unit *victim, float threat, SpellSchoolMask schoolMask=SPELL_SCHOOL_MASK_NORMAL, SpellInfo const *threatSpell=NULL)
Definition: ThreatManager.cpp:406
void updateOnlineStatus()
Definition: ThreatManager.cpp:167
Definition: UnitEvents.h:37
void fireStatusChanged(ThreatRefStatusChangeEvent &threatRefStatusChangeEvent)
Definition: ThreatManager.cpp:128
float iThreat
Definition: ThreatManager.h:134
Unit * GetCharmerOrOwner() const
Definition: Unit.cpp:7627
bool IsAlive() const
Definition: Unit.h:1692
ThreatManager * GetSource() const
Definition: Reference.h:96
bool isValid() const
Definition: Reference.h:78
Definition: Unit.h:1305
Definition: UnitEvents.h:84
Unit * getTarget() const
Definition: Reference.h:94

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void HostileReference::addThreatPercent ( int32  percent)
158 {
159  float tmpThreat = iThreat;
160  AddPct(tmpThreat, percent);
161  addThreat(tmpThreat - iThreat);
162 }
void addThreat(float modThreat)
Definition: ThreatManager.cpp:136
float iThreat
Definition: ThreatManager.h:134
T AddPct(T &base, U pct)
Definition: Util.h:98

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void HostileReference::fireStatusChanged ( ThreatRefStatusChangeEvent threatRefStatusChangeEvent)
private
129 {
130  if (GetSource())
131  GetSource()->processThreatEvent(&threatRefStatusChangeEvent);
132 }
void processThreatEvent(ThreatRefStatusChangeEvent *threatRefStatusChangeEvent)
Definition: ThreatManager.cpp:516
ThreatManager * GetSource() const
Definition: Reference.h:96

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Unit * HostileReference::GetSourceUnit ( )
private
245 {
246  return (GetSource()->GetOwner());
247 }
ThreatManager * GetSource() const
Definition: Reference.h:96

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

float HostileReference::getTempThreatModifier ( )
inline
92 { return iTempThreatModifier; }
float iTempThreatModifier
Definition: ThreatManager.h:135

+ Here is the caller graph for this function:

float HostileReference::getThreat ( ) const
inline
61 { return iThreat; }
float iThreat
Definition: ThreatManager.h:134

+ Here is the caller graph for this function:

ObjectGuid HostileReference::getUnitGuid ( ) const
inline
107 { return iUnitGuid; }
ObjectGuid iUnitGuid
Definition: ThreatManager.h:136

+ Here is the caller graph for this function:

bool HostileReference::isAccessible ( ) const
inline
67 { return iAccessible; }
bool iAccessible
Definition: ThreatManager.h:138

+ Here is the caller graph for this function:

bool HostileReference::isOnline ( ) const
inline
63 { return iOnline; }
bool iOnline
Definition: ThreatManager.h:137

+ Here is the caller graph for this function:

HostileReference* HostileReference::next ( )
inline
Definition: ThreatManager.h:49
Definition: Reference.h:27

+ Here is the caller graph for this function:

bool HostileReference::operator== ( const HostileReference hostileRef) const
inline
103 { return hostileRef.getUnitGuid() == getUnitGuid(); }
ObjectGuid getUnitGuid() const
Definition: ThreatManager.h:107

+ Here is the call graph for this function:

void HostileReference::removeReference ( )
235 {
236  invalidate();
237 
239  fireStatusChanged(event);
240 }
void fireStatusChanged(ThreatRefStatusChangeEvent &threatRefStatusChangeEvent)
Definition: ThreatManager.cpp:128
Definition: UnitEvents.h:40
void invalidate()
Definition: Reference.h:71
Definition: UnitEvents.h:84

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void HostileReference::resetTempThreat ( )
inline
84  {
85  if (iTempThreatModifier != 0.0f)
86  {
88  iTempThreatModifier = 0.0f;
89  }
90  }
void addThreat(float modThreat)
Definition: ThreatManager.cpp:136
float iTempThreatModifier
Definition: ThreatManager.h:135

+ Here is the caller graph for this function:

void HostileReference::setAccessibleState ( bool  isAccessible)
220 {
221  if (iAccessible != isAccessible)
222  {
224 
226  fireStatusChanged(event);
227  }
228 }
Definition: UnitEvents.h:43
void fireStatusChanged(ThreatRefStatusChangeEvent &threatRefStatusChangeEvent)
Definition: ThreatManager.cpp:128
bool iAccessible
Definition: ThreatManager.h:138
bool isAccessible() const
Definition: ThreatManager.h:67
Definition: UnitEvents.h:84

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void HostileReference::setOnlineOfflineState ( bool  isOnline)
205 {
206  if (iOnline != isOnline)
207  {
208  iOnline = isOnline;
209  if (!iOnline)
210  setAccessibleState(false); // if not online that not accessable as well
211 
213  fireStatusChanged(event);
214  }
215 }
bool isOnline() const
Definition: ThreatManager.h:63
void fireStatusChanged(ThreatRefStatusChangeEvent &threatRefStatusChangeEvent)
Definition: ThreatManager.cpp:128
Definition: UnitEvents.h:34
void setAccessibleState(bool isAccessible)
Definition: ThreatManager.cpp:219
Definition: UnitEvents.h:84
bool iOnline
Definition: ThreatManager.h:137

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void HostileReference::setTempThreat ( float  threat)
inline
72  {
73  addTempThreat(threat - getThreat());
74  }
float getThreat() const
Definition: ThreatManager.h:61
void addTempThreat(float threat)
Definition: ThreatManager.h:76

+ Here is the caller graph for this function:

void HostileReference::setThreat ( float  threat)
inline
57 { addThreat(threat - getThreat()); }
void addThreat(float modThreat)
Definition: ThreatManager.cpp:136
float getThreat() const
Definition: ThreatManager.h:61

+ Here is the caller graph for this function:

void HostileReference::sourceObjectDestroyLink ( )
overridevirtual

Implements Reference< Unit, ThreatManager >.

121 {
122  setOnlineOfflineState(false);
123 }
void setOnlineOfflineState(bool isOnline)
Definition: ThreatManager.cpp:204

+ Here is the call graph for this function:

void HostileReference::targetObjectBuildLink ( )
overridevirtual

Implements Reference< Unit, ThreatManager >.

106 {
107  getTarget()->addHatedBy(this);
108 }
void addHatedBy(HostileReference *pHostileReference)
Definition: Unit.h:1999
Unit * getTarget() const
Definition: Reference.h:94

+ Here is the call graph for this function:

void HostileReference::targetObjectDestroyLink ( )
overridevirtual

Implements Reference< Unit, ThreatManager >.

113 {
114  getTarget()->removeHatedBy(this);
115 }
void removeHatedBy(HostileReference *)
Definition: Unit.h:2000
Unit * getTarget() const
Definition: Reference.h:94

+ Here is the call graph for this function:

void HostileReference::updateOnlineStatus ( )
168 {
169  bool online = false;
170  bool accessible = false;
171 
172  if (!isValid())
174  link(target, GetSource());
175 
176  // only check for online status if
177  // ref is valid
178  // target is no player or not gamemaster
179  // target is not in flight
180  if (isValid()
181  && (getTarget()->GetTypeId() != TYPEID_PLAYER || !getTarget()->ToPlayer()->IsGameMaster())
182  && !getTarget()->HasUnitState(UNIT_STATE_IN_FLIGHT)
183  && getTarget()->IsInMap(GetSourceUnit())
184  && getTarget()->IsInPhase(GetSourceUnit())
185  )
186  {
187  Creature* creature = GetSourceUnit()->ToCreature();
188  online = getTarget()->isInAccessiblePlaceFor(creature);
189  if (!online)
190  {
191  if (creature->IsWithinCombatRange(getTarget(), creature->m_CombatDistance))
192  online = true; // not accessible but stays online
193  }
194  else
195  accessible = true;
196  }
197  setAccessibleState(accessible);
198  setOnlineOfflineState(online);
199 }
bool IsWithinCombatRange(const Unit *obj, float dist2compare) const
Definition: Unit.cpp:492
TC_GAME_API Unit * GetUnit(WorldObject const &, ObjectGuid const &guid)
Definition: ObjectAccessor.cpp:163
void setOnlineOfflineState(bool isOnline)
Definition: ThreatManager.cpp:204
Definition: Creature.h:467
ObjectGuid getUnitGuid() const
Definition: ThreatManager.h:107
bool isInAccessiblePlaceFor(Creature const *c) const
Definition: Unit.cpp:2956
void link(Unit *toObj, ThreatManager *fromObj)
Definition: Reference.h:46
Definition: Unit.h:558
Definition: ObjectGuid.h:33
ThreatManager * GetSource() const
Definition: Reference.h:96
Creature * ToCreature()
Definition: Object.h:194
void setAccessibleState(bool isAccessible)
Definition: ThreatManager.cpp:219
bool isValid() const
Definition: Reference.h:78
Unit * GetSourceUnit()
Definition: ThreatManager.cpp:244
Definition: Unit.h:1305
float m_CombatDistance
Definition: Creature.h:704
Unit * getTarget() const
Definition: Reference.h:94

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

bool HostileReference::iAccessible
private
bool HostileReference::iOnline
private
float HostileReference::iTempThreatModifier
private
float HostileReference::iThreat
private
ObjectGuid HostileReference::iUnitGuid
private

The documentation for this class was generated from the following files: