Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Toggle main menu visibility
Loading...
Searching...
No Matches
SpellAuraProcRuntime.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 "
CellImpl.h
"
7
#include "
Common.h
"
8
#include "
DynamicObject.h
"
9
#include "
GridNotifiers.h
"
10
#include "
GridNotifiersImpl.h
"
11
#include "
Log.h
"
12
#include "
ObjectAccessor.h
"
13
#include "
ObjectMgr.h
"
14
#include "
Opcodes.h
"
15
#include "
Player.h
"
16
#include "
ScriptMgr.h
"
17
#include "
Spell.h
"
18
#include "
SpellAuraEffects.h
"
19
#include "
SpellMgr.h
"
20
#include "
SpellScript.h
"
21
#include "
Unit.h
"
22
#include "
Util.h
"
23
#include "
Vehicle.h
"
24
#include "
WorldPacket.h
"
25
26
bool
Aura::IsProcOnCooldown
()
const
27
{
28
/*if (m_procCooldown)
29
{
30
if (m_procCooldown > time(NULL))
31
return true;
32
}*/
33
return
false
;
34
}
35
36
void
Aura::AddProcCooldown
(
uint32
/*msec*/
)
37
{
38
//m_procCooldown = time(NULL) + msec;
39
}
40
41
void
Aura::PrepareProcToTrigger
(
AuraApplication
* aurApp,
ProcEventInfo
& eventInfo)
42
{
43
bool
prepare =
CallScriptPrepareProcHandlers
(aurApp, eventInfo);
44
if
(!prepare)
45
return
;
46
47
// take one charge, aura expiration will be handled in Aura::TriggerProcOnEvent (if needed)
48
if
(
IsUsingCharges
())
49
{
50
--
m_procCharges
;
51
SetNeedClientUpdateForTargets
();
52
}
53
54
SpellProcEntry
const
* procEntry =
sSpellMgr
->GetSpellProcEntry(
GetId
());
55
56
ASSERT
(procEntry);
57
58
// cooldowns should be added to the whole aura (see 51698 area aura)
59
AddProcCooldown
(procEntry->
cooldown
);
60
}
61
62
bool
Aura::IsProcTriggeredOnEvent
(
AuraApplication
* aurApp,
ProcEventInfo
& eventInfo)
const
63
{
64
SpellProcEntry
const
* procEntry =
sSpellMgr
->GetSpellProcEntry(
GetId
());
65
// only auras with spell proc entry can trigger proc
66
if
(!procEntry)
67
return
false
;
68
69
// check if we have charges to proc with
70
if
(
IsUsingCharges
() && !
GetCharges
())
71
return
false
;
72
73
// check proc cooldown
74
if
(
IsProcOnCooldown
())
75
return
false
;
76
78
// something about triggered spells triggering, and add extra attack effect
79
80
// do checks against db data
81
if
(!
sSpellMgr
->CanSpellTriggerProcOnEvent(*procEntry, eventInfo))
82
return
false
;
83
84
// do checks using conditions table
85
ConditionList
conditions =
sConditionMgr
->GetConditionsForNotGroupedEntry(
CONDITION_SOURCE_TYPE_SPELL_PROC
,
GetId
());
86
ConditionSourceInfo
condInfo =
ConditionSourceInfo
(eventInfo.
GetActor
(), eventInfo.
GetActionTarget
());
87
if
(!
sConditionMgr
->IsObjectMeetToConditions(condInfo, conditions))
88
return
false
;
89
90
// AuraScript Hook
91
bool
check =
const_cast<
Aura
*
>
(
this
)->
CallScriptCheckProcHandlers
(aurApp, eventInfo);
92
if
(!check)
93
return
false
;
94
96
// do allow additional requirements for procs
97
// this is needed because this is the last moment in which you can prevent aura charge drop on proc
98
// and possibly a way to prevent default checks (if there're going to be any)
99
100
// Check if current equipment meets aura requirements
101
// do that only for passive spells
103
Unit
* target = aurApp->
GetTarget
();
104
if
(
IsPassive
() && target->
GetTypeId
() ==
TypeID::TYPEID_PLAYER
)
105
{
106
if
(
GetSpellInfo
()->EquippedItemClass ==
ITEM_CLASS_WEAPON
)
107
{
108
if
(target->
ToPlayer
()->
IsInFeralForm
())
109
return
false
;
110
111
if
(eventInfo.
GetDamageInfo
())
112
{
113
WeaponAttackType
attType = eventInfo.
GetDamageInfo
()->
GetAttackType
();
114
Item
* item = NULL;
115
if
(attType ==
WeaponAttackType::BASE_ATTACK
|| attType ==
WeaponAttackType::RANGED_ATTACK
)
116
item = target->
ToPlayer
()->
GetUseableItemByPos
(
INVENTORY_SLOT_BAG_0
,
EQUIPMENT_SLOT_MAINHAND
);
117
else
if
(attType ==
WeaponAttackType::OFF_ATTACK
)
118
item = target->
ToPlayer
()->
GetUseableItemByPos
(
INVENTORY_SLOT_BAG_0
,
EQUIPMENT_SLOT_OFFHAND
);
119
120
if
(!item || item->
IsBroken
() || item->
GetTemplate
()->
Class
!=
ITEM_CLASS_WEAPON
|| !((1 << item->
GetTemplate
()->
SubClass
) &
GetSpellInfo
()->EquippedItemSubClassMask))
121
return
false
;
122
}
123
}
124
else
if
(
GetSpellInfo
()->EquippedItemClass ==
ITEM_CLASS_ARMOR
)
125
{
126
// Check if player is wearing shield
127
Item
* item = target->
ToPlayer
()->
GetUseableItemByPos
(
INVENTORY_SLOT_BAG_0
,
EQUIPMENT_SLOT_OFFHAND
);
128
if
(!item || item->
IsBroken
() || item->
GetTemplate
()->
Class
!=
ITEM_CLASS_ARMOR
|| !((1 << item->
GetTemplate
()->
SubClass
) &
GetSpellInfo
()->EquippedItemSubClassMask))
129
return
false
;
130
}
131
}
132
133
return
roll_chance_f
(
CalcProcChance
(*procEntry, eventInfo));
134
}
135
136
float
Aura::CalcProcChance
(
SpellProcEntry
const
& procEntry,
ProcEventInfo
& eventInfo)
const
137
{
138
float
chance = procEntry.
chance
;
139
// calculate chances depending on unit with caster's data
140
// so talents modifying chances and judgements will have properly calculated proc chance
141
if
(
Unit
* caster =
GetCaster
())
142
{
143
// calculate ppm chance if present and we're using weapon
144
if
(eventInfo.
GetDamageInfo
() && procEntry.
ratePerMinute
!= 0)
145
{
146
uint32
WeaponSpeed = caster->GetAttackTime(eventInfo.
GetDamageInfo
()->
GetAttackType
());
147
chance = caster->GetPPMProcChance(WeaponSpeed, procEntry.
ratePerMinute
,
GetSpellInfo
());
148
}
149
// apply chance modifer aura, applies also to ppm chance (see improved judgement of light spell)
150
if
(
Player
* modOwner = caster->
GetSpellModOwner
())
151
modOwner->ApplySpellMod(
GetId
(),
SPELLMOD_CHANCE_OF_SUCCESS
, chance);
152
}
153
return
chance;
154
}
155
156
void
Aura::TriggerProcOnEvent
(
AuraApplication
* aurApp,
ProcEventInfo
& eventInfo)
157
{
158
CallScriptProcHandlers
(aurApp, eventInfo);
159
160
for
(
uint32
i = 0; i <
MAX_SPELL_EFFECTS
; ++i)
161
if
(aurApp->
HasEffect
(i))
162
// OnEffectProc / AfterEffectProc hooks handled in AuraEffect::HandleProc()
163
GetEffect
(i)->
HandleProc
(aurApp, eventInfo);
164
165
CallScriptAfterProcHandlers
(aurApp, eventInfo);
166
167
// Remove aura if we've used last charge to proc
168
if
(
IsUsingCharges
() && !
GetCharges
())
169
Remove
();
170
}
CellImpl.h
Common.h
sConditionMgr
#define sConditionMgr
Definition
ConditionMgr.h:260
CONDITION_SOURCE_TYPE_SPELL_PROC
@ CONDITION_SOURCE_TYPE_SPELL_PROC
Definition
ConditionMgr.h:120
ConditionList
std::list< Condition * > ConditionList
Definition
ConditionMgr.h:205
MAX_SPELL_EFFECTS
#define MAX_SPELL_EFFECTS
Definition
DBCStructure.h:2584
uint32
std::uint32_t uint32
Definition
Define.h:77
DynamicObject.h
ASSERT
#define ASSERT
Definition
Errors.h:29
GridNotifiers.h
GridNotifiersImpl.h
ITEM_CLASS_ARMOR
@ ITEM_CLASS_ARMOR
Definition
ItemPrototype.h:293
ITEM_CLASS_WEAPON
@ ITEM_CLASS_WEAPON
Definition
ItemPrototype.h:291
Log.h
TypeID::TYPEID_PLAYER
@ TYPEID_PLAYER
Definition
Object.h:55
ObjectAccessor.h
ObjectMgr.h
Opcodes.h
Player.h
EQUIPMENT_SLOT_MAINHAND
@ EQUIPMENT_SLOT_MAINHAND
Definition
Player.h:704
EQUIPMENT_SLOT_OFFHAND
@ EQUIPMENT_SLOT_OFFHAND
Definition
Player.h:705
INVENTORY_SLOT_BAG_0
#define INVENTORY_SLOT_BAG_0
Definition
Player.h:684
ScriptMgr.h
Spell.h
SpellAuraEffects.h
SpellMgr.h
sSpellMgr
#define sSpellMgr
Definition
SpellMgr.h:744
SpellScript.h
Unit.h
WeaponAttackType
WeaponAttackType
Definition
Unit.h:572
WeaponAttackType::RANGED_ATTACK
@ RANGED_ATTACK
Definition
Unit.h:575
WeaponAttackType::BASE_ATTACK
@ BASE_ATTACK
Definition
Unit.h:573
WeaponAttackType::OFF_ATTACK
@ OFF_ATTACK
Definition
Unit.h:574
SPELLMOD_CHANCE_OF_SUCCESS
@ SPELLMOD_CHANCE_OF_SUCCESS
Definition
Unit.h:91
Util.h
roll_chance_f
bool roll_chance_f(float chance)
Definition
Util.h:83
Vehicle.h
WorldPacket.h
AuraApplication
Definition
SpellAuras.h:29
AuraApplication::GetTarget
Unit * GetTarget() const
Definition
SpellAuras.h:54
AuraApplication::HasEffect
bool HasEffect(uint32 effect) const
Definition
SpellAuras.h:60
AuraEffect::HandleProc
void HandleProc(AuraApplication *aurApp, ProcEventInfo &eventInfo)
Definition
SpellAuraEffects.cpp:1144
Aura::AddProcCooldown
void AddProcCooldown(uint32 msec)
Definition
SpellAuraProcRuntime.cpp:36
Aura::CallScriptAfterProcHandlers
void CallScriptAfterProcHandlers(AuraApplication const *aurApp, ProcEventInfo &eventInfo)
Definition
SpellAuraScriptHooks.cpp:355
Aura::GetId
uint32 GetId() const
Definition
SpellAuras.h:88
Aura::IsUsingCharges
bool IsUsingCharges() const
Definition
SpellAuras.h:192
Aura::CallScriptPrepareProcHandlers
bool CallScriptPrepareProcHandlers(AuraApplication const *aurApp, ProcEventInfo &eventInfo)
Definition
SpellAuraScriptHooks.cpp:319
Aura::GetEffect
AuraEffect * GetEffect(uint8 effIndex) const
Definition
SpellAuras.h:168
Aura::GetCaster
Unit * GetCaster() const
Definition
SpellAuras.cpp:196
Aura::CallScriptCheckProcHandlers
bool CallScriptCheckProcHandlers(AuraApplication const *aurApp, ProcEventInfo &eventInfo)
Definition
SpellAuraScriptHooks.cpp:303
Aura::SetNeedClientUpdateForTargets
void SetNeedClientUpdateForTargets() const
Definition
SpellAuraLifecycle.cpp:700
Aura::CallScriptProcHandlers
bool CallScriptProcHandlers(AuraApplication const *aurApp, ProcEventInfo &eventInfo)
Definition
SpellAuraScriptHooks.cpp:338
Aura::IsProcOnCooldown
bool IsProcOnCooldown() const
Definition
SpellAuraProcRuntime.cpp:26
Aura::CalcProcChance
float CalcProcChance(SpellProcEntry const &procEntry, ProcEventInfo &eventInfo) const
Definition
SpellAuraProcRuntime.cpp:136
Aura::GetCharges
uint8 GetCharges() const
Definition
SpellAuras.h:126
Aura::TriggerProcOnEvent
void TriggerProcOnEvent(AuraApplication *aurApp, ProcEventInfo &eventInfo)
Definition
SpellAuraProcRuntime.cpp:156
Aura::GetSpellInfo
SpellInfo const * GetSpellInfo() const
Definition
SpellAuras.h:87
Aura::IsProcTriggeredOnEvent
bool IsProcTriggeredOnEvent(AuraApplication *aurApp, ProcEventInfo &eventInfo) const
Definition
SpellAuraProcRuntime.cpp:62
Aura::PrepareProcToTrigger
void PrepareProcToTrigger(AuraApplication *aurApp, ProcEventInfo &eventInfo)
Definition
SpellAuraProcRuntime.cpp:41
Aura::Aura
Aura(SpellInfo const *spellproto, WorldObject *owner, Unit *caster, Item *castItem, uint64 casterGUID)
Definition
SpellAuras.cpp:155
Aura::IsPassive
bool IsPassive() const
Definition
SpellAuraLifecycle.cpp:536
Aura::m_procCharges
uint8 m_procCharges
Definition
SpellAuras.h:243
Aura::Remove
virtual void Remove(AuraRemoveMode removeMode=AURA_REMOVE_BY_DEFAULT)=0
DamageInfo::GetAttackType
WeaponAttackType GetAttackType() const
Definition
Unit.h:919
Item
Definition
Item.h:202
Item::GetTemplate
ItemTemplate const * GetTemplate() const
Definition
Item.cpp:528
Item::IsBroken
bool IsBroken() const
Definition
Item.h:247
Object::ToPlayer
Player * ToPlayer()
Definition
Object.h:204
Object::GetTypeId
TypeID GetTypeId() const
Definition
Object.h:131
Player
Definition
Player.h:1289
Player::GetUseableItemByPos
Item * GetUseableItemByPos(uint8 bag, uint8 slot) const
Definition
PlayerStorage.cpp:141
ProcEventInfo
Definition
Unit.h:966
ProcEventInfo::GetActionTarget
Unit * GetActionTarget() const
Definition
Unit.h:973
ProcEventInfo::GetDamageInfo
DamageInfo * GetDamageInfo() const
Definition
Unit.h:985
ProcEventInfo::GetActor
Unit * GetActor() const
Definition
Unit.h:972
Unit
Definition
Unit.h:1367
Unit::GetSpellModOwner
Player * GetSpellModOwner() const
Definition
Unit.cpp:5818
Unit::IsInFeralForm
bool IsInFeralForm() const
Definition
Unit.cpp:4936
ConditionSourceInfo
Definition
ConditionMgr.h:150
ItemTemplate::Class
uint32 Class
Definition
ItemPrototype.h:639
ItemTemplate::SubClass
uint32 SubClass
Definition
ItemPrototype.h:640
SpellProcEntry
Definition
SpellMgr.h:277
SpellProcEntry::cooldown
uint32 cooldown
Definition
SpellMgr.h:288
SpellProcEntry::chance
float chance
Definition
SpellMgr.h:287
SpellProcEntry::ratePerMinute
float ratePerMinute
Definition
SpellMgr.h:286
src
server
game
Spells
Auras
SpellAuraProcRuntime.cpp
Generated on
for Project SkyFire Core by
1.17.0