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 
)
95{
96 iThreat = threat;
98 link(refUnit, threatMgr);
99 iUnitGuid = refUnit->GetGUID();
100 iOnline = true;
101}
void link(Unit *toObj, ThreatMgr *fromObj)
Definition: Reference.h:45
bool iOnline
Definition: ThreatMgr.h:137
ObjectGuid iUnitGuid
Definition: ThreatMgr.h:136
float iThreat
Definition: ThreatMgr.h:134
float iTempThreatModifier
Definition: ThreatMgr.h:135
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:106

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

Member Function Documentation

◆ addTempThreat()

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

References AddThreat(), and iTempThreatModifier.

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

◆ AddThreat()

void HostileReference::AddThreat ( float  modThreat)
140{
141 iThreat += modThreat;
142 // the threat is changed. Source and target unit have to be available
143 // if the link was cut before relink it again
144 if (!IsOnline())
146 if (modThreat != 0.0f)
147 {
149 fireStatusChanged(event);
150 }
151
152 if (isValid() && modThreat >= 0.0f)
153 {
154 Unit* target = getTarget();
155 if (target->GetEntry() != NPC_EYE_OF_KILROGG) // Excluded Eye of Kilrogg
156 {
157 Unit* victimOwner = target->GetCharmerOrOwner();
158 if (victimOwner && victimOwner->IsAlive())
159 {
160 GetSource()->AddThreat(victimOwner, 0.0f); // create a threat to the owner of a pet, if the pet attacks
161 }
162 }
163 }
164}
@ UEV_THREAT_REF_THREAT_CHANGE
Definition: UnitEvents.h:36
@ NPC_EYE_OF_KILROGG
Definition: PetDefines.h:101
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:181
bool IsOnline() const
Definition: ThreatMgr.h:67
void fireStatusChanged(ThreatRefStatusChangeEvent &threatRefStatusChangeEvent)
Definition: ThreatMgr.cpp:128
void AddThreat(Unit *victim, float threat, SpellSchoolMask schoolMask=SPELL_SCHOOL_MASK_NORMAL, SpellInfo const *threatSpell=nullptr)
Definition: ThreatMgr.cpp:437
Definition: UnitEvents.h:84
uint32 GetEntry() const
Definition: Object.h:109
Definition: Unit.h:1290
bool IsAlive() const
Definition: Unit.h:1808
Unit * GetCharmerOrOwner() const
Definition: Unit.h:1847

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

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

Referenced by HostileRefMgr::addThreatPercent().

◆ ClearThreat()

void HostileReference::ClearThreat ( )
inline
65{ removeReference(); }
void removeReference()
Definition: ThreatMgr.cpp:230

References removeReference().

◆ fireStatusChanged()

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

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

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

◆ GetOwner()

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

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

Referenced by GetSourceUnit().

◆ GetSourceUnit()

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

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
68{ return iOnline; } // unused for now

References iOnline.

◆ IsOffline()

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

References iOnline.

◆ IsOnline()

bool HostileReference::IsOnline ( ) const
inline

◆ next()

◆ operator==()

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

References getUnitGuid().

◆ removeReference()

◆ resetTempThreat()

void HostileReference::resetTempThreat ( )
inline

◆ setOnlineOfflineState()

void HostileReference::setOnlineOfflineState ( bool  isOnline)
216{
217 if (iOnline != isOnline)
218 {
219 iOnline = isOnline;
220
222 fireStatusChanged(event);
223 }
224}
@ 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
74 {
75 addTempThreat(threat - GetThreat());
76 }
float GetThreat() const
Definition: ThreatMgr.h:63
void addTempThreat(float threat)
Definition: ThreatMgr.h:78

References addTempThreat(), and GetThreat().

Referenced by ThreatMgr::tauntApply().

◆ SetThreat()

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

References AddThreat(), and GetThreat().

◆ sourceObjectDestroyLink()

void HostileReference::sourceObjectDestroyLink ( )
overridevirtual

Implements Reference< Unit, ThreatMgr >.

121{
123}
void setOnlineOfflineState(bool isOnline)
Definition: ThreatMgr.cpp:215

References setOnlineOfflineState().

◆ targetObjectBuildLink()

void HostileReference::targetObjectBuildLink ( )
overridevirtual

Implements Reference< Unit, ThreatMgr >.

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

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

◆ targetObjectDestroyLink()

void HostileReference::targetObjectDestroyLink ( )
overridevirtual

Implements Reference< Unit, ThreatMgr >.

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

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

◆ updateOnlineStatus()

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

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(), Object::ToCreature(), and TYPEID_PLAYER.

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