AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
HostileReference Class Reference

#include "ThreatMgr.h"

Inheritance diagram for HostileReference:
Reference< Unit, ThreatMgr > LinkedListElement

Public Member Functions

 HostileReference (Unit *refUnit, ThreatMgr *threatMgr, float threat)
 
UnitGetOwner () const
 
UnitGetVictim () const
 
void AddThreat (float modThreat)
 
void SetThreat (float threat)
 
void addThreatPercent (int32 percent)
 
float GetThreat () const
 
void ClearThreat ()
 
bool IsOnline () const
 
bool IsAvailable () const
 
bool IsOffline () const
 
void setTempThreat (float threat)
 
void addTempThreat (float threat)
 
void resetTempThreat ()
 
float getTempThreatModifier ()
 
void updateOnlineStatus ()
 
void setOnlineOfflineState (bool isOnline)
 
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, ThreatMgr >
 Reference ()
 
virtual ~Reference ()=default
 
void link (Unit *toObj, ThreatMgr *fromObj)
 
void unlink ()
 
void invalidate ()
 
bool isValid () const
 
Reference< Unit, ThreatMgr > * next ()
 
Reference< Unit, ThreatMgr > const * next () const
 
Reference< Unit, ThreatMgr > * prev ()
 
Reference< Unit, ThreatMgr > const * prev () const
 
Reference< Unit, ThreatMgr > * nocheck_next ()
 
Reference< Unit, ThreatMgr > const * nocheck_next () const
 
Reference< Unit, ThreatMgr > * nocheck_prev ()
 
Reference< Unit, ThreatMgr > const * nocheck_prev () const
 
Unitoperator-> () const
 
UnitgetTarget () const
 
ThreatMgrGetSource () const
 
- Public Member Functions inherited from LinkedListElement
 LinkedListElement ()=default
 
 ~LinkedListElement ()
 
bool hasNext () const
 
bool hasPrev () const
 
bool isInList () const
 
LinkedListElementnext ()
 
LinkedListElement const * next () const
 
LinkedListElementprev ()
 
LinkedListElement const * prev () const
 
LinkedListElementnocheck_next ()
 
LinkedListElement const * nocheck_next () const
 
LinkedListElementnocheck_prev ()
 
LinkedListElement const * nocheck_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
 

Additional Inherited Members

virtual void targetObjectBuildLink ()=0
 
virtual void targetObjectDestroyLink ()=0
 
virtual void sourceObjectDestroyLink ()=0
 

Detailed Description

Constructor & Destructor Documentation

◆ HostileReference()

HostileReference::HostileReference ( Unit refUnit,
ThreatMgr threatMgr,
float  threat 
)
94{
95 iThreat = threat;
97 link(refUnit, threatMgr);
98 iUnitGuid = refUnit->GetGUID();
99 iOnline = true;
100}
void link(Unit *toObj, ThreatMgr *fromObj)
Definition: Reference.h:45
bool iOnline
Definition: ThreatMgr.h:136
ObjectGuid iUnitGuid
Definition: ThreatMgr.h:135
float iThreat
Definition: ThreatMgr.h:133
float iTempThreatModifier
Definition: ThreatMgr.h:134
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:112

References Object::GetGUID(), iOnline, iTempThreatModifier, iThreat, iUnitGuid, and Reference< Unit, ThreatMgr >::link().

Member Function Documentation

◆ addTempThreat()

void HostileReference::addTempThreat ( float  threat)
inline
78 {
79 iTempThreatModifier = threat;
80 if (iTempThreatModifier != 0.0f)
82 }
void AddThreat(float modThreat)
Definition: ThreatMgr.cpp:138

References AddThreat(), and iTempThreatModifier.

Referenced by HostileRefMgr::addTempThreat(), and setTempThreat().

◆ AddThreat()

void HostileReference::AddThreat ( float  modThreat)
139{
140 iThreat += modThreat;
141 // the threat is changed. Source and target unit have to be available
142 // if the link was cut before relink it again
143 if (!IsOnline())
145 if (modThreat != 0.0f)
146 {
148 fireStatusChanged(event);
149 }
150
151 if (isValid() && modThreat >= 0.0f)
152 {
153 Unit* target = getTarget();
154 if (target->GetEntry() != NPC_EYE_OF_KILROGG) // Excluded Eye of Kilrogg
155 {
156 Unit* victimOwner = target->GetCharmerOrOwner();
157 if (victimOwner && victimOwner->IsAlive())
158 {
159 GetSource()->AddThreat(victimOwner, 0.0f); // create a threat to the owner of a pet, if the pet attacks
160 }
161 }
162 }
163}
@ NPC_EYE_OF_KILROGG
Definition: PetDefines.h:101
@ UEV_THREAT_REF_THREAT_CHANGE
Definition: UnitEvents.h:36
Unit * getTarget() const
Definition: Reference.h:95
bool isValid() const
Definition: Reference.h:79
ThreatMgr * GetSource() const
Definition: Reference.h:97
void updateOnlineStatus()
Definition: ThreatMgr.cpp:180
bool IsOnline() const
Definition: ThreatMgr.h:66
void fireStatusChanged(ThreatRefStatusChangeEvent &threatRefStatusChangeEvent)
Definition: ThreatMgr.cpp:127
void AddThreat(Unit *victim, float threat, SpellSchoolMask schoolMask=SPELL_SCHOOL_MASK_NORMAL, SpellInfo const *threatSpell=nullptr)
Definition: ThreatMgr.cpp:436
Definition: UnitEvents.h:84
uint32 GetEntry() const
Definition: Object.h:115
Definition: Unit.h:630
bool IsAlive() const
Definition: Unit.h:1654
Unit * GetCharmerOrOwner() const
Definition: Unit.h:1211

References ThreatMgr::AddThreat(), fireStatusChanged(), Unit::GetCharmerOrOwner(), Object::GetEntry(), Reference< Unit, ThreatMgr >::GetSource(), Reference< Unit, ThreatMgr >::getTarget(), Unit::IsAlive(), IsOnline(), Reference< Unit, ThreatMgr >::isValid(), iThreat, NPC_EYE_OF_KILROGG, UEV_THREAT_REF_THREAT_CHANGE, and updateOnlineStatus().

Referenced by ThreatMgr::_addThreat(), addTempThreat(), ThreatContainer::AddThreat(), addThreatPercent(), npc_pet_mage_mirror_image::InitializeAI(), resetTempThreat(), and SetThreat().

◆ addThreatPercent()

void HostileReference::addThreatPercent ( int32  percent)
166{
167 // Xinef: Do not allow to modify threat by percent if threat is negative (forced to big value < 0 by spells adding temporary threat)
168 // Xinef: When the temporary effect ends, temporary threat is added back which results in huge additional amount of threat
169 if (iThreat <= 0)
170 return;
171
172 float tmpThreat = iThreat;
173 AddPct(tmpThreat, percent);
174 AddThreat(tmpThreat - iThreat);
175}
T AddPct(T &base, U pct)
Definition: Util.h:67

References AddPct(), AddThreat(), and iThreat.

Referenced by HostileRefMgr::addThreatPercent().

◆ ClearThreat()

void HostileReference::ClearThreat ( )
inline
64{ removeReference(); }
void removeReference()
Definition: ThreatMgr.cpp:229

References removeReference().

◆ fireStatusChanged()

void HostileReference::fireStatusChanged ( ThreatRefStatusChangeEvent threatRefStatusChangeEvent)
private
128{
129 if (GetSource())
130 GetSource()->processThreatEvent(&threatRefStatusChangeEvent);
131}
void processThreatEvent(ThreatRefStatusChangeEvent *threatRefStatusChangeEvent)
Definition: ThreatMgr.cpp:585

References Reference< Unit, ThreatMgr >::GetSource(), and ThreatMgr::processThreatEvent().

Referenced by AddThreat(), removeReference(), and setOnlineOfflineState().

◆ GetOwner()

Unit * HostileReference::GetOwner ( ) const
134{ return GetSource()->GetOwner(); }
Unit * GetOwner() const
Definition: ThreatMgr.h:236

References ThreatMgr::GetOwner(), and Reference< Unit, ThreatMgr >::GetSource().

Referenced by GetSourceUnit().

◆ GetSourceUnit()

Unit * HostileReference::GetSourceUnit ( )
private
240{
241 return (GetSource()->GetOwner());
242}
Unit * GetOwner() const
Definition: ThreatMgr.cpp:134

References GetOwner(), and Reference< Unit, ThreatMgr >::GetSource().

Referenced by updateOnlineStatus().

◆ getTempThreatModifier()

float HostileReference::getTempThreatModifier ( )
inline

◆ GetThreat()

◆ getUnitGuid()

◆ GetVictim()

Unit * HostileReference::GetVictim ( ) const
inline

◆ IsAvailable()

bool HostileReference::IsAvailable ( ) const
inline
67{ return iOnline; } // unused for now

References iOnline.

◆ IsOffline()

bool HostileReference::IsOffline ( ) const
inline
68{ return !iOnline; } // unused for now

References iOnline.

◆ IsOnline()

bool HostileReference::IsOnline ( ) const
inline

◆ next()

◆ operator==()

bool HostileReference::operator== ( const HostileReference hostileRef) const
inline
102{ return hostileRef.getUnitGuid() == getUnitGuid(); }
ObjectGuid getUnitGuid() const
Definition: ThreatMgr.h:106

References getUnitGuid().

◆ removeReference()

◆ resetTempThreat()

void HostileReference::resetTempThreat ( )
inline

◆ setOnlineOfflineState()

void HostileReference::setOnlineOfflineState ( bool  isOnline)
215{
216 if (iOnline != isOnline)
217 {
218 iOnline = isOnline;
219
221 fireStatusChanged(event);
222 }
223}
@ UEV_THREAT_REF_ONLINE_STATUS
Definition: UnitEvents.h:33

References fireStatusChanged(), iOnline, and UEV_THREAT_REF_ONLINE_STATUS.

Referenced by ThreatMgr::_addThreat(), HostileRefMgr::setOnlineOfflineState(), sourceObjectDestroyLink(), and updateOnlineStatus().

◆ setTempThreat()

void HostileReference::setTempThreat ( float  threat)
inline
73 {
74 addTempThreat(threat - GetThreat());
75 }
float GetThreat() const
Definition: ThreatMgr.h:62
void addTempThreat(float threat)
Definition: ThreatMgr.h:77

References addTempThreat(), and GetThreat().

Referenced by ThreatMgr::tauntApply().

◆ SetThreat()

void HostileReference::SetThreat ( float  threat)
inline
58{ AddThreat(threat - GetThreat()); }

References AddThreat(), and GetThreat().

◆ sourceObjectDestroyLink()

void HostileReference::sourceObjectDestroyLink ( )
overridevirtual

Implements Reference< Unit, ThreatMgr >.

120{
122}
void setOnlineOfflineState(bool isOnline)
Definition: ThreatMgr.cpp:214

References setOnlineOfflineState().

◆ targetObjectBuildLink()

void HostileReference::targetObjectBuildLink ( )
overridevirtual

Implements Reference< Unit, ThreatMgr >.

105{
106 getTarget()->addHatedBy(this);
107}
void addHatedBy(HostileReference *pHostileReference)
Definition: Unit.h:905

References Unit::addHatedBy(), and Reference< Unit, ThreatMgr >::getTarget().

◆ targetObjectDestroyLink()

void HostileReference::targetObjectDestroyLink ( )
overridevirtual

Implements Reference< Unit, ThreatMgr >.

112{
113 getTarget()->removeHatedBy(this);
114}
void removeHatedBy(HostileReference *)
Definition: Unit.h:906

References Reference< Unit, ThreatMgr >::getTarget(), and Unit::removeHatedBy().

◆ updateOnlineStatus()

void HostileReference::updateOnlineStatus ( )
181{
182 bool online = false;
183
184 if (!isValid())
186 link(target, GetSource());
187
188 // only check for online status if
189 // ref is valid
190 // target is no player or not gamemaster
191 // target is not in flight
192 if (isValid()
193 && (!getTarget()->IsPlayer() || !getTarget()->ToPlayer()->IsGameMaster())
194 && !getTarget()->IsInFlight()
195 && getTarget()->IsInMap(GetSourceUnit())
196 && getTarget()->InSamePhase(GetSourceUnit())
197 )
198 {
199 Creature* creature = GetSourceUnit()->ToCreature();
200 online = getTarget()->isInAccessiblePlaceFor(creature);
201 if (!online)
202 {
203 if (creature->IsWithinCombatRange(getTarget(), creature->m_CombatDistance))
204 online = true; // not accessible but stays online
205 }
206 }
207
208 setOnlineOfflineState(online);
209}
Unit * GetUnit(WorldObject const &, ObjectGuid const guid)
Definition: ObjectAccessor.cpp:199
Unit * GetSourceUnit()
Definition: ThreatMgr.cpp:239
Definition: Creature.h:43
float m_CombatDistance
Definition: Creature.h:371
Creature * ToCreature()
Definition: Object.h:205
bool IsWithinCombatRange(Unit const *obj, float dist2compare) const
Definition: Unit.cpp:648
bool isInAccessiblePlaceFor(Creature const *c) const
Definition: Unit.cpp:4193

References Reference< Unit, ThreatMgr >::GetSource(), GetSourceUnit(), Reference< Unit, ThreatMgr >::getTarget(), ObjectAccessor::GetUnit(), getUnitGuid(), Unit::isInAccessiblePlaceFor(), Reference< Unit, ThreatMgr >::isValid(), Unit::IsWithinCombatRange(), Reference< Unit, ThreatMgr >::link(), Creature::m_CombatDistance, setOnlineOfflineState(), and Object::ToCreature().

Referenced by AddThreat(), and HostileRefMgr::updateThreatTables().

Member Data Documentation

◆ iOnline

bool HostileReference::iOnline
private

◆ iTempThreatModifier

float HostileReference::iTempThreatModifier
private

◆ iThreat

float HostileReference::iThreat
private

◆ iUnitGuid

ObjectGuid HostileReference::iUnitGuid
private

Referenced by getUnitGuid(), and HostileReference().