-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
SpellMgr.h
1175 lines (994 loc) · 43.4 KB
/
SpellMgr.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2005-2011 MaNGOS <http://getmangos.com/>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _SPELLMGR_H
#define _SPELLMGR_H
// For static or at-server-startup loaded spell data
// For more high level function for sSpellStore data
#include "Common.h"
#include "SharedDefines.h"
#include "SpellAuraDefines.h"
#include "DBCStructure.h"
#include "DBCStores.h"
#include "SQLStorages.h"
#include "Utilities/UnorderedMapSet.h"
#include <map>
class Player;
class Spell;
class Unit;
struct CreatureInfo;
struct SpellModifier;
// only used in code
enum SpellCategories
{
SPELLCATEGORY_HEALTH_MANA_POTIONS = 4,
SPELLCATEGORY_DEVOUR_MAGIC = 12,
SPELLCATEGORY_JUDGEMENT = 1210, // Judgement (seal trigger)
};
//Some SpellFamilyFlags
#define SPELLFAMILYFLAG_ROGUE_VANISH UI64LIT(0x0000000000000800)
#define SPELLFAMILYFLAG_ROGUE_STEALTH UI64LIT(0x0000000000400000)
#define SPELLFAMILYFLAG_ROGUE_BACKSTAB UI64LIT(0x0000000000800004)
#define SPELLFAMILYFLAG_ROGUE_SAP UI64LIT(0x0000000000000080)
#define SPELLFAMILYFLAG_ROGUE_FEINT UI64LIT(0x0000000008000000)
#define SPELLFAMILYFLAG_ROGUE_KIDNEYSHOT UI64LIT(0x0000000000200000)
#define SPELLFAMILYFLAG_ROGUE__FINISHING_MOVE UI64LIT(0x00000009003E0000)
#define SPELLFAMILYFLAG_PALADIN_SEALS UI64LIT(0x26000C000A000000)
// Spell clasification
enum SpellSpecific
{
SPELL_NORMAL = 0,
SPELL_SEAL = 1,
SPELL_BLESSING = 2,
SPELL_AURA = 3,
SPELL_STING = 4,
SPELL_CURSE = 5,
SPELL_ASPECT = 6,
SPELL_TRACKER = 7,
SPELL_WARLOCK_ARMOR = 8,
SPELL_MAGE_ARMOR = 9,
SPELL_ELEMENTAL_SHIELD = 10,
SPELL_MAGE_POLYMORPH = 11,
SPELL_POSITIVE_SHOUT = 12,
SPELL_JUDGEMENT = 13,
SPELL_BATTLE_ELIXIR = 14,
SPELL_GUARDIAN_ELIXIR = 15,
SPELL_FLASK_ELIXIR = 16,
SPELL_PRESENCE = 17,
SPELL_HAND = 18,
SPELL_WELL_FED = 19,
SPELL_FOOD = 20,
SPELL_DRINK = 21,
SPELL_FOOD_AND_DRINK = 22,
SPELL_UA_IMMOLATE = 23, // Unstable Affliction and Immolate
};
SpellSpecific GetSpellSpecific(uint32 spellId);
// Different spell properties
inline float GetSpellRadius(SpellRadiusEntry const *radius) { return (radius ? radius->Radius : 0); }
uint32 GetSpellCastTime(SpellEntry const* spellInfo, Spell const* spell = NULL);
uint32 GetSpellCastTimeForBonus( SpellEntry const *spellProto, DamageEffectType damagetype );
float CalculateDefaultCoefficient(SpellEntry const *spellProto, DamageEffectType const damagetype);
inline float GetSpellMinRange(SpellRangeEntry const *range, bool friendly = false)
{
if(!range)
return 0;
return (friendly ? range->minRangeFriendly : range->minRange);
}
inline float GetSpellMaxRange(SpellRangeEntry const *range, bool friendly = false)
{
if(!range)
return 0;
return (friendly ? range->maxRangeFriendly : range->maxRange);
}
inline uint32 GetSpellRecoveryTime(SpellEntry const *spellInfo) { return spellInfo->RecoveryTime > spellInfo->CategoryRecoveryTime ? spellInfo->RecoveryTime : spellInfo->CategoryRecoveryTime; }
int32 GetSpellDuration(SpellEntry const *spellInfo);
int32 GetSpellMaxDuration(SpellEntry const *spellInfo);
int32 CalculateSpellDuration(SpellEntry const *spellInfo, Unit const* caster = NULL);
uint16 GetSpellAuraMaxTicks(SpellEntry const* spellInfo);
WeaponAttackType GetWeaponAttackType(SpellEntry const *spellInfo);
inline bool IsSpellHaveEffect(SpellEntry const *spellInfo, SpellEffects effect)
{
for(int i = 0; i < MAX_EFFECT_INDEX; ++i)
if(SpellEffects(spellInfo->Effect[i])==effect)
return true;
return false;
}
inline bool IsSpellAppliesAura(SpellEntry const *spellInfo, uint32 effectMask = ((1 << EFFECT_INDEX_0) | (1 << EFFECT_INDEX_1) | (1 << EFFECT_INDEX_2)))
{
for(int i = 0; i < MAX_EFFECT_INDEX; ++i)
{
if (effectMask & (1 << i))
{
switch (spellInfo->Effect[i])
{
case SPELL_EFFECT_APPLY_AURA:
case SPELL_EFFECT_APPLY_AREA_AURA_PARTY:
case SPELL_EFFECT_APPLY_AREA_AURA_RAID:
case SPELL_EFFECT_APPLY_AREA_AURA_PET:
case SPELL_EFFECT_APPLY_AREA_AURA_FRIEND:
case SPELL_EFFECT_APPLY_AREA_AURA_ENEMY:
case SPELL_EFFECT_APPLY_AREA_AURA_OWNER:
return true;
}
}
}
return false;
}
inline bool IsEffectHandledOnDelayedSpellLaunch(SpellEntry const *spellInfo, SpellEffectIndex effecIdx)
{
switch (spellInfo->Effect[effecIdx])
{
case SPELL_EFFECT_SCHOOL_DAMAGE:
case SPELL_EFFECT_WEAPON_DAMAGE_NOSCHOOL:
case SPELL_EFFECT_WEAPON_PERCENT_DAMAGE:
case SPELL_EFFECT_WEAPON_DAMAGE:
case SPELL_EFFECT_NORMALIZED_WEAPON_DMG:
return true;
default:
return false;
}
}
inline bool IsSpellHaveAura(SpellEntry const *spellInfo, AuraType aura)
{
for(int i = 0; i < MAX_EFFECT_INDEX; ++i)
if(AuraType(spellInfo->EffectApplyAuraName[i])==aura)
return true;
return false;
}
inline bool IsSpellLastAuraEffect(SpellEntry const *spellInfo, SpellEffectIndex effecIdx)
{
for(int i = effecIdx+1; i < MAX_EFFECT_INDEX; ++i)
if(spellInfo->EffectApplyAuraName[i])
return false;
return true;
}
bool IsNoStackAuraDueToAura(uint32 spellId_1, uint32 spellId_2);
inline bool IsSealSpell(SpellEntry const *spellInfo)
{
//Collection of all the seal family flags. No other paladin spell has any of those.
return spellInfo->SpellFamilyName == SPELLFAMILY_PALADIN &&
( spellInfo->SpellFamilyFlags & SPELLFAMILYFLAG_PALADIN_SEALS ) &&
// avoid counting target triggered effect as seal for avoid remove it or seal by it.
spellInfo->EffectImplicitTargetA[EFFECT_INDEX_0] == TARGET_SELF;
}
inline bool IsElementalShield(SpellEntry const *spellInfo)
{
// family flags 10 (Lightning), 42 (Earth), 37 (Water), proc shield from T2 8 pieces bonus
return (spellInfo->SpellFamilyFlags & UI64LIT(0x42000000400)) || spellInfo->Id == 23552;
}
inline bool IsExplicitDiscoverySpell(SpellEntry const *spellInfo)
{
return (((spellInfo->Effect[EFFECT_INDEX_0] == SPELL_EFFECT_CREATE_RANDOM_ITEM
|| spellInfo->Effect[EFFECT_INDEX_0] == SPELL_EFFECT_CREATE_ITEM_2)
&& spellInfo->Effect[EFFECT_INDEX_1] == SPELL_EFFECT_SCRIPT_EFFECT)
|| spellInfo->Id == 64323); // Book of Glyph Mastery (Effect0==SPELL_EFFECT_SCRIPT_EFFECT without any other data)
}
inline bool IsLootCraftingSpell(SpellEntry const *spellInfo)
{
return (spellInfo->Effect[EFFECT_INDEX_0] == SPELL_EFFECT_CREATE_RANDOM_ITEM ||
// different random cards from Inscription (121==Virtuoso Inking Set category) r without explicit item
(spellInfo->Effect[EFFECT_INDEX_0] == SPELL_EFFECT_CREATE_ITEM_2 &&
(spellInfo->TotemCategory[0] != 0 || spellInfo->EffectItemType[0]==0)));
}
int32 CompareAuraRanks(uint32 spellId_1, uint32 spellId_2);
// order from less to more strict
bool IsSingleFromSpellSpecificPerTargetPerCaster(SpellSpecific spellSpec1,SpellSpecific spellSpec2);
bool IsSingleFromSpellSpecificSpellRanksPerTarget(SpellSpecific spellSpec1,SpellSpecific spellSpec2);
bool IsSingleFromSpellSpecificPerTarget(SpellSpecific spellSpec1,SpellSpecific spellSpec2);
bool IsPassiveSpell(uint32 spellId);
bool IsPassiveSpell(SpellEntry const* spellProto);
inline bool IsPassiveSpellStackableWithRanks(SpellEntry const* spellProto)
{
if(!IsPassiveSpell(spellProto))
return false;
return !IsSpellHaveEffect(spellProto,SPELL_EFFECT_APPLY_AURA);
}
inline bool IsSpellRemoveAllMovementAndControlLossEffects(SpellEntry const* spellProto)
{
return spellProto->EffectApplyAuraName[EFFECT_INDEX_0] == SPELL_AURA_MECHANIC_IMMUNITY &&
spellProto->EffectMiscValue[EFFECT_INDEX_0] == 1 &&
spellProto->EffectApplyAuraName[EFFECT_INDEX_1] == 0 &&
spellProto->EffectApplyAuraName[EFFECT_INDEX_2] == 0 &&
(spellProto->AttributesEx & SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY)/* && -- all above selected spells have SPELL_ATTR_EX5_* mask
((spellProto->AttributesEx5 &
(SPELL_ATTR_EX5_USABLE_WHILE_CONFUSED|SPELL_ATTR_EX5_USABLE_WHILE_FEARED|SPELL_ATTR_EX5_USABLE_WHILE_STUNNED)) ==
(SPELL_ATTR_EX5_USABLE_WHILE_CONFUSED|SPELL_ATTR_EX5_USABLE_WHILE_FEARED|SPELL_ATTR_EX5_USABLE_WHILE_STUNNED))*/;
}
inline bool IsDeathOnlySpell(SpellEntry const *spellInfo)
{
return spellInfo->AttributesEx3 & SPELL_ATTR_EX3_CAST_ON_DEAD
|| spellInfo->Id == 2584;
}
inline bool IsDeathPersistentSpell(SpellEntry const *spellInfo)
{
return spellInfo->AttributesEx3 & SPELL_ATTR_EX3_DEATH_PERSISTENT;
}
inline bool IsNonCombatSpell(SpellEntry const *spellInfo)
{
return (spellInfo->Attributes & SPELL_ATTR_CANT_USED_IN_COMBAT) != 0;
}
bool IsPositiveSpell(uint32 spellId);
bool IsPositiveSpell(SpellEntry const *spellproto);
bool IsPositiveEffect(SpellEntry const *spellInfo, SpellEffectIndex effIndex);
bool IsPositiveTarget(uint32 targetA, uint32 targetB);
bool IsExplicitPositiveTarget(uint32 targetA);
bool IsExplicitNegativeTarget(uint32 targetA);
bool IsSingleTargetSpell(SpellEntry const *spellInfo);
bool IsSingleTargetSpells(SpellEntry const *spellInfo1, SpellEntry const *spellInfo2);
inline bool IsCasterSourceTarget(uint32 target)
{
switch (target )
{
case TARGET_SELF:
case TARGET_PET:
case TARGET_ALL_PARTY_AROUND_CASTER:
case TARGET_IN_FRONT_OF_CASTER:
case TARGET_MASTER:
case TARGET_MINION:
case TARGET_ALL_PARTY:
case TARGET_ALL_PARTY_AROUND_CASTER_2:
case TARGET_SELF_FISHING:
case TARGET_TOTEM_EARTH:
case TARGET_TOTEM_WATER:
case TARGET_TOTEM_AIR:
case TARGET_TOTEM_FIRE:
case TARGET_AREAEFFECT_GO_AROUND_DEST:
case TARGET_ALL_RAID_AROUND_CASTER:
case TARGET_SELF2:
case TARGET_DIRECTLY_FORWARD:
case TARGET_NONCOMBAT_PET:
case TARGET_IN_FRONT_OF_CASTER_30:
return true;
default:
break;
}
return false;
}
inline bool IsSpellWithCasterSourceTargetsOnly(SpellEntry const* spellInfo)
{
for(int i = 0; i < MAX_EFFECT_INDEX; ++i)
{
uint32 targetA = spellInfo->EffectImplicitTargetA[i];
if(targetA && !IsCasterSourceTarget(targetA))
return false;
uint32 targetB = spellInfo->EffectImplicitTargetB[i];
if(targetB && !IsCasterSourceTarget(targetB))
return false;
if(!targetA && !targetB)
return false;
}
return true;
}
inline bool IsPointEffectTarget( Targets target )
{
switch (target )
{
case TARGET_INNKEEPER_COORDINATES:
case TARGET_TABLE_X_Y_Z_COORDINATES:
case TARGET_CASTER_COORDINATES:
case TARGET_SCRIPT_COORDINATES:
case TARGET_CURRENT_ENEMY_COORDINATES:
case TARGET_DUELVSPLAYER_COORDINATES:
case TARGET_DYNAMIC_OBJECT_COORDINATES:
case TARGET_POINT_AT_NORTH:
case TARGET_POINT_AT_SOUTH:
case TARGET_POINT_AT_EAST:
case TARGET_POINT_AT_WEST:
case TARGET_POINT_AT_NE:
case TARGET_POINT_AT_NW:
case TARGET_POINT_AT_SE:
case TARGET_POINT_AT_SW:
return true;
default:
break;
}
return false;
}
inline bool IsAreaEffectPossitiveTarget( Targets target )
{
switch (target )
{
case TARGET_ALL_PARTY_AROUND_CASTER:
case TARGET_ALL_FRIENDLY_UNITS_AROUND_CASTER:
case TARGET_ALL_FRIENDLY_UNITS_IN_AREA:
case TARGET_ALL_PARTY:
case TARGET_ALL_PARTY_AROUND_CASTER_2:
case TARGET_AREAEFFECT_PARTY:
case TARGET_ALL_RAID_AROUND_CASTER:
case TARGET_AREAEFFECT_PARTY_AND_CLASS:
return true;
default:
break;
}
return false;
}
inline bool IsAreaEffectTarget( Targets target )
{
switch (target )
{
case TARGET_AREAEFFECT_INSTANT:
case TARGET_AREAEFFECT_CUSTOM:
case TARGET_ALL_ENEMY_IN_AREA:
case TARGET_ALL_ENEMY_IN_AREA_INSTANT:
case TARGET_ALL_PARTY_AROUND_CASTER:
case TARGET_IN_FRONT_OF_CASTER:
case TARGET_ALL_ENEMY_IN_AREA_CHANNELED:
case TARGET_ALL_FRIENDLY_UNITS_AROUND_CASTER:
case TARGET_ALL_FRIENDLY_UNITS_IN_AREA:
case TARGET_ALL_PARTY:
case TARGET_ALL_PARTY_AROUND_CASTER_2:
case TARGET_AREAEFFECT_PARTY:
case TARGET_AREAEFFECT_GO_AROUND_DEST:
case TARGET_ALL_RAID_AROUND_CASTER:
case TARGET_AREAEFFECT_PARTY_AND_CLASS:
case TARGET_IN_FRONT_OF_CASTER_30:
return true;
default:
break;
}
return false;
}
inline bool IsAreaOfEffectSpell(SpellEntry const *spellInfo)
{
if(IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetA[EFFECT_INDEX_0])) || IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetB[EFFECT_INDEX_0])))
return true;
if(IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetA[EFFECT_INDEX_1])) || IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetB[EFFECT_INDEX_1])))
return true;
if(IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetA[EFFECT_INDEX_2])) || IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetB[EFFECT_INDEX_2])))
return true;
return false;
}
inline bool IsAreaAuraEffect(uint32 effect)
{
if( effect == SPELL_EFFECT_APPLY_AREA_AURA_PARTY ||
effect == SPELL_EFFECT_APPLY_AREA_AURA_RAID ||
effect == SPELL_EFFECT_APPLY_AREA_AURA_FRIEND ||
effect == SPELL_EFFECT_APPLY_AREA_AURA_ENEMY ||
effect == SPELL_EFFECT_APPLY_AREA_AURA_PET ||
effect == SPELL_EFFECT_APPLY_AREA_AURA_OWNER)
return true;
return false;
}
inline bool HasAreaAuraEffect(SpellEntry const *spellInfo)
{
for (int32 i = 0; i < MAX_EFFECT_INDEX; ++i)
if (IsAreaAuraEffect(spellInfo->Effect[i]))
return true;
return false;
}
inline bool HasAuraWithTriggerEffect(SpellEntry const *spellInfo)
{
for (int32 i = 0; i < MAX_EFFECT_INDEX; ++i)
{
switch(spellInfo->Effect[i])
{
case SPELL_AURA_PERIODIC_TRIGGER_SPELL:
case SPELL_AURA_PROC_TRIGGER_SPELL:
case SPELL_AURA_PROC_TRIGGER_DAMAGE:
case SPELL_AURA_PROC_TRIGGER_SPELL_WITH_VALUE:
return true;
}
}
return false;
}
inline bool IsDispelSpell(SpellEntry const *spellInfo)
{
return IsSpellHaveEffect(spellInfo, SPELL_EFFECT_DISPEL);
}
inline bool isSpellBreakStealth(SpellEntry const* spellInfo)
{
return !(spellInfo->AttributesEx & SPELL_ATTR_EX_NOT_BREAK_STEALTH);
}
inline bool IsAutoRepeatRangedSpell(SpellEntry const* spellInfo)
{
return (spellInfo->Attributes & SPELL_ATTR_RANGED) && (spellInfo->AttributesEx2 & SPELL_ATTR_EX2_AUTOREPEAT_FLAG);
}
inline bool IsSpellRequiresRangedAP(SpellEntry const* spellInfo)
{
return (spellInfo->SpellFamilyName == SPELLFAMILY_HUNTER && spellInfo->DmgClass != SPELL_DAMAGE_CLASS_MELEE);
}
SpellCastResult GetErrorAtShapeshiftedCast (SpellEntry const *spellInfo, uint32 form);
inline bool IsChanneledSpell(SpellEntry const* spellInfo)
{
return (spellInfo->AttributesEx & (SPELL_ATTR_EX_CHANNELED_1 | SPELL_ATTR_EX_CHANNELED_2));
}
inline bool IsNeedCastSpellAtFormApply(SpellEntry const* spellInfo, ShapeshiftForm form)
{
if (!(spellInfo->Attributes & (SPELL_ATTR_PASSIVE | SPELL_ATTR_UNK7)) || !form)
return false;
// passive spells with SPELL_ATTR_EX2_NOT_NEED_SHAPESHIFT are already active without shapeshift, do no recast!
return (spellInfo->Stances & (1<<(form-1)) && !(spellInfo->AttributesEx2 & SPELL_ATTR_EX2_NOT_NEED_SHAPESHIFT));
}
inline bool NeedsComboPoints(SpellEntry const* spellInfo)
{
return (spellInfo->AttributesEx & (SPELL_ATTR_EX_REQ_TARGET_COMBO_POINTS | SPELL_ATTR_EX_REQ_COMBO_POINTS));
}
inline SpellSchoolMask GetSpellSchoolMask(SpellEntry const* spellInfo)
{
return SpellSchoolMask(spellInfo->SchoolMask);
}
inline uint32 GetSpellMechanicMask(SpellEntry const* spellInfo, uint32 effectMask)
{
uint32 mask = 0;
if (spellInfo->Mechanic)
mask |= 1 << (spellInfo->Mechanic - 1);
for (uint32 i = 0; i < MAX_EFFECT_INDEX; ++i)
{
if (!(effectMask & (1 << i)))
continue;
if (spellInfo->EffectMechanic[i])
mask |= 1 << (spellInfo->EffectMechanic[i]-1);
}
return mask;
}
inline uint32 GetAllSpellMechanicMask(SpellEntry const* spellInfo)
{
uint32 mask = 0;
if (spellInfo->Mechanic)
mask |= 1 << (spellInfo->Mechanic - 1);
for (int i=0; i< MAX_EFFECT_INDEX; ++i)
if (spellInfo->EffectMechanic[i])
mask |= 1 << (spellInfo->EffectMechanic[i]-1);
return mask;
}
inline Mechanics GetEffectMechanic(SpellEntry const* spellInfo, SpellEffectIndex effect)
{
if (spellInfo->EffectMechanic[effect])
return Mechanics(spellInfo->EffectMechanic[effect]);
if (spellInfo->Mechanic)
return Mechanics(spellInfo->Mechanic);
return MECHANIC_NONE;
}
inline uint32 GetDispellMask(DispelType dispel)
{
// If dispell all
if (dispel == DISPEL_ALL)
return DISPEL_ALL_MASK;
else
return (1 << dispel);
}
// Diminishing Returns interaction with spells
DiminishingGroup GetDiminishingReturnsGroupForSpell(SpellEntry const* spellproto, bool triggered);
bool IsDiminishingReturnsGroupDurationLimited(DiminishingGroup group);
DiminishingReturnsType GetDiminishingReturnsGroupType(DiminishingGroup group);
int32 GetDiminishingReturnsLimitDuration(DiminishingGroup group, SpellEntry const* spellproto);
SpellEntry const* GetSpellEntryByDifficulty(uint32 id, Difficulty difficulty);
// Spell proc event related declarations (accessed using SpellMgr functions)
enum ProcFlags
{
PROC_FLAG_NONE = 0x00000000,
PROC_FLAG_KILLED = 0x00000001, // 00 Killed by aggressor
PROC_FLAG_KILL = 0x00000002, // 01 Kill target (in most cases need XP/Honor reward, see Unit::IsTriggeredAtSpellProcEvent for additinoal check)
PROC_FLAG_SUCCESSFUL_MELEE_HIT = 0x00000004, // 02 Successful melee auto attack
PROC_FLAG_TAKEN_MELEE_HIT = 0x00000008, // 03 Taken damage from melee auto attack hit
PROC_FLAG_SUCCESSFUL_MELEE_SPELL_HIT = 0x00000010, // 04 Successful attack by Spell that use melee weapon
PROC_FLAG_TAKEN_MELEE_SPELL_HIT = 0x00000020, // 05 Taken damage by Spell that use melee weapon
PROC_FLAG_SUCCESSFUL_RANGED_HIT = 0x00000040, // 06 Successful Ranged auto attack
PROC_FLAG_TAKEN_RANGED_HIT = 0x00000080, // 07 Taken damage from ranged auto attack
PROC_FLAG_SUCCESSFUL_RANGED_SPELL_HIT = 0x00000100, // 08 Successful Ranged attack by Spell that use ranged weapon
PROC_FLAG_TAKEN_RANGED_SPELL_HIT = 0x00000200, // 09 Taken damage by Spell that use ranged weapon
PROC_FLAG_SUCCESSFUL_POSITIVE_AOE_HIT = 0x00000400, // 10 Successful AoE (not 100% shure unused)
PROC_FLAG_TAKEN_POSITIVE_AOE = 0x00000800, // 11 Taken AoE (not 100% shure unused)
PROC_FLAG_SUCCESSFUL_AOE_SPELL_HIT = 0x00001000, // 12 Successful AoE damage spell hit (not 100% shure unused)
PROC_FLAG_TAKEN_AOE_SPELL_HIT = 0x00002000, // 13 Taken AoE damage spell hit (not 100% shure unused)
PROC_FLAG_SUCCESSFUL_POSITIVE_SPELL = 0x00004000, // 14 Successful cast positive spell (by default only on healing)
PROC_FLAG_TAKEN_POSITIVE_SPELL = 0x00008000, // 15 Taken positive spell hit (by default only on healing)
PROC_FLAG_SUCCESSFUL_NEGATIVE_SPELL_HIT = 0x00010000, // 16 Successful negative spell cast (by default only on damage)
PROC_FLAG_TAKEN_NEGATIVE_SPELL_HIT = 0x00020000, // 17 Taken negative spell (by default only on damage)
PROC_FLAG_ON_DO_PERIODIC = 0x00040000, // 18 Successful do periodic (damage / healing, determined by PROC_EX_PERIODIC_POSITIVE or negative if no procEx)
PROC_FLAG_ON_TAKE_PERIODIC = 0x00080000, // 19 Taken spell periodic (damage / healing, determined by PROC_EX_PERIODIC_POSITIVE or negative if no procEx)
PROC_FLAG_TAKEN_ANY_DAMAGE = 0x00100000, // 20 Taken any damage
PROC_FLAG_ON_TRAP_ACTIVATION = 0x00200000, // 21 On trap activation
PROC_FLAG_TAKEN_OFFHAND_HIT = 0x00400000, // 22 Taken off-hand melee attacks(not used)
PROC_FLAG_SUCCESSFUL_OFFHAND_HIT = 0x00800000 // 23 Successful off-hand melee attacks
};
#define MELEE_BASED_TRIGGER_MASK (PROC_FLAG_SUCCESSFUL_MELEE_HIT | \
PROC_FLAG_TAKEN_MELEE_HIT | \
PROC_FLAG_SUCCESSFUL_MELEE_SPELL_HIT | \
PROC_FLAG_TAKEN_MELEE_SPELL_HIT | \
PROC_FLAG_SUCCESSFUL_RANGED_HIT | \
PROC_FLAG_TAKEN_RANGED_HIT | \
PROC_FLAG_SUCCESSFUL_RANGED_SPELL_HIT | \
PROC_FLAG_TAKEN_RANGED_SPELL_HIT)
#define NEGATIVE_TRIGGER_MASK (MELEE_BASED_TRIGGER_MASK | \
PROC_FLAG_SUCCESSFUL_AOE_SPELL_HIT | \
PROC_FLAG_TAKEN_AOE_SPELL_HIT | \
PROC_FLAG_SUCCESSFUL_NEGATIVE_SPELL_HIT | \
PROC_FLAG_TAKEN_NEGATIVE_SPELL_HIT)
enum ProcFlagsEx
{
PROC_EX_NONE = 0x0000000, // If none can tigger on Hit/Crit only (passive spells MUST defined by SpellFamily flag)
PROC_EX_NORMAL_HIT = 0x0000001, // If set only from normal hit (only damage spells)
PROC_EX_CRITICAL_HIT = 0x0000002,
PROC_EX_MISS = 0x0000004,
PROC_EX_RESIST = 0x0000008,
PROC_EX_DODGE = 0x0000010,
PROC_EX_PARRY = 0x0000020,
PROC_EX_BLOCK = 0x0000040,
PROC_EX_EVADE = 0x0000080,
PROC_EX_IMMUNE = 0x0000100,
PROC_EX_DEFLECT = 0x0000200,
PROC_EX_ABSORB = 0x0000400,
PROC_EX_REFLECT = 0x0000800,
PROC_EX_INTERRUPT = 0x0001000, // Melee hit result can be Interrupt (not used)
PROC_EX_FULL_BLOCK = 0x0002000, // block al attack damage
PROC_EX_RESERVED2 = 0x0004000,
PROC_EX_RESERVED3 = 0x0008000,
PROC_EX_EX_TRIGGER_ALWAYS = 0x0010000, // If set trigger always ( no matter another flags) used for drop charges
PROC_EX_EX_ONE_TIME_TRIGGER = 0x0020000, // If set trigger always but only one time (not used)
PROC_EX_PERIODIC_POSITIVE = 0x0040000 // For periodic heal
};
struct SpellProcEventEntry
{
uint32 schoolMask; // if nonzero - bit mask for matching proc condition based on spell candidate's school: Fire=2, Mask=1<<(2-1)=2
uint32 spellFamilyName; // if nonzero - for matching proc condition based on candidate spell's SpellFamilyNamer value
uint64 spellFamilyMask[MAX_EFFECT_INDEX]; // if nonzero - for matching proc condition based on candidate spell's SpellFamilyFlags (like auras 107 and 108 do)
uint32 spellFamilyMask2[MAX_EFFECT_INDEX]; // if nonzero - for matching proc condition based on candidate spell's SpellFamilyFlags2 (like auras 107 and 108 do)
uint32 procFlags; // bitmask for matching proc event
uint32 procEx; // proc Extend info (see ProcFlagsEx)
float ppmRate; // for melee (ranged?) damage spells - proc rate per minute. if zero, falls back to flat chance from Spell.dbc
float customChance; // Owerride chance (in most cases for debug only)
uint32 cooldown; // hidden cooldown used for some spell proc events, applied to _triggered_spell_
};
struct SpellBonusEntry
{
float direct_damage;
float dot_damage;
float ap_bonus;
float ap_dot_bonus;
};
typedef UNORDERED_MAP<uint32, SpellProcEventEntry> SpellProcEventMap;
typedef UNORDERED_MAP<uint32, SpellBonusEntry> SpellBonusMap;
#define ELIXIR_BATTLE_MASK 0x01
#define ELIXIR_GUARDIAN_MASK 0x02
#define ELIXIR_FLASK_MASK (ELIXIR_BATTLE_MASK|ELIXIR_GUARDIAN_MASK)
#define ELIXIR_UNSTABLE_MASK 0x04
#define ELIXIR_SHATTRATH_MASK 0x08
#define ELIXIR_WELL_FED 0x10 // Some foods have SPELLFAMILY_POTION
struct SpellThreatEntry
{
uint16 threat;
float multiplier;
float ap_bonus;
};
typedef std::map<uint32, uint8> SpellElixirMap;
typedef std::map<uint32, float> SpellProcItemEnchantMap;
typedef std::map<uint32, SpellThreatEntry> SpellThreatMap;
// Spell script target related declarations (accessed using SpellMgr functions)
enum SpellTargetType
{
SPELL_TARGET_TYPE_GAMEOBJECT = 0,
SPELL_TARGET_TYPE_CREATURE = 1,
SPELL_TARGET_TYPE_DEAD = 2
};
#define MAX_SPELL_TARGET_TYPE 3
struct SpellTargetEntry
{
SpellTargetEntry(SpellTargetType type_,uint32 targetEntry_) : type(type_), targetEntry(targetEntry_) {}
SpellTargetType type;
uint32 targetEntry;
};
typedef std::multimap<uint32,SpellTargetEntry> SpellScriptTarget;
typedef std::pair<SpellScriptTarget::const_iterator,SpellScriptTarget::const_iterator> SpellScriptTargetBounds;
// coordinates for spells (accessed using SpellMgr functions)
struct SpellTargetPosition
{
uint32 target_mapId;
float target_X;
float target_Y;
float target_Z;
float target_Orientation;
};
typedef UNORDERED_MAP<uint32, SpellTargetPosition> SpellTargetPositionMap;
// Spell pet auras
class PetAura
{
public:
PetAura()
{
auras.clear();
}
PetAura(uint32 petEntry, uint32 aura, bool _removeOnChangePet, int _damage) :
removeOnChangePet(_removeOnChangePet), damage(_damage)
{
auras[petEntry] = aura;
}
uint32 GetAura(uint32 petEntry) const
{
std::map<uint32, uint32>::const_iterator itr = auras.find(petEntry);
if(itr != auras.end())
return itr->second;
else
{
std::map<uint32, uint32>::const_iterator itr2 = auras.find(0);
if(itr2 != auras.end())
return itr2->second;
else
return 0;
}
}
void AddAura(uint32 petEntry, uint32 aura)
{
auras[petEntry] = aura;
}
bool IsRemovedOnChangePet() const
{
return removeOnChangePet;
}
int32 GetDamage() const
{
return damage;
}
private:
std::map<uint32, uint32> auras;
bool removeOnChangePet;
int32 damage;
};
typedef std::map<uint32, PetAura> SpellPetAuraMap;
struct SpellArea
{
uint32 spellId;
uint32 areaId; // zone/subzone/or 0 is not limited to zone
uint32 questStart; // quest start (quest must be active or rewarded for spell apply)
uint32 questEnd; // quest end (quest don't must be rewarded for spell apply)
int32 auraSpell; // spell aura must be applied for spell apply )if possitive) and it don't must be applied in other case
uint32 raceMask; // can be applied only to races
Gender gender; // can be applied only to gender
bool questStartCanActive; // if true then quest start can be active (not only rewarded)
bool autocast; // if true then auto applied at area enter, in other case just allowed to cast
// helpers
bool IsFitToRequirements(Player const* player, uint32 newZone, uint32 newArea) const;
};
typedef std::multimap<uint32,SpellArea> SpellAreaMap;
typedef std::multimap<uint32,SpellArea const*> SpellAreaForQuestMap;
typedef std::multimap<uint32,SpellArea const*> SpellAreaForAuraMap;
typedef std::multimap<uint32,SpellArea const*> SpellAreaForAreaMap;
typedef std::pair<SpellAreaMap::const_iterator,SpellAreaMap::const_iterator> SpellAreaMapBounds;
typedef std::pair<SpellAreaForQuestMap::const_iterator,SpellAreaForQuestMap::const_iterator> SpellAreaForQuestMapBounds;
typedef std::pair<SpellAreaForAuraMap::const_iterator, SpellAreaForAuraMap::const_iterator> SpellAreaForAuraMapBounds;
typedef std::pair<SpellAreaForAreaMap::const_iterator, SpellAreaForAreaMap::const_iterator> SpellAreaForAreaMapBounds;
// Spell rank chain (accessed using SpellMgr functions)
struct SpellChainNode
{
uint32 prev;
uint32 first;
uint32 req;
uint8 rank;
};
typedef UNORDERED_MAP<uint32, SpellChainNode> SpellChainMap;
typedef std::multimap<uint32, uint32> SpellChainMapNext;
// Spell learning properties (accessed using SpellMgr functions)
struct SpellLearnSkillNode
{
uint16 skill;
uint16 step;
uint16 value; // 0 - max skill value for player level
uint16 maxvalue; // 0 - max skill value for player level
};
typedef std::map<uint32, SpellLearnSkillNode> SpellLearnSkillMap;
struct SpellLearnSpellNode
{
uint32 spell;
bool active; // show in spellbook or not
bool autoLearned;
};
typedef std::multimap<uint32, SpellLearnSpellNode> SpellLearnSpellMap;
typedef std::pair<SpellLearnSpellMap::const_iterator,SpellLearnSpellMap::const_iterator> SpellLearnSpellMapBounds;
typedef std::multimap<uint32, SkillLineAbilityEntry const*> SkillLineAbilityMap;
typedef std::pair<SkillLineAbilityMap::const_iterator,SkillLineAbilityMap::const_iterator> SkillLineAbilityMapBounds;
typedef std::multimap<uint32, uint32> PetLevelupSpellSet;
typedef std::map<uint32, PetLevelupSpellSet> PetLevelupSpellMap;
struct PetDefaultSpellsEntry
{
uint32 spellid[MAX_CREATURE_SPELL_DATA_SLOT];
};
// < 0 for petspelldata id, > 0 for creature_id
typedef std::map<int32, PetDefaultSpellsEntry> PetDefaultSpellsMap;
inline bool IsPrimaryProfessionSkill(uint32 skill)
{
SkillLineEntry const *pSkill = sSkillLineStore.LookupEntry(skill);
if(!pSkill)
return false;
if(pSkill->categoryId != SKILL_CATEGORY_PROFESSION)
return false;
return true;
}
inline bool IsProfessionSkill(uint32 skill)
{
return IsPrimaryProfessionSkill(skill) || skill == SKILL_FISHING || skill == SKILL_COOKING || skill == SKILL_FIRST_AID;
}
inline bool IsProfessionOrRidingSkill(uint32 skill)
{
return IsProfessionSkill(skill) || skill == SKILL_RIDING;
}
class SpellMgr
{
friend struct DoSpellBonuses;
friend struct DoSpellProcEvent;
friend struct DoSpellProcItemEnchant;
// Constructors
public:
SpellMgr();
~SpellMgr();
// Accessors (const or static functions)
public:
SpellElixirMap const& GetSpellElixirMap() const { return mSpellElixirs; }
uint32 GetSpellElixirMask(uint32 spellid) const
{
SpellElixirMap::const_iterator itr = mSpellElixirs.find(spellid);
if(itr==mSpellElixirs.end())
return 0x0;
return itr->second;
}
SpellSpecific GetSpellElixirSpecific(uint32 spellid) const
{
uint32 mask = GetSpellElixirMask(spellid);
if((mask & ELIXIR_FLASK_MASK)==ELIXIR_FLASK_MASK)
return SPELL_FLASK_ELIXIR;
else if(mask & ELIXIR_BATTLE_MASK)
return SPELL_BATTLE_ELIXIR;
else if(mask & ELIXIR_GUARDIAN_MASK)
return SPELL_GUARDIAN_ELIXIR;
else if(mask & ELIXIR_WELL_FED)
return SPELL_WELL_FED;
else
return SPELL_NORMAL;
}
SpellThreatEntry const* GetSpellThreatEntry(uint32 spellid) const
{
SpellThreatMap::const_iterator itr = mSpellThreatMap.find(spellid);
if (itr != mSpellThreatMap.end())
return &itr->second;
return NULL;
}
float GetSpellThreatMultiplier(SpellEntry const *spellInfo) const
{
if (!spellInfo)
return 1.0f;
if (SpellThreatEntry const *entry = GetSpellThreatEntry(spellInfo->Id))
return entry->multiplier;
return 1.0f;
}
// Spell proc events
SpellProcEventEntry const* GetSpellProcEvent(uint32 spellId) const
{
SpellProcEventMap::const_iterator itr = mSpellProcEventMap.find(spellId);
if( itr != mSpellProcEventMap.end( ) )
return &itr->second;
return NULL;
}
// Spell procs from item enchants
float GetItemEnchantProcChance(uint32 spellid) const
{
SpellProcItemEnchantMap::const_iterator itr = mSpellProcItemEnchantMap.find(spellid);
if(itr==mSpellProcItemEnchantMap.end())
return 0.0f;
return itr->second;
}
static bool IsSpellProcEventCanTriggeredBy( SpellProcEventEntry const * spellProcEvent, uint32 EventProcFlag, SpellEntry const * procSpell, uint32 procFlags, uint32 procExtra);
// Spell bonus data
SpellBonusEntry const* GetSpellBonusData(uint32 spellId) const
{
// Lookup data
SpellBonusMap::const_iterator itr = mSpellBonusMap.find(spellId);
if( itr != mSpellBonusMap.end( ) )
return &itr->second;
return NULL;
}
// Spell target coordinates
SpellTargetPosition const* GetSpellTargetPosition(uint32 spell_id) const
{
SpellTargetPositionMap::const_iterator itr = mSpellTargetPositions.find( spell_id );
if( itr != mSpellTargetPositions.end( ) )
return &itr->second;
return NULL;
}
// Spell ranks chains
SpellChainNode const* GetSpellChainNode(uint32 spell_id) const
{
SpellChainMap::const_iterator itr = mSpellChains.find(spell_id);
if(itr == mSpellChains.end())
return NULL;
return &itr->second;
}
uint32 GetFirstSpellInChain(uint32 spell_id) const
{
if(SpellChainNode const* node = GetSpellChainNode(spell_id))
return node->first;
return spell_id;
}
uint32 GetPrevSpellInChain(uint32 spell_id) const
{
if(SpellChainNode const* node = GetSpellChainNode(spell_id))
return node->prev;
return 0;
}
SpellChainMapNext const& GetSpellChainNext() const { return mSpellChainsNext; }
template<typename Worker>
void doForHighRanks(uint32 spellid, Worker& worker)
{
SpellChainMapNext const& nextMap = GetSpellChainNext();
for(SpellChainMapNext::const_iterator itr = nextMap.lower_bound(spellid); itr != nextMap.upper_bound(spellid); ++itr)
{
worker(itr->second);
doForHighRanks(itr->second,worker);
}
}
// Note: not use rank for compare to spell ranks: spell chains isn't linear order
// Use IsHighRankOfSpell instead
uint8 GetSpellRank(uint32 spell_id) const
{
if(SpellChainNode const* node = GetSpellChainNode(spell_id))
return node->rank;
return 0;
}
uint8 IsHighRankOfSpell(uint32 spell1,uint32 spell2) const
{
SpellChainMap::const_iterator itr = mSpellChains.find(spell1);
uint32 rank2 = GetSpellRank(spell2);
// not ordered correctly by rank value
if(itr == mSpellChains.end() || !rank2 || itr->second.rank <= rank2)
return false;
// check present in same rank chain
for(; itr != mSpellChains.end(); itr = mSpellChains.find(itr->second.prev))