-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
Copy pathSpellMgr.cpp
3516 lines (3064 loc) · 133 KB
/
SpellMgr.cpp
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
/*
* This file is part of the AzerothCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by the
* Free Software Foundation; either version 3 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 Affero General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "SpellMgr.h"
#include "BattlefieldMgr.h"
#include "BattlegroundIC.h"
#include "BattlegroundMgr.h"
#include "Chat.h"
#include "DBCStores.h"
#include "GameGraveyard.h"
#include "InstanceScript.h"
#include "MapMgr.h"
#include "ObjectMgr.h"
#include "Player.h"
#include "ScriptMgr.h"
#include "SharedDefines.h"
#include "Spell.h"
#include "SpellAuraDefines.h"
#include "SpellAuras.h"
#include "SpellInfo.h"
#include "World.h"
bool IsPrimaryProfessionSkill(uint32 skill)
{
SkillLineEntry const* pSkill = sSkillLineStore.LookupEntry(skill);
if (!pSkill)
return false;
if (pSkill->categoryId != SKILL_CATEGORY_PROFESSION)
return false;
return true;
}
bool IsPartOfSkillLine(uint32 skillId, uint32 spellId)
{
SkillLineAbilityMapBounds skillBounds = sSpellMgr->GetSkillLineAbilityMapBounds(spellId);
for (SkillLineAbilityMap::const_iterator itr = skillBounds.first; itr != skillBounds.second; ++itr)
if (itr->second->SkillLine == skillId)
return true;
return false;
}
DiminishingGroup GetDiminishingReturnsGroupForSpell(SpellInfo const* spellproto, bool triggered)
{
if (spellproto->IsPositive())
return DIMINISHING_NONE;
for (uint8 i = 0; i < MAX_SPELL_EFFECTS; ++i)
{
if (spellproto->Effects[i].ApplyAuraName == SPELL_AURA_MOD_TAUNT)
return DIMINISHING_TAUNT;
}
// Explicit Diminishing Groups
switch (spellproto->SpellFamilyName)
{
case SPELLFAMILY_GENERIC:
{
// Pet charge effects (Infernal Awakening, Demon Charge)
if (spellproto->SpellVisual[0] == 2816 && spellproto->SpellIconID == 15)
return DIMINISHING_CONTROLLED_STUN;
// Gnaw
else if (spellproto->Id == 47481)
return DIMINISHING_CONTROLLED_STUN;
// Screams of the Past
else if (spellproto->Id == 7074)
return DIMINISHING_NONE;
break;
}
// Event spells
case SPELLFAMILY_UNK1:
return DIMINISHING_NONE;
case SPELLFAMILY_MAGE:
{
// Frostbite
if (spellproto->Id == 12494)
return DIMINISHING_ROOT;
// Shattered Barrier
else if (spellproto->Id == 55080)
return DIMINISHING_ROOT;
// Deep Freeze
else if (spellproto->SpellIconID == 2939 && spellproto->SpellVisual[0] == 9963)
return DIMINISHING_CONTROLLED_STUN;
// Frost Nova / Freeze (Water Elemental)
else if (spellproto->SpellIconID == 193)
return DIMINISHING_CONTROLLED_ROOT;
// Dragon's Breath
else if (spellproto->SpellFamilyFlags[0] & 0x800000)
return DIMINISHING_DRAGONS_BREATH;
break;
}
case SPELLFAMILY_WARRIOR:
{
// Hamstring - limit duration to 10s in PvP
if (spellproto->SpellFamilyFlags[0] & 0x2)
return DIMINISHING_LIMITONLY;
// Improved Hamstring
else if (spellproto->Id == 23694)
return DIMINISHING_ROOT;
// Charge Stun (own diminishing)
else if (spellproto->SpellFamilyFlags[0] & 0x01000000)
return DIMINISHING_CHARGE;
break;
}
case SPELLFAMILY_WARLOCK:
{
// Curses/etc
if ((spellproto->SpellFamilyFlags[0] & 0x80000000) || (spellproto->SpellFamilyFlags[1] & 0x200))
return DIMINISHING_LIMITONLY;
// Seduction
else if (spellproto->SpellFamilyFlags[1] & 0x10000000)
return DIMINISHING_FEAR;
break;
}
case SPELLFAMILY_DRUID:
{
// Pounce
if (spellproto->SpellFamilyFlags[0] & 0x20000)
return DIMINISHING_OPENING_STUN;
// Cyclone
else if (spellproto->SpellFamilyFlags[1] & 0x20)
return DIMINISHING_CYCLONE;
// Entangling Roots
// Nature's Grasp
else if (spellproto->SpellFamilyFlags[0] & 0x00000200)
return DIMINISHING_CONTROLLED_ROOT;
// Faerie Fire
else if (spellproto->SpellFamilyFlags[0] & 0x400)
return DIMINISHING_LIMITONLY;
// Feral Charge Root Effect
else if (spellproto->Id == 45334)
return DIMINISHING_NONE;
break;
}
case SPELLFAMILY_ROGUE:
{
// Gouge
if (spellproto->SpellFamilyFlags[0] & 0x8)
return DIMINISHING_DISORIENT;
// Blind
else if (spellproto->SpellFamilyFlags[0] & 0x1000000)
return DIMINISHING_FEAR;
// Cheap Shot
else if (spellproto->SpellFamilyFlags[0] & 0x400)
return DIMINISHING_OPENING_STUN;
// Crippling poison - Limit to 10 seconds in PvP (No SpellFamilyFlags)
else if (spellproto->SpellIconID == 163)
return DIMINISHING_LIMITONLY;
break;
}
case SPELLFAMILY_HUNTER:
{
// Hunter's Mark
if ((spellproto->SpellFamilyFlags[0] & 0x400) && spellproto->SpellIconID == 538)
return DIMINISHING_LIMITONLY;
// Scatter Shot (own diminishing)
else if ((spellproto->SpellFamilyFlags[0] & 0x40000) && spellproto->SpellIconID == 132)
return DIMINISHING_SCATTER_SHOT;
// Entrapment (own diminishing)
else if (spellproto->SpellVisual[0] == 7484 && spellproto->SpellIconID == 20)
return DIMINISHING_ENTRAPMENT;
// Wyvern Sting mechanic is MECHANIC_SLEEP but the diminishing is DIMINISHING_DISORIENT
else if ((spellproto->SpellFamilyFlags[1] & 0x1000) && spellproto->SpellIconID == 1721)
return DIMINISHING_DISORIENT;
// Freezing Arrow
else if (spellproto->SpellFamilyFlags[0] & 0x8)
return DIMINISHING_DISORIENT;
break;
}
case SPELLFAMILY_PALADIN:
{
// Judgement of Justice - limit duration to 10s in PvP
if (spellproto->SpellFamilyFlags[0] & 0x100000)
return DIMINISHING_LIMITONLY;
// Turn Evil
else if ((spellproto->SpellFamilyFlags[1] & 0x804000) && spellproto->SpellIconID == 309)
return DIMINISHING_FEAR;
break;
}
case SPELLFAMILY_SHAMAN:
{
// Storm, Earth and Fire - Earthgrab
if (spellproto->SpellFamilyFlags[2] & 0x4000)
return DIMINISHING_NONE;
break;
}
case SPELLFAMILY_DEATHKNIGHT:
{
// Hungering Cold (no flags)
if (spellproto->SpellIconID == 2797)
return DIMINISHING_DISORIENT;
// Mark of Blood
else if ((spellproto->SpellFamilyFlags[0] & 0x10000000) && spellproto->SpellIconID == 2285)
return DIMINISHING_LIMITONLY;
break;
}
default:
break;
}
// Lastly - Set diminishing depending on mechanic
uint32 mechanic = spellproto->GetAllEffectsMechanicMask();
if (mechanic & (1 << MECHANIC_CHARM))
return DIMINISHING_MIND_CONTROL;
if (mechanic & (1 << MECHANIC_SILENCE))
return DIMINISHING_SILENCE;
if (mechanic & (1 << MECHANIC_SLEEP))
return DIMINISHING_SLEEP;
if (mechanic & ((1 << MECHANIC_SAPPED) | (1 << MECHANIC_POLYMORPH) | (1 << MECHANIC_SHACKLE)))
return DIMINISHING_DISORIENT;
// Mechanic Knockout, except Blast Wave
if (mechanic & (1 << MECHANIC_KNOCKOUT) && spellproto->SpellIconID != 292)
return DIMINISHING_DISORIENT;
if (mechanic & (1 << MECHANIC_DISARM))
return DIMINISHING_DISARM;
if (mechanic & (1 << MECHANIC_FEAR))
return DIMINISHING_FEAR;
if (mechanic & (1 << MECHANIC_STUN))
return triggered ? DIMINISHING_STUN : DIMINISHING_CONTROLLED_STUN;
if (mechanic & (1 << MECHANIC_BANISH))
return DIMINISHING_BANISH;
if (mechanic & (1 << MECHANIC_ROOT))
return triggered ? DIMINISHING_ROOT : DIMINISHING_CONTROLLED_ROOT;
if (mechanic & (1 << MECHANIC_HORROR))
return DIMINISHING_HORROR;
return DIMINISHING_NONE;
}
DiminishingReturnsType GetDiminishingReturnsGroupType(DiminishingGroup group)
{
switch (group)
{
case DIMINISHING_TAUNT:
case DIMINISHING_CONTROLLED_STUN:
case DIMINISHING_STUN:
case DIMINISHING_OPENING_STUN:
case DIMINISHING_CYCLONE:
case DIMINISHING_CHARGE:
return DRTYPE_ALL;
case DIMINISHING_LIMITONLY:
case DIMINISHING_NONE:
return DRTYPE_NONE;
default:
return DRTYPE_PLAYER;
}
}
DiminishingLevels GetDiminishingReturnsMaxLevel(DiminishingGroup group)
{
switch (group)
{
case DIMINISHING_TAUNT:
return DIMINISHING_LEVEL_TAUNT_IMMUNE;
default:
return DIMINISHING_LEVEL_IMMUNE;
}
}
int32 GetDiminishingReturnsLimitDuration(DiminishingGroup group, SpellInfo const* spellproto)
{
if (!IsDiminishingReturnsGroupDurationLimited(group))
return 0;
// Explicit diminishing duration
switch (spellproto->SpellFamilyName)
{
case SPELLFAMILY_DRUID:
{
// Faerie Fire - limit to 40 seconds in PvP (3.1)
if (spellproto->SpellFamilyFlags[0] & 0x400)
return 40 * IN_MILLISECONDS;
break;
}
case SPELLFAMILY_HUNTER:
{
// Wyvern Sting
if (spellproto->SpellFamilyFlags[1] & 0x1000)
return 6 * IN_MILLISECONDS;
// Hunter's Mark
if (spellproto->SpellFamilyFlags[0] & 0x400)
return 120 * IN_MILLISECONDS;
break;
}
case SPELLFAMILY_PALADIN:
{
// Repentance - limit to 6 seconds in PvP
if (spellproto->SpellFamilyFlags[0] & 0x4)
return 6 * IN_MILLISECONDS;
break;
}
case SPELLFAMILY_WARLOCK:
{
// Banish - limit to 6 seconds in PvP
if (spellproto->SpellFamilyFlags[1] & 0x8000000)
return 6 * IN_MILLISECONDS;
// Curse of Tongues - limit to 12 seconds in PvP
else if (spellproto->SpellFamilyFlags[2] & 0x800)
return 12 * IN_MILLISECONDS;
// Curse of Elements - limit to 120 seconds in PvP
else if (spellproto->SpellFamilyFlags[1] & 0x200)
return 120 * IN_MILLISECONDS;
// Curse of Exhaustion
else if (spellproto->SpellFamilyFlags[0] & 0x400000)
return 12 * IN_MILLISECONDS;
break;
}
default:
break;
}
return 10 * IN_MILLISECONDS;
}
bool IsDiminishingReturnsGroupDurationLimited(DiminishingGroup group)
{
switch (group)
{
case DIMINISHING_BANISH:
case DIMINISHING_CONTROLLED_STUN:
case DIMINISHING_CONTROLLED_ROOT:
case DIMINISHING_CYCLONE:
case DIMINISHING_DISORIENT:
case DIMINISHING_ENTRAPMENT:
case DIMINISHING_FEAR:
case DIMINISHING_HORROR:
case DIMINISHING_MIND_CONTROL:
case DIMINISHING_OPENING_STUN:
case DIMINISHING_ROOT:
case DIMINISHING_STUN:
case DIMINISHING_SLEEP:
case DIMINISHING_LIMITONLY:
return true;
default:
return false;
}
}
SpellMgr::SpellMgr()
{
}
SpellMgr::~SpellMgr()
{
UnloadSpellInfoStore();
}
SpellMgr* SpellMgr::instance()
{
static SpellMgr instance;
return &instance;
}
/// Some checks for spells, to prevent adding deprecated/broken spells for trainers, spell book, etc
bool SpellMgr::ComputeIsSpellValid(SpellInfo const* spellInfo, bool msg)
{
// not exist
if (!spellInfo)
return false;
bool need_check_reagents = false;
// check effects
for (uint8 i = 0; i < MAX_SPELL_EFFECTS; ++i)
{
switch (spellInfo->Effects[i].Effect)
{
case 0:
continue;
// craft spell for crafting non-existed item (break client recipes list show)
case SPELL_EFFECT_CREATE_ITEM:
case SPELL_EFFECT_CREATE_ITEM_2:
{
if (spellInfo->Effects[i].ItemType == 0)
{
// skip auto-loot crafting spells, its not need explicit item info (but have special fake items sometime)
if (!spellInfo->IsLootCrafting())
{
if (msg)
LOG_ERROR("sql.sql", "Craft spell {} not have create item entry.", spellInfo->Id);
return false;
}
}
// also possible IsLootCrafting case but fake item must exist anyway
else if (!sObjectMgr->GetItemTemplate(spellInfo->Effects[i].ItemType))
{
if (msg)
LOG_ERROR("sql.sql", "Craft spell {} create not-exist in DB item (Entry: {}) and then...", spellInfo->Id, spellInfo->Effects[i].ItemType);
return false;
}
need_check_reagents = true;
break;
}
case SPELL_EFFECT_LEARN_SPELL:
{
SpellInfo const* spellInfo2 = sSpellMgr->GetSpellInfo(spellInfo->Effects[i].TriggerSpell);
if (!ComputeIsSpellValid(spellInfo2, msg))
{
if (msg)
LOG_ERROR("sql.sql", "Spell {} learn to invalid spell {}, and then...", spellInfo->Id, spellInfo->Effects[i].TriggerSpell);
return false;
}
break;
}
}
}
if (need_check_reagents)
{
for (uint8 j = 0; j < MAX_SPELL_REAGENTS; ++j)
{
if (spellInfo->Reagent[j] > 0 && !sObjectMgr->GetItemTemplate(spellInfo->Reagent[j]))
{
if (msg)
LOG_ERROR("sql.sql", "Craft spell {} have not-exist reagent in DB item (Entry: {}) and then...", spellInfo->Id, spellInfo->Reagent[j]);
return false;
}
}
}
return true;
}
bool SpellMgr::IsSpellValid(SpellInfo const* spellInfo)
{
if (!spellInfo)
return false;
return spellInfo->IsSpellValid();
}
void DeleteSpellFromAllPlayers(uint32 spellId)
{
CharacterDatabaseStatements stmts[2] = {CHAR_DEL_INVALID_SPELL_SPELLS, CHAR_DEL_INVALID_SPELL_TALENTS};
for (uint8 i = 0; i < 2; i++)
{
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(stmts[i]);
stmt->SetData(0, spellId);
CharacterDatabase.Execute(stmt);
}
}
bool SpellMgr::CheckSpellValid(SpellInfo const* spellInfo, uint32 spellId, bool isTalent)
{
if (!spellInfo)
{
DeleteSpellFromAllPlayers(spellId);
LOG_ERROR("spells", "Player::{}: Non-existed in SpellStore spell #{} request.", (isTalent ? "AddTalent" : "addSpell"), spellId);
return false;
}
if (!IsSpellValid(spellInfo))
{
DeleteSpellFromAllPlayers(spellId);
LOG_ERROR("spells", "Player::{}: Broken spell #{} learning not allowed.", (isTalent ? "AddTalent" : "addSpell"), spellId);
return false;
}
return true;
}
uint32 SpellMgr::GetSpellDifficultyId(uint32 spellId) const
{
SpellDifficultySearcherMap::const_iterator i = mSpellDifficultySearcherMap.find(spellId);
return i == mSpellDifficultySearcherMap.end() ? 0 : (*i).second;
}
void SpellMgr::SetSpellDifficultyId(uint32 spellId, uint32 id)
{
mSpellDifficultySearcherMap[spellId] = id;
}
uint32 SpellMgr::GetSpellIdForDifficulty(uint32 spellId, Unit const* caster) const
{
if (!GetSpellInfo(spellId))
return spellId;
if (!caster || !caster->GetMap() || !caster->GetMap()->IsDungeon())
return spellId;
uint32 mode = uint32(caster->GetMap()->GetSpawnMode());
if (mode >= MAX_DIFFICULTY)
{
LOG_ERROR("spells", "SpellMgr::GetSpellIdForDifficulty: Incorrect Difficulty for spell {}.", spellId);
return spellId; //return source spell
}
uint32 difficultyId = GetSpellDifficultyId(spellId);
if (!difficultyId)
return spellId; //return source spell, it has only REGULAR_DIFFICULTY
SpellDifficultyEntry const* difficultyEntry = sSpellDifficultyStore.LookupEntry(difficultyId);
if (!difficultyEntry)
{
LOG_DEBUG("spells.aura", "SpellMgr::GetSpellIdForDifficulty: SpellDifficultyEntry not found for spell {}. This should never happen.", spellId);
return spellId; //return source spell
}
if (difficultyEntry->SpellID[mode] <= 0 && mode > DUNGEON_DIFFICULTY_HEROIC)
{
LOG_DEBUG("spells.aura", "SpellMgr::GetSpellIdForDifficulty: spell {} mode {} spell is nullptr, using mode {}", spellId, mode, mode - 2);
mode -= 2;
}
if (difficultyEntry->SpellID[mode] <= 0)
{
LOG_ERROR("sql.sql", "SpellMgr::GetSpellIdForDifficulty: spell {} mode {} spell is 0. Check spelldifficulty_dbc!", spellId, mode);
return spellId;
}
LOG_DEBUG("spells.aura", "SpellMgr::GetSpellIdForDifficulty: spellid for spell {} in mode {} is {}", spellId, mode, difficultyEntry->SpellID[mode]);
return uint32(difficultyEntry->SpellID[mode]);
}
SpellInfo const* SpellMgr::GetSpellForDifficultyFromSpell(SpellInfo const* spell, Unit const* caster) const
{
uint32 newSpellId = GetSpellIdForDifficulty(spell->Id, caster);
SpellInfo const* newSpell = GetSpellInfo(newSpellId);
if (!newSpell)
{
LOG_DEBUG("spells.aura", "SpellMgr::GetSpellForDifficultyFromSpell: spell {} not found. Check spelldifficulty_dbc!", newSpellId);
return spell;
}
LOG_DEBUG("spells.aura", "SpellMgr::GetSpellForDifficultyFromSpell: Spell id for instance mode is {} (original {})", newSpell->Id, spell->Id);
return newSpell;
}
SpellChainNode const* SpellMgr::GetSpellChainNode(uint32 spell_id) const
{
SpellChainMap::const_iterator itr = mSpellChains.find(spell_id);
if (itr == mSpellChains.end())
return nullptr;
return &itr->second;
}
uint32 SpellMgr::GetFirstSpellInChain(uint32 spell_id) const
{
if (SpellChainNode const* node = GetSpellChainNode(spell_id))
return node->first->Id;
return spell_id;
}
uint32 SpellMgr::GetLastSpellInChain(uint32 spell_id) const
{
if (SpellChainNode const* node = GetSpellChainNode(spell_id))
return node->last->Id;
return spell_id;
}
uint32 SpellMgr::GetNextSpellInChain(uint32 spell_id) const
{
if (SpellChainNode const* node = GetSpellChainNode(spell_id))
if (node->next)
return node->next->Id;
return 0;
}
uint32 SpellMgr::GetPrevSpellInChain(uint32 spell_id) const
{
if (SpellChainNode const* node = GetSpellChainNode(spell_id))
if (node->prev)
return node->prev->Id;
return 0;
}
uint8 SpellMgr::GetSpellRank(uint32 spell_id) const
{
if (SpellChainNode const* node = GetSpellChainNode(spell_id))
return node->rank;
return 0;
}
uint32 SpellMgr::GetSpellWithRank(uint32 spell_id, uint32 rank, bool strict) const
{
if (SpellChainNode const* node = GetSpellChainNode(spell_id))
{
if (rank != node->rank)
return GetSpellWithRank(node->rank < rank ? node->next->Id : node->prev->Id, rank, strict);
}
else if (strict && rank > 1)
return 0;
return spell_id;
}
SpellRequiredMapBounds SpellMgr::GetSpellsRequiredForSpellBounds(uint32 spell_id) const
{
return mSpellReq.equal_range(spell_id);
}
SpellsRequiringSpellMapBounds SpellMgr::GetSpellsRequiringSpellBounds(uint32 spell_id) const
{
return mSpellsReqSpell.equal_range(spell_id);
}
bool SpellMgr::IsSpellRequiringSpell(uint32 spellid, uint32 req_spellid) const
{
SpellsRequiringSpellMapBounds spellsRequiringSpell = GetSpellsRequiringSpellBounds(req_spellid);
for (SpellsRequiringSpellMap::const_iterator itr = spellsRequiringSpell.first; itr != spellsRequiringSpell.second; ++itr)
{
if (itr->second == spellid)
return true;
}
return false;
}
bool SpellMgr::IsAdditionalTalentSpell(uint32 spellId) const
{
return mTalentSpellAdditionalSet.find(spellId) != mTalentSpellAdditionalSet.end();
}
SpellLearnSkillNode const* SpellMgr::GetSpellLearnSkill(uint32 spell_id) const
{
SpellLearnSkillMap::const_iterator itr = mSpellLearnSkills.find(spell_id);
if (itr != mSpellLearnSkills.end())
return &itr->second;
else
return nullptr;
}
SpellTargetPosition const* SpellMgr::GetSpellTargetPosition(uint32 spell_id, SpellEffIndex effIndex) const
{
SpellTargetPositionMap::const_iterator itr = mSpellTargetPositions.find(std::make_pair(spell_id, effIndex));
if (itr != mSpellTargetPositions.end())
return &itr->second;
return nullptr;
}
SpellGroupStackFlags SpellMgr::GetGroupStackFlags(uint32 groupid) const
{
SpellGroupStackMap::const_iterator itr = mSpellGroupStackMap.find(groupid);
if (itr != mSpellGroupStackMap.end())
return itr->second;
return SPELL_GROUP_STACK_FLAG_NONE;
}
uint32 SpellMgr::GetSpellGroup(uint32 spell_id) const
{
uint32 first_rank = GetFirstSpellInChain(spell_id);
SpellGroupMap::const_iterator itr = mSpellGroupMap.find(first_rank);
if (itr != mSpellGroupMap.end())
return itr->second.groupId;
return 0;
}
SpellGroupSpecialFlags SpellMgr::GetSpellGroupSpecialFlags(uint32 spell_id) const
{
uint32 first_rank = GetFirstSpellInChain(spell_id);
SpellGroupMap::const_iterator itr = mSpellGroupMap.find(first_rank);
if (itr != mSpellGroupMap.end())
return itr->second.specialFlags;
return SPELL_GROUP_SPECIAL_FLAG_NONE;
}
SpellGroupStackFlags SpellMgr::CheckSpellGroupStackRules(SpellInfo const* spellInfo1, SpellInfo const* spellInfo2, bool remove, bool areaAura) const
{
uint32 spellid_1 = spellInfo1->GetFirstRankSpell()->Id;
uint32 spellid_2 = spellInfo2->GetFirstRankSpell()->Id;
uint32 groupId = GetSpellGroup(spellid_1);
SpellGroupSpecialFlags flag1 = GetSpellGroupSpecialFlags(spellid_1);
// xinef: dunno why i added this
if (spellid_1 == spellid_2 && remove && !areaAura)
{
if (flag1 & SPELL_GROUP_SPECIAL_FLAG_SAME_SPELL_CHECK)
{
return SPELL_GROUP_STACK_FLAG_EXCLUSIVE;
}
return SPELL_GROUP_STACK_FLAG_NONE;
}
if (groupId > 0 && groupId == GetSpellGroup(spellid_2))
{
SpellGroupSpecialFlags flag2 = GetSpellGroupSpecialFlags(spellid_2);
SpellGroupStackFlags additionFlag = SPELL_GROUP_STACK_FLAG_NONE;
// xinef: first flags are used for elixir stacking rules
if (flag1 & SPELL_GROUP_SPECIAL_FLAG_STACK_EXCLUSIVE_MAX && flag2 & SPELL_GROUP_SPECIAL_FLAG_STACK_EXCLUSIVE_MAX)
{
if (flag1 & flag2)
return SPELL_GROUP_STACK_FLAG_NEVER_STACK;
}
// xinef: check only flag1 (new spell)
else if (flag1 & SPELL_GROUP_SPECIAL_FLAG_FORCED_STRONGEST)
additionFlag = SPELL_GROUP_STACK_FLAG_FORCED_STRONGEST;
else if (flag2 & SPELL_GROUP_SPECIAL_FLAG_FORCED_STRONGEST)
additionFlag = SPELL_GROUP_STACK_FLAG_FORCED_WEAKEST;
return SpellGroupStackFlags(GetGroupStackFlags(groupId) | additionFlag);
}
return SPELL_GROUP_STACK_FLAG_NONE;
}
void SpellMgr::GetSetOfSpellsInSpellGroupWithFlag(uint32 group_id, SpellGroupSpecialFlags flag, std::set<uint32>& availableElixirs) const
{
for (SpellGroupMap::const_iterator itr = mSpellGroupMap.begin(); itr != mSpellGroupMap.end(); ++itr)
if (itr->second.groupId == group_id && itr->second.specialFlags == flag)
availableElixirs.insert(itr->first); // insert spell id
}
SpellProcEventEntry const* SpellMgr::GetSpellProcEvent(uint32 spellId) const
{
SpellProcEventMap::const_iterator itr = mSpellProcEventMap.find(spellId);
if (itr != mSpellProcEventMap.end())
return &itr->second;
return nullptr;
}
bool SpellMgr::IsSpellProcEventCanTriggeredBy(SpellInfo const* spellProto, SpellProcEventEntry const* spellProcEvent, uint32 EventProcFlag, ProcEventInfo const& eventInfo, bool active) const
{
// No extra req need
uint32 procEvent_procEx = PROC_EX_NONE;
uint32 procEvent_procPhase = PROC_SPELL_PHASE_HIT;
uint32 procFlags = eventInfo.GetTypeMask();
uint32 procExtra = eventInfo.GetHitMask();
uint32 procPhase = eventInfo.GetSpellPhaseMask();
SpellInfo const* procSpellInfo = eventInfo.GetSpellInfo();
// check prockFlags for condition
if ((procFlags & EventProcFlag) == 0)
return false;
// Xinef: Always trigger for this, including TAKEN_DAMAGE
if (EventProcFlag & (PROC_FLAG_KILLED | PROC_FLAG_KILL | PROC_FLAG_DEATH | PROC_FLAG_TAKEN_DAMAGE))
return true;
bool hasFamilyMask = false;
if (procFlags & PROC_FLAG_DONE_PERIODIC)
{
if (procExtra & PROC_EX_INTERNAL_HOT)
{
if (EventProcFlag == PROC_FLAG_DONE_PERIODIC)
{
/// no aura with only PROC_FLAG_DONE_PERIODIC and spellFamilyName == 0 can proc from a HOT.
if (!spellProto->SpellFamilyName)
return false;
}
/// Aura must have positive procflags for a HOT to proc
else if (!(EventProcFlag & (PROC_FLAG_DONE_SPELL_MAGIC_DMG_CLASS_POS | PROC_FLAG_DONE_SPELL_NONE_DMG_CLASS_POS)))
return false;
}
/// Aura must have negative or neutral(PROC_FLAG_DONE_PERIODIC only) procflags for a DOT to proc
else if (EventProcFlag != PROC_FLAG_DONE_PERIODIC)
if (!(EventProcFlag & (PROC_FLAG_DONE_SPELL_MAGIC_DMG_CLASS_NEG | PROC_FLAG_DONE_SPELL_NONE_DMG_CLASS_NEG | PROC_FLAG_DONE_TRAP_ACTIVATION)))
return false;
}
if (procFlags & PROC_FLAG_TAKEN_PERIODIC)
{
if (procExtra & PROC_EX_INTERNAL_HOT)
{
/// No aura that only has PROC_FLAG_TAKEN_PERIODIC can proc from a HOT.
if (EventProcFlag == PROC_FLAG_TAKEN_PERIODIC)
return false;
/// Aura must have positive procflags for a HOT to proc
if (!(EventProcFlag & (PROC_FLAG_TAKEN_SPELL_MAGIC_DMG_CLASS_POS | PROC_FLAG_TAKEN_SPELL_NONE_DMG_CLASS_POS)))
return false;
}
/// Aura must have negative or neutral(PROC_FLAG_TAKEN_PERIODIC only) procflags for a DOT to proc
else if (EventProcFlag != PROC_FLAG_TAKEN_PERIODIC)
if (!(EventProcFlag & (PROC_FLAG_TAKEN_SPELL_MAGIC_DMG_CLASS_NEG | PROC_FLAG_TAKEN_SPELL_NONE_DMG_CLASS_NEG)))
return false;
}
// Trap casts are active by default
if (procFlags & PROC_FLAG_DONE_TRAP_ACTIVATION)
active = true;
if (spellProcEvent) // Exist event data
{
// Store extra req
procEvent_procEx = spellProcEvent->procEx;
procEvent_procPhase = spellProcEvent->procPhase;
// For melee triggers
if (!procSpellInfo)
{
// Check (if set) for school (melee attack have Normal school)
if (spellProcEvent->schoolMask && (spellProcEvent->schoolMask & SPELL_SCHOOL_MASK_NORMAL) == 0)
return false;
}
else // For spells need check school/spell family/family mask
{
// Check (if set) for school
if (spellProcEvent->schoolMask && (spellProcEvent->schoolMask & procSpellInfo->SchoolMask) == 0)
return false;
// Check (if set) for spellFamilyName
if (spellProcEvent->spellFamilyName && (spellProcEvent->spellFamilyName != procSpellInfo->SpellFamilyName))
return false;
// spellFamilyName is Ok need check for spellFamilyMask if present
if (spellProcEvent->spellFamilyMask)
{
if (!(spellProcEvent->spellFamilyMask & procSpellInfo->SpellFamilyFlags))
return false;
hasFamilyMask = true;
// Some spells are not considered as active even with have spellfamilyflags
if (!(procEvent_procEx & PROC_EX_ONLY_ACTIVE_SPELL))
active = true;
}
// Check tick numbers
if (procEvent_procEx & PROC_EX_ONLY_FIRST_TICK)
{
if (Spell const* procSpell = eventInfo.GetProcSpell())
{
if (procSpell->GetTriggeredByAuraTickNumber() > 1)
{
return false;
}
}
}
}
}
if (procExtra & (PROC_EX_INTERNAL_REQ_FAMILY))
{
if (!hasFamilyMask)
return false;
}
if (!(procEvent_procPhase & procPhase))
{
return false;
}
// Check for extra req (if none) and hit/crit
if (procEvent_procEx == PROC_EX_NONE)
{
// No extra req, so can trigger only for hit/crit - spell has to be active
if ((procExtra & (PROC_EX_NORMAL_HIT | PROC_EX_CRITICAL_HIT)) && active)
return true;
}
else // Passive spells hits here only if resist/reflect/immune/evade
{
if (procExtra & AURA_SPELL_PROC_EX_MASK)
{
// if spell marked as procing only from not active spells
if (active && procEvent_procEx & PROC_EX_NOT_ACTIVE_SPELL)
return false;
// if spell marked as procing only from active spells
if (!active && procEvent_procEx & PROC_EX_ONLY_ACTIVE_SPELL)
return false;
// Exist req for PROC_EX_EX_TRIGGER_ALWAYS
if (procEvent_procEx & PROC_EX_EX_TRIGGER_ALWAYS)
return true;
// PROC_EX_NOT_ACTIVE_SPELL and PROC_EX_ONLY_ACTIVE_SPELL flags handle: if passed checks before
if ((procExtra & (PROC_EX_NORMAL_HIT | PROC_EX_CRITICAL_HIT)) && ((procEvent_procEx & (AURA_SPELL_PROC_EX_MASK)) == 0))
return true;
}
// Check Extra Requirement like (hit/crit/miss/resist/parry/dodge/block/immune/reflect/absorb and other)
if (procEvent_procEx & procExtra)
return true;
}
return false;
}
SpellProcEntry const* SpellMgr::GetSpellProcEntry(uint32 spellId) const
{
SpellProcMap::const_iterator itr = mSpellProcMap.find(spellId);
if (itr != mSpellProcMap.end())
return &itr->second;
return nullptr;
}
bool SpellMgr::CanSpellTriggerProcOnEvent(SpellProcEntry const& procEntry, ProcEventInfo& eventInfo) const
{
// proc type doesn't match
if (!(eventInfo.GetTypeMask() & procEntry.ProcFlags))
return false;
// check XP or honor target requirement
if (procEntry.AttributesMask & PROC_ATTR_REQ_EXP_OR_HONOR)
if (Player* actor = eventInfo.GetActor()->ToPlayer())
if (eventInfo.GetActionTarget() && !actor->isHonorOrXPTarget(eventInfo.GetActionTarget()))
return false;
// always trigger for these types
if (eventInfo.GetTypeMask() & (PROC_FLAG_KILLED | PROC_FLAG_KILL | PROC_FLAG_DEATH))
return true;
// check school mask (if set) for other trigger types
if (procEntry.SchoolMask && !(eventInfo.GetSchoolMask() & procEntry.SchoolMask))
return false;
// check spell family name/flags (if set) for spells
if (eventInfo.GetTypeMask() & (PERIODIC_PROC_FLAG_MASK | SPELL_PROC_FLAG_MASK | PROC_FLAG_DONE_TRAP_ACTIVATION))
{
if (procEntry.SpellFamilyName && (procEntry.SpellFamilyName != eventInfo.GetSpellInfo()->SpellFamilyName))
return false;
if (procEntry.SpellFamilyMask && !(procEntry.SpellFamilyMask & eventInfo.GetSpellInfo()->SpellFamilyFlags))
return false;
}
// check spell type mask (if set)
if (eventInfo.GetTypeMask() & (SPELL_PROC_FLAG_MASK | PERIODIC_PROC_FLAG_MASK))
{
if (procEntry.SpellTypeMask && !(eventInfo.GetSpellTypeMask() & procEntry.SpellTypeMask))
return false;
}
// check spell phase mask
if (eventInfo.GetTypeMask() & REQ_SPELL_PHASE_PROC_FLAG_MASK)
{
if (!(eventInfo.GetSpellPhaseMask() & procEntry.SpellPhaseMask))
return false;
}
// check hit mask (on taken hit or on done hit, but not on spell cast phase)
if ((eventInfo.GetTypeMask() & TAKEN_HIT_PROC_FLAG_MASK) || ((eventInfo.GetTypeMask() & DONE_HIT_PROC_FLAG_MASK) && !(eventInfo.GetSpellPhaseMask() & PROC_SPELL_PHASE_CAST)))
{
uint32 hitMask = procEntry.HitMask;
// get default values if hit mask not set
if (!hitMask)
{
// for taken procs allow normal + critical hits by default
if (eventInfo.GetTypeMask() & TAKEN_HIT_PROC_FLAG_MASK)
hitMask |= PROC_HIT_NORMAL | PROC_HIT_CRITICAL;
// for done procs allow normal + critical + absorbs by default
else
hitMask |= PROC_HIT_NORMAL | PROC_HIT_CRITICAL | PROC_HIT_ABSORB;
}
if (!(eventInfo.GetHitMask() & hitMask))
return false;
}
return true;
}
SpellBonusEntry const* SpellMgr::GetSpellBonusData(uint32 spellId) const
{
// Lookup data
SpellBonusMap::const_iterator itr = mSpellBonusMap.find(spellId);
if (itr != mSpellBonusMap.end())
return &itr->second;
// Not found, try lookup for 1 spell rank if exist
if (uint32 rank_1 = GetFirstSpellInChain(spellId))
{
SpellBonusMap::const_iterator itr2 = mSpellBonusMap.find(rank_1);
if (itr2 != mSpellBonusMap.end())
return &itr2->second;
}
return nullptr;
}
SpellThreatEntry const* SpellMgr::GetSpellThreatEntry(uint32 spellID) const
{
SpellThreatMap::const_iterator itr = mSpellThreatMap.find(spellID);
if (itr != mSpellThreatMap.end())
return &itr->second;
else
{
uint32 firstSpell = GetFirstSpellInChain(spellID);
itr = mSpellThreatMap.find(firstSpell);
if (itr != mSpellThreatMap.end())
return &itr->second;
}
return nullptr;
}
float SpellMgr::GetSpellMixologyBonus(uint32 spellId) const
{
SpellMixologyMap::const_iterator itr = mSpellMixologyMap.find(spellId);
if (itr == mSpellMixologyMap.end())
return 30.0f;
return itr->second;