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
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
|
/*
* This file is part of the TrinityCore 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 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef TRINITY_SPELL_SCRIPT_H
#define TRINITY_SPELL_SCRIPT_H
#include "ObjectGuid.h"
#include "SharedDefines.h"
#include "SpellAuraDefines.h"
#include "Util.h"
#include <stack>
#ifdef TRINITY_API_USE_DYNAMIC_LINKING
#include <memory>
#endif
class Aura;
class AuraApplication;
class AuraEffect;
class Creature;
class Corpse;
class DamageInfo;
class DispelInfo;
class DynamicObject;
class GameObject;
class HealInfo;
class Item;
class ModuleReference;
class Player;
class ProcEventInfo;
class Spell;
class SpellEffectInfo;
class SpellInfo;
class SpellScript;
class Unit;
class WorldLocation;
class WorldObject;
struct SpellDestination;
struct SpellModifier;
struct SpellValue;
enum Difficulty : uint8;
enum class ItemContext : uint8;
#define SPELL_EFFECT_ANY ((uint16)-1)
#define SPELL_AURA_ANY ((uint16)-1)
enum SpellScriptState
{
SPELL_SCRIPT_STATE_NONE = 0,
SPELL_SCRIPT_STATE_REGISTRATION,
SPELL_SCRIPT_STATE_LOADING,
SPELL_SCRIPT_STATE_UNLOADING
};
#define SPELL_SCRIPT_STATE_END (SPELL_SCRIPT_STATE_UNLOADING + 1)
// helper class from which SpellScript and AuraScript derive, use these classes instead
class TC_GAME_API SpellScriptBase
{
// internal use classes & functions
// DO NOT OVERRIDE THESE IN SCRIPTS
public:
SpellScriptBase();
virtual ~SpellScriptBase();
SpellScriptBase(SpellScriptBase const& right) = delete;
SpellScriptBase(SpellScriptBase&& right) = delete;
SpellScriptBase& operator=(SpellScriptBase const& right) = delete;
SpellScriptBase& operator=(SpellScriptBase&& right) = delete;
void _Register();
void _Unload();
void _Init(std::string const& scriptname, uint32 spellId);
std::string_view GetScriptName() const;
protected:
virtual bool _Validate(SpellInfo const* entry);
class TC_GAME_API EffectHook
{
public:
explicit EffectHook(uint8 effIndex);
EffectHook(EffectHook const& right) = delete;
EffectHook(EffectHook&& right) noexcept;
EffectHook& operator=(EffectHook const& right) = delete;
EffectHook& operator=(EffectHook&& right) noexcept;
virtual ~EffectHook();
uint32 GetAffectedEffectsMask(SpellInfo const* spellInfo) const;
bool IsEffectAffected(SpellInfo const* spellInfo, uint8 effIndex) const;
virtual bool CheckEffect(SpellInfo const* spellInfo, uint8 effIndex) const = 0;
std::string EffIndexToString() const;
protected:
uint8 _effIndex;
};
template<typename>
struct GetScriptClass
{
using type = void;
};
template<typename Return, typename Class, typename... Args>
struct GetScriptClass<Return(Class::*)(Args...)>
{
using type = Class;
};
template<typename Return, typename Class, typename... Args>
struct GetScriptClass<Return(Class::*)(Args...) const>
{
using type = Class;
};
template<typename ScriptFunc>
using GetScriptClass_t = typename GetScriptClass<ScriptFunc>::type;
uint8 m_currentScriptState;
std::string_view m_scriptName;
uint32 m_scriptSpellId;
private:
#ifdef TRINITY_API_USE_DYNAMIC_LINKING
// Strong reference to keep the binary code loaded
std::shared_ptr<ModuleReference> m_moduleReference;
#endif // #ifndef TRINITY_API_USE_DYNAMIC_LINKING
public:
//
// SpellScript/AuraScript interface base
// these functions are safe to override, see notes below for usage instructions
//
// Function in which handler functions are registered, must be implemented in script
virtual void Register() = 0;
// Function called on server startup, if returns false script won't be used in core
// use for: dbc/template data presence/correctness checks
virtual bool Validate([[maybe_unused]] SpellInfo const* spellInfo) { return true; }
// Function called when script is created, if returns false script will be unloaded afterwards
// use for: initializing local script variables (DO NOT USE CONSTRUCTOR FOR THIS PURPOSE!)
virtual bool Load() { return true; }
// Function called when script is destroyed
// use for: deallocating memory allocated by script
virtual void Unload() { }
// Helpers
static bool ValidateSpellInfo(std::initializer_list<uint32> spellIds)
{
return ValidateSpellInfoImpl(spellIds.begin(), spellIds.end());
}
template <class T>
static bool ValidateSpellInfo(T const& spellIds)
{
return ValidateSpellInfoImpl(std::cbegin(spellIds), std::cend(spellIds));
}
static bool ValidateSpellEffect(std::initializer_list<std::pair<uint32, SpellEffIndex>> effects)
{
return ValidateSpellEffectsImpl(effects.begin(), effects.end());
}
template <class T>
static bool ValidateSpellEffect(T const& spellEffects)
{
return ValidateSpellEffectsImpl(std::cbegin(spellEffects), std::cend(spellEffects));
}
private:
template<typename Iterator>
static bool ValidateSpellInfoImpl(Iterator begin, Iterator end)
{
bool allValid = true;
while (begin != end)
{
if (!ValidateSpellInfoImpl(*begin))
allValid = false;
++begin;
}
return allValid;
}
template<typename Iterator>
static bool ValidateSpellEffectsImpl(Iterator begin, Iterator end)
{
bool allValid = true;
while (begin != end)
{
if (!ValidateSpellEffectImpl(begin->first, begin->second))
allValid = false;
++begin;
}
return allValid;
}
static bool ValidateSpellInfoImpl(uint32 spellId);
static bool ValidateSpellEffectImpl(uint32 spellId, SpellEffIndex effectIndex);
};
// SpellScript interface - enum used for runtime checks of script function calls
enum SpellScriptHookType
{
SPELL_SCRIPT_HOOK_EFFECT_LAUNCH = SPELL_SCRIPT_STATE_END,
SPELL_SCRIPT_HOOK_EFFECT_LAUNCH_TARGET,
SPELL_SCRIPT_HOOK_EFFECT_HIT,
SPELL_SCRIPT_HOOK_EFFECT_HIT_TARGET,
SPELL_SCRIPT_HOOK_EFFECT_SUCCESSFUL_DISPEL,
SPELL_SCRIPT_HOOK_BEFORE_HIT,
SPELL_SCRIPT_HOOK_HIT,
SPELL_SCRIPT_HOOK_AFTER_HIT,
SPELL_SCRIPT_HOOK_OBJECT_AREA_TARGET_SELECT,
SPELL_SCRIPT_HOOK_OBJECT_TARGET_SELECT,
SPELL_SCRIPT_HOOK_DESTINATION_TARGET_SELECT,
SPELL_SCRIPT_HOOK_CHECK_CAST,
SPELL_SCRIPT_HOOK_BEFORE_CAST,
SPELL_SCRIPT_HOOK_ON_CAST,
SPELL_SCRIPT_HOOK_ON_RESIST_ABSORB_CALCULATION,
SPELL_SCRIPT_HOOK_AFTER_CAST,
SPELL_SCRIPT_HOOK_CALC_CRIT_CHANCE,
SPELL_SCRIPT_HOOK_CALC_DAMAGE,
SPELL_SCRIPT_HOOK_CALC_HEALING,
SPELL_SCRIPT_HOOK_ON_PRECAST,
SPELL_SCRIPT_HOOK_CALC_CAST_TIME,
};
#define HOOK_SPELL_HIT_START SPELL_SCRIPT_HOOK_EFFECT_HIT
#define HOOK_SPELL_HIT_END SPELL_SCRIPT_HOOK_AFTER_HIT + 1
class TC_GAME_API SpellScript : public SpellScriptBase
{
// internal use classes & functions
// DO NOT OVERRIDE THESE IN SCRIPTS
public:
class CastHandler final
{
public:
using SpellCastFnType = void(SpellScript::*)();
using SafeWrapperType = void(*)(SpellScript* spellScript, SpellCastFnType callImpl);
template<typename ScriptFunc>
explicit CastHandler(ScriptFunc handler)
{
using ScriptClass = GetScriptClass_t<ScriptFunc>;
static_assert(sizeof(SpellCastFnType) >= sizeof(ScriptFunc));
static_assert(alignof(SpellCastFnType) >= alignof(ScriptFunc));
static_assert(std::is_invocable_r_v<void, ScriptFunc, ScriptClass>,
"CastHandler signature must be \"void HandleCast()\"");
_callImpl = reinterpret_cast<SpellCastFnType>(handler);
_safeWrapper = [](SpellScript* spellScript, SpellCastFnType callImpl) -> void
{
return (static_cast<ScriptClass*>(spellScript)->*reinterpret_cast<ScriptFunc>(callImpl))();
};
}
void Call(SpellScript* spellScript) const
{
return _safeWrapper(spellScript, _callImpl);
}
private:
SpellCastFnType _callImpl;
SafeWrapperType _safeWrapper;
};
class CheckCastHandler final
{
public:
union SpellCheckCastFnType
{
SpellCastResult(SpellScript::* Member)();
SpellCastResult(*Static)();
};
using SafeWrapperType = SpellCastResult(*)(SpellScript* spellScript, SpellCheckCastFnType callImpl);
template<typename ScriptFunc>
explicit CheckCastHandler(ScriptFunc handler)
{
using ScriptClass = GetScriptClass_t<ScriptFunc>;
static_assert(sizeof(SpellCheckCastFnType) >= sizeof(ScriptFunc));
static_assert(alignof(SpellCheckCastFnType) >= alignof(ScriptFunc));
if constexpr (!std::is_void_v<ScriptClass>)
{
static_assert(std::is_invocable_r_v<SpellCastResult, ScriptFunc, ScriptClass>,
"CheckCastHandler signature must be \"SpellCastResult CheckCast()\"");
_callImpl = { .Member = reinterpret_cast<decltype(SpellCheckCastFnType::Member)>(handler) };
_safeWrapper = [](SpellScript* spellScript, SpellCheckCastFnType callImpl) -> SpellCastResult
{
return (static_cast<ScriptClass*>(spellScript)->*reinterpret_cast<ScriptFunc>(callImpl.Member))();
};
}
else
{
static_assert(std::is_invocable_r_v<SpellCastResult, ScriptFunc>,
"CheckCastHandler signature must be \"static SpellCastResult CheckCast()\"");
_callImpl = { .Static = reinterpret_cast<decltype(SpellCheckCastFnType::Static)>(handler) };
_safeWrapper = [](SpellScript* /*spellScript*/, SpellCheckCastFnType callImpl) -> SpellCastResult
{
return reinterpret_cast<ScriptFunc>(callImpl.Static)();
};
}
}
SpellCastResult Call(SpellScript* spellScript) const
{
return _safeWrapper(spellScript, _callImpl);
}
private:
SpellCheckCastFnType _callImpl;
SafeWrapperType _safeWrapper;
};
class TC_GAME_API EffectBase : public EffectHook
{
public:
EffectBase(uint8 effIndex, uint16 effName);
EffectBase(EffectBase const& right) = delete;
EffectBase(EffectBase&& right) noexcept;
EffectBase& operator=(EffectBase const& right) = delete;
EffectBase& operator=(EffectBase&& right) noexcept;
~EffectBase();
std::string ToString() const;
bool CheckEffect(SpellInfo const* spellInfo, uint8 effIndex) const override;
private:
uint16 _effName;
};
class EffectHandler final : public EffectBase
{
public:
using SpellEffectFnType = void(SpellScript::*)(SpellEffIndex effIndex);
using SafeWrapperType = void(*)(SpellScript* spellScript, SpellEffIndex effIndex, SpellEffectFnType callImpl);
template<typename ScriptFunc>
explicit EffectHandler(ScriptFunc handler, uint8 effIndex, uint16 effName)
: EffectBase(effIndex, effName)
{
using ScriptClass = GetScriptClass_t<ScriptFunc>;
static_assert(sizeof(SpellEffectFnType) >= sizeof(ScriptFunc));
static_assert(alignof(SpellEffectFnType) >= alignof(ScriptFunc));
static_assert(std::is_invocable_r_v<void, ScriptFunc, ScriptClass, SpellEffIndex>,
"EffectHandler signature must be \"void HandleEffect(SpellEffIndex effIndex)\"");
_callImpl = reinterpret_cast<SpellEffectFnType>(handler);
_safeWrapper = [](SpellScript* spellScript, SpellEffIndex effIndex, SpellEffectFnType callImpl) -> void
{
return (static_cast<ScriptClass*>(spellScript)->*reinterpret_cast<ScriptFunc>(callImpl))(effIndex);
};
}
void Call(SpellScript* spellScript, SpellEffIndex effIndex) const
{
return _safeWrapper(spellScript, effIndex, _callImpl);
}
private:
SpellEffectFnType _callImpl;
SafeWrapperType _safeWrapper;
};
class BeforeHitHandler final
{
public:
using SpellBeforeHitFnType = void(SpellScript::*)(SpellMissInfo missInfo);
using SafeWrapperType = void(*)(SpellScript* spellScript, SpellMissInfo missInfo, SpellBeforeHitFnType callImpl);
template<typename ScriptFunc>
explicit BeforeHitHandler(ScriptFunc handler)
{
using ScriptClass = GetScriptClass_t<ScriptFunc>;
static_assert(sizeof(SpellBeforeHitFnType) >= sizeof(ScriptFunc));
static_assert(alignof(SpellBeforeHitFnType) >= alignof(ScriptFunc));
static_assert(std::is_invocable_r_v<void, ScriptFunc, ScriptClass, SpellMissInfo>,
"BeforeHitHandler signature must be \"void HandleBeforeHit(SpellMissInfo missInfo)\"");
_callImpl = reinterpret_cast<SpellBeforeHitFnType>(handler);
_safeWrapper = [](SpellScript* spellScript, SpellMissInfo missInfo, SpellBeforeHitFnType callImpl) -> void
{
return (static_cast<ScriptClass*>(spellScript)->*reinterpret_cast<ScriptFunc>(callImpl))(missInfo);
};
}
void Call(SpellScript* spellScript, SpellMissInfo missInfo) const
{
return _safeWrapper(spellScript, missInfo, _callImpl);
}
private:
SpellBeforeHitFnType _callImpl;
SafeWrapperType _safeWrapper;
};
class HitHandler final
{
public:
using SpellHitFnType = void(SpellScript::*)();
using SafeWrapperType = void(*)(SpellScript* spellScript, SpellHitFnType callImpl);
template<typename ScriptFunc>
explicit HitHandler(ScriptFunc handler)
{
using ScriptClass = GetScriptClass_t<ScriptFunc>;
static_assert(sizeof(SpellHitFnType) >= sizeof(ScriptFunc));
static_assert(alignof(SpellHitFnType) >= alignof(ScriptFunc));
static_assert(std::is_invocable_r_v<void, ScriptFunc, ScriptClass>,
"HitHandler signature must be \"void HandleHit()\"");
_callImpl = reinterpret_cast<SpellHitFnType>(handler);
_safeWrapper = [](SpellScript* spellScript, SpellHitFnType callImpl) -> void
{
return (static_cast<ScriptClass*>(spellScript)->*reinterpret_cast<ScriptFunc>(callImpl))();
};
}
void Call(SpellScript* spellScript) const
{
return _safeWrapper(spellScript, _callImpl);
}
private:
SpellHitFnType _callImpl;
SafeWrapperType _safeWrapper;
};
class OnCalcCritChanceHandler final
{
public:
union SpellOnCalcCritChanceFnType
{
void(SpellScript::* Member)(Unit const* victim, float& critChance);
void(*Static)(Unit const* victim, float& critChance);
};
using SafeWrapperType = void(*)(SpellScript* spellScript, Unit const* victim, float& critChance, SpellOnCalcCritChanceFnType callImpl);
template<typename ScriptFunc>
explicit OnCalcCritChanceHandler(ScriptFunc handler)
{
using ScriptClass = GetScriptClass_t<ScriptFunc>;
static_assert(sizeof(SpellOnCalcCritChanceFnType) >= sizeof(ScriptFunc));
static_assert(alignof(SpellOnCalcCritChanceFnType) >= alignof(ScriptFunc));
if constexpr (!std::is_void_v<ScriptClass>)
{
static_assert(std::is_invocable_r_v<void, ScriptFunc, ScriptClass, Unit const*, float&>,
"OnCalcCritChanceHandler signature must be \"void CalcCritChance(Unit const* victim, float& critChance)\"");
_callImpl = { .Member = reinterpret_cast<decltype(SpellOnCalcCritChanceFnType::Member)>(handler) };
_safeWrapper = [](SpellScript* spellScript, Unit const* victim, float& critChance, SpellOnCalcCritChanceFnType callImpl) -> void
{
return (static_cast<ScriptClass*>(spellScript)->*reinterpret_cast<ScriptFunc>(callImpl.Member))(victim, critChance);
};
}
else
{
static_assert(std::is_invocable_r_v<void, ScriptFunc, Unit const*, float&>,
"OnCalcCritChanceHandler signature must be \"static void CalcCritChance(Unit const* victim, float& critChance)\"");
_callImpl = { .Static = reinterpret_cast<decltype(SpellOnCalcCritChanceFnType::Static)>(handler) };
_safeWrapper = [](SpellScript* /*spellScript*/, Unit const* victim, float& critChance, SpellOnCalcCritChanceFnType callImpl) -> void
{
return reinterpret_cast<ScriptFunc>(callImpl.Static)(victim, critChance);
};
}
}
void Call(SpellScript* spellScript, Unit const* victim, float& critChance) const
{
return _safeWrapper(spellScript, victim, critChance, _callImpl);
}
private:
SpellOnCalcCritChanceFnType _callImpl;
SafeWrapperType _safeWrapper;
};
class TC_GAME_API TargetHook : public EffectHook
{
public:
TargetHook(uint8 effectIndex, uint16 targetType, bool area, bool dest);
TargetHook(TargetHook const& right) = delete;
TargetHook(TargetHook&& right) noexcept;
TargetHook& operator=(TargetHook const& right) = delete;
TargetHook& operator=(TargetHook&& right) noexcept;
virtual ~TargetHook();
bool CheckEffect(SpellInfo const* spellInfo, uint8 effIndex) const override;
std::string ToString() const;
uint16 GetTarget() const { return _targetType; }
protected:
uint16 _targetType;
bool _area;
bool _dest;
};
class ObjectAreaTargetSelectHandler final : public TargetHook
{
public:
union SpellObjectAreaTargetSelectFnType
{
void(SpellScript::* Member)(std::list<WorldObject*>& targets);
void(*Static)(std::list<WorldObject*>& targets);
};
using SafeWrapperType = void(*)(SpellScript* spellScript, std::list<WorldObject*>& targets, SpellObjectAreaTargetSelectFnType callImpl);
template<typename ScriptFunc>
explicit ObjectAreaTargetSelectHandler(ScriptFunc handler, uint8 effIndex, uint16 targetType)
: TargetHook(effIndex, targetType, true, false)
{
using ScriptClass = GetScriptClass_t<ScriptFunc>;
static_assert(sizeof(SpellObjectAreaTargetSelectFnType) >= sizeof(ScriptFunc));
static_assert(alignof(SpellObjectAreaTargetSelectFnType) >= alignof(ScriptFunc));
if constexpr (!std::is_void_v<ScriptClass>)
{
static_assert(std::is_invocable_r_v<void, ScriptFunc, ScriptClass, std::list<WorldObject*>&>,
"ObjectAreaTargetSelectHandler signature must be \"void SetTargets(std::list<WorldObject*>& targets)\"");
_callImpl = { .Member = reinterpret_cast<decltype(SpellObjectAreaTargetSelectFnType::Member)>(handler) };
_safeWrapper = [](SpellScript* spellScript, std::list<WorldObject*>& targets, SpellObjectAreaTargetSelectFnType callImpl) -> void
{
return (static_cast<ScriptClass*>(spellScript)->*reinterpret_cast<ScriptFunc>(callImpl.Member))(targets);
};
}
else
{
static_assert(std::is_invocable_r_v<void, ScriptFunc, std::list<WorldObject*>&>,
"ObjectAreaTargetSelectHandler signature must be \"static void SetTargets(std::list<WorldObject*>& targets)\"");
_callImpl = { .Static = reinterpret_cast<decltype(SpellObjectAreaTargetSelectFnType::Static)>(handler) };
_safeWrapper = [](SpellScript* /*spellScript*/, std::list<WorldObject*>& targets, SpellObjectAreaTargetSelectFnType callImpl) -> void
{
return reinterpret_cast<ScriptFunc>(callImpl.Static)(targets);
};
}
}
void Call(SpellScript* spellScript, std::list<WorldObject*>& targets) const
{
return _safeWrapper(spellScript, targets, _callImpl);
}
bool HasSameTargetFunctionAs(ObjectAreaTargetSelectHandler const& other) const
{
return _callImpl.Member == other._callImpl.Member || _callImpl.Static == other._callImpl.Static;
}
private:
SpellObjectAreaTargetSelectFnType _callImpl;
SafeWrapperType _safeWrapper;
};
class ObjectTargetSelectHandler final : public TargetHook
{
public:
union SpellObjectTargetSelectFnType
{
void(SpellScript::* Member)(WorldObject*& target);
void(*Static)(WorldObject*& target);
};
using SafeWrapperType = void(*)(SpellScript* spellScript, WorldObject*& target, SpellObjectTargetSelectFnType callImpl);
template<typename ScriptFunc>
explicit ObjectTargetSelectHandler(ScriptFunc handler, uint8 effIndex, uint16 targetType)
: TargetHook(effIndex, targetType, false, false)
{
using ScriptClass = GetScriptClass_t<ScriptFunc>;
static_assert(sizeof(SpellObjectTargetSelectFnType) >= sizeof(ScriptFunc));
static_assert(alignof(SpellObjectTargetSelectFnType) >= alignof(ScriptFunc));
if constexpr (!std::is_void_v<ScriptClass>)
{
static_assert(std::is_invocable_r_v<void, ScriptFunc, ScriptClass, WorldObject*&>,
"ObjectTargetSelectHandler signature must be \"void SetTarget(WorldObject*& target)\"");
_callImpl = { .Member = reinterpret_cast<decltype(SpellObjectTargetSelectFnType::Member)>(handler) };
_safeWrapper = [](SpellScript* spellScript, WorldObject*& target, SpellObjectTargetSelectFnType callImpl) -> void
{
return (static_cast<ScriptClass*>(spellScript)->*reinterpret_cast<ScriptFunc>(callImpl.Member))(target);
};
}
else
{
static_assert(std::is_invocable_r_v<void, ScriptFunc, WorldObject*&>,
"ObjectTargetSelectHandler signature must be \"static void SetTarget(WorldObject*& target)\"");
_callImpl = { .Static = reinterpret_cast<decltype(SpellObjectTargetSelectFnType::Static)>(handler) };
_safeWrapper = [](SpellScript* /*spellScript*/, WorldObject*& target, SpellObjectTargetSelectFnType callImpl) -> void
{
return reinterpret_cast<ScriptFunc>(callImpl.Static)(target);
};
}
}
void Call(SpellScript* spellScript, WorldObject*& target) const
{
return _safeWrapper(spellScript, target, _callImpl);
}
bool HasSameTargetFunctionAs(ObjectTargetSelectHandler const& other) const
{
return _callImpl.Member == other._callImpl.Member || _callImpl.Static == other._callImpl.Static;
}
private:
SpellObjectTargetSelectFnType _callImpl;
SafeWrapperType _safeWrapper;
};
class DestinationTargetSelectHandler final : public TargetHook
{
public:
union SpellDestinationTargetSelectFnType
{
void(SpellScript::* Member)(SpellDestination& target);
void(*Static)(SpellDestination& target);
};
using SafeWrapperType = void(*)(SpellScript* spellScript, SpellDestination& target, SpellDestinationTargetSelectFnType callImpl);
template<typename ScriptFunc>
explicit DestinationTargetSelectHandler(ScriptFunc handler, uint8 effIndex, uint16 targetType)
: TargetHook(effIndex, targetType, false, true)
{
using ScriptClass = GetScriptClass_t<ScriptFunc>;
static_assert(sizeof(SpellDestinationTargetSelectFnType) >= sizeof(ScriptFunc));
static_assert(alignof(SpellDestinationTargetSelectFnType) >= alignof(ScriptFunc));
if constexpr (!std::is_void_v<ScriptClass>)
{
static_assert(std::is_invocable_r_v<void, ScriptFunc, ScriptClass, SpellDestination&>,
"DestinationTargetSelectHandler signature must be \"void SetTarget(SpellDestination& target)\"");
_callImpl = { .Member = reinterpret_cast<decltype(SpellDestinationTargetSelectFnType::Member)>(handler) };
_safeWrapper = [](SpellScript* spellScript, SpellDestination& target, SpellDestinationTargetSelectFnType callImpl) -> void
{
return (static_cast<ScriptClass*>(spellScript)->*reinterpret_cast<ScriptFunc>(callImpl.Member))(target);
};
}
else
{
static_assert(std::is_invocable_r_v<void, ScriptFunc, SpellDestination&>,
"DestinationTargetSelectHandler signature must be \"static void SetTarget(SpellDestination& target)\"");
_callImpl = { .Static = reinterpret_cast<decltype(SpellDestinationTargetSelectFnType::Static)>(handler) };
_safeWrapper = [](SpellScript* /*spellScript*/, SpellDestination& target, SpellDestinationTargetSelectFnType callImpl) -> void
{
return reinterpret_cast<ScriptFunc>(callImpl.Static)(target);
};
}
}
void Call(SpellScript* spellScript, SpellDestination& target) const
{
return _safeWrapper(spellScript, target, _callImpl);
}
private:
SpellDestinationTargetSelectFnType _callImpl;
SafeWrapperType _safeWrapper;
};
class DamageAndHealingCalcHandler final
{
public:
union DamageAndHealingCalcFnType
{
void(SpellScript::* Member)(SpellEffectInfo const& spellEffectInfo, Unit* victim, int32& damageOrHealing, int32& flatMod, float& pctMod);
void(*Static)(SpellEffectInfo const& spellEffectInfo, Unit* victim, int32& damageOrHealing, int32& flatMod, float& pctMod);
};
using SafeWrapperType = void(*)(SpellScript* spellScript, SpellEffectInfo const& spellEffectInfo, Unit* victim, int32& damageOrHealing, int32& flatMod, float& pctMod, DamageAndHealingCalcFnType callImpl);
template<typename ScriptFunc>
explicit DamageAndHealingCalcHandler(ScriptFunc handler)
{
using ScriptClass = GetScriptClass_t<ScriptFunc>;
static_assert(sizeof(DamageAndHealingCalcFnType) >= sizeof(ScriptFunc));
static_assert(alignof(DamageAndHealingCalcFnType) >= alignof(ScriptFunc));
if constexpr (!std::is_void_v<ScriptClass>)
{
static_assert(std::is_invocable_r_v<void, ScriptFunc, ScriptClass, SpellEffectInfo const&, Unit*, int32&, int32&, float&>,
"DamageAndHealingCalcHandler signature must be \"void CalcDamage(SpellEffectInfo const& spellEffectInfo, Unit* victim, int32& damageOrHealing, int32& flatMod, float& pctMod)\"");
_callImpl = { .Member = reinterpret_cast<decltype(DamageAndHealingCalcFnType::Member)>(handler) };
_safeWrapper = [](SpellScript* spellScript, SpellEffectInfo const& spellEffectInfo, Unit* victim, int32& damageOrHealing, int32& flatMod, float& pctMod, DamageAndHealingCalcFnType callImpl) -> void
{
return (static_cast<ScriptClass*>(spellScript)->*reinterpret_cast<ScriptFunc>(callImpl.Member))(spellEffectInfo, victim, damageOrHealing, flatMod, pctMod);
};
}
else
{
static_assert(std::is_invocable_r_v<void, ScriptFunc, SpellEffectInfo const&, Unit*, int32&, int32&, float&>,
"DamageAndHealingCalcHandler signature must be \"static void CalcDamage(SpellEffectInfo const& spellEffectInfo, Unit* victim, int32& damageOrHealing, int32& flatMod, float& pctMod)\"");
_callImpl = { .Static = reinterpret_cast<decltype(DamageAndHealingCalcFnType::Static)>(handler) };
_safeWrapper = [](SpellScript* /*spellScript*/, SpellEffectInfo const& spellEffectInfo, Unit* victim, int32& damageOrHealing, int32& flatMod, float& pctMod, DamageAndHealingCalcFnType callImpl) -> void
{
return reinterpret_cast<ScriptFunc>(callImpl.Static)(spellEffectInfo, victim, damageOrHealing, flatMod, pctMod);
};
}
}
void Call(SpellScript* spellScript, SpellEffectInfo const& spellEffectInfo, Unit* victim, int32& damageOrHealing, int32& flatMod, float& pctMod) const
{
return _safeWrapper(spellScript, spellEffectInfo, victim, damageOrHealing, flatMod, pctMod, _callImpl);
}
private:
DamageAndHealingCalcFnType _callImpl;
SafeWrapperType _safeWrapper;
};
class OnCalculateResistAbsorbHandler final
{
public:
union SpellOnResistAbsorbCalculateFnType
{
void(SpellScript::* Member)(DamageInfo const& damageInfo, uint32& resistAmount, int32& absorbAmount);
void(*Static)(DamageInfo const& damageInfo, uint32& resistAmount, int32& absorbAmount);
};
using SafeWrapperType = void(*)(SpellScript* spellScript, DamageInfo const& damageInfo, uint32& resistAmount, int32& absorbAmount, SpellOnResistAbsorbCalculateFnType callImpl);
template<typename ScriptFunc>
explicit OnCalculateResistAbsorbHandler(ScriptFunc handler)
{
using ScriptClass = GetScriptClass_t<ScriptFunc>;
static_assert(sizeof(SpellOnResistAbsorbCalculateFnType) >= sizeof(ScriptFunc));
static_assert(alignof(SpellOnResistAbsorbCalculateFnType) >= alignof(ScriptFunc));
if constexpr (!std::is_void_v<ScriptClass>)
{
static_assert(std::is_invocable_r_v<void, ScriptFunc, ScriptClass, DamageInfo const&, uint32&, int32&>,
"OnCalculateResistAbsorbHandler signature must be \"void CalcAbsorbResist(DamageInfo const& damageInfo, uint32& resistAmount, int32& absorbAmount)\"");
_callImpl = { .Member = reinterpret_cast<decltype(SpellOnResistAbsorbCalculateFnType::Member)>(handler) };
_safeWrapper = [](SpellScript* spellScript, DamageInfo const& damageInfo, uint32& resistAmount, int32& absorbAmount, SpellOnResistAbsorbCalculateFnType callImpl) -> void
{
return (static_cast<ScriptClass*>(spellScript)->*reinterpret_cast<ScriptFunc>(callImpl.Member))(damageInfo, resistAmount, absorbAmount);
};
}
else
{
static_assert(std::is_invocable_r_v<void, ScriptFunc, DamageInfo const&, uint32&, int32&>,
"OnCalculateResistAbsorbHandler signature must be \"static void CalcAbsorbResist(DamageInfo const& damageInfo, uint32& resistAmount, int32& absorbAmount)\"");
_callImpl = { .Static = reinterpret_cast<decltype(SpellOnResistAbsorbCalculateFnType::Static)>(handler) };
_safeWrapper = [](SpellScript* /*spellScript*/, DamageInfo const& damageInfo, uint32& resistAmount, int32& absorbAmount, SpellOnResistAbsorbCalculateFnType callImpl) -> void
{
return reinterpret_cast<ScriptFunc>(callImpl.Static)(damageInfo, resistAmount, absorbAmount);
};
}
}
void Call(SpellScript* spellScript, DamageInfo const& damageInfo, uint32& resistAmount, int32& absorbAmount) const
{
return _safeWrapper(spellScript, damageInfo, resistAmount, absorbAmount, _callImpl);
}
private:
SpellOnResistAbsorbCalculateFnType _callImpl;
SafeWrapperType _safeWrapper;
};
// left for custom compatibility only, DO NOT USE
#define PrepareSpellScript(CLASSNAME)
SpellScript();
~SpellScript();
bool _Validate(SpellInfo const* entry) override;
bool _Load(Spell* spell);
void _InitHit();
bool _IsEffectPrevented(SpellEffIndex effIndex) const { return (m_hitPreventEffectMask & (1 << effIndex)) != 0; }
bool _IsDefaultEffectPrevented(SpellEffIndex effIndex) const { return (m_hitPreventDefaultEffectMask & (1 << effIndex)) != 0; }
void _PrepareScriptCall(SpellScriptHookType hookType);
void _FinishScriptCall();
bool IsInCheckCastHook() const;
bool IsAfterTargetSelectionPhase() const;
bool IsInTargetHook() const;
bool IsInModifiableHook() const;
bool IsInHitPhase() const;
bool IsInEffectHook() const;
private:
Spell* m_spell;
uint32 m_hitPreventEffectMask;
uint32 m_hitPreventDefaultEffectMask;
public:
//
// SpellScript interface
//
// example: void OnPrecast() override { }
virtual void OnPrecast() { }
//
// hooks to which you can attach your functions
//
// example: BeforeCast += SpellCastFn(class::function);
HookList<CastHandler> BeforeCast;
// example: OnCast += SpellCastFn(class::function);
HookList<CastHandler> OnCast;
// example: AfterCast += SpellCastFn(class::function);
HookList<CastHandler> AfterCast;
#define SpellCastFn(F) CastHandler(&F)
// example: OnCheckCast += SpellCheckCastFn();
// where function is SpellCastResult function()
HookList<CheckCastHandler> OnCheckCast;
#define SpellCheckCastFn(F) CheckCastHandler(&F)
// example: int32 CalcCastTime(int32 castTime) override { return 1500; }
virtual int32 CalcCastTime(int32 castTime) { return castTime; }
// example: OnEffect**** += SpellEffectFn(class::function, EffectIndexSpecifier, EffectNameSpecifier);
// where function is void function(SpellEffIndex effIndex)
HookList<EffectHandler> OnEffectLaunch;
HookList<EffectHandler> OnEffectLaunchTarget;
HookList<EffectHandler> OnEffectHit;
HookList<EffectHandler> OnEffectHitTarget;
HookList<EffectHandler> OnEffectSuccessfulDispel;
#define SpellEffectFn(F, I, N) EffectHandler(&F, I, N)
// example: BeforeHit += BeforeSpellHitFn(class::function);
// where function is void function(SpellMissInfo missInfo)
HookList<BeforeHitHandler> BeforeHit;
#define BeforeSpellHitFn(F) BeforeHitHandler(&F)
// example: OnHit += SpellHitFn(class::function);
HookList<HitHandler> OnHit;
// example: AfterHit += SpellHitFn(class::function);
HookList<HitHandler> AfterHit;
// where function is: void function()
#define SpellHitFn(F) HitHandler(&F)
// example: OnCalcCritChance += SpellOnCalcCritChanceFn(class::function);
// where function is: void function(Unit* victim, float& critChance)
HookList<OnCalcCritChanceHandler> OnCalcCritChance;
#define SpellOnCalcCritChanceFn(F) OnCalcCritChanceHandler(&F)
// example: OnObjectAreaTargetSelect += SpellObjectAreaTargetSelectFn(class::function, EffectIndexSpecifier, TargetsNameSpecifier);
// where function is void function(std::list<WorldObject*>& targets)
HookList<ObjectAreaTargetSelectHandler> OnObjectAreaTargetSelect;
#define SpellObjectAreaTargetSelectFn(F, I, N) ObjectAreaTargetSelectHandler(&F, I, N)
// example: OnObjectTargetSelect += SpellObjectTargetSelectFn(class::function, EffectIndexSpecifier, TargetsNameSpecifier);
// where function is void function(WorldObject*& target)
HookList<ObjectTargetSelectHandler> OnObjectTargetSelect;
#define SpellObjectTargetSelectFn(F, I, N) ObjectTargetSelectHandler(&F, I, N)
// example: OnDestinationTargetSelect += SpellDestinationTargetSelectFn(class::function, EffectIndexSpecifier, TargetsNameSpecifier);
// where function is void function(SpellDestination& target)
HookList<DestinationTargetSelectHandler> OnDestinationTargetSelect;
#define SpellDestinationTargetSelectFn(F, I, N) DestinationTargetSelectHandler(&F, I, N)
// example: CalcDamage += SpellCalcDamageFn(class::function);
// where function is void function(SpellEffectInfo const& effectInfo, Unit* victim, int32& damage, int32& flatMod, float& pctMod)
HookList<DamageAndHealingCalcHandler> CalcDamage;
#define SpellCalcDamageFn(F) DamageAndHealingCalcHandler(&F)
// example: CalcHealing += SpellCalcHealingFn(class::function);
// where function is void function(SpellEffectInfo const& effectInfo, Unit* victim, int32& healing, int32& flatMod, float& pctMod)
HookList<DamageAndHealingCalcHandler> CalcHealing;
#define SpellCalcHealingFn(F) DamageAndHealingCalcHandler(&F)
// example: OnCalculateResistAbsorb += SpellOnResistAbsorbCalculateFn(class::function);
// where function is void function(DamageInfo const& damageInfo, uint32& resistAmount, int32& absorbAmount)
HookList<OnCalculateResistAbsorbHandler> OnCalculateResistAbsorb;
#define SpellOnResistAbsorbCalculateFn(F) OnCalculateResistAbsorbHandler(&F)
// hooks are executed in following order, at specified event of spell:
// 1. OnPrecast - executed during spell preparation (before cast bar starts)
// 2. BeforeCast - executed when spell preparation is finished (when cast bar becomes full) before cast is handled
// 3. OnCheckCast - allows to override result of CheckCast function
// 4a. OnObjectAreaTargetSelect - executed just before adding selected targets to final target list (for area targets)
// 4b. OnObjectTargetSelect - executed just before adding selected target to final target list (for single unit targets)
// 4c. OnDestinationTargetSelect - executed just before adding selected target to final target list (for destination targets)
// 5. OnCast - executed just before spell is launched (creates missile) or executed
// 6. AfterCast - executed after spell missile is launched and immediate spell actions are done
// 7. OnEffectLaunch - executed just before specified effect handler call - when spell missile is launched
// 8. OnCalcCritChance - executed just after specified effect handler call - when spell missile is launched - called for each target from spell target map
// 9. OnEffectLaunchTarget - executed just before specified effect handler call - when spell missile is launched - called for each target from spell target map
// 10a. CalcDamage - executed during specified effect handler call - when spell missile is launched - called for each target from spell target map
// 10b. CalcHealing - executed during specified effect handler call - when spell missile is launched - called for each target from spell target map
// 11. OnCalculateResistAbsorb - executed when damage resist/absorbs is calculated - before spell hit target
// 12. OnEffectHit - executed just before specified effect handler call - when spell missile hits dest
// 13. BeforeHit - executed just before spell hits a target - called for each target from spell target map
// 14. OnEffectHitTarget - executed just before specified effect handler call - called for each target from spell target map
// 15. OnHit - executed just before spell deals damage and procs auras - when spell hits target - called for each target from spell target map
// 16. AfterHit - executed just after spell finishes all it's jobs for target - called for each target from spell target map
// this hook is only executed after a successful dispel of any aura
// OnEffectSuccessfulDispel - executed just after effect successfully dispelled aura(s)
//
// methods allowing interaction with Spell object
//
// methods useable during all spell handling phases
Unit* GetCaster() const;
GameObject* GetGObjCaster() const;
Unit* GetOriginalCaster() const;
SpellInfo const* GetSpellInfo() const;
SpellEffectInfo const& GetEffectInfo(SpellEffIndex effIndex) const;
SpellValue const* GetSpellValue() const;
// methods useable after spell is prepared
// accessors to the explicit targets of the spell
// explicit target - target selected by caster (player, game client, or script - DoCast(explicitTarget, ...), required for spell to be cast
// examples:
// -shadowstep - explicit target is the unit you want to go behind of
// -chain heal - explicit target is the unit to be healed first
// -holy nova/arcane explosion - explicit target = NULL because target you are selecting doesn't affect how spell targets are selected
// you can determine if spell requires explicit targets by dbc columns:
// - Targets - mask of explicit target types
// - ImplicitTargetXX set to TARGET_XXX_TARGET_YYY, _TARGET_ here means that explicit target is used by the effect, so spell needs one too
// returns: WorldLocation which was selected as a spell destination or NULL
WorldLocation const* GetExplTargetDest() const;
void SetExplTargetDest(WorldLocation const& loc);
// returns: WorldObject which was selected as an explicit spell target or NULL if there's no target
WorldObject* GetExplTargetWorldObject() const;
// returns: Unit which was selected as an explicit spell target or NULL if there's no target
Unit* GetExplTargetUnit() const;
// returns: GameObject which was selected as an explicit spell target or NULL if there's no target
GameObject* GetExplTargetGObj() const;
// returns: Item which was selected as an explicit spell target or NULL if there's no target
Item* GetExplTargetItem() const;
// methods usable only after spell targets have been fully selected
int64 GetUnitTargetCountForEffect(SpellEffIndex effect) const;
int64 GetGameObjectTargetCountForEffect(SpellEffIndex effect) const;
int64 GetItemTargetCountForEffect(SpellEffIndex effect) const;
int64 GetCorpseTargetCountForEffect(SpellEffIndex effect) const;
// methods useable only during spell hit on target, or during spell launch on target:
// returns: target of current effect if it was Unit otherwise NULL
Unit* GetHitUnit() const;
// returns: target of current effect if it was Creature otherwise NULL
Creature* GetHitCreature() const;
// returns: target of current effect if it was Player otherwise NULL
Player* GetHitPlayer() const;
// returns: target of current effect if it was Item otherwise NULL
Item* GetHitItem() const;
// returns: target of current effect if it was GameObject otherwise NULL
GameObject* GetHitGObj() const;
// returns: target of current effect if it was Corpse otherwise nullptr
Corpse* GetHitCorpse() const;
// returns: destination of current effect
WorldLocation* GetHitDest() const;
// setter/getter for for damage done by spell to target of spell hit
// returns damage calculated before hit, and real dmg done after hit
int32 GetHitDamage() const;
void SetHitDamage(int32 damage);
void PreventHitDamage() { SetHitDamage(0); }
// setter/getter for for heal done by spell to target of spell hit
// returns healing calculated before hit, and real dmg done after hit
int32 GetHitHeal() const;
void SetHitHeal(int32 heal);
void PreventHitHeal() { SetHitHeal(0); }
// returns: true if spell critically hits current HitUnit
bool IsHitCrit() const;
Spell* GetSpell() const { return m_spell; }
// returns current spell hit target aura
Aura* GetHitAura(bool dynObjAura = false) const;
// prevents applying aura on current spell hit target
void PreventHitAura();
// prevents effect execution on current spell hit target
// including other effect/hit scripts
// will not work on aura/damage/heal
// will not work if effects were already handled
void PreventHitEffect(SpellEffIndex effIndex);
// prevents default effect execution on current spell hit target
// will not work on aura/damage/heal effects
// will not work if effects were already handled
void PreventHitDefaultEffect(SpellEffIndex effIndex);
// method available only in EffectHandler method
SpellEffectInfo const& GetEffectInfo() const;
int32 GetEffectValue() const;
void SetEffectValue(int32 value);
float GetEffectVariance() const;
void SetEffectVariance(float variance);
// returns: cast item if present.
Item* GetCastItem() const;
// Creates item. Calls Spell::DoCreateItem method.
void CreateItem(uint32 itemId, ItemContext context);
// Returns SpellInfo from the spell that triggered the current one
SpellInfo const* GetTriggeringSpell() const;
// finishes spellcast prematurely with selected error message
void FinishCast(SpellCastResult result, int32* param1 = nullptr, int32* param2 = nullptr);
void SetCustomCastResultMessage(SpellCustomErrors result);
// returns desired cast difficulty for triggered spells
Difficulty GetCastDifficulty() const;
};
// AuraScript interface - enum used for runtime checks of script function calls
enum AuraScriptHookType
{
AURA_SCRIPT_HOOK_EFFECT_APPLY = SPELL_SCRIPT_STATE_END,
AURA_SCRIPT_HOOK_EFFECT_AFTER_APPLY,
AURA_SCRIPT_HOOK_EFFECT_REMOVE,
AURA_SCRIPT_HOOK_EFFECT_AFTER_REMOVE,
AURA_SCRIPT_HOOK_EFFECT_PERIODIC,
AURA_SCRIPT_HOOK_EFFECT_UPDATE_PERIODIC,
AURA_SCRIPT_HOOK_EFFECT_CALC_AMOUNT,
AURA_SCRIPT_HOOK_EFFECT_CALC_PERIODIC,
AURA_SCRIPT_HOOK_EFFECT_CALC_SPELLMOD,
AURA_SCRIPT_HOOK_EFFECT_CALC_CRIT_CHANCE,
AURA_SCRIPT_HOOK_EFFECT_CALC_DAMAGE_AND_HEALING,
AURA_SCRIPT_HOOK_EFFECT_ABSORB,
AURA_SCRIPT_HOOK_EFFECT_AFTER_ABSORB,
AURA_SCRIPT_HOOK_EFFECT_MANASHIELD,
AURA_SCRIPT_HOOK_EFFECT_AFTER_MANASHIELD,
AURA_SCRIPT_HOOK_EFFECT_SPLIT,
AURA_SCRIPT_HOOK_CHECK_AREA_TARGET,
AURA_SCRIPT_HOOK_DISPEL,
AURA_SCRIPT_HOOK_AFTER_DISPEL,
AURA_SCRIPT_HOOK_ON_HEARTBEAT,
AURA_SCRIPT_HOOK_ENTER_LEAVE_COMBAT,
// Spell Proc Hooks
AURA_SCRIPT_HOOK_CHECK_PROC,
AURA_SCRIPT_HOOK_CHECK_EFFECT_PROC,
AURA_SCRIPT_HOOK_PREPARE_PROC,
AURA_SCRIPT_HOOK_PROC,
AURA_SCRIPT_HOOK_EFFECT_PROC,
AURA_SCRIPT_HOOK_EFFECT_AFTER_PROC,
AURA_SCRIPT_HOOK_AFTER_PROC,
/*AURA_SCRIPT_HOOK_APPLY,
AURA_SCRIPT_HOOK_REMOVE, */
};
/*
#define HOOK_AURA_EFFECT_START HOOK_AURA_EFFECT_APPLY
#define HOOK_AURA_EFFECT_END HOOK_AURA_EFFECT_CALC_SPELLMOD + 1
#define HOOK_AURA_EFFECT_COUNT HOOK_AURA_EFFECT_END - HOOK_AURA_EFFECT_START
*/
class TC_GAME_API AuraScript : public SpellScriptBase
{
// internal use classes & functions
// DO NOT OVERRIDE THESE IN SCRIPTS
public:
class CheckAreaTargetHandler final
{
public:
union AuraCheckAreaTargetFnType
{
bool(AuraScript::* Member)(Unit* target);
bool(*Static)(Unit* target);
};
using SafeWrapperType = bool(*)(AuraScript* auraScript, Unit* target, AuraCheckAreaTargetFnType callImpl);
template<typename ScriptFunc>
explicit CheckAreaTargetHandler(ScriptFunc handler)
{
using ScriptClass = GetScriptClass_t<ScriptFunc>;
static_assert(sizeof(AuraCheckAreaTargetFnType) >= sizeof(ScriptFunc));
static_assert(alignof(AuraCheckAreaTargetFnType) >= alignof(ScriptFunc));
if constexpr (!std::is_void_v<ScriptClass>)
{
static_assert(std::is_invocable_r_v<bool, ScriptFunc, ScriptClass, Unit*>,
"CheckAreaTargetHandler signature must be \"bool CheckTarget(Unit* target)\"");
_callImpl = { .Member = reinterpret_cast<decltype(AuraCheckAreaTargetFnType::Member)>(handler) };
_safeWrapper = [](AuraScript* auraScript, Unit* target, AuraCheckAreaTargetFnType callImpl) -> bool
{
return (static_cast<ScriptClass*>(auraScript)->*reinterpret_cast<ScriptFunc>(callImpl.Member))(target);
};
}
else
{
static_assert(std::is_invocable_r_v<bool, ScriptFunc, Unit*>,
"CheckAreaTargetHandler signature must be \"static bool CheckTarget(Unit* target)\"");
_callImpl = { .Static = reinterpret_cast<decltype(AuraCheckAreaTargetFnType::Static)>(handler) };
_safeWrapper = [](AuraScript* /*auraScript*/, Unit* target, AuraCheckAreaTargetFnType callImpl) -> bool
{
return reinterpret_cast<ScriptFunc>(callImpl.Static)(target);
};
}
}
bool Call(AuraScript* auraScript, Unit* target) const
{
return _safeWrapper(auraScript, target, _callImpl);
}
private:
AuraCheckAreaTargetFnType _callImpl;
SafeWrapperType _safeWrapper;
};
class AuraDispelHandler final
{
public:
union AuraDispelFnType
{
void(AuraScript::* Member)(DispelInfo* dispelInfo);
void(*Static)(DispelInfo* dispelInfo);
};
using SafeWrapperType = void(*)(AuraScript* auraScript, DispelInfo* dispelInfo, AuraDispelFnType callImpl);
template<typename ScriptFunc>
explicit AuraDispelHandler(ScriptFunc handler)
{
using ScriptClass = GetScriptClass_t<ScriptFunc>;
static_assert(sizeof(AuraDispelFnType) >= sizeof(ScriptFunc));
static_assert(alignof(AuraDispelFnType) >= alignof(ScriptFunc));
if constexpr (!std::is_void_v<ScriptClass>)
{
static_assert(std::is_invocable_r_v<void, ScriptFunc, ScriptClass, DispelInfo*>,
"AuraDispelHandler signature must be \"void HandleDispel(DispelInfo* dispelInfo)\"");
_callImpl = { .Member = reinterpret_cast<decltype(AuraDispelFnType::Member)>(handler) };
_safeWrapper = [](AuraScript* auraScript, DispelInfo* dispelInfo, AuraDispelFnType callImpl) -> void
{
return (static_cast<ScriptClass*>(auraScript)->*reinterpret_cast<ScriptFunc>(callImpl.Member))(dispelInfo);
};
}
else
{
static_assert(std::is_invocable_r_v<void, ScriptFunc, DispelInfo*>,
"AuraDispelHandler signature must be \"static void HandleDispel(DispelInfo* dispelInfo)\"");
_callImpl = { .Static = reinterpret_cast<decltype(AuraDispelFnType::Static)>(handler) };
_safeWrapper = [](AuraScript* /*auraScript*/, DispelInfo* dispelInfo, AuraDispelFnType callImpl) -> void
{
return reinterpret_cast<ScriptFunc>(callImpl.Static)(dispelInfo);
};
}
}
void Call(AuraScript* auraScript, DispelInfo* dispelInfo) const
{
return _safeWrapper(auraScript, dispelInfo, _callImpl);
}
private:
AuraDispelFnType _callImpl;
SafeWrapperType _safeWrapper;
};
class AuraHeartbeatHandler final
{
public:
union AuraHeartbeatFnType
{
void(AuraScript::* Member)();
void(*Static)();
};
using SafeWrapperType = void(*)(AuraScript* auraScript, AuraHeartbeatFnType callImpl);
template<typename ScriptFunc>
explicit AuraHeartbeatHandler(ScriptFunc handler)
{
using ScriptClass = GetScriptClass_t<ScriptFunc>;
static_assert(sizeof(AuraHeartbeatFnType) >= sizeof(ScriptFunc));
static_assert(alignof(AuraHeartbeatFnType) >= alignof(ScriptFunc));
if constexpr (!std::is_void_v<ScriptClass>)
{
static_assert(std::is_invocable_r_v<void, ScriptFunc, ScriptClass>,
"AuraHeartbeat signature must be \"void HandleHeartbeat()\"");
_callImpl = { .Member = reinterpret_cast<decltype(AuraHeartbeatFnType::Member)>(handler) };
_safeWrapper = [](AuraScript* auraScript, AuraHeartbeatFnType callImpl) -> void
{
return (static_cast<ScriptClass*>(auraScript)->*reinterpret_cast<ScriptFunc>(callImpl.Member))();
};
}
else
{
static_assert(std::is_invocable_r_v<void, ScriptFunc>,
"AuraHeartbeatHandler signature must be \"static void HandleHeartbeat()\"");
_callImpl = { .Static = reinterpret_cast<decltype(AuraHeartbeatFnType::Static)>(handler) };
_safeWrapper = [](AuraScript* /*auraScript*/, AuraHeartbeatFnType callImpl) -> void
{
return reinterpret_cast<ScriptFunc>(callImpl.Static)();
};
}
}
void Call(AuraScript* auraScript) const
{
return _safeWrapper(auraScript, _callImpl);
}
private:
AuraHeartbeatFnType _callImpl;
SafeWrapperType _safeWrapper;
};
class TC_GAME_API EffectBase : public EffectHook
{
public:
EffectBase(uint8 effIndex, uint16 auraType);
EffectBase(EffectBase const& right) = delete;
EffectBase(EffectBase&& right) noexcept;
EffectBase& operator=(EffectBase const& right) = delete;
EffectBase& operator=(EffectBase&& right) noexcept;
virtual ~EffectBase();
std::string ToString() const;
bool CheckEffect(SpellInfo const* spellInfo, uint8 effIndex) const override;
private:
uint16 _auraType;
};
class EffectPeriodicHandler final : public EffectBase
{
public:
union AuraEffectPeriodicFnType
{
void(AuraScript::* Member)(AuraEffect const* aurEff);
void(*Static)(AuraEffect const* aurEff);
};
using SafeWrapperType = void(*)(AuraScript* auraScript, AuraEffect const* aurEff, AuraEffectPeriodicFnType callImpl);
template<typename ScriptFunc>
explicit EffectPeriodicHandler(ScriptFunc handler, uint8 effIndex, uint16 auraType)
: EffectBase(effIndex, auraType)
{
using ScriptClass = GetScriptClass_t<ScriptFunc>;
static_assert(sizeof(AuraEffectPeriodicFnType) >= sizeof(ScriptFunc));
static_assert(alignof(AuraEffectPeriodicFnType) >= alignof(ScriptFunc));
if constexpr (!std::is_void_v<ScriptClass>)
{
static_assert(std::is_invocable_r_v<void, ScriptFunc, ScriptClass, AuraEffect const*>,
"EffectPeriodicHandler signature must be \"void HandlePeriodic(AuraEffect const* aurEff)\"");
_callImpl = { .Member = reinterpret_cast<decltype(AuraEffectPeriodicFnType::Member)>(handler) };
_safeWrapper = [](AuraScript* auraScript, AuraEffect const* aurEff, AuraEffectPeriodicFnType callImpl) -> void
{
return (static_cast<ScriptClass*>(auraScript)->*reinterpret_cast<ScriptFunc>(callImpl.Member))(aurEff);
};
}
else
{
static_assert(std::is_invocable_r_v<void, ScriptFunc, AuraEffect const*>,
"EffectPeriodicHandler signature must be \"static void HandlePeriodic(AuraEffect const* aurEff)\"");
_callImpl = { .Static = reinterpret_cast<decltype(AuraEffectPeriodicFnType::Static)>(handler) };
_safeWrapper = [](AuraScript* /*auraScript*/, AuraEffect const* aurEff, AuraEffectPeriodicFnType callImpl) -> void
{
return reinterpret_cast<ScriptFunc>(callImpl.Static)(aurEff);
};
}
}
void Call(AuraScript* auraScript, AuraEffect const* aurEff) const
{
return _safeWrapper(auraScript, aurEff, _callImpl);
}
private:
AuraEffectPeriodicFnType _callImpl;
SafeWrapperType _safeWrapper;
};
class EffectUpdatePeriodicHandler final : public EffectBase
{
public:
union AuraEffectUpdatePeriodicFnType
{
void(AuraScript::* Member)(AuraEffect* aurEff);
void(*Static)(AuraEffect* aurEff);
};
using SafeWrapperType = void(*)(AuraScript* auraScript, AuraEffect* aurEff, AuraEffectUpdatePeriodicFnType callImpl);
template<typename ScriptFunc>
explicit EffectUpdatePeriodicHandler(ScriptFunc handler, uint8 effIndex, uint16 auraType)
: EffectBase(effIndex, auraType)
{
using ScriptClass = GetScriptClass_t<ScriptFunc>;
static_assert(sizeof(AuraEffectUpdatePeriodicFnType) >= sizeof(ScriptFunc));
static_assert(alignof(AuraEffectUpdatePeriodicFnType) >= alignof(ScriptFunc));
if constexpr (!std::is_void_v<ScriptClass>)
{
static_assert(std::is_invocable_r_v<void, ScriptFunc, ScriptClass, AuraEffect*>,
"EffectUpdatePeriodicHandler signature must be \"void HandleUpdatePeriodic(AuraEffect* aurEff)\"");
_callImpl = { .Member = reinterpret_cast<decltype(AuraEffectUpdatePeriodicFnType::Member)>(handler) };
_safeWrapper = [](AuraScript* auraScript, AuraEffect* aurEff, AuraEffectUpdatePeriodicFnType callImpl) -> void
{
return (static_cast<ScriptClass*>(auraScript)->*reinterpret_cast<ScriptFunc>(callImpl.Member))(aurEff);
};
}
else
{
static_assert(std::is_invocable_r_v<void, ScriptFunc, AuraEffect*>,
"EffectUpdatePeriodicHandler signature must be \"static void HandleUpdatePeriodic(AuraEffect* aurEff)\"");
_callImpl = { .Static = reinterpret_cast<decltype(AuraEffectUpdatePeriodicFnType::Static)>(handler) };
_safeWrapper = [](AuraScript* /*auraScript*/, AuraEffect* aurEff, AuraEffectUpdatePeriodicFnType callImpl) -> void
{
return reinterpret_cast<ScriptFunc>(callImpl.Static)(aurEff);
};
}
}
void Call(AuraScript* auraScript, AuraEffect* aurEff) const
{
return _safeWrapper(auraScript, aurEff, _callImpl);
}
private:
AuraEffectUpdatePeriodicFnType _callImpl;
SafeWrapperType _safeWrapper;
};
class EffectCalcAmountHandler final : public EffectBase
{
public:
union AuraEffectCalcAmountFnType
{
void(AuraScript::* Member)(AuraEffect const* aurEff, int32& amount, bool& canBeRecalculated);
void(*Static)(AuraEffect const* aurEff, int32& amount, bool& canBeRecalculated);
};
using SafeWrapperType = void(*)(AuraScript* auraScript, AuraEffect const* aurEff, int32& amount, bool& canBeRecalculated, AuraEffectCalcAmountFnType callImpl);
template<typename ScriptFunc>
explicit EffectCalcAmountHandler(ScriptFunc handler, uint8 effIndex, uint16 auraType)
: EffectBase(effIndex, auraType)
{
using ScriptClass = GetScriptClass_t<ScriptFunc>;
static_assert(sizeof(AuraEffectCalcAmountFnType) >= sizeof(ScriptFunc));
static_assert(alignof(AuraEffectCalcAmountFnType) >= alignof(ScriptFunc));
if constexpr (!std::is_void_v<ScriptClass>)
{
static_assert(std::is_invocable_r_v<void, ScriptFunc, ScriptClass, AuraEffect const*, int32&, bool&>,
"EffectCalcAmountHandler signature must be \"void CalcAmount(AuraEffect const* aurEff, int32& amount, bool& canBeRecalculated)\"");
_callImpl = { .Member = reinterpret_cast<decltype(AuraEffectCalcAmountFnType::Member)>(handler) };
_safeWrapper = [](AuraScript* auraScript, AuraEffect const* aurEff, int32& amount, bool& canBeRecalculated, AuraEffectCalcAmountFnType callImpl) -> void
{
return (static_cast<ScriptClass*>(auraScript)->*reinterpret_cast<ScriptFunc>(callImpl.Member))(aurEff, amount, canBeRecalculated);
};
}
else
{
static_assert(std::is_invocable_r_v<void, ScriptFunc, AuraEffect const*, int32&, bool&>,
"EffectCalcAmountHandler signature must be \"static void CalcAmount(AuraEffect const* aurEff, int32& amount, bool& canBeRecalculated)\"");
_callImpl = { .Static = reinterpret_cast<decltype(AuraEffectCalcAmountFnType::Static)>(handler) };
_safeWrapper = [](AuraScript* /*auraScript*/, AuraEffect const* aurEff, int32& amount, bool& canBeRecalculated, AuraEffectCalcAmountFnType callImpl) -> void
{
return reinterpret_cast<ScriptFunc>(callImpl.Static)(aurEff, amount, canBeRecalculated);
};
}
}
void Call(AuraScript* auraScript, AuraEffect const* aurEff, int32& amount, bool& canBeRecalculated) const
{
return _safeWrapper(auraScript, aurEff, amount, canBeRecalculated, _callImpl);
}
private:
AuraEffectCalcAmountFnType _callImpl;
SafeWrapperType _safeWrapper;
};
class EffectCalcPeriodicHandler final : public EffectBase
{
public:
union AuraEffectCalcPeriodicFnType
{
void(AuraScript::* Member)(AuraEffect const* aurEff, bool& isPeriodic, int32& periodicTimer);
void(*Static)(AuraEffect const* aurEff, bool& isPeriodic, int32& periodicTimer);
};
using SafeWrapperType = void(*)(AuraScript* auraScript, AuraEffect const* aurEff, bool& isPeriodic, int32& periodicTimer, AuraEffectCalcPeriodicFnType callImpl);
template<typename ScriptFunc>
explicit EffectCalcPeriodicHandler(ScriptFunc handler, uint8 effIndex, uint16 auraType)
: EffectBase(effIndex, auraType)
{
using ScriptClass = GetScriptClass_t<ScriptFunc>;
static_assert(sizeof(AuraEffectCalcPeriodicFnType) >= sizeof(ScriptFunc));
static_assert(alignof(AuraEffectCalcPeriodicFnType) >= alignof(ScriptFunc));
if constexpr (!std::is_void_v<ScriptClass>)
{
static_assert(std::is_invocable_r_v<void, ScriptFunc, ScriptClass, AuraEffect const*, bool&, int32&>,
"EffectCalcPeriodicHandler signature must be \"void CalcPeriodic(AuraEffect const* aurEff, bool& isPeriodic, int32& periodicTimer)\"");
_callImpl = { .Member = reinterpret_cast<decltype(AuraEffectCalcPeriodicFnType::Member)>(handler) };
_safeWrapper = [](AuraScript* auraScript, AuraEffect const* aurEff, bool& isPeriodic, int32& periodicTimer, AuraEffectCalcPeriodicFnType callImpl) -> void
{
return (static_cast<ScriptClass*>(auraScript)->*reinterpret_cast<ScriptFunc>(callImpl.Member))(aurEff, isPeriodic, periodicTimer);
};
}
else
{
static_assert(std::is_invocable_r_v<void, ScriptFunc, AuraEffect const*, bool&, int32&>,
"EffectCalcPeriodicHandler signature must be \"static void CalcPeriodic(AuraEffect const* aurEff, bool& isPeriodic, int32& periodicTimer)\"");
_callImpl = { .Static = reinterpret_cast<decltype(AuraEffectCalcPeriodicFnType::Static)>(handler) };
_safeWrapper = [](AuraScript* /*auraScript*/, AuraEffect const* aurEff, bool& isPeriodic, int32& periodicTimer, AuraEffectCalcPeriodicFnType callImpl) -> void
{
return reinterpret_cast<ScriptFunc>(callImpl.Static)(aurEff, isPeriodic, periodicTimer);
};
}
}
void Call(AuraScript* auraScript, AuraEffect const* aurEff, bool& isPeriodic, int32& periodicTimer) const
{
return _safeWrapper(auraScript, aurEff, isPeriodic, periodicTimer, _callImpl);
}
private:
AuraEffectCalcPeriodicFnType _callImpl;
SafeWrapperType _safeWrapper;
};
class EffectCalcSpellModHandler final : public EffectBase
{
public:
union AuraEffectCalcSpellModFnType
{
void(AuraScript::* Member)(AuraEffect const* aurEff, SpellModifier*& spellMod);
void(*Static)(AuraEffect const* aurEff, SpellModifier*& spellMod);
};
using SafeWrapperType = void(*)(AuraScript* auraScript, AuraEffect const* aurEff, SpellModifier*& spellMod, AuraEffectCalcSpellModFnType callImpl);
template<typename ScriptFunc>
explicit EffectCalcSpellModHandler(ScriptFunc handler, uint8 effIndex, uint16 auraType)
: EffectBase(effIndex, auraType)
{
using ScriptClass = GetScriptClass_t<ScriptFunc>;
static_assert(sizeof(AuraEffectCalcSpellModFnType) >= sizeof(ScriptFunc));
static_assert(alignof(AuraEffectCalcSpellModFnType) >= alignof(ScriptFunc));
if constexpr (!std::is_void_v<ScriptClass>)
{
static_assert(std::is_invocable_r_v<void, ScriptFunc, ScriptClass, AuraEffect const*, SpellModifier*&>,
"EffectCalcSpellModHandler signature must be \"void CalcSpellMod(AuraEffect const* aurEff, SpellModifier*& spellMod)\"");
_callImpl = { .Member = reinterpret_cast<decltype(AuraEffectCalcSpellModFnType::Member)>(handler) };
_safeWrapper = [](AuraScript* auraScript, AuraEffect const* aurEff, SpellModifier*& spellMod, AuraEffectCalcSpellModFnType callImpl) -> void
{
return (static_cast<ScriptClass*>(auraScript)->*reinterpret_cast<ScriptFunc>(callImpl.Member))(aurEff, spellMod);
};
}
else
{
static_assert(std::is_invocable_r_v<void, ScriptFunc, AuraEffect const*, SpellModifier*&>,
"EffectCalcSpellModHandler signature must be \"static void CalcSpellMod(AuraEffect const* aurEff, SpellModifier*& spellMod)\"");
_callImpl = { .Static = reinterpret_cast<decltype(AuraEffectCalcSpellModFnType::Static)>(handler) };
_safeWrapper = [](AuraScript* /*auraScript*/, AuraEffect const* aurEff, SpellModifier*& spellMod, AuraEffectCalcSpellModFnType callImpl) -> void
{
return reinterpret_cast<ScriptFunc>(callImpl.Static)(aurEff, spellMod);
};
}
}
void Call(AuraScript* auraScript, AuraEffect const* aurEff, SpellModifier*& spellMod) const
{
return _safeWrapper(auraScript, aurEff, spellMod, _callImpl);
}
private:
AuraEffectCalcSpellModFnType _callImpl;
SafeWrapperType _safeWrapper;
};
class EffectCalcCritChanceHandler final : public EffectBase
{
public:
union AuraEffectCalcCritChanceFnType
{
void(AuraScript::* Member)(AuraEffect const* aurEff, Unit const* victim, float& critChance);
void(*Static)(AuraEffect const* aurEff, Unit const* victim, float& critChance);
};
using SafeWrapperType = void(*)(AuraScript* auraScript, AuraEffect const* aurEff, Unit const* victim, float& critChance, AuraEffectCalcCritChanceFnType callImpl);
template<typename ScriptFunc>
explicit EffectCalcCritChanceHandler(ScriptFunc handler, uint8 effIndex, uint16 auraType)
: EffectBase(effIndex, auraType)
{
using ScriptClass = GetScriptClass_t<ScriptFunc>;
static_assert(sizeof(AuraEffectCalcCritChanceFnType) >= sizeof(ScriptFunc));
static_assert(alignof(AuraEffectCalcCritChanceFnType) >= alignof(ScriptFunc));
if constexpr (!std::is_void_v<ScriptClass>)
{
static_assert(std::is_invocable_r_v<void, ScriptFunc, ScriptClass, AuraEffect const*, Unit const*, float&>,
"EffectCalcCritChanceHandler signature must be \"void CalcCritChance(AuraEffect const* aurEff, Unit const* victim, float& critChance)\"");
_callImpl = { .Member = reinterpret_cast<decltype(AuraEffectCalcCritChanceFnType::Member)>(handler) };
_safeWrapper = [](AuraScript* auraScript, AuraEffect const* aurEff, Unit const* victim, float& critChance, AuraEffectCalcCritChanceFnType callImpl) -> void
{
return (static_cast<ScriptClass*>(auraScript)->*reinterpret_cast<ScriptFunc>(callImpl.Member))(aurEff, victim, critChance);
};
}
else
{
static_assert(std::is_invocable_r_v<void, ScriptFunc, AuraEffect const*, Unit const*, float&>,
"EffectCalcCritChanceHandler signature must be \"static void CalcCritChance(AuraEffect const* aurEff, Unit const* victim, float& critChance)\"");
_callImpl = { .Static = reinterpret_cast<decltype(AuraEffectCalcCritChanceFnType::Static)>(handler) };
_safeWrapper = [](AuraScript* /*auraScript*/, AuraEffect const* aurEff, Unit const* victim, float& critChance, AuraEffectCalcCritChanceFnType callImpl) -> void
{
return reinterpret_cast<ScriptFunc>(callImpl.Static)(aurEff, victim, critChance);
};
}
}
void Call(AuraScript* auraScript, AuraEffect const* aurEff, Unit const* victim, float& critChance) const
{
return _safeWrapper(auraScript, aurEff, victim, critChance, _callImpl);
}
private:
AuraEffectCalcCritChanceFnType _callImpl;
SafeWrapperType _safeWrapper;
};
class EffectCalcDamageAndHealingHandler final : public EffectBase
{
public:
union AuraEffectDamageAndHealingCalcFnType
{
void(AuraScript::* Member)(AuraEffect const* aurEff, Unit* victim, int32& damageOrHealing, int32& flatMod, float& pctMod);
void(*Static)(AuraEffect const* aurEff, Unit* victim, int32& damageOrHealing, int32& flatMod, float& pctMod);
};
using SafeWrapperType = void(*)(AuraScript* auraScript, AuraEffect const* aurEff, Unit* victim, int32& damageOrHealing, int32& flatMod, float& pctMod, AuraEffectDamageAndHealingCalcFnType callImpl);
template<typename ScriptFunc>
explicit EffectCalcDamageAndHealingHandler(ScriptFunc handler, uint8 effIndex, uint16 auraType)
: EffectBase(effIndex, auraType)
{
using ScriptClass = GetScriptClass_t<ScriptFunc>;
static_assert(sizeof(AuraEffectDamageAndHealingCalcFnType) >= sizeof(ScriptFunc));
static_assert(alignof(AuraEffectDamageAndHealingCalcFnType) >= alignof(ScriptFunc));
if constexpr (!std::is_void_v<ScriptClass>)
{
static_assert(std::is_invocable_r_v<void, ScriptFunc, ScriptClass, AuraEffect const*, Unit*, int32&, int32&, float&>,
"EffectCalcDamageAndHealingHandler signature must be \"void CalcDamageAndHealing(AuraEffect const* aurEff, Unit* victim, int32& damageOrHealing, int32& flatMod, float& pctMod)\"");
_callImpl = { .Member = reinterpret_cast<decltype(AuraEffectDamageAndHealingCalcFnType::Member)>(handler) };
_safeWrapper = [](AuraScript* auraScript, AuraEffect const* aurEff, Unit* victim, int32& damageOrHealing, int32& flatMod, float& pctMod, AuraEffectDamageAndHealingCalcFnType callImpl) -> void
{
return (static_cast<ScriptClass*>(auraScript)->*reinterpret_cast<ScriptFunc>(callImpl.Member))(aurEff, victim, damageOrHealing, flatMod, pctMod);
};
}
else
{
static_assert(std::is_invocable_r_v<void, ScriptFunc, AuraEffect const*, Unit*, int32&, int32&, float&>,
"EffectCalcDamageAndHealingHandler signature must be \"static void CalcDamageAndHealing(AuraEffect const* aurEff, Unit* victim, int32& damageOrHealing, int32& flatMod, float& pctMod)\"");
_callImpl = { .Static = reinterpret_cast<decltype(AuraEffectDamageAndHealingCalcFnType::Static)>(handler) };
_safeWrapper = [](AuraScript* /*auraScript*/, AuraEffect const* aurEff, Unit* victim, int32& damageOrHealing, int32& flatMod, float& pctMod, AuraEffectDamageAndHealingCalcFnType callImpl) -> void
{
return reinterpret_cast<ScriptFunc>(callImpl.Static)(aurEff, victim, damageOrHealing, flatMod, pctMod);
};
}
}
void Call(AuraScript* auraScript, AuraEffect const* aurEff, Unit* victim, int32& damageOrHealing, int32& flatMod, float& pctMod) const
{
return _safeWrapper(auraScript, aurEff, victim, damageOrHealing, flatMod, pctMod, _callImpl);
}
private:
AuraEffectDamageAndHealingCalcFnType _callImpl;
SafeWrapperType _safeWrapper;
};
class EffectApplyHandler final : public EffectBase
{
public:
union AuraEffectApplicationModeFnType
{
void(AuraScript::* Member)(AuraEffect const* aurEff, AuraEffectHandleModes mode);
void(*Static)(AuraEffect const* aurEff, AuraEffectHandleModes mode);
};
using SafeWrapperType = void(*)(AuraScript* auraScript, AuraEffect const* aurEff, AuraEffectHandleModes mode, AuraEffectApplicationModeFnType callImpl);
template<typename ScriptFunc>
explicit EffectApplyHandler(ScriptFunc handler, uint8 effIndex, uint16 auraType, AuraEffectHandleModes mode)
: EffectBase(effIndex, auraType), _mode(mode)
{
using ScriptClass = GetScriptClass_t<ScriptFunc>;
static_assert(sizeof(AuraEffectApplicationModeFnType) >= sizeof(ScriptFunc));
static_assert(alignof(AuraEffectApplicationModeFnType) >= alignof(ScriptFunc));
if constexpr (!std::is_void_v<ScriptClass>)
{
static_assert(std::is_invocable_r_v<void, ScriptFunc, ScriptClass, AuraEffect const*, AuraEffectHandleModes>,
"EffectApplyHandler signature must be \"void HandleApplyOrRemove(AuraEffect const* aurEff, AuraEffectHandleModes mode)\"");
_callImpl = { .Member = reinterpret_cast<decltype(AuraEffectApplicationModeFnType::Member)>(handler) };
_safeWrapper = [](AuraScript* auraScript, AuraEffect const* aurEff, AuraEffectHandleModes mode, AuraEffectApplicationModeFnType callImpl) -> void
{
return (static_cast<ScriptClass*>(auraScript)->*reinterpret_cast<ScriptFunc>(callImpl.Member))(aurEff, mode);
};
}
else
{
static_assert(std::is_invocable_r_v<void, ScriptFunc, AuraEffect const*, AuraEffectHandleModes>,
"EffectApplyHandler signature must be \"static void HandleApplyOrRemove(AuraEffect const* aurEff, AuraEffectHandleModes mode)\"");
_callImpl = { .Static = reinterpret_cast<decltype(AuraEffectApplicationModeFnType::Static)>(handler) };
_safeWrapper = [](AuraScript* /*auraScript*/, AuraEffect const* aurEff, AuraEffectHandleModes mode, AuraEffectApplicationModeFnType callImpl) -> void
{
return reinterpret_cast<ScriptFunc>(callImpl.Static)(aurEff, mode);
};
}
}
void Call(AuraScript* auraScript, AuraEffect const* aurEff, AuraEffectHandleModes mode) const
{
if (!(_mode & mode))
return;
return _safeWrapper(auraScript, aurEff, mode, _callImpl);
}
private:
AuraEffectApplicationModeFnType _callImpl;
SafeWrapperType _safeWrapper;
AuraEffectHandleModes _mode;
};
class EffectAbsorbHandler final : public EffectBase
{
public:
union AuraEffectAbsorbFnType
{
void(AuraScript::* Member)(AuraEffect* aurEff, DamageInfo& dmgInfo, uint32& absorbAmount);
void(*Static)(AuraEffect* aurEff, DamageInfo& dmgInfo, uint32& absorbAmount);
};
using SafeWrapperType = void(*)(AuraScript* auraScript, AuraEffect* aurEff, DamageInfo& dmgInfo, uint32& absorbAmount, AuraEffectAbsorbFnType callImpl);
template<typename ScriptFunc>
explicit EffectAbsorbHandler(ScriptFunc handler, uint8 effIndex, uint16 auraType)
: EffectBase(effIndex, auraType)
{
using ScriptClass = GetScriptClass_t<ScriptFunc>;
static_assert(sizeof(AuraEffectAbsorbFnType) >= sizeof(ScriptFunc));
static_assert(alignof(AuraEffectAbsorbFnType) >= alignof(ScriptFunc));
if constexpr (!std::is_void_v<ScriptClass>)
{
static_assert(std::is_invocable_r_v<void, ScriptFunc, ScriptClass, AuraEffect*, DamageInfo&, uint32&>,
"EffectAbsorbHandler signature must be \"void HandleAbsorb(AuraEffect* aurEff, DamageInfo& dmgInfo, uint32& absorbAmount)\"");
_callImpl = { .Member = reinterpret_cast<decltype(AuraEffectAbsorbFnType::Member)>(handler) };
_safeWrapper = [](AuraScript* auraScript, AuraEffect* aurEff, DamageInfo& dmgInfo, uint32& absorbAmount, AuraEffectAbsorbFnType callImpl) -> void
{
return (static_cast<ScriptClass*>(auraScript)->*reinterpret_cast<ScriptFunc>(callImpl.Member))(aurEff, dmgInfo, absorbAmount);
};
}
else
{
static_assert(std::is_invocable_r_v<void, ScriptFunc, AuraEffect*, DamageInfo&, uint32&>,
"EffectAbsorbHandler signature must be \"static void HandleAbsorb(AuraEffect* aurEff, DamageInfo& dmgInfo, uint32& absorbAmount)\"");
_callImpl = { .Static = reinterpret_cast<decltype(AuraEffectAbsorbFnType::Static)>(handler) };
_safeWrapper = [](AuraScript* /*auraScript*/, AuraEffect* aurEff, DamageInfo& dmgInfo, uint32& absorbAmount, AuraEffectAbsorbFnType callImpl) -> void
{
return reinterpret_cast<ScriptFunc>(callImpl.Static)(aurEff, dmgInfo, absorbAmount);
};
}
}
void Call(AuraScript* auraScript, AuraEffect* aurEff, DamageInfo& dmgInfo, uint32& absorbAmount) const
{
return _safeWrapper(auraScript, aurEff, dmgInfo, absorbAmount, _callImpl);
}
private:
AuraEffectAbsorbFnType _callImpl;
SafeWrapperType _safeWrapper;
};
class EffectAbsorbHealHandler final : public EffectBase
{
public:
union AuraEffectAbsorbHealFnType
{
void(AuraScript::* Member)(AuraEffect* aurEff, HealInfo& healInfo, uint32& absorbAmount);
void(*Static)(AuraEffect* aurEff, HealInfo& healInfo, uint32& absorbAmount);
};
using SafeWrapperType = void(*)(AuraScript* auraScript, AuraEffect* aurEff, HealInfo& healInfo, uint32& absorbAmount, AuraEffectAbsorbHealFnType callImpl);
template<typename ScriptFunc>
explicit EffectAbsorbHealHandler(ScriptFunc handler, uint8 effIndex, uint16 auraType)
: EffectBase(effIndex, auraType)
{
using ScriptClass = GetScriptClass_t<ScriptFunc>;
static_assert(sizeof(AuraEffectAbsorbHealFnType) >= sizeof(ScriptFunc));
static_assert(alignof(AuraEffectAbsorbHealFnType) >= alignof(ScriptFunc));
if constexpr (!std::is_void_v<ScriptClass>)
{
static_assert(std::is_invocable_r_v<void, ScriptFunc, ScriptClass, AuraEffect*, HealInfo&, uint32&>,
"EffectAbsorbHealHandler signature must be \"void HandleAbsorb(AuraEffect* aurEff, HealInfo& healInfo, uint32& absorbAmount)\"");
_callImpl = { .Member = reinterpret_cast<decltype(AuraEffectAbsorbHealFnType::Member)>(handler) };
_safeWrapper = [](AuraScript* auraScript, AuraEffect* aurEff, HealInfo& healInfo, uint32& absorbAmount, AuraEffectAbsorbHealFnType callImpl) -> void
{
return (static_cast<ScriptClass*>(auraScript)->*reinterpret_cast<ScriptFunc>(callImpl.Member))(aurEff, healInfo, absorbAmount);
};
}
else
{
static_assert(std::is_invocable_r_v<void, ScriptFunc, AuraEffect*, HealInfo&, uint32&>,
"EffectAbsorbHealHandler signature must be \"static void HandleAbsorb(AuraEffect* aurEff, HealInfo& healInfo, uint32& absorbAmount)\"");
_callImpl = { .Static = reinterpret_cast<decltype(AuraEffectAbsorbHealFnType::Static)>(handler) };
_safeWrapper = [](AuraScript* /*auraScript*/, AuraEffect* aurEff, HealInfo& healInfo, uint32& absorbAmount, AuraEffectAbsorbHealFnType callImpl) -> void
{
return reinterpret_cast<ScriptFunc>(callImpl.Static)(aurEff, healInfo, absorbAmount);
};
}
}
void Call(AuraScript* auraScript, AuraEffect* aurEff, HealInfo& healInfo, uint32& absorbAmount) const
{
return _safeWrapper(auraScript, aurEff, healInfo, absorbAmount, _callImpl);
}
private:
AuraEffectAbsorbHealFnType _callImpl;
SafeWrapperType _safeWrapper;
};
class CheckProcHandler final
{
public:
union AuraCheckProcFnType
{
bool(AuraScript::* Member)(ProcEventInfo& eventInfo);
bool(*Static)(ProcEventInfo& eventInfo);
};
using SafeWrapperType = bool(*)(AuraScript* auraScript, ProcEventInfo& eventInfo, AuraCheckProcFnType callImpl);
template<typename ScriptFunc>
explicit CheckProcHandler(ScriptFunc handler)
{
using ScriptClass = GetScriptClass_t<ScriptFunc>;
static_assert(sizeof(AuraCheckProcFnType) >= sizeof(ScriptFunc));
static_assert(alignof(AuraCheckProcFnType) >= alignof(ScriptFunc));
if constexpr (!std::is_void_v<ScriptClass>)
{
static_assert(std::is_invocable_r_v<bool, ScriptFunc, ScriptClass, ProcEventInfo&>,
"CheckProcHandler signature must be \"bool CheckProc(ProcEventInfo& eventInfo)\"");
_callImpl = { .Member = reinterpret_cast<decltype(AuraCheckProcFnType::Member)>(handler) };
_safeWrapper = [](AuraScript* auraScript, ProcEventInfo& eventInfo, AuraCheckProcFnType callImpl) -> bool
{
return (static_cast<ScriptClass*>(auraScript)->*reinterpret_cast<ScriptFunc>(callImpl.Member))(eventInfo);
};
}
else
{
static_assert(std::is_invocable_r_v<bool, ScriptFunc, ProcEventInfo&>,
"CheckProcHandler signature must be \"static bool CheckProc(ProcEventInfo& eventInfo)\"");
_callImpl = { .Static = reinterpret_cast<decltype(AuraCheckProcFnType::Static)>(handler) };
_safeWrapper = [](AuraScript* /*auraScript*/, ProcEventInfo& eventInfo, AuraCheckProcFnType callImpl) -> bool
{
return reinterpret_cast<ScriptFunc>(callImpl.Static)(eventInfo);
};
}
}
bool Call(AuraScript* auraScript, ProcEventInfo& eventInfo) const
{
return _safeWrapper(auraScript, eventInfo, _callImpl);
}
private:
AuraCheckProcFnType _callImpl;
SafeWrapperType _safeWrapper;
};
class CheckEffectProcHandler final : public EffectBase
{
public:
union AuraCheckEffectProcFnType
{
bool(AuraScript::* Member)(AuraEffect const* aurEff, ProcEventInfo& eventInfo);
bool(*Static)(AuraEffect const* aurEff, ProcEventInfo& eventInfo);
};
using SafeWrapperType = bool(*)(AuraScript* auraScript, AuraEffect const* aurEff, ProcEventInfo& eventInfo, AuraCheckEffectProcFnType callImpl);
template<typename ScriptFunc>
explicit CheckEffectProcHandler(ScriptFunc handler, uint8 effIndex, uint16 auraType)
: EffectBase(effIndex, auraType)
{
using ScriptClass = GetScriptClass_t<ScriptFunc>;
static_assert(sizeof(AuraCheckEffectProcFnType) >= sizeof(ScriptFunc));
static_assert(alignof(AuraCheckEffectProcFnType) >= alignof(ScriptFunc));
if constexpr (!std::is_void_v<ScriptClass>)
{
static_assert(std::is_invocable_r_v<bool, ScriptFunc, ScriptClass, AuraEffect const*, ProcEventInfo&>,
"CheckEffectProcHandler signature must be \"bool CheckProc(AuraEffect const* aurEff, ProcEventInfo& eventInfo)\"");
_callImpl = { .Member = reinterpret_cast<decltype(AuraCheckEffectProcFnType::Member)>(handler) };
_safeWrapper = [](AuraScript* auraScript, AuraEffect const* aurEff, ProcEventInfo& eventInfo, AuraCheckEffectProcFnType callImpl) -> bool
{
return (static_cast<ScriptClass*>(auraScript)->*reinterpret_cast<ScriptFunc>(callImpl.Member))(aurEff, eventInfo);
};
}
else
{
static_assert(std::is_invocable_r_v<bool, ScriptFunc, AuraEffect const*, ProcEventInfo&>,
"CheckEffectProcHandler signature must be \"static bool CheckProc(AuraEffect const* aurEff, ProcEventInfo& eventInfo)\"");
_callImpl = { .Static = reinterpret_cast<decltype(AuraCheckEffectProcFnType::Static)>(handler) };
_safeWrapper = [](AuraScript* /*auraScript*/, AuraEffect const* aurEff, ProcEventInfo& eventInfo, AuraCheckEffectProcFnType callImpl) -> bool
{
return reinterpret_cast<ScriptFunc>(callImpl.Static)(aurEff, eventInfo);
};
}
}
bool Call(AuraScript* auraScript, AuraEffect const* aurEff, ProcEventInfo& eventInfo) const
{
return _safeWrapper(auraScript, aurEff, eventInfo, _callImpl);
}
private:
AuraCheckEffectProcFnType _callImpl;
SafeWrapperType _safeWrapper;
};
class AuraProcHandler final
{
public:
union AuraProcFnType
{
void(AuraScript::* Member)(ProcEventInfo& eventInfo);
void(*Static)(ProcEventInfo& eventInfo);
};
using SafeWrapperType = void(*)(AuraScript* auraScript, ProcEventInfo& eventInfo, AuraProcFnType callImpl);
template<typename ScriptFunc>
explicit AuraProcHandler(ScriptFunc handler)
{
using ScriptClass = GetScriptClass_t<ScriptFunc>;
static_assert(sizeof(AuraProcFnType) >= sizeof(ScriptFunc));
static_assert(alignof(AuraProcFnType) >= alignof(ScriptFunc));
if constexpr (!std::is_void_v<ScriptClass>)
{
static_assert(std::is_invocable_r_v<void, ScriptFunc, ScriptClass, ProcEventInfo&>,
"AuraProcHandler signature must be \"void HandleProc(ProcEventInfo& eventInfo)\"");
_callImpl = { .Member = reinterpret_cast<decltype(AuraProcFnType::Member)>(handler) };
_safeWrapper = [](AuraScript* auraScript, ProcEventInfo& eventInfo, AuraProcFnType callImpl) -> void
{
return (static_cast<ScriptClass*>(auraScript)->*reinterpret_cast<ScriptFunc>(callImpl.Member))(eventInfo);
};
}
else
{
static_assert(std::is_invocable_r_v<void, ScriptFunc, ProcEventInfo&>,
"AuraProcHandler signature must be \"static void HandleProc(ProcEventInfo& eventInfo)\"");
_callImpl = { .Member = reinterpret_cast<decltype(AuraProcFnType::Member)>(handler) };
_safeWrapper = [](AuraScript* /*auraScript*/, ProcEventInfo& eventInfo, AuraProcFnType callImpl) -> void
{
return reinterpret_cast<ScriptFunc>(callImpl.Member)(eventInfo);
};
}
}
void Call(AuraScript* auraScript, ProcEventInfo& eventInfo) const
{
return _safeWrapper(auraScript, eventInfo, _callImpl);
}
private:
AuraProcFnType _callImpl;
SafeWrapperType _safeWrapper;
};
class EffectProcHandler final : public EffectBase
{
public:
union AuraEffectProcFnType
{
void(AuraScript::* Member)(AuraEffect* aurEff, ProcEventInfo& eventInfo);
void(*Static)(AuraEffect* aurEff, ProcEventInfo& eventInfo);
};
using SafeWrapperType = void (*)(AuraScript* auraScript, AuraEffect* aurEff, ProcEventInfo& eventInfo, AuraEffectProcFnType callImpl);
template<typename ScriptFunc>
explicit EffectProcHandler(ScriptFunc handler, uint8 effIndex, uint16 auraType)
: EffectBase(effIndex, auraType)
{
using ScriptClass = GetScriptClass_t<ScriptFunc>;
static_assert(sizeof(AuraEffectProcFnType) >= sizeof(ScriptFunc));
static_assert(alignof(AuraEffectProcFnType) >= alignof(ScriptFunc));
if constexpr (!std::is_void_v<ScriptClass>)
{
static_assert(std::is_invocable_r_v<void, ScriptFunc, ScriptClass, AuraEffect*, ProcEventInfo&>,
"EffectProcHandler signature must be \"void HandleProc(AuraEffect* aurEff, ProcEventInfo& eventInfo)\"");
_callImpl = { .Member = reinterpret_cast<decltype(AuraEffectProcFnType::Member)>(handler) };
_safeWrapper = [](AuraScript* auraScript, AuraEffect* aurEff, ProcEventInfo& eventInfo, AuraEffectProcFnType callImpl) -> void
{
return (static_cast<ScriptClass*>(auraScript)->*reinterpret_cast<ScriptFunc>(callImpl.Member))(aurEff, eventInfo);
};
}
else
{
static_assert(std::is_invocable_r_v<void, ScriptFunc, AuraEffect*, ProcEventInfo&>,
"EffectProcHandler signature must be \"static void HandleProc(AuraEffect* aurEff, ProcEventInfo& eventInfo)\"");
_callImpl = { .Static = reinterpret_cast<decltype(AuraEffectProcFnType::Static)>(handler) };
_safeWrapper = [](AuraScript* /*auraScript*/, AuraEffect* aurEff, ProcEventInfo& eventInfo, AuraEffectProcFnType callImpl) -> void
{
return reinterpret_cast<ScriptFunc>(callImpl.Static)(aurEff, eventInfo);
};
}
}
void Call(AuraScript* auraScript, AuraEffect* aurEff, ProcEventInfo& eventInfo) const
{
return _safeWrapper(auraScript, aurEff, eventInfo, _callImpl);
}
private:
AuraEffectProcFnType _callImpl;
SafeWrapperType _safeWrapper;
};
class EnterLeaveCombatHandler final
{
public:
using AuraEnterLeaveCombatFnType = void(AuraScript::*)(bool isNowInCombat);
using SafeWrapperType = void(*)(AuraScript* auraScript, bool isNowInCombat, AuraEnterLeaveCombatFnType callImpl);
template<typename ScriptFunc>
explicit EnterLeaveCombatHandler(ScriptFunc handler)
{
using ScriptClass = GetScriptClass_t<ScriptFunc>;
static_assert(sizeof(AuraEnterLeaveCombatFnType) >= sizeof(ScriptFunc));
static_assert(alignof(AuraEnterLeaveCombatFnType) >= alignof(ScriptFunc));
static_assert(std::is_invocable_r_v<void, ScriptFunc, ScriptClass, bool>,
"EnterLeaveCombatHandler signature must be \"void HandleEnterLeaveCombat(bool isNowInCombat)\"");
_callImpl = reinterpret_cast<AuraEnterLeaveCombatFnType>(handler);
_safeWrapper = [](AuraScript* auraScript, bool isNowInCombat, AuraEnterLeaveCombatFnType callImpl) -> void
{
return (static_cast<ScriptClass*>(auraScript)->*reinterpret_cast<ScriptFunc>(callImpl))(isNowInCombat);
};
}
void Call(AuraScript* auraScript, bool isNowInCombat) const
{
return _safeWrapper(auraScript, isNowInCombat, _callImpl);
}
private:
AuraEnterLeaveCombatFnType _callImpl;
SafeWrapperType _safeWrapper;
};
// left for custom compatibility only, DO NOT USE
#define PrepareAuraScript(CLASSNAME)
public:
AuraScript();
~AuraScript();
bool _Validate(SpellInfo const* entry) override;
bool _Load(Aura* aura);
void _PrepareScriptCall(AuraScriptHookType hookType, AuraApplication const* aurApp = nullptr);
void _FinishScriptCall();
bool _IsDefaultActionPrevented() const;
private:
Aura* m_aura;
AuraApplication const* m_auraApplication;
bool m_defaultActionPrevented;
class TC_GAME_API ScriptStateStore
{
public:
AuraApplication const* _auraApplication;
uint8 _currentScriptState;
bool _defaultActionPrevented;
ScriptStateStore(uint8 currentScriptState, AuraApplication const* auraApplication, bool defaultActionPrevented)
: _auraApplication(auraApplication), _currentScriptState(currentScriptState), _defaultActionPrevented(defaultActionPrevented)
{ }
};
typedef std::stack<ScriptStateStore> ScriptStateStack;
ScriptStateStack m_scriptStates;
public:
//
// AuraScript interface
// hooks to which you can attach your functions
//
// executed when area aura checks if it can be applied on target
// example: OnEffectApply += AuraEffectApplyFn(class::function);
// where function is: bool function(Unit* target);
HookList<CheckAreaTargetHandler> DoCheckAreaTarget;
#define AuraCheckAreaTargetFn(F) CheckAreaTargetHandler(&F)
// executed when aura is dispelled by a unit
// example: OnDispel += AuraDispelFn(class::function);
// where function is: void function(DispelInfo* dispelInfo);
HookList<AuraDispelHandler> OnDispel;
// executed after aura is dispelled by a unit
// example: AfterDispel += AuraDispelFn(class::function);
// where function is: void function(DispelInfo* dispelInfo);
HookList<AuraDispelHandler> AfterDispel;
#define AuraDispelFn(F) AuraDispelHandler(&F)
// executed on every heartbeat of a unit
// example: OnHeartbeat += AuraHeartbeatFn(class::function);
// where function is: void function();
HookList<AuraHeartbeatHandler> OnHeartbeat;
#define AuraHeartbeatFn(F) AuraHeartbeatHandler(&F)
// executed when aura effect is applied with specified mode to target
// should be used when when effect handler preventing/replacing is needed, do not use this hook for triggering spellcasts/removing auras etc - may be unsafe
// example: OnEffectApply += AuraEffectApplyFn(class::function, EffectIndexSpecifier, EffectAuraNameSpecifier, AuraEffectHandleModes);
// where function is: void function(AuraEffect const* aurEff, AuraEffectHandleModes mode);
HookList<EffectApplyHandler> OnEffectApply;
// executed after aura effect is applied with specified mode to target
// example: AfterEffectApply += AuraEffectApplyFn(class::function, EffectIndexSpecifier, EffectAuraNameSpecifier, AuraEffectHandleModes);
// where function is: void function(AuraEffect const* aurEff, AuraEffectHandleModes mode);
HookList<EffectApplyHandler> AfterEffectApply;
#define AuraEffectApplyFn(F, I, N, M) EffectApplyHandler(&F, I, N, M)
// executed after aura effect is removed with specified mode from target
// should be used when effect handler preventing/replacing is needed, do not use this hook for triggering spellcasts/removing auras etc - may be unsafe
// example: OnEffectRemove += AuraEffectRemoveFn(class::function, EffectIndexSpecifier, EffectAuraNameSpecifier, AuraEffectHandleModes);
// where function is: void function(AuraEffect const* aurEff, AuraEffectHandleModes mode);
HookList<EffectApplyHandler> OnEffectRemove;
// executed when aura effect is removed with specified mode from target
// example: AfterEffectRemove += AuraEffectRemoveFn(class::function, EffectIndexSpecifier, EffectAuraNameSpecifier, AuraEffectHandleModes);
// where function is: void function(AuraEffect const* aurEff, AuraEffectHandleModes mode);
HookList<EffectApplyHandler> AfterEffectRemove;
#define AuraEffectRemoveFn(F, I, N, M) EffectApplyHandler(&F, I, N, M)
// executed when periodic aura effect ticks on target
// example: OnEffectPeriodic += AuraEffectPeriodicFn(class::function, EffectIndexSpecifier, EffectAuraNameSpecifier);
// where function is: void function(AuraEffect const* aurEff);
HookList<EffectPeriodicHandler> OnEffectPeriodic;
#define AuraEffectPeriodicFn(F, I, N) EffectPeriodicHandler(&F, I, N)
// executed when periodic aura effect is updated
// example: OnEffectUpdatePeriodic += AuraEffectUpdatePeriodicFn(class::function, EffectIndexSpecifier, EffectAuraNameSpecifier);
// where function is: void function(AuraEffect* aurEff);
HookList<EffectUpdatePeriodicHandler> OnEffectUpdatePeriodic;
#define AuraEffectUpdatePeriodicFn(F, I, N) EffectUpdatePeriodicHandler(&F, I, N)
// executed when aura effect calculates amount
// example: DoEffectCalcAmount += AuraEffectCalcAmounFn(class::function, EffectIndexSpecifier, EffectAuraNameSpecifier);
// where function is: void function(AuraEffect* aurEff, int32& amount, bool& canBeRecalculated);
HookList<EffectCalcAmountHandler> DoEffectCalcAmount;
#define AuraEffectCalcAmountFn(F, I, N) EffectCalcAmountHandler(&F, I, N)
// executed when aura effect calculates periodic data
// example: DoEffectCalcPeriodic += AuraEffectCalcPeriodicFn(class::function, EffectIndexSpecifier, EffectAuraNameSpecifier);
// where function is: void function(AuraEffect const* aurEff, bool& isPeriodic, int32& amplitude);
HookList<EffectCalcPeriodicHandler> DoEffectCalcPeriodic;
#define AuraEffectCalcPeriodicFn(F, I, N) EffectCalcPeriodicHandler(&F, I, N)
// executed when aura effect calculates spellmod
// example: DoEffectCalcSpellMod += AuraEffectCalcSpellModFn(class::function, EffectIndexSpecifier, EffectAuraNameSpecifier);
// where function is: void function(AuraEffect const* aurEff, SpellModifier*& spellMod);
HookList<EffectCalcSpellModHandler> DoEffectCalcSpellMod;
#define AuraEffectCalcSpellModFn(F, I, N) EffectCalcSpellModHandler(&F, I, N)
// executed when aura effect calculates crit chance for dots and hots
// example: DoEffectCalcCritChance += AuraEffectCalcCritChanceFn(class::function, EffectIndexSpecifier, EffectAuraNameSpecifier);
// where function is: void function(AuraEffect const* aurEff, Unit* victim, float& critChance);
HookList<EffectCalcCritChanceHandler> DoEffectCalcCritChance;
#define AuraEffectCalcCritChanceFn(F, I, N) EffectCalcCritChanceHandler(&F, I, N)
// executed when aura effect calculates damage or healing for dots and hots
// example: DoEffectCalcDamageAndHealing += AuraEffectCalcDamageFn(class::function, EffectIndexSpecifier, EffectAuraNameSpecifier);
// example: DoEffectCalcDamageAndHealing += AuraEffectCalcHealingFn(class::function, EffectIndexSpecifier, EffectAuraNameSpecifier);
// where function is: void function(AuraEffect const* aurEff, Unit* victim, int32& damageOrHealing, int32& flatMod, float& pctMod);
HookList<EffectCalcDamageAndHealingHandler> DoEffectCalcDamageAndHealing;
#define AuraEffectCalcDamageFn(F, I, N) EffectCalcDamageAndHealingHandler(&F, I, N)
#define AuraEffectCalcHealingFn(F, I, N) EffectCalcDamageAndHealingHandler(&F, I, N)
// executed when absorb aura effect is going to reduce damage
// example: OnEffectAbsorb += AuraEffectAbsorbFn(class::function, EffectIndexSpecifier);
// where function is: void function(AuraEffect* aurEff, DamageInfo& dmgInfo, uint32& absorbAmount);
HookList<EffectAbsorbHandler> OnEffectAbsorb;
#define AuraEffectAbsorbFn(F, I) EffectAbsorbHandler(&F, I, SPELL_AURA_SCHOOL_ABSORB)
#define AuraEffectAbsorbOverkillFn(F, I) EffectAbsorbHandler(&F, I, SPELL_AURA_SCHOOL_ABSORB_OVERKILL)
// executed after absorb aura effect reduced damage to target - absorbAmount is real amount absorbed by aura
// example: AfterEffectAbsorb += AuraEffectAbsorbFn(class::function, EffectIndexSpecifier);
// where function is: void function(AuraEffect* aurEff, DamageInfo& dmgInfo, uint32& absorbAmount);
HookList<EffectAbsorbHandler> AfterEffectAbsorb;
// executed when absorb aura effect is going to reduce damage
// example: OnEffectAbsorbHeal += AuraEffectAbsorbHealFn(class::function, EffectIndexSpecifier);
// where function is: void function(AuraEffect const* aurEff, HealInfo& healInfo, uint32& absorbAmount);
HookList<EffectAbsorbHealHandler> OnEffectAbsorbHeal;
#define AuraEffectAbsorbHealFn(F, I) EffectAbsorbHealHandler(&F, I, SPELL_AURA_SCHOOL_HEAL_ABSORB)
// executed after absorb aura effect reduced heal to target - absorbAmount is real amount absorbed by aura
// example: AfterEffectAbsorbHeal += AuraEffectAbsorbHealFn(class::function, EffectIndexSpecifier);
// where function is: void function(AuraEffect* aurEff, HealInfo& healInfo, uint32& absorbAmount);
HookList<EffectAbsorbHealHandler> AfterEffectAbsorbHeal;
// executed when mana shield aura effect is going to reduce damage
// example: OnEffectManaShield += AuraEffectManaShieldFn(class::function, EffectIndexSpecifier);
// where function is: void function (AuraEffect* aurEff, DamageInfo& dmgInfo, uint32& absorbAmount);
HookList<EffectAbsorbHandler> OnEffectManaShield;
#define AuraEffectManaShieldFn(F, I) EffectAbsorbHandler(&F, I, SPELL_AURA_MANA_SHIELD)
// executed after mana shield aura effect reduced damage to target - absorbAmount is real amount absorbed by aura
// example: AfterEffectManaShield += AuraEffectManaShieldFn(class::function, EffectIndexSpecifier);
// where function is: void function(AuraEffect* aurEff, DamageInfo& dmgInfo, uint32& absorbAmount);
HookList<EffectAbsorbHandler> AfterEffectManaShield;
// executed when the caster of some spell with split dmg aura gets damaged through it
// example: OnEffectSplit += AuraEffectSplitFn(class::function, EffectIndexSpecifier);
// where function is: void function(AuraEffect* aurEff, DamageInfo& dmgInfo, uint32& splitAmount);
HookList<EffectAbsorbHandler> OnEffectSplit;
#define AuraEffectSplitFn(F, I) EffectAbsorbHandler(&F, I, SPELL_AURA_SPLIT_DAMAGE_PCT)
// executed when aura checks if it can proc
// example: DoCheckProc += AuraCheckProcFn(class::function);
// where function is: bool function(ProcEventInfo& eventInfo);
HookList<CheckProcHandler> DoCheckProc;
#define AuraCheckProcFn(F) CheckProcHandler(&F)
// executed when aura effect checks if it can proc the aura
// example: DoCheckEffectProc += AuraCheckEffectProcFn(class::function, EffectIndexSpecifier, EffectAuraNameSpecifier);
// where function is bool function(AuraEffect const* aurEff, ProcEventInfo& eventInfo);
HookList<CheckEffectProcHandler> DoCheckEffectProc;
#define AuraCheckEffectProcFn(F, I, N) CheckEffectProcHandler(&F, I, N)
// executed before aura procs (possibility to prevent charge drop/cooldown)
// example: DoPrepareProc += AuraProcFn(class::function);
// where function is: void function(ProcEventInfo& eventInfo);
HookList<AuraProcHandler> DoPrepareProc;
// executed when aura procs
// example: OnProc += AuraProcFn(class::function);
// where function is: void function(ProcEventInfo& eventInfo);
HookList<AuraProcHandler> OnProc;
// executed after aura proced
// example: AfterProc += AuraProcFn(class::function);
// where function is: void function(ProcEventInfo& eventInfo);
HookList<AuraProcHandler> AfterProc;
#define AuraProcFn(F) AuraProcHandler(&F)
// executed when aura effect procs
// example: OnEffectProc += AuraEffectProcFn(class::function, EffectIndexSpecifier, EffectAuraNameSpecifier);
// where function is: void function(AuraEffect* aurEff, ProcEventInfo& procInfo);
HookList<EffectProcHandler> OnEffectProc;
// executed after aura effect proced
// example: AfterEffectProc += AuraEffectProcFn(class::function, EffectIndexSpecifier, EffectAuraNameSpecifier);
// where function is: void function(AuraEffect* aurEff, ProcEventInfo& procInfo);
HookList<EffectProcHandler> AfterEffectProc;
#define AuraEffectProcFn(F, I, N) EffectProcHandler(&F, I, N)
// executed when target enters or leaves combat
// example: OnEnterLeaveCombat += AuraEnterLeaveCombatFn(class::function)
// where function is: void function (bool isNowInCombat);
HookList<EnterLeaveCombatHandler> OnEnterLeaveCombat;
#define AuraEnterLeaveCombatFn(F) EnterLeaveCombatHandler(&F)
// AuraScript interface - hook/effect execution manipulators
// prevents default action of a hook from being executed (works only while called in a hook which default action can be prevented)
void PreventDefaultAction();
// AuraScript interface - functions which are redirecting to Aura class
// returns proto of the spell
SpellInfo const* GetSpellInfo() const;
SpellEffectInfo const& GetEffectInfo(SpellEffIndex effIndex) const;
// returns spellid of the spell
uint32 GetId() const;
// returns guid of object which cast the aura (m_originalCaster of the Spell class)
ObjectGuid GetCasterGUID() const;
// returns unit which cast the aura or NULL if not avalible (caster logged out for example)
Unit* GetCaster() const;
// returns gameobject which cast the aura or NULL if not available
GameObject* GetGObjCaster() const;
// returns object on which aura was cast, target for non-area auras, area aura source for area auras
WorldObject* GetOwner() const;
// returns owner if it's unit or unit derived object, NULL otherwise (only for persistent area auras NULL is returned)
Unit* GetUnitOwner() const;
// returns owner if it's dynobj, NULL otherwise
DynamicObject* GetDynobjOwner() const;
// removes aura with remove mode (see AuraRemoveMode enum)
void Remove(AuraRemoveMode removeMode = AURA_REMOVE_BY_DEFAULT);
// returns aura object of script
Aura* GetAura() const;
// returns type of the aura, may be dynobj owned aura or unit owned aura
AuraObjectType GetType() const;
// aura duration manipulation - when duration goes to 0 aura is removed
int32 GetDuration() const;
void SetDuration(int32 duration, bool withMods = false);
// sets duration to maxduration
void RefreshDuration();
time_t GetApplyTime() const;
int32 GetMaxDuration() const;
void SetMaxDuration(int32 duration);
int32 CalcMaxDuration() const;
// expired - duration just went to 0
bool IsExpired() const;
// permament - has infinite duration
bool IsPermanent() const;
// charges manipulation - 0 - not charged aura
uint8 GetCharges() const;
void SetCharges(uint8 charges);
uint8 CalcMaxCharges() const;
bool ModCharges(int8 num, AuraRemoveMode removeMode = AURA_REMOVE_BY_DEFAULT);
// returns true if last charge dropped
bool DropCharge(AuraRemoveMode removeMode = AURA_REMOVE_BY_DEFAULT);
// stack amount manipulation
uint8 GetStackAmount() const;
void SetStackAmount(uint8 num);
bool ModStackAmount(int32 num, AuraRemoveMode removeMode = AURA_REMOVE_BY_DEFAULT);
// passive - "working in background", not saved, not removed by immunities, not seen by player
bool IsPassive() const;
// death persistent - not removed on death
bool IsDeathPersistent() const;
// check if aura has effect of given effindex
bool HasEffect(uint8 effIndex) const;
// returns aura effect of given effect index or NULL
AuraEffect* GetEffect(uint8 effIndex) const;
// check if aura has effect of given aura type
bool HasEffectType(AuraType type) const;
// AuraScript interface - functions which are redirecting to AuraApplication class
// Do not call these in hooks in which AuraApplication is not avalible, otherwise result will differ from expected (the functions will return NULL)
// returns currently processed target of an aura
// Return value does not need to be NULL-checked, the only situation this will (always)
// return NULL is when the call happens in an unsupported hook, in other cases, it is always valid
Unit* GetTarget() const;
// returns AuraApplication object of currently processed target
AuraApplication const* GetTargetApplication() const;
// returns desired cast difficulty for triggered spells
Difficulty GetCastDifficulty() const;
};
//
// definitions:
//
// EffectIndexSpecifier - specifies conditions for effects
// EFFECT_0 - first effect matches
// EFFECT_1 - second effect matches
// EFFECT_2 - third effect matches
// EFFECT_FIRST_FOUND - first effect matching other conditions matches
// EFFECT_ALL - all effects of spell match
//
// EffectNameSpecifier - specifies conditions for spell effect names
// SPELL_EFFECT_ANY - any effect but not 0 matches condition
// SPELL_EFFECT_XXX - one of values of enum SpellEffects - effect with equal name matches
//
#endif // TRINITY_SPELL_SCRIPT_H
|