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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
|
/*
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU GPL v2 license: http://github.com/azerothcore/azerothcore-wotlk/LICENSE-GPL2
* Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*/
/*
* Scripts for spells with SPELLFAMILY_MAGE and SPELLFAMILY_GENERIC spells used by mage players.
* Ordered alphabetically using scriptname.
* Scriptnames of files in this file should be prefixed with "spell_mage_".
*/
#include "ScriptMgr.h"
#include "SpellScript.h"
#include "SpellAuraEffects.h"
#include "Player.h"
#include "SpellMgr.h"
#include "TemporarySummon.h"
enum MageSpells
{
// Ours
SPELL_MAGE_BURNOUT_TRIGGER = 44450,
SPELL_MAGE_IMPROVED_BLIZZARD_CHILLED = 12486,
// Theirs
SPELL_MAGE_COLD_SNAP = 11958,
SPELL_MAGE_FOCUS_MAGIC_PROC = 54648,
SPELL_MAGE_FROST_WARDING_R1 = 11189,
SPELL_MAGE_FROST_WARDING_TRIGGERED = 57776,
SPELL_MAGE_INCANTERS_ABSORBTION_R1 = 44394,
SPELL_MAGE_INCANTERS_ABSORBTION_TRIGGERED = 44413,
SPELL_MAGE_IGNITE = 12654,
SPELL_MAGE_MASTER_OF_ELEMENTS_ENERGIZE = 29077,
SPELL_MAGE_SQUIRREL_FORM = 32813,
SPELL_MAGE_GIRAFFE_FORM = 32816,
SPELL_MAGE_SERPENT_FORM = 32817,
SPELL_MAGE_DRAGONHAWK_FORM = 32818,
SPELL_MAGE_WORGEN_FORM = 32819,
SPELL_MAGE_SHEEP_FORM = 32820,
SPELL_MAGE_GLYPH_OF_ETERNAL_WATER = 70937,
SPELL_MAGE_SUMMON_WATER_ELEMENTAL_PERMANENT = 70908,
SPELL_MAGE_SUMMON_WATER_ELEMENTAL_TEMPORARY = 70907,
SPELL_MAGE_GLYPH_OF_BLAST_WAVE = 62126,
};
// Ours
class spell_mage_arcane_blast : public SpellScriptLoader
{
public:
spell_mage_arcane_blast() : SpellScriptLoader("spell_mage_arcane_blast") { }
class spell_mage_arcane_blast_SpellScript : public SpellScript
{
PrepareSpellScript(spell_mage_arcane_blast_SpellScript);
bool Load() { _triggerSpellId = 0; return true; }
void HandleTriggerSpell(SpellEffIndex effIndex)
{
_triggerSpellId = GetSpellInfo()->Effects[effIndex].TriggerSpell;
PreventHitDefaultEffect(effIndex);
}
void HandleAfterCast()
{
GetCaster()->CastSpell(GetCaster(), _triggerSpellId, TRIGGERED_FULL_MASK);
}
void Register()
{
OnEffectLaunch += SpellEffectFn(spell_mage_arcane_blast_SpellScript::HandleTriggerSpell, EFFECT_1, SPELL_EFFECT_TRIGGER_SPELL);
OnEffectLaunchTarget += SpellEffectFn(spell_mage_arcane_blast_SpellScript::HandleTriggerSpell, EFFECT_1, SPELL_EFFECT_TRIGGER_SPELL);
AfterCast += SpellCastFn(spell_mage_arcane_blast_SpellScript::HandleAfterCast);
}
private:
uint32 _triggerSpellId;
};
SpellScript* GetSpellScript() const
{
return new spell_mage_arcane_blast_SpellScript();
}
};
class spell_mage_deep_freeze : public SpellScriptLoader
{
public:
spell_mage_deep_freeze() : SpellScriptLoader("spell_mage_deep_freeze") { }
class spell_mage_deep_freeze_SpellScript : public SpellScript
{
PrepareSpellScript(spell_mage_deep_freeze_SpellScript)
void HandleOnHit()
{
if (Unit* caster = GetCaster())
if (Unit* target = (caster->ToPlayer() ? caster->ToPlayer()->GetSelectedUnit() : NULL))
if (Creature* cTarget = target->ToCreature())
if (cTarget->HasMechanicTemplateImmunity(1 << (MECHANIC_STUN - 1)))
caster->CastSpell(cTarget, 71757, true);
}
void Register()
{
OnHit += SpellHitFn(spell_mage_deep_freeze_SpellScript::HandleOnHit);
}
};
SpellScript * GetSpellScript() const
{
return new spell_mage_deep_freeze_SpellScript();
}
};
class spell_mage_burning_determination : public SpellScriptLoader
{
public:
spell_mage_burning_determination() : SpellScriptLoader("spell_mage_burning_determination") { }
class spell_mage_burning_determination_AuraScript : public AuraScript
{
PrepareAuraScript(spell_mage_burning_determination_AuraScript);
bool CheckProc(ProcEventInfo& eventInfo)
{
if (!eventInfo.GetDamageInfo()->GetSpellInfo() || !eventInfo.GetActionTarget())
return false;
// Need Interrupt or Silenced mechanic
if (!(eventInfo.GetDamageInfo()->GetSpellInfo()->GetAllEffectsMechanicMask() & ((1<<MECHANIC_INTERRUPT)|(1<<MECHANIC_SILENCE))))
return false;
// Xinef: immuned effect should just eat charge
if (eventInfo.GetHitMask() & PROC_EX_IMMUNE)
{
eventInfo.GetActionTarget()->RemoveAurasDueToSpell(54748);
return false;
}
if (Aura* aura = eventInfo.GetActionTarget()->GetAura(54748))
{
if (aura->GetDuration() < aura->GetMaxDuration())
eventInfo.GetActionTarget()->RemoveAurasDueToSpell(54748);
return false;
}
return true;
}
void HandleProc(AuraEffect const* aurEff, ProcEventInfo& eventInfo)
{
PreventDefaultAction();
GetUnitOwner()->CastSpell(GetUnitOwner(), 54748, true);
}
void Register()
{
DoCheckProc += AuraCheckProcFn(spell_mage_burning_determination_AuraScript::CheckProc);
OnEffectProc += AuraEffectProcFn(spell_mage_burning_determination_AuraScript::HandleProc, EFFECT_0, SPELL_AURA_PROC_TRIGGER_SPELL);
}
};
AuraScript* GetAuraScript() const
{
return new spell_mage_burning_determination_AuraScript();
}
};
class spell_mage_molten_armor : public SpellScriptLoader
{
public:
spell_mage_molten_armor() : SpellScriptLoader("spell_mage_molten_armor") { }
class spell_mage_molten_armor_AuraScript : public AuraScript
{
PrepareAuraScript(spell_mage_molten_armor_AuraScript);
bool CheckProc(ProcEventInfo& eventInfo)
{
const SpellInfo* spellInfo = eventInfo.GetDamageInfo()->GetSpellInfo();
if (!spellInfo || (eventInfo.GetTypeMask() & PROC_FLAG_TAKEN_MELEE_AUTO_ATTACK))
return true;
// Xinef: Molten Shields talent
if (AuraEffect* aurEff = eventInfo.GetActionTarget()->GetAuraEffect(SPELL_AURA_ADD_FLAT_MODIFIER, SPELLFAMILY_MAGE, 16, EFFECT_0))
return roll_chance_i(aurEff->GetSpellInfo()->GetRank()*50);
return false;
}
void Register()
{
DoCheckProc += AuraCheckProcFn(spell_mage_molten_armor_AuraScript::CheckProc);
}
};
AuraScript* GetAuraScript() const
{
return new spell_mage_molten_armor_AuraScript();
}
};
class spell_mage_mirror_image : public SpellScriptLoader
{
public:
spell_mage_mirror_image() : SpellScriptLoader("spell_mage_mirror_image") { }
class spell_mage_mirror_image_AuraScript : public AuraScript
{
PrepareAuraScript(spell_mage_mirror_image_AuraScript)
void HandleEffectApply(AuraEffect const* aurEff, AuraEffectHandleModes /*mode*/)
{
GetTarget()->CastSpell((Unit*)NULL, GetSpellInfo()->Effects[aurEff->GetEffIndex()].TriggerSpell, true);
}
void CalcPeriodic(AuraEffect const* /*effect*/, bool& isPeriodic, int32& amplitude)
{
isPeriodic = false;
}
void Register()
{
OnEffectApply += AuraEffectApplyFn(spell_mage_mirror_image_AuraScript::HandleEffectApply, EFFECT_2, SPELL_AURA_PERIODIC_DUMMY, AURA_EFFECT_HANDLE_REAL);
DoEffectCalcPeriodic += AuraEffectCalcPeriodicFn(spell_mage_mirror_image_AuraScript::CalcPeriodic, EFFECT_2, SPELL_AURA_PERIODIC_DUMMY);
}
};
AuraScript* GetAuraScript() const
{
return new spell_mage_mirror_image_AuraScript();
}
};
class spell_mage_burnout : public SpellScriptLoader
{
public:
spell_mage_burnout() : SpellScriptLoader("spell_mage_burnout") { }
class spell_mage_burnout_AuraScript : public AuraScript
{
PrepareAuraScript(spell_mage_burnout_AuraScript);
bool Validate(SpellInfo const* /*spellInfo*/)
{
if (!sSpellMgr->GetSpellInfo(SPELL_MAGE_BURNOUT_TRIGGER))
return false;
return true;
}
bool CheckProc(ProcEventInfo& eventInfo)
{
return eventInfo.GetDamageInfo()->GetSpellInfo(); // eventInfo.GetSpellInfo()
}
void HandleProc(AuraEffect const* aurEff, ProcEventInfo& eventInfo)
{
PreventDefaultAction();
int32 mana = int32(eventInfo.GetDamageInfo()->GetSpellInfo()->CalcPowerCost(GetTarget(), eventInfo.GetDamageInfo()->GetSchoolMask()));
mana = CalculatePct(mana, aurEff->GetAmount());
GetTarget()->CastCustomSpell(SPELL_MAGE_BURNOUT_TRIGGER, SPELLVALUE_BASE_POINT0, mana, GetTarget(), true, NULL, aurEff);
}
void Register()
{
DoCheckProc += AuraCheckProcFn(spell_mage_burnout_AuraScript::CheckProc);
OnEffectProc += AuraEffectProcFn(spell_mage_burnout_AuraScript::HandleProc, EFFECT_1, SPELL_AURA_DUMMY);
}
};
AuraScript* GetAuraScript() const
{
return new spell_mage_burnout_AuraScript();
}
};
class spell_mage_burnout_trigger : public SpellScriptLoader
{
public:
spell_mage_burnout_trigger() : SpellScriptLoader("spell_mage_burnout_trigger") { }
class spell_mage_burnout_trigger_SpellScript : public SpellScript
{
PrepareSpellScript(spell_mage_burnout_trigger_SpellScript);
void HandleDummy(SpellEffIndex effIndex)
{
PreventHitDefaultEffect(effIndex);
if (Unit* target = GetHitUnit())
{
int32 newDamage = -(target->ModifyPower(POWER_MANA, -GetEffectValue()));
GetSpell()->ExecuteLogEffectTakeTargetPower(effIndex, target, POWER_MANA, newDamage, 0.0f);
}
}
void Register()
{
OnEffectHitTarget += SpellEffectFn(spell_mage_burnout_trigger_SpellScript::HandleDummy, EFFECT_0, SPELL_EFFECT_POWER_BURN);
}
};
SpellScript* GetSpellScript() const
{
return new spell_mage_burnout_trigger_SpellScript();
}
};
class spell_mage_pet_scaling : public SpellScriptLoader
{
public:
spell_mage_pet_scaling() : SpellScriptLoader("spell_mage_pet_scaling") { }
class spell_mage_pet_scaling_AuraScript : public AuraScript
{
PrepareAuraScript(spell_mage_pet_scaling_AuraScript);
void CalculateResistanceAmount(AuraEffect const* aurEff, int32 & amount, bool & /*canBeRecalculated*/)
{
// xinef: mage pet inherits 40% of resistance from owner and 35% of armor (guessed)
if (Unit* owner = GetUnitOwner()->GetOwner())
{
SpellSchoolMask schoolMask = SpellSchoolMask(aurEff->GetSpellInfo()->Effects[aurEff->GetEffIndex()].MiscValue);
int32 modifier = schoolMask == SPELL_SCHOOL_MASK_NORMAL ? 35 : 40;
amount = CalculatePct(std::max<int32>(0, owner->GetResistance(schoolMask)), modifier);
}
}
void CalculateStatAmount(AuraEffect const* aurEff, int32 & amount, bool & /*canBeRecalculated*/)
{
// xinef: mage pet inherits 30% of intellect / stamina
if (Unit* owner = GetUnitOwner()->GetOwner())
{
Stats stat = Stats(aurEff->GetSpellInfo()->Effects[aurEff->GetEffIndex()].MiscValue);
amount = CalculatePct(std::max<int32>(0, owner->GetStat(stat)), 30);
}
}
void CalculateAPAmount(AuraEffect const* aurEff, int32 & amount, bool & /*canBeRecalculated*/)
{
// xinef: mage pet inherits 0% AP
}
void CalculateSPAmount(AuraEffect const* aurEff, int32 & amount, bool & /*canBeRecalculated*/)
{
// xinef: mage pet inherits 33% of SP
if (Unit* owner = GetUnitOwner()->GetOwner())
{
int32 frost = owner->SpellBaseDamageBonusDone(SPELL_SCHOOL_MASK_FROST);
amount = CalculatePct(std::max<int32>(0, frost), 33);
// xinef: Update appropriate player field
if (owner->GetTypeId() == TYPEID_PLAYER)
owner->SetUInt32Value(PLAYER_PET_SPELL_POWER, (uint32)amount);
}
}
void HandleEffectApply(AuraEffect const* aurEff, AuraEffectHandleModes /*mode*/)
{
if (GetUnitOwner()->IsPet())
return;
GetUnitOwner()->ApplySpellImmune(0, IMMUNITY_STATE, aurEff->GetAuraType(), true, SPELL_BLOCK_TYPE_POSITIVE);
if (aurEff->GetAuraType() == SPELL_AURA_MOD_ATTACK_POWER)
GetUnitOwner()->ApplySpellImmune(0, IMMUNITY_STATE, SPELL_AURA_MOD_ATTACK_POWER_PCT, true, SPELL_BLOCK_TYPE_POSITIVE);
else if (aurEff->GetAuraType() == SPELL_AURA_MOD_STAT)
GetUnitOwner()->ApplySpellImmune(0, IMMUNITY_STATE, SPELL_AURA_MOD_TOTAL_STAT_PERCENTAGE, true, SPELL_BLOCK_TYPE_POSITIVE);
}
void CalcPeriodic(AuraEffect const* /*aurEff*/, bool& isPeriodic, int32& amplitude)
{
if (!GetUnitOwner()->IsPet())
return;
isPeriodic = true;
amplitude = 2*IN_MILLISECONDS;
}
void HandlePeriodic(AuraEffect const* aurEff)
{
PreventDefaultAction();
if (aurEff->GetAuraType() == SPELL_AURA_MOD_STAT && (aurEff->GetMiscValue() == STAT_STAMINA || aurEff->GetMiscValue() == STAT_INTELLECT))
{
int32 currentAmount = aurEff->GetAmount();
int32 newAmount = GetEffect(aurEff->GetEffIndex())->CalculateAmount(GetCaster());
if (newAmount != currentAmount)
{
if (aurEff->GetMiscValue() == STAT_STAMINA)
{
uint32 actStat = GetUnitOwner()->GetHealth();
GetEffect(aurEff->GetEffIndex())->ChangeAmount(newAmount, false);
GetUnitOwner()->SetHealth(std::min<uint32>(GetUnitOwner()->GetMaxHealth(), actStat));
}
else
{
uint32 actStat = GetUnitOwner()->GetPower(POWER_MANA);
GetEffect(aurEff->GetEffIndex())->ChangeAmount(newAmount, false);
GetUnitOwner()->SetPower(POWER_MANA, std::min<uint32>(GetUnitOwner()->GetMaxPower(POWER_MANA), actStat));
}
}
}
else
GetEffect(aurEff->GetEffIndex())->RecalculateAmount();
}
void Register()
{
if (m_scriptSpellId != 35657)
DoEffectCalcAmount += AuraEffectCalcAmountFn(spell_mage_pet_scaling_AuraScript::CalculateResistanceAmount, EFFECT_ALL, SPELL_AURA_MOD_RESISTANCE);
if (m_scriptSpellId == 35657 || m_scriptSpellId == 35658)
DoEffectCalcAmount += AuraEffectCalcAmountFn(spell_mage_pet_scaling_AuraScript::CalculateStatAmount, EFFECT_ALL, SPELL_AURA_MOD_STAT);
if (m_scriptSpellId == 35657)
{
DoEffectCalcAmount += AuraEffectCalcAmountFn(spell_mage_pet_scaling_AuraScript::CalculateAPAmount, EFFECT_ALL, SPELL_AURA_MOD_ATTACK_POWER);
DoEffectCalcAmount += AuraEffectCalcAmountFn(spell_mage_pet_scaling_AuraScript::CalculateSPAmount, EFFECT_ALL, SPELL_AURA_MOD_DAMAGE_DONE);
}
OnEffectApply += AuraEffectApplyFn(spell_mage_pet_scaling_AuraScript::HandleEffectApply, EFFECT_ALL, SPELL_AURA_ANY, AURA_EFFECT_HANDLE_REAL);
DoEffectCalcPeriodic += AuraEffectCalcPeriodicFn(spell_mage_pet_scaling_AuraScript::CalcPeriodic, EFFECT_ALL, SPELL_AURA_ANY);
OnEffectPeriodic += AuraEffectPeriodicFn(spell_mage_pet_scaling_AuraScript::HandlePeriodic, EFFECT_ALL, SPELL_AURA_ANY);
}
};
AuraScript* GetAuraScript() const
{
return new spell_mage_pet_scaling_AuraScript();
}
};
class spell_mage_brain_freeze : public SpellScriptLoader
{
public:
spell_mage_brain_freeze() : SpellScriptLoader("spell_mage_brain_freeze") { }
class spell_mage_brain_freeze_AuraScript : public AuraScript
{
PrepareAuraScript(spell_mage_brain_freeze_AuraScript);
bool CheckProc(ProcEventInfo& eventInfo)
{
const SpellInfo* spellInfo = eventInfo.GetDamageInfo()->GetSpellInfo();
if (!spellInfo)
return false;
// xinef: Improved Blizzard, generic chilled check
if (spellInfo->SpellFamilyFlags[0] & 0x100000)
return spellInfo->Id == SPELL_MAGE_IMPROVED_BLIZZARD_CHILLED;
return true;
}
void Register()
{
DoCheckProc += AuraCheckProcFn(spell_mage_brain_freeze_AuraScript::CheckProc);
}
};
AuraScript* GetAuraScript() const
{
return new spell_mage_brain_freeze_AuraScript();
}
};
// Theirs
// Incanter's Absorbtion
class spell_mage_incanters_absorbtion_base_AuraScript : public AuraScript
{
public:
bool Validate(SpellInfo const* /*spellInfo*/)
{
if (!sSpellMgr->GetSpellInfo(SPELL_MAGE_INCANTERS_ABSORBTION_TRIGGERED))
return false;
if (!sSpellMgr->GetSpellInfo(SPELL_MAGE_INCANTERS_ABSORBTION_R1))
return false;
return true;
}
void Trigger(AuraEffect* aurEff, DamageInfo& /*dmgInfo*/, uint32& absorbAmount)
{
Unit* target = GetTarget();
if (AuraEffect* talentAurEff = target->GetAuraEffectOfRankedSpell(SPELL_MAGE_INCANTERS_ABSORBTION_R1, EFFECT_0))
{
int32 bp = CalculatePct(absorbAmount, talentAurEff->GetAmount());
if (AuraEffect* currentAura = target->GetAuraEffect(SPELL_AURA_MOD_DAMAGE_DONE, SPELLFAMILY_MAGE, 2941, EFFECT_0))
{
bp += int32(currentAura->GetAmount() * (currentAura->GetBase()->GetDuration() / (float)currentAura->GetBase()->GetMaxDuration()));
currentAura->ChangeAmount(bp);
currentAura->GetBase()->RefreshDuration();
}
else
target->CastCustomSpell(target, SPELL_MAGE_INCANTERS_ABSORBTION_TRIGGERED, &bp, NULL, NULL, true, NULL, aurEff);
}
}
};
// -11113 - Blast Wave
class spell_mage_blast_wave : public SpellScriptLoader
{
public:
spell_mage_blast_wave() : SpellScriptLoader("spell_mage_blast_wave") { }
class spell_mage_blast_wave_SpellScript : public SpellScript
{
PrepareSpellScript(spell_mage_blast_wave_SpellScript);
bool Validate(SpellInfo const* /*spellInfo*/)
{
if (!sSpellMgr->GetSpellInfo(SPELL_MAGE_GLYPH_OF_BLAST_WAVE))
return false;
return true;
}
void HandleKnockBack(SpellEffIndex effIndex)
{
if (GetCaster()->HasAura(SPELL_MAGE_GLYPH_OF_BLAST_WAVE))
PreventHitDefaultEffect(effIndex);
}
void Register()
{
OnEffectHitTarget += SpellEffectFn(spell_mage_blast_wave_SpellScript::HandleKnockBack, EFFECT_2, SPELL_EFFECT_KNOCK_BACK);
}
};
SpellScript* GetSpellScript() const
{
return new spell_mage_blast_wave_SpellScript();
}
};
// 11958 - Cold Snap
class spell_mage_cold_snap : public SpellScriptLoader
{
public:
spell_mage_cold_snap() : SpellScriptLoader("spell_mage_cold_snap") { }
class spell_mage_cold_snap_SpellScript : public SpellScript
{
PrepareSpellScript(spell_mage_cold_snap_SpellScript);
bool Load()
{
return GetCaster()->GetTypeId() == TYPEID_PLAYER;
}
void HandleDummy(SpellEffIndex /*effIndex*/)
{
Player* caster = GetCaster()->ToPlayer();
// immediately finishes the cooldown on Frost spells
PlayerSpellMap const& spellMap = caster->GetSpellMap();
for (PlayerSpellMap::const_iterator itr = spellMap.begin(); itr != spellMap.end(); ++itr)
{
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(itr->first);
if (spellInfo->SpellFamilyName == SPELLFAMILY_MAGE && (spellInfo->GetSchoolMask() & SPELL_SCHOOL_MASK_FROST) && spellInfo->Id != SPELL_MAGE_COLD_SNAP && spellInfo->GetRecoveryTime() > 0)
{
SpellCooldowns::iterator citr = caster->GetSpellCooldownMap().find(spellInfo->Id);
if (citr != caster->GetSpellCooldownMap().end() && citr->second.needSendToClient)
caster->RemoveSpellCooldown(spellInfo->Id, true);
else
caster->RemoveSpellCooldown(spellInfo->Id, false);
}
}
}
void Register()
{
OnEffectHit += SpellEffectFn(spell_mage_cold_snap_SpellScript::HandleDummy, EFFECT_0, SPELL_EFFECT_DUMMY);
}
};
SpellScript* GetSpellScript() const
{
return new spell_mage_cold_snap_SpellScript();
}
};
// -543 - Fire Ward
// -6143 - Frost Ward
class spell_mage_fire_frost_ward : public SpellScriptLoader
{
public:
spell_mage_fire_frost_ward() : SpellScriptLoader("spell_mage_fire_frost_ward") { }
class spell_mage_fire_frost_ward_AuraScript : public spell_mage_incanters_absorbtion_base_AuraScript
{
PrepareAuraScript(spell_mage_fire_frost_ward_AuraScript);
bool Validate(SpellInfo const* /*spellInfo*/)
{
if (!sSpellMgr->GetSpellInfo(SPELL_MAGE_FROST_WARDING_TRIGGERED))
return false;
if (!sSpellMgr->GetSpellInfo(SPELL_MAGE_FROST_WARDING_R1))
return false;
return true;
}
void CalculateAmount(AuraEffect const* /*aurEff*/, int32& amount, bool& canBeRecalculated)
{
canBeRecalculated = false;
if (Unit* caster = GetCaster())
{
// +80.68% from sp bonus
float bonus = 0.8068f;
bonus *= caster->SpellBaseDamageBonusDone(GetSpellInfo()->GetSchoolMask());
bonus *= caster->CalculateLevelPenalty(GetSpellInfo());
amount += int32(bonus);
}
}
void Absorb(AuraEffect* aurEff, DamageInfo& dmgInfo, uint32& absorbAmount)
{
Unit* target = GetTarget();
if (AuraEffect* talentAurEff = target->GetAuraEffectOfRankedSpell(SPELL_MAGE_FROST_WARDING_R1, EFFECT_0))
{
int32 chance = talentAurEff->GetSpellInfo()->Effects[EFFECT_1].CalcValue(); // SPELL_EFFECT_DUMMY with NO_TARGET
if (roll_chance_i(chance))
{
int32 bp = dmgInfo.GetDamage();
target->CastCustomSpell(target, SPELL_MAGE_FROST_WARDING_TRIGGERED, &bp, NULL, NULL, true, NULL, aurEff);
absorbAmount = 0;
// Xinef: trigger Incanters Absorbtion
uint32 damage = dmgInfo.GetDamage();
Trigger(aurEff, dmgInfo, damage);
// Xinef: hack for chaos bolt
if (!dmgInfo.GetSpellInfo() || dmgInfo.GetSpellInfo()->SpellIconID != 3178)
dmgInfo.AbsorbDamage(bp);
PreventDefaultAction();
}
}
}
void Register()
{
DoEffectCalcAmount += AuraEffectCalcAmountFn(spell_mage_fire_frost_ward_AuraScript::CalculateAmount, EFFECT_0, SPELL_AURA_SCHOOL_ABSORB);
OnEffectAbsorb += AuraEffectAbsorbFn(spell_mage_fire_frost_ward_AuraScript::Absorb, EFFECT_0);
AfterEffectAbsorb += AuraEffectAbsorbFn(spell_mage_fire_frost_ward_AuraScript::Trigger, EFFECT_0);
}
};
AuraScript* GetAuraScript() const
{
return new spell_mage_fire_frost_ward_AuraScript();
}
};
// 54646 - Focus Magic
class spell_mage_focus_magic : public SpellScriptLoader
{
public:
spell_mage_focus_magic() : SpellScriptLoader("spell_mage_focus_magic") { }
class spell_mage_focus_magic_AuraScript : public AuraScript
{
PrepareAuraScript(spell_mage_focus_magic_AuraScript);
bool Validate(SpellInfo const* /*spellInfo*/)
{
if (!sSpellMgr->GetSpellInfo(SPELL_MAGE_FOCUS_MAGIC_PROC))
return false;
return true;
}
bool Load()
{
_procTarget = NULL;
return true;
}
bool CheckProc(ProcEventInfo& /*eventInfo*/)
{
_procTarget = GetCaster();
return _procTarget && _procTarget->IsAlive();
}
void HandleProc(AuraEffect const* aurEff, ProcEventInfo& /*eventInfo*/)
{
PreventDefaultAction();
GetTarget()->CastSpell(_procTarget, SPELL_MAGE_FOCUS_MAGIC_PROC, true, NULL, aurEff);
}
void Register()
{
DoCheckProc += AuraCheckProcFn(spell_mage_focus_magic_AuraScript::CheckProc);
OnEffectProc += AuraEffectProcFn(spell_mage_focus_magic_AuraScript::HandleProc, EFFECT_0, SPELL_AURA_MOD_SPELL_CRIT_CHANCE);
}
private:
Unit* _procTarget;
};
AuraScript* GetAuraScript() const
{
return new spell_mage_focus_magic_AuraScript();
}
};
// -11426 - Ice Barrier
class spell_mage_ice_barrier : public SpellScriptLoader
{
public:
spell_mage_ice_barrier() : SpellScriptLoader("spell_mage_ice_barrier") { }
static int32 CalculateSpellAmount(Unit* caster, int32 amount, const SpellInfo* spellInfo, const AuraEffect* aurEff)
{
// +80.68% from sp bonus
float bonus = 0.8068f;
bonus *= caster->SpellBaseDamageBonusDone(spellInfo->GetSchoolMask());
// Glyph of Ice Barrier: its weird having a SPELLMOD_ALL_EFFECTS here but its blizzards doing :)
// Glyph of Ice Barrier is only applied at the spell damage bonus because it was already applied to the base value in CalculateSpellDamage
bonus = caster->ApplyEffectModifiers(spellInfo, aurEff->GetEffIndex(), bonus);
bonus *= caster->CalculateLevelPenalty(spellInfo);
amount += int32(bonus);
return amount;
}
class spell_mage_ice_barrier_AuraScript : public spell_mage_incanters_absorbtion_base_AuraScript
{
PrepareAuraScript(spell_mage_ice_barrier_AuraScript);
void CalculateAmount(AuraEffect const* aurEff, int32& amount, bool& canBeRecalculated)
{
canBeRecalculated = false;
if (Unit* caster = GetCaster())
amount = CalculateSpellAmount(caster, amount, GetSpellInfo(), aurEff);
}
void Register()
{
DoEffectCalcAmount += AuraEffectCalcAmountFn(spell_mage_ice_barrier_AuraScript::CalculateAmount, EFFECT_0, SPELL_AURA_SCHOOL_ABSORB);
AfterEffectAbsorb += AuraEffectAbsorbFn(spell_mage_ice_barrier_AuraScript::Trigger, EFFECT_0);
}
};
AuraScript* GetAuraScript() const
{
return new spell_mage_ice_barrier_AuraScript();
}
class spell_mage_ice_barrier_SpellScript : public SpellScript
{
PrepareSpellScript(spell_mage_ice_barrier_SpellScript);
SpellCastResult CheckCast()
{
Unit* caster = GetCaster();
if (AuraEffect* aurEff = caster->GetAuraEffect(SPELL_AURA_SCHOOL_ABSORB, (SpellFamilyNames)GetSpellInfo()->SpellFamilyName, GetSpellInfo()->SpellIconID, EFFECT_0))
{
int32 newAmount = GetSpellInfo()->Effects[EFFECT_0].CalcValue(caster, NULL, NULL);
newAmount = CalculateSpellAmount(caster, newAmount, GetSpellInfo(), aurEff);
if (aurEff->GetAmount() > newAmount)
return SPELL_FAILED_AURA_BOUNCED;
}
return SPELL_CAST_OK;
}
void Register()
{
OnCheckCast += SpellCheckCastFn(spell_mage_ice_barrier_SpellScript::CheckCast);
}
};
SpellScript* GetSpellScript() const
{
return new spell_mage_ice_barrier_SpellScript;
}
};
// -11119 - Ignite
class spell_mage_ignite : public SpellScriptLoader
{
public:
spell_mage_ignite() : SpellScriptLoader("spell_mage_ignite") { }
class spell_mage_ignite_AuraScript : public AuraScript
{
PrepareAuraScript(spell_mage_ignite_AuraScript);
bool Validate(SpellInfo const* /*spellInfo*/)
{
if (!sSpellMgr->GetSpellInfo(SPELL_MAGE_IGNITE))
return false;
return true;
}
bool CheckProc(ProcEventInfo& eventInfo)
{
if (!eventInfo.GetActor() || !eventInfo.GetProcTarget())
return false;
// Molten Armor
if (SpellInfo const* spellInfo = eventInfo.GetDamageInfo()->GetSpellInfo())
if (spellInfo->SpellFamilyFlags[1] & 0x8)
return false;
return true;
}
void HandleProc(AuraEffect const* aurEff, ProcEventInfo& eventInfo)
{
PreventDefaultAction();
SpellInfo const* igniteDot = sSpellMgr->GetSpellInfo(SPELL_MAGE_IGNITE);
int32 pct = 8 * GetSpellInfo()->GetRank();
int32 amount = int32(CalculatePct(eventInfo.GetDamageInfo()->GetDamage(), pct) / igniteDot->GetMaxTicks());
// Xinef: implement ignite bug
eventInfo.GetProcTarget()->CastDelayedSpellWithPeriodicAmount(eventInfo.GetActor(), SPELL_MAGE_IGNITE, SPELL_AURA_PERIODIC_DAMAGE, amount);
//GetTarget()->CastCustomSpell(SPELL_MAGE_IGNITE, SPELLVALUE_BASE_POINT0, amount, eventInfo.GetProcTarget(), true, NULL, aurEff);
}
void Register()
{
DoCheckProc += AuraCheckProcFn(spell_mage_ignite_AuraScript::CheckProc);
OnEffectProc += AuraEffectProcFn(spell_mage_ignite_AuraScript::HandleProc, EFFECT_0, SPELL_AURA_DUMMY);
}
};
AuraScript* GetAuraScript() const
{
return new spell_mage_ignite_AuraScript();
}
};
// -44457 - Living Bomb
class spell_mage_living_bomb : public SpellScriptLoader
{
public:
spell_mage_living_bomb() : SpellScriptLoader("spell_mage_living_bomb") { }
class spell_mage_living_bomb_AuraScript : public AuraScript
{
PrepareAuraScript(spell_mage_living_bomb_AuraScript);
bool Validate(SpellInfo const* spell)
{
if (!sSpellMgr->GetSpellInfo(uint32(spell->Effects[EFFECT_1].CalcValue())))
return false;
return true;
}
void AfterRemove(AuraEffect const* aurEff, AuraEffectHandleModes /*mode*/)
{
AuraRemoveMode removeMode = GetTargetApplication()->GetRemoveMode();
if (removeMode != AURA_REMOVE_BY_ENEMY_SPELL && removeMode != AURA_REMOVE_BY_EXPIRE)
return;
if (Unit* caster = GetCaster())
caster->CastSpell(GetTarget(), uint32(aurEff->GetAmount()), true, NULL, aurEff);
}
void Register()
{
AfterEffectRemove += AuraEffectRemoveFn(spell_mage_living_bomb_AuraScript::AfterRemove, EFFECT_1, SPELL_AURA_DUMMY, AURA_EFFECT_HANDLE_REAL);
}
};
AuraScript* GetAuraScript() const
{
return new spell_mage_living_bomb_AuraScript();
}
};
// -1463 - Mana Shield
class spell_mage_mana_shield : public SpellScriptLoader
{
public:
spell_mage_mana_shield() : SpellScriptLoader("spell_mage_mana_shield") { }
class spell_mage_mana_shield_AuraScript : public spell_mage_incanters_absorbtion_base_AuraScript
{
PrepareAuraScript(spell_mage_mana_shield_AuraScript);
void CalculateAmount(AuraEffect const* /*aurEff*/, int32& amount, bool& canBeRecalculated)
{
canBeRecalculated = false;
if (Unit* caster = GetCaster())
{
// +80.53% from sp bonus
float bonus = 0.8053f;
bonus *= caster->SpellBaseDamageBonusDone(GetSpellInfo()->GetSchoolMask());
bonus *= caster->CalculateLevelPenalty(GetSpellInfo());
amount += int32(bonus);
}
}
void Register()
{
DoEffectCalcAmount += AuraEffectCalcAmountFn(spell_mage_mana_shield_AuraScript::CalculateAmount, EFFECT_0, SPELL_AURA_MANA_SHIELD);
AfterEffectManaShield += AuraEffectManaShieldFn(spell_mage_mana_shield_AuraScript::Trigger, EFFECT_0);
}
};
AuraScript* GetAuraScript() const
{
return new spell_mage_mana_shield_AuraScript();
}
};
// -29074 - Master of Elements
class spell_mage_master_of_elements : public SpellScriptLoader
{
public:
spell_mage_master_of_elements() : SpellScriptLoader("spell_mage_master_of_elements") { }
class spell_mage_master_of_elements_AuraScript : public AuraScript
{
PrepareAuraScript(spell_mage_master_of_elements_AuraScript);
bool Validate(SpellInfo const* /*spellInfo*/)
{
if (!sSpellMgr->GetSpellInfo(SPELL_MAGE_MASTER_OF_ELEMENTS_ENERGIZE))
return false;
return true;
}
bool CheckProc(ProcEventInfo& eventInfo)
{
return eventInfo.GetDamageInfo()->GetSpellInfo(); // eventInfo.GetSpellInfo()
}
void HandleProc(AuraEffect const* aurEff, ProcEventInfo& eventInfo)
{
PreventDefaultAction();
int32 mana = int32(eventInfo.GetDamageInfo()->GetSpellInfo()->CalcPowerCost(GetTarget(), eventInfo.GetDamageInfo()->GetSchoolMask()));
mana = CalculatePct(mana, aurEff->GetAmount());
if (mana > 0)
GetTarget()->CastCustomSpell(SPELL_MAGE_MASTER_OF_ELEMENTS_ENERGIZE, SPELLVALUE_BASE_POINT0, mana, GetTarget(), true, NULL, aurEff);
}
void Register()
{
DoCheckProc += AuraCheckProcFn(spell_mage_master_of_elements_AuraScript::CheckProc);
OnEffectProc += AuraEffectProcFn(spell_mage_master_of_elements_AuraScript::HandleProc, EFFECT_0, SPELL_AURA_DUMMY);
}
};
AuraScript* GetAuraScript() const
{
return new spell_mage_master_of_elements_AuraScript();
}
};
enum SilvermoonPolymorph
{
NPC_AUROSALIA = 18744,
};
/// @todo move out of here and rename - not a mage spell
// 32826 - Polymorph (Visual)
class spell_mage_polymorph_cast_visual : public SpellScriptLoader
{
public:
spell_mage_polymorph_cast_visual() : SpellScriptLoader("spell_mage_polymorph_visual") { }
class spell_mage_polymorph_cast_visual_SpellScript : public SpellScript
{
PrepareSpellScript(spell_mage_polymorph_cast_visual_SpellScript);
static const uint32 PolymorhForms[6];
bool Validate(SpellInfo const* /*spellInfo*/)
{
// check if spell ids exist in dbc
for (uint32 i = 0; i < 6; ++i)
if (!sSpellMgr->GetSpellInfo(PolymorhForms[i]))
return false;
return true;
}
void HandleDummy(SpellEffIndex /*effIndex*/)
{
if (Unit* target = GetCaster()->FindNearestCreature(NPC_AUROSALIA, 30.0f))
if (target->GetTypeId() == TYPEID_UNIT)
target->CastSpell(target, PolymorhForms[urand(0, 5)], true);
}
void Register()
{
OnEffectHitTarget += SpellEffectFn(spell_mage_polymorph_cast_visual_SpellScript::HandleDummy, EFFECT_0, SPELL_EFFECT_DUMMY);
}
};
SpellScript* GetSpellScript() const
{
return new spell_mage_polymorph_cast_visual_SpellScript();
}
};
const uint32 spell_mage_polymorph_cast_visual::spell_mage_polymorph_cast_visual_SpellScript::PolymorhForms[6] =
{
SPELL_MAGE_SQUIRREL_FORM,
SPELL_MAGE_GIRAFFE_FORM,
SPELL_MAGE_SERPENT_FORM,
SPELL_MAGE_DRAGONHAWK_FORM,
SPELL_MAGE_WORGEN_FORM,
SPELL_MAGE_SHEEP_FORM
};
// 31687 - Summon Water Elemental
class spell_mage_summon_water_elemental : public SpellScriptLoader
{
public:
spell_mage_summon_water_elemental() : SpellScriptLoader("spell_mage_summon_water_elemental") { }
class spell_mage_summon_water_elemental_SpellScript : public SpellScript
{
PrepareSpellScript(spell_mage_summon_water_elemental_SpellScript)
bool Validate(SpellInfo const* /*spellEntry*/)
{
if (!sSpellMgr->GetSpellInfo(SPELL_MAGE_GLYPH_OF_ETERNAL_WATER))
return false;
if (!sSpellMgr->GetSpellInfo(SPELL_MAGE_SUMMON_WATER_ELEMENTAL_TEMPORARY))
return false;
if (!sSpellMgr->GetSpellInfo(SPELL_MAGE_SUMMON_WATER_ELEMENTAL_PERMANENT))
return false;
return true;
}
void HandleDummy(SpellEffIndex /*effIndex*/)
{
Unit* caster = GetCaster();
if (Creature *pet = ObjectAccessor::GetCreature(*caster, caster->GetPetGUID()))
if (!pet->IsAlive())
pet->ToTempSummon()->UnSummon();
// Glyph of Eternal Water
if (caster->HasAura(SPELL_MAGE_GLYPH_OF_ETERNAL_WATER))
caster->CastSpell(caster, SPELL_MAGE_SUMMON_WATER_ELEMENTAL_PERMANENT, true);
else
caster->CastSpell(caster, SPELL_MAGE_SUMMON_WATER_ELEMENTAL_TEMPORARY, true);
if (Creature *pet = ObjectAccessor::GetCreature(*caster, caster->GetPetGUID()))
if (pet->GetCharmInfo() && caster->ToPlayer())
{
pet->m_CreatureSpellCooldowns.clear();
const SpellInfo* spellEntry = sSpellMgr->GetSpellInfo(31707);
pet->GetCharmInfo()->ToggleCreatureAutocast(spellEntry, true);
pet->GetCharmInfo()->SetSpellAutocast(spellEntry, true);
caster->ToPlayer()->CharmSpellInitialize();
}
}
void Register()
{
OnEffectHit += SpellEffectFn(spell_mage_summon_water_elemental_SpellScript::HandleDummy, EFFECT_0, SPELL_EFFECT_DUMMY);
}
};
SpellScript* GetSpellScript() const
{
return new spell_mage_summon_water_elemental_SpellScript();
}
};
void AddSC_mage_spell_scripts()
{
// Ours
new spell_mage_arcane_blast();
new spell_mage_deep_freeze();
new spell_mage_burning_determination();
new spell_mage_molten_armor();
new spell_mage_mirror_image();
new spell_mage_burnout();
new spell_mage_burnout_trigger();
new spell_mage_pet_scaling();
new spell_mage_brain_freeze();
// Theirs
new spell_mage_blast_wave();
new spell_mage_cold_snap();
new spell_mage_fire_frost_ward();
new spell_mage_focus_magic();
new spell_mage_ice_barrier();
new spell_mage_ignite();
new spell_mage_living_bomb();
new spell_mage_mana_shield();
new spell_mage_master_of_elements();
new spell_mage_polymorph_cast_visual();
new spell_mage_summon_water_elemental();
}
|