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

#include <SpellAuras.h>

Public Member Functions

UnitGetTarget () const
 
AuraGetBase () const
 
uint8 GetSlot () const
 
uint8 GetFlags () const
 
uint32 GetEffectMask () const
 
bool HasEffect (uint8 effect) const
 
bool IsPositive () const
 
bool IsSelfcast () const
 
uint32 GetEffectsToApply () const
 
void SetRemoveMode (AuraRemoveMode mode)
 
AuraRemoveMode GetRemoveMode () const
 
void SetNeedClientUpdate ()
 
bool IsNeedClientUpdate () const
 
void BuildUpdatePacket (WorldPackets::Spells::AuraInfo &data, bool remove) const
 
void ClientUpdate (bool remove=false)
 

Private Member Functions

 AuraApplication (Unit *target, Unit *caster, Aura *base, uint32 effMask)
 
void _Remove ()
 
void _InitFlags (Unit *caster, uint32 effMask)
 
void _HandleEffect (uint8 effIndex, bool apply)
 

Private Attributes

Unit *const _target
 
Aura *const _base
 
AuraRemoveMode _removeMode:8
 
uint8 _slot
 
uint8 _flags
 
uint32 _effectsToApply
 
bool _needClientUpdate:1
 
uint32 _effectMask
 

Friends

void Unit::_ApplyAura (AuraApplication *aurApp, uint32 effMask)
 
void Unit::_UnapplyAura (AuraApplicationMap::iterator &i, AuraRemoveMode removeMode)
 
void Unit::_ApplyAuraEffect (Aura *aura, uint8 effIndex)
 
void Unit::RemoveAura (AuraApplication *aurApp, AuraRemoveMode mode)
 
AuraApplicationUnit::_CreateAuraApplication (Aura *aura, uint32 effMask)
 

Constructor & Destructor Documentation

AuraApplication::AuraApplication ( Unit target,
Unit caster,
Aura base,
uint32  effMask 
)
explicitprivate
42  :
45 {
46  ASSERT(GetTarget() && GetBase());
47 
48  if (GetBase()->CanBeSentToClient())
49  {
50  // Try find slot for aura
51  uint8 slot = MAX_AURAS;
52  // Lookup for auras already applied from spell
53  if (AuraApplication * foundAura = GetTarget()->GetAuraApplication(GetBase()->GetId(), GetBase()->GetCasterGUID(), GetBase()->GetCastItemGUID()))
54  {
55  // allow use single slot only by auras from same caster
56  slot = foundAura->GetSlot();
57  }
58  else
59  {
60  Unit::VisibleAuraMap const* visibleAuras = GetTarget()->GetVisibleAuras();
61  // lookup for free slots in units visibleAuras
62  Unit::VisibleAuraMap::const_iterator itr = visibleAuras->find(0);
63  for (uint32 freeSlot = 0; freeSlot < MAX_AURAS; ++itr, ++freeSlot)
64  {
65  if (itr == visibleAuras->end() || itr->first != freeSlot)
66  {
67  slot = freeSlot;
68  break;
69  }
70  }
71  }
72 
73  // Register Visible Aura
74  if (slot < MAX_AURAS)
75  {
76  _slot = slot;
77  GetTarget()->SetVisibleAura(slot, this);
79  TC_LOG_DEBUG("spells", "Aura: %u Effect: %d put to unit visible auras slot: %u", GetBase()->GetId(), GetEffectMask(), slot);
80  }
81  else
82  TC_LOG_DEBUG("spells", "Aura: %u Effect: %d could not find empty unit visible slot", GetBase()->GetId(), GetEffectMask());
83  }
84 
85  _InitFlags(caster, effMask);
86 }
Aura *const _base
Definition: SpellAuras.h:59
Unit * GetTarget() const
Definition: SpellAuras.h:74
Aura * GetBase() const
Definition: SpellAuras.h:75
uint8 _flags
Definition: SpellAuras.h:62
Definition: SpellAuras.h:50
Definition: Unit.h:450
uint32 GetEffectMask() const
Definition: SpellAuras.h:79
void _InitFlags(Unit *caster, uint32 effMask)
Definition: SpellAuras.cpp:118
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
void SetNeedClientUpdate()
Definition: SpellAuras.h:88
TC_GAME_API uint32 GetId(std::string const &username)
Definition: BattlenetAccountMgr.cpp:128
std::map< uint8, AuraApplication * > VisibleAuraMap
Definition: Unit.h:1327
uint8 _slot
Definition: SpellAuras.h:61
AuraRemoveMode _removeMode
Definition: SpellAuras.h:60
VisibleAuraMap const * GetVisibleAuras()
Definition: Unit.h:2003
uint32 _effectMask
Definition: SpellAuras.h:65
uint32_t uint32
Definition: Define.h:150
Unit *const _target
Definition: SpellAuras.h:58
void SetVisibleAura(uint8 slot, AuraApplication *aur)
Definition: Unit.cpp:545
uint32 _effectsToApply
Definition: SpellAuras.h:63
Definition: SpellAuraDefines.h:25
bool _needClientUpdate
Definition: SpellAuras.h:64
uint8_t uint8
Definition: Define.h:152
#define ASSERT
Definition: Errors.h:55
#define MAX_AURAS
Definition: SpellAuraDefines.h:21

+ Here is the call graph for this function:

Member Function Documentation

void AuraApplication::_HandleEffect ( uint8  effIndex,
bool  apply 
)
private
162 {
163  AuraEffect* aurEff = GetBase()->GetEffect(effIndex);
164  if (!aurEff)
165  {
166  TC_LOG_ERROR("spells", "Aura %u has no effect at effectIndex %u but _HandleEffect was called", GetBase()->GetSpellInfo()->Id, uint32(effIndex));
167  return;
168  }
169  ASSERT(aurEff);
170  ASSERT(HasEffect(effIndex) == (!apply));
171  ASSERT((1<<effIndex) & _effectsToApply);
172  TC_LOG_DEBUG("spells", "AuraApplication::_HandleEffect: %u, apply: %u: amount: %u", aurEff->GetAuraType(), apply, aurEff->GetAmount());
173 
174  if (apply)
175  {
176  ASSERT(!(_effectMask & (1<<effIndex)));
177  _effectMask |= 1<<effIndex;
178  aurEff->HandleEffect(this, AURA_EFFECT_HANDLE_REAL, true);
179  }
180  else
181  {
182  ASSERT(_effectMask & (1<<effIndex));
183  _effectMask &= ~(1<<effIndex);
184  aurEff->HandleEffect(this, AURA_EFFECT_HANDLE_REAL, false);
185 
186  // Remove all triggered by aura spells vs unlimited duration
188  }
189 
191 }
Definition: SpellAuraEffects.h:30
Unit * GetTarget() const
Definition: SpellAuras.h:74
Aura * GetBase() const
Definition: SpellAuras.h:75
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
void HandleEffect(AuraApplication *aurApp, uint8 mode, bool apply)
Definition: SpellAuraEffects.cpp:861
void apply(T *val)
Definition: ByteConverter.h:41
AuraType GetAuraType() const
Definition: SpellAuraEffects.h:54
void SetNeedClientUpdate()
Definition: SpellAuras.h:88
AuraEffect * GetEffect(uint32 index) const
Definition: SpellAuras.cpp:448
bool HasEffect(uint8 effect) const
Definition: SpellAuras.h:80
void CleanupTriggeredSpells(Unit *target)
Definition: SpellAuraEffects.cpp:1250
int32 GetAmount() const
Definition: SpellAuraEffects.h:55
uint32 _effectMask
Definition: SpellAuras.h:65
Definition: SpellAuraDefines.h:39
uint32 _effectsToApply
Definition: SpellAuras.h:63
#define ASSERT
Definition: Errors.h:55
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
uint32_t uint32
Definition: g3dmath.h:168

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void AuraApplication::_InitFlags ( Unit caster,
uint32  effMask 
)
private
119 {
120  // mark as selfcast if needed
122 
123  // aura is cast by self or an enemy
124  // one negative effect and we know aura is negative
125  if (IsSelfcast() || !caster || !caster->IsFriendlyTo(GetTarget()))
126  {
127  bool negativeFound = false;
128  for (SpellEffectInfo const* effect : GetBase()->GetSpellEffectInfos())
129  {
130  if (effect && ((1 << effect->EffectIndex) & effMask) && !GetBase()->GetSpellInfo()->IsPositiveEffect(effect->EffectIndex))
131  {
132  negativeFound = true;
133  break;
134  }
135  }
136  _flags |= negativeFound ? AFLAG_NEGATIVE : AFLAG_POSITIVE;
137  }
138  // aura is cast by friend
139  // one positive effect and we know aura is positive
140  else
141  {
142  bool positiveFound = false;
143  for (SpellEffectInfo const* effect : GetBase()->GetSpellEffectInfos())
144  {
145  if (effect && ((1 << effect->EffectIndex) & effMask) && GetBase()->GetSpellInfo()->IsPositiveEffect(effect->EffectIndex))
146  {
147  positiveFound = true;
148  break;
149  }
150  }
151  _flags |= positiveFound ? AFLAG_POSITIVE : AFLAG_NEGATIVE;
152  }
153 
159 }
SpellInfo const * GetSpellInfo() const
Definition: SpellAuras.h:130
Unit * GetTarget() const
Definition: SpellAuras.h:74
Aura * GetBase() const
Definition: SpellAuras.h:75
bool IsPositiveEffect(uint8 effIndex) const
Definition: SpellInfo.cpp:1500
Definition: SpellAuraDefines.h:27
uint8 _flags
Definition: SpellAuras.h:62
Definition: SpellAuraDefines.h:471
Definition: SpellAuraDefines.h:29
Definition: SpellAuraDefines.h:514
bool HasAttribute(SpellAttr0 attribute) const
Definition: SpellInfo.h:462
Definition: SpellAuraDefines.h:26
Definition: SpellInfo.h:238
bool IsFriendlyTo(Unit const *unit) const
Definition: Unit.cpp:7170
bool IsSelfcast() const
Definition: SpellAuras.h:82
Definition: SpellAuraDefines.h:30
bool HasEffectType(AuraType type) const
Definition: SpellAuras.cpp:1186
ObjectGuid const & GetGUID() const
Definition: Object.h:105
Definition: SpellAuraDefines.h:25
Definition: SpellAuraDefines.h:513
Definition: SharedDefines.h:656
ObjectGuid GetCasterGUID() const
Definition: SpellAuras.h:135
SpellEffectInfoVector GetSpellEffectInfos() const
Definition: SpellAuras.h:290

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void AuraApplication::_Remove ( )
private
89 {
90  uint8 slot = GetSlot();
91 
92  if (slot >= MAX_AURAS)
93  return;
94 
95  if (AuraApplication * foundAura = _target->GetAuraApplication(GetBase()->GetId(), GetBase()->GetCasterGUID(), GetBase()->GetCastItemGUID()))
96  {
97  // Reuse visible aura slot by aura which is still applied - prevent storing dead pointers
98  if (slot == foundAura->GetSlot())
99  {
100  if (GetTarget()->GetVisibleAura(slot) == this)
101  {
102  GetTarget()->SetVisibleAura(slot, foundAura);
103  foundAura->SetNeedClientUpdate();
104  }
105  // set not valid slot for aura - prevent removing other visible aura
106  slot = MAX_AURAS;
107  }
108  }
109 
110  // update for out of range group members
111  if (slot < MAX_AURAS)
112  {
113  GetTarget()->RemoveVisibleAura(slot);
114  ClientUpdate(true);
115  }
116 }
Unit * GetTarget() const
Definition: SpellAuras.h:74
Aura * GetBase() const
Definition: SpellAuras.h:75
void RemoveVisibleAura(uint8 slot)
Definition: Unit.cpp:551
Definition: SpellAuras.h:50
uint8 GetSlot() const
Definition: SpellAuras.h:77
TC_GAME_API uint32 GetId(std::string const &username)
Definition: BattlenetAccountMgr.cpp:128
AuraApplication * GetAuraApplication(uint32 spellId, ObjectGuid casterGUID=ObjectGuid::Empty, ObjectGuid itemCasterGUID=ObjectGuid::Empty, uint32 reqEffMask=0, AuraApplication *except=NULL) const
Definition: Unit.cpp:4132
AuraApplication * GetVisibleAura(uint8 slot) const
Definition: Unit.cpp:537
Unit *const _target
Definition: SpellAuras.h:58
void SetVisibleAura(uint8 slot, AuraApplication *aur)
Definition: Unit.cpp:545
void ClientUpdate(bool remove=false)
Definition: SpellAuras.cpp:239
uint8_t uint8
Definition: Define.h:152
#define MAX_AURAS
Definition: SpellAuraDefines.h:21

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void AuraApplication::BuildUpdatePacket ( WorldPackets::Spells::AuraInfo data,
bool  remove 
) const
194 {
195  ASSERT((_target->GetVisibleAura(_slot) != nullptr) ^ remove);
196 
197  auraInfo.Slot = GetSlot();
198  if (remove)
199  return;
200 
201  Aura const* aura = GetBase();
202 
204  auraData.SpellID = aura->GetId();
206  auraData.Flags = GetFlags();
207  if (aura->GetMaxDuration() > 0 && !(aura->GetSpellInfo()->AttributesEx5 & SPELL_ATTR5_HIDE_DURATION))
208  auraData.Flags |= AFLAG_DURATION;
209 
210  auraData.ActiveFlags = GetEffectMask();
212  auraData.CastLevel = aura->GetCasterLevel();
213  else
214  auraData.CastLevel = uint16(aura->GetCastItemLevel());
215 
216  // send stack amount for aura which could be stacked (never 0 - causes incorrect display) or charges
217  // stack amount has priority over charges (checked on retail with spell 50262)
218  auraData.Applications = aura->GetSpellInfo()->StackAmount ? aura->GetStackAmount() : aura->GetCharges();
219  if (!(auraData.Flags & AFLAG_NOCASTER))
220  auraData.CastUnit = aura->GetCasterGUID();
221 
222  if (auraData.Flags & AFLAG_DURATION)
223  {
224  auraData.Duration = aura->GetMaxDuration();
225  auraData.Remaining = aura->GetDuration();
226  }
227 
228  if (auraData.Flags & AFLAG_SCALABLE)
229  {
230  auraData.Points.resize(aura->GetAuraEffects().size(), 0.0f);
231  for (AuraEffect const* effect : GetBase()->GetAuraEffects())
232  if (effect && HasEffect(effect->GetEffIndex())) // Not all of aura's effects have to be applied on every target
233  auraData.Points[effect->GetEffIndex()] = float(effect->GetAmount());
234  }
235 
236  auraInfo.AuraData = auraData;
237 }
Definition: SpellAuraEffects.h:30
SpellInfo const * GetSpellInfo() const
Definition: SpellAuras.h:130
Map * GetMap() const
Definition: Object.h:543
int32 GetMaxDuration() const
Definition: SpellAuras.h:159
Optional< int32 > Remaining
Definition: SpellPackets.h:194
Aura * GetBase() const
Definition: SpellAuras.h:75
Difficulty GetDifficultyID() const
Definition: Map.h:390
uint32 GetSpellXSpellVisualId(Difficulty difficulty) const
Definition: SpellInfo.cpp:2837
uint32 ActiveFlags
Definition: SpellPackets.h:189
uint32 GetEffectMask() const
Definition: SpellAuras.h:79
uint8 GetSlot() const
Definition: SpellAuras.h:77
uint16_t uint16
Definition: g3dmath.h:166
uint8 GetFlags() const
Definition: SpellAuras.h:78
Optional< int32 > Duration
Definition: SpellPackets.h:193
AuraEffectVector GetAuraEffects() const
Definition: SpellAuras.h:288
Definition: SharedDefines.h:546
uint8 _slot
Definition: SpellAuras.h:61
Definition: SpellAuraDefines.h:29
uint16 CastLevel
Definition: SpellPackets.h:190
bool HasEffect(uint8 effect) const
Definition: SpellAuras.h:80
AuraApplication * GetVisibleAura(uint8 slot) const
Definition: Unit.cpp:537
bool HasAttribute(SpellAttr0 attribute) const
Definition: SpellInfo.h:462
Optional< ObjectGuid > CastUnit
Definition: SpellPackets.h:192
Definition: SpellAuraDefines.h:26
Unit *const _target
Definition: SpellAuras.h:58
int32 GetDuration() const
Definition: SpellAuras.h:163
uint8 GetCasterLevel() const
Definition: SpellAuras.h:185
uint32 AttributesEx5
Definition: SpellInfo.h:338
int32 SpellID
Definition: SpellPackets.h:186
uint8 GetStackAmount() const
Definition: SpellAuras.h:179
uint32 SpellXSpellVisualID
Definition: SpellPackets.h:187
uint8 GetCharges() const
Definition: SpellAuras.h:170
Definition: SharedDefines.h:754
uint8 Flags
Definition: SpellPackets.h:188
#define ASSERT
Definition: Errors.h:55
int32 GetCastItemLevel() const
Definition: SpellAuras.h:134
Definition: SpellPackets.h:184
uint32 StackAmount
Definition: SpellInfo.h:381
uint8 Applications
Definition: SpellPackets.h:191
Definition: SpellAuras.h:116
ObjectGuid GetCasterGUID() const
Definition: SpellAuras.h:135
Definition: SpellAuraDefines.h:28
std::vector< float > Points
Definition: SpellPackets.h:195
uint32 GetId() const
Definition: SpellAuras.h:131

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void AuraApplication::ClientUpdate ( bool  remove = false)
240 {
241  _needClientUpdate = false;
242 
244  update.UpdateAll = false;
245  update.UnitGUID = GetTarget()->GetGUID();
246 
248  BuildUpdatePacket(auraInfo, remove);
249  update.Auras.push_back(auraInfo);
250 
251  _target->SendMessageToSet(update.Write(), true);
252 }
Unit * GetTarget() const
Definition: SpellAuras.h:74
Definition: SpellPackets.h:199
std::vector< AuraInfo > Auras
Definition: SpellPackets.h:214
Unit *const _target
Definition: SpellAuras.h:58
bool UpdateAll
Definition: SpellPackets.h:212
ObjectGuid const & GetGUID() const
Definition: Object.h:105
ObjectGuid UnitGUID
Definition: SpellPackets.h:213
WorldPacket const * Write() override
Definition: SpellPackets.cpp:117
bool _needClientUpdate
Definition: SpellAuras.h:64
Definition: SpellPackets.h:205
void BuildUpdatePacket(WorldPackets::Spells::AuraInfo &data, bool remove) const
Definition: SpellAuras.cpp:193
virtual void SendMessageToSet(WorldPacket const *data, bool self)
Definition: Object.cpp:2144

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Aura* AuraApplication::GetBase ( ) const
inline
75 { return _base; }
Aura *const _base
Definition: SpellAuras.h:59

+ Here is the caller graph for this function:

uint32 AuraApplication::GetEffectMask ( ) const
inline
79 { return _effectMask; }
uint32 _effectMask
Definition: SpellAuras.h:65

+ Here is the caller graph for this function:

uint32 AuraApplication::GetEffectsToApply ( ) const
inline
83 { return _effectsToApply; }
uint32 _effectsToApply
Definition: SpellAuras.h:63
uint8 AuraApplication::GetFlags ( ) const
inline
78 { return _flags; }
uint8 _flags
Definition: SpellAuras.h:62

+ Here is the caller graph for this function:

AuraRemoveMode AuraApplication::GetRemoveMode ( ) const
inline
86 {return _removeMode;}
AuraRemoveMode _removeMode
Definition: SpellAuras.h:60

+ Here is the caller graph for this function:

uint8 AuraApplication::GetSlot ( ) const
inline
77 { return _slot; }
uint8 _slot
Definition: SpellAuras.h:61

+ Here is the caller graph for this function:

Unit* AuraApplication::GetTarget ( ) const
inline
74 { return _target; }
Unit *const _target
Definition: SpellAuras.h:58
bool AuraApplication::HasEffect ( uint8  effect) const
inline
80 { ASSERT(effect < MAX_SPELL_EFFECTS); return (_effectMask & (1 << effect)) != 0; }
uint32 _effectMask
Definition: SpellAuras.h:65
#define ASSERT
Definition: Errors.h:55
#define MAX_SPELL_EFFECTS
Definition: DBCStructure.h:1026

+ Here is the caller graph for this function:

bool AuraApplication::IsNeedClientUpdate ( ) const
inline
89 { return _needClientUpdate;}
bool _needClientUpdate
Definition: SpellAuras.h:64
bool AuraApplication::IsPositive ( ) const
inline
81 { return (_flags & AFLAG_POSITIVE) != 0; }
Definition: SpellAuraDefines.h:27
uint8 _flags
Definition: SpellAuras.h:62

+ Here is the caller graph for this function:

bool AuraApplication::IsSelfcast ( ) const
inline
82 { return (_flags & AFLAG_NOCASTER) != 0; }
uint8 _flags
Definition: SpellAuras.h:62
Definition: SpellAuraDefines.h:26

+ Here is the caller graph for this function:

void AuraApplication::SetNeedClientUpdate ( )
inline
88 { _needClientUpdate = true;}
bool _needClientUpdate
Definition: SpellAuras.h:64

+ Here is the caller graph for this function:

void AuraApplication::SetRemoveMode ( AuraRemoveMode  mode)
inline
85 { _removeMode = mode; }
AuraRemoveMode _removeMode
Definition: SpellAuras.h:60

+ Here is the caller graph for this function:

Friends And Related Function Documentation

void Unit::_ApplyAura ( AuraApplication aurApp,
uint32  effMask 
)
friend
void Unit::_ApplyAuraEffect ( Aura aura,
uint8  effIndex 
)
friend
AuraApplication* Unit::_CreateAuraApplication ( Aura aura,
uint32  effMask 
)
friend
void Unit::_UnapplyAura ( AuraApplicationMap::iterator &  i,
AuraRemoveMode  removeMode 
)
friend
void Unit::RemoveAura ( AuraApplication aurApp,
AuraRemoveMode  mode 
)
friend

Member Data Documentation

Aura* const AuraApplication::_base
private
uint32 AuraApplication::_effectMask
private
uint32 AuraApplication::_effectsToApply
private
uint8 AuraApplication::_flags
private
bool AuraApplication::_needClientUpdate
private
AuraRemoveMode AuraApplication::_removeMode
private
uint8 AuraApplication::_slot
private
Unit* const AuraApplication::_target
private

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