-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Expand file tree
/
Copy pathSmartScriptMgr.cpp
More file actions
2105 lines (1978 loc) · 106 KB
/
SmartScriptMgr.cpp
File metadata and controls
2105 lines (1978 loc) · 106 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* This file is part of the AzerothCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU 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/>.
*/
#include "SmartScriptMgr.h"
#include "CellImpl.h"
#include "CreatureTextMgr.h"
#include "DatabaseEnv.h"
#include "GameEventMgr.h"
#include "GridDefines.h"
#include "InstanceScript.h"
#include "ObjectDefines.h"
#include "ObjectMgr.h"
#include "ScriptedCreature.h"
#include "SpellMgr.h"
bool SmartAIMgr::IsSAIBoolValid(SmartScriptHolder const& e, SAIBool value)
{
if (value != 0 && value != 1)
{
LOG_ERROR("sql.sql", "SmartAIMgr: Entry {} SourceType {} Event {} Action {} uses param {} of type Boolean with value {}, valid values are 0 or 1, skipped.",
e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType(), STRINGIZE(value), value);
return false;
}
return true;
}
SmartWaypointMgr* SmartWaypointMgr::instance()
{
static SmartWaypointMgr instance;
return &instance;
}
void SmartWaypointMgr::LoadFromDB()
{
uint32 oldMSTime = getMSTime();
waypoint_map.clear();
WorldDatabasePreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_SMARTAI_WP);
PreparedQueryResult result = WorldDatabase.Query(stmt);
if (!result)
{
LOG_WARN("server.loading", ">> Loaded 0 SmartAI Waypoint Paths. DB table `waypoints` is empty.");
LOG_INFO("server.loading", " ");
return;
}
uint32 count = 0;
uint32 total = 0;
uint32 last_entry = 0;
uint32 last_id = 1;
do
{
Field* fields = result->Fetch();
uint32 entry = fields[0].Get<uint32>();
uint32 id = fields[1].Get<uint32>();
float x = fields[2].Get<float>();
float y = fields[3].Get<float>();
float z = fields[4].Get<float>();
std::optional<float> o;
if (!fields[5].IsNull())
o = fields[5].Get<float>();
uint32 delay = fields[6].Get<uint32>();
if (last_entry != entry)
{
waypoint_map[entry] = WaypointPath();
waypoint_map[entry].Id = entry;
last_id = 1;
count++;
}
if (last_id != id)
LOG_ERROR("sql.sql", "SmartWaypointMgr::LoadFromDB: Path entry {}, unexpected point id {}, expected {}.", entry, id, last_id);
last_id++;
WaypointNode node;
node.Id = id;
node.X = x;
node.Y = y;
node.Z = z;
node.Orientation = o;
node.Delay = delay;
node.MoveType = WAYPOINT_MOVE_TYPE_MAX;
waypoint_map[entry].Nodes.push_back(std::move(node));
last_entry = entry;
total++;
} while (result->NextRow());
LOG_INFO("server.loading", ">> Loaded {} SmartAI waypoint paths (total {} waypoints) in {} ms", count, total, GetMSTimeDiffToNow(oldMSTime));
LOG_INFO("server.loading", " ");
}
SmartAIMgr* SmartAIMgr::instance()
{
static SmartAIMgr instance;
return &instance;
}
void SmartAIMgr::LoadSmartAIFromDB()
{
uint32 oldMSTime = getMSTime();
for (uint8 i = 0; i < SMART_SCRIPT_TYPE_MAX; i++)
mEventMap[i].clear(); //Drop Existing SmartAI List
WorldDatabasePreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_SMART_SCRIPTS);
PreparedQueryResult result = WorldDatabase.Query(stmt);
if (!result)
{
LOG_WARN("server.loading", ">> Loaded 0 SmartAI scripts. DB table `smart_scripts` is empty.");
LOG_INFO("server.loading", " ");
return;
}
uint32 count = 0;
do
{
Field* fields = result->Fetch();
SmartScriptHolder temp;
temp.entryOrGuid = fields[0].Get<int32>();
if (!temp.entryOrGuid)
{
LOG_ERROR("sql.sql", "SmartAIMgr::LoadSmartAIFromDB: invalid entryorguid (0), skipped loading.");
continue;
}
SmartScriptType source_type = (SmartScriptType)fields[1].Get<uint8>();
if (source_type >= SMART_SCRIPT_TYPE_MAX)
{
LOG_ERROR("sql.sql", "SmartAIMgr::LoadSmartAIFromDB: invalid source_type ({}), skipped loading.", uint32(source_type));
continue;
}
if (temp.entryOrGuid >= 0)
{
switch (source_type)
{
case SMART_SCRIPT_TYPE_CREATURE:
{
if (!sObjectMgr->GetCreatureTemplate((uint32)temp.entryOrGuid))
{
LOG_ERROR("sql.sql", "SmartAIMgr::LoadSmartAIFromDB: Creature entry ({}) does not exist, skipped loading.", uint32(temp.entryOrGuid));
continue;
}
break;
}
case SMART_SCRIPT_TYPE_GAMEOBJECT:
{
if (!sObjectMgr->GetGameObjectTemplate((uint32)temp.entryOrGuid))
{
LOG_ERROR("sql.sql", "SmartAIMgr::LoadSmartAIFromDB: GameObject entry ({}) does not exist, skipped loading.", uint32(temp.entryOrGuid));
continue;
}
break;
}
case SMART_SCRIPT_TYPE_AREATRIGGER:
{
if (!sObjectMgr->GetAreaTrigger((uint32)temp.entryOrGuid))
{
LOG_ERROR("sql.sql", "SmartAIMgr::LoadSmartAIFromDB: AreaTrigger entry ({}) does not exist, skipped loading.", uint32(temp.entryOrGuid));
continue;
}
break;
}
case SMART_SCRIPT_TYPE_TIMED_ACTIONLIST:
break;//nothing to check, really
default:
LOG_ERROR("sql.sql", "SmartAIMgr::LoadSmartAIFromDB: not yet implemented source_type {}", (uint32)source_type);
continue;
}
}
else
{
switch (source_type)
{
case SMART_SCRIPT_TYPE_CREATURE:
{
if (!sObjectMgr->GetCreatureData(uint32(std::abs(temp.entryOrGuid))))
{
LOG_ERROR("sql.sql", "SmartAIMgr::LoadSmartAIFromDB: Creature guid ({}) does not exist, skipped loading.", uint32(std::abs(temp.entryOrGuid)));
continue;
}
break;
}
case SMART_SCRIPT_TYPE_GAMEOBJECT:
{
if (!sObjectMgr->GetGameObjectData(uint32(std::abs(temp.entryOrGuid))))
{
LOG_ERROR("sql.sql", "SmartAIMgr::LoadSmartAIFromDB: GameObject guid ({}) does not exist, skipped loading.", uint32(temp.entryOrGuid));
continue;
}
break;
}
default:
LOG_ERROR("sql.sql", "SmartAIMgr::LoadSmartAIFromDB: not yet implemented source_type {}", (uint32)source_type);
continue;
}
}
temp.source_type = source_type;
temp.event_id = fields[2].Get<uint16>();
temp.link = fields[3].Get<uint16>();
temp.event.type = (SMART_EVENT)fields[4].Get<uint8>();
temp.event.event_phase_mask = fields[5].Get<uint16>();
temp.event.event_chance = fields[6].Get<uint8>();
temp.event.event_flags = fields[7].Get<uint16>();
temp.event.raw.param1 = fields[8].Get<uint32>();
temp.event.raw.param2 = fields[9].Get<uint32>();
temp.event.raw.param3 = fields[10].Get<uint32>();
temp.event.raw.param4 = fields[11].Get<uint32>();
temp.event.raw.param5 = fields[12].Get<uint32>();
temp.event.raw.param6 = fields[13].Get<uint32>();
temp.action.type = (SMART_ACTION)fields[14].Get<uint8>();
temp.action.raw.param1 = fields[15].Get<uint32>();
temp.action.raw.param2 = fields[16].Get<uint32>();
temp.action.raw.param3 = fields[17].Get<uint32>();
temp.action.raw.param4 = fields[18].Get<uint32>();
temp.action.raw.param5 = fields[19].Get<uint32>();
temp.action.raw.param6 = fields[20].Get<uint32>();
temp.target.type = (SMARTAI_TARGETS)fields[21].Get<uint8>();
temp.target.raw.param1 = fields[22].Get<uint32>();
temp.target.raw.param2 = fields[23].Get<uint32>();
temp.target.raw.param3 = fields[24].Get<uint32>();
temp.target.raw.param4 = fields[25].Get<uint32>();
temp.target.x = fields[26].Get<float>();
temp.target.y = fields[27].Get<float>();
temp.target.z = fields[28].Get<float>();
temp.target.o = fields[29].Get<float>();
//check target
if (!IsTargetValid(temp))
continue;
// check all event and action params
if (!IsEventValid(temp))
continue;
// xinef: specific check for timed events, fix db makers
switch (temp.event.type)
{
case SMART_EVENT_UPDATE:
case SMART_EVENT_UPDATE_OOC:
case SMART_EVENT_UPDATE_IC:
case SMART_EVENT_HEALTH_PCT:
case SMART_EVENT_TARGET_HEALTH_PCT:
case SMART_EVENT_MANA_PCT:
case SMART_EVENT_TARGET_MANA_PCT:
case SMART_EVENT_FRIENDLY_HEALTH:
case SMART_EVENT_FRIENDLY_HEALTH_PCT:
case SMART_EVENT_FRIENDLY_MISSING_BUFF:
case SMART_EVENT_HAS_AURA:
case SMART_EVENT_TARGET_BUFFED:
case SMART_EVENT_RANGE:
case SMART_EVENT_AREA_RANGE:
case SMART_EVENT_AREA_CASTING:
case SMART_EVENT_IS_BEHIND_TARGET:
case SMART_EVENT_IS_IN_MELEE_RANGE:
if (temp.event.minMaxRepeat.repeatMin == 0 && temp.event.minMaxRepeat.repeatMax == 0)
temp.event.event_flags |= SMART_EVENT_FLAG_NOT_REPEATABLE;
break;
case SMART_EVENT_VICTIM_CASTING:
case SMART_EVENT_FRIENDLY_IS_CC:
if (temp.event.friendlyCC.repeatMin == 0 && temp.event.friendlyCC.repeatMax == 0)
temp.event.event_flags |= SMART_EVENT_FLAG_NOT_REPEATABLE;
break;
default:
break;
}
if (temp.action.type == SMART_ACTION_MOVE_TO_POS)
if (temp.target.type == SMART_TARGET_SELF && (std::fabs(temp.target.x) > 200.0f || std::fabs(temp.target.y) > 200.0f || std::fabs(temp.target.z) > 200.0f))
temp.target.type = SMART_TARGET_POSITION;
// creature entry / guid not found in storage, create empty event list for it and increase counters
if (mEventMap[source_type].find(temp.entryOrGuid) == mEventMap[source_type].end())
{
++count;
SmartAIEventList eventList;
mEventMap[source_type][temp.entryOrGuid] = eventList;
}
// store the new event
mEventMap[source_type][temp.entryOrGuid].push_back(temp);
} while (result->NextRow());
CheckIfSmartAIInDatabaseExists();
LOG_INFO("server.loading", ">> Loaded {} SmartAI scripts in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
LOG_INFO("server.loading", " ");
}
void SmartAIMgr::CheckIfSmartAIInDatabaseExists()
{
// SMART_SCRIPT_TYPE_CREATURE
for (auto const& [entry, creatureTemplate] : *sObjectMgr->GetCreatureTemplates())
{
if (creatureTemplate.AIName != "SmartAI")
continue;
bool found = false;
// check template SAI
if (mEventMap[uint32(SmartScriptType::SMART_SCRIPT_TYPE_CREATURE)].find(creatureTemplate.Entry) != mEventMap[uint32(SmartScriptType::SMART_SCRIPT_TYPE_CREATURE)].end())
found = true;
else
{
// check GUID SAI
for (auto const& pair : sObjectMgr->GetAllCreatureData())
{
if (pair.second.id != creatureTemplate.Entry)
continue;
if (mEventMap[uint32(SmartScriptType::SMART_SCRIPT_TYPE_CREATURE)].find((-1) * pair.first) != mEventMap[uint32(SmartScriptType::SMART_SCRIPT_TYPE_CREATURE)].end())
{
found = true;
break;
}
}
}
if (!found)
LOG_ERROR("sql.sql", "Creature entry ({}) has SmartAI enabled but no SmartAI entries in the database.", creatureTemplate.Entry);
}
// SMART_SCRIPT_TYPE_GAMEOBJECT
for (auto const& [entry, gameobjectTemplate] : *sObjectMgr->GetGameObjectTemplates())
{
if (gameobjectTemplate.AIName != "SmartGameObjectAI")
continue;
bool found = false;
// check template SAI
if (mEventMap[uint32(SmartScriptType::SMART_SCRIPT_TYPE_GAMEOBJECT)].find(gameobjectTemplate.entry) != mEventMap[uint32(SmartScriptType::SMART_SCRIPT_TYPE_GAMEOBJECT)].end())
found = true;
else
{
// check GUID SAI
for (auto const& pair : sObjectMgr->GetAllGOData())
{
if (pair.second.id != gameobjectTemplate.entry)
continue;
if (mEventMap[uint32(SmartScriptType::SMART_SCRIPT_TYPE_GAMEOBJECT)].find((-1) * pair.first) != mEventMap[uint32(SmartScriptType::SMART_SCRIPT_TYPE_GAMEOBJECT)].end())
{
found = true;
break;
}
}
}
if (!found)
LOG_ERROR("sql.sql", "Gameobject entry ({}) has SmartGameobjectAI enabled but no SmartAI entries in the database.", gameobjectTemplate.entry);
}
// SMART_SCRIPT_TYPE_AREATRIGGER
uint32 scriptID = sObjectMgr->GetScriptId("SmartTrigger");
for (auto const& pair : sObjectMgr->GetAllAreaTriggerScriptData())
{
if (pair.second != scriptID)
continue;
if (mEventMap[uint32(SmartScriptType::SMART_SCRIPT_TYPE_AREATRIGGER)].find(pair.first) == mEventMap[uint32(SmartScriptType::SMART_SCRIPT_TYPE_AREATRIGGER)].end())
LOG_ERROR("sql.sql", "AreaTrigger entry ({}) has SmartTrigger enabled but no SmartAI entries in the database.", pair.first);
}
}
/*static*/ bool SmartAIMgr::EventHasInvoker(SMART_EVENT event)
{
switch (event)
{ // white list of events that actually have an invoker passed to them
case SMART_EVENT_AGGRO:
case SMART_EVENT_DEATH:
case SMART_EVENT_KILL:
case SMART_EVENT_SUMMONED_UNIT:
case SMART_EVENT_SUMMONED_UNIT_DIES:
case SMART_EVENT_SPELLHIT:
case SMART_EVENT_SPELLHIT_TARGET:
case SMART_EVENT_DAMAGED:
case SMART_EVENT_RECEIVE_HEAL:
case SMART_EVENT_RECEIVE_EMOTE:
case SMART_EVENT_JUST_SUMMONED:
case SMART_EVENT_DAMAGED_TARGET:
case SMART_EVENT_SUMMON_DESPAWNED:
case SMART_EVENT_PASSENGER_BOARDED:
case SMART_EVENT_PASSENGER_REMOVED:
case SMART_EVENT_GOSSIP_HELLO:
case SMART_EVENT_GOSSIP_SELECT:
case SMART_EVENT_ACCEPTED_QUEST:
case SMART_EVENT_REWARD_QUEST:
case SMART_EVENT_FOLLOW_COMPLETED:
case SMART_EVENT_ON_SPELLCLICK:
case SMART_EVENT_GO_STATE_CHANGED:
case SMART_EVENT_AREATRIGGER_ONTRIGGER:
case SMART_EVENT_IC_LOS:
case SMART_EVENT_OOC_LOS:
case SMART_EVENT_DISTANCE_CREATURE:
case SMART_EVENT_FRIENDLY_HEALTH:
case SMART_EVENT_FRIENDLY_HEALTH_PCT:
case SMART_EVENT_FRIENDLY_IS_CC:
case SMART_EVENT_FRIENDLY_MISSING_BUFF:
case SMART_EVENT_ACTION_DONE:
case SMART_EVENT_TARGET_HEALTH_PCT:
case SMART_EVENT_TARGET_MANA_PCT:
case SMART_EVENT_RANGE:
case SMART_EVENT_AREA_RANGE:
case SMART_EVENT_VICTIM_CASTING:
case SMART_EVENT_AREA_CASTING:
case SMART_EVENT_TARGET_BUFFED:
case SMART_EVENT_IS_BEHIND_TARGET:
case SMART_EVENT_INSTANCE_PLAYER_ENTER:
case SMART_EVENT_TRANSPORT_ADDCREATURE:
case SMART_EVENT_NEAR_PLAYERS:
case SMART_EVENT_SUMMONED_UNIT_EVADE:
case SMART_EVENT_DATA_SET:
case SMART_EVENT_IS_IN_MELEE_RANGE:
return true;
default:
return false;
}
}
bool SmartAIMgr::IsTargetValid(SmartScriptHolder const& e)
{
if (e.GetActionType() == SMART_ACTION_INSTALL_AI_TEMPLATE)
return true; // AI template has special handling
switch (e.GetTargetType())
{
case SMART_TARGET_CREATURE_DISTANCE:
case SMART_TARGET_CREATURE_RANGE:
{
if (e.target.unitDistance.creature && !sObjectMgr->GetCreatureTemplate(e.target.unitDistance.creature))
{
LOG_ERROR("sql.sql", "SmartAIMgr: Entry {} SourceType {} Event {} Action {} uses non-existent Creature entry {} as target_param1, skipped.", e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType(), e.target.unitDistance.creature);
return false;
}
break;
}
case SMART_TARGET_GAMEOBJECT_DISTANCE:
case SMART_TARGET_GAMEOBJECT_RANGE:
{
if (e.target.goDistance.entry && !sObjectMgr->GetGameObjectTemplate(e.target.goDistance.entry))
{
LOG_ERROR("sql.sql", "SmartAIMgr: Entry {} SourceType {} Event {} Action {} uses non-existent GameObject entry {} as target_param1, skipped.", e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType(), e.target.goDistance.entry);
return false;
}
break;
}
case SMART_TARGET_CREATURE_GUID:
{
if (e.target.unitGUID.entry && !IsCreatureValid(e, e.target.unitGUID.entry))
return false;
break;
}
case SMART_TARGET_GAMEOBJECT_GUID:
{
if (e.target.goGUID.entry && !IsGameObjectValid(e, e.target.goGUID.entry))
return false;
break;
}
case SMART_TARGET_PLAYER_DISTANCE:
case SMART_TARGET_CLOSEST_PLAYER:
{
if (e.target.playerDistance.dist == 0)
{
LOG_ERROR("sql.sql", "SmartAIMgr: Entry {} SourceType {} Event {} Action {} has maxDist 0 as target_param1, skipped.", e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType());
return false;
}
break;
}
case SMART_TARGET_ACTION_INVOKER:
case SMART_TARGET_ACTION_INVOKER_VEHICLE:
case SMART_TARGET_INVOKER_PARTY:
if (e.GetScriptType() != SMART_SCRIPT_TYPE_TIMED_ACTIONLIST && e.GetEventType() != SMART_EVENT_LINK && !EventHasInvoker(e.event.type))
{
LOG_ERROR("sql.sql", "SmartAIMgr: Entry {} SourceType {} Event {} Action {} has invoker target, but event does not provide any invoker!", e.entryOrGuid, e.GetScriptType(), e.GetEventType(), e.GetActionType());
return false;
}
break;
case SMART_TARGET_SUMMONED_CREATURES:
{
if (e.target.summonedCreatures.entry && !IsCreatureValid(e, e.target.summonedCreatures.entry))
{
return false;
}
break;
}
case SMART_TARGET_INSTANCE_STORAGE:
{
if (e.target.instanceStorage.type != 1 && e.target.instanceStorage.type != 2)
{
LOG_ERROR("sql.sql", "SmartAIMgr: Entry {} SourceType {} Event {} Action {} has invalid instance storage type as target ({}).",
e.entryOrGuid, e.GetScriptType(), e.GetEventType(), e.GetActionType(), e.target.instanceStorage.type);
return false;
}
break;
}
case SMART_TARGET_FORMATION:
{
if (e.target.formation.type > 2)
{
LOG_ERROR("sql.sql", "SmartAIMgr: Entry {} SourceType {} Event {} Action {} has invalid formation target type ({}, must be 0-2).",
e.entryOrGuid, e.GetScriptType(), e.GetEventType(), e.GetActionType(), e.target.formation.type);
return false;
}
if (e.target.formation.entry && !IsCreatureValid(e, e.target.formation.entry))
return false;
return IsSAIBoolValid(e, e.target.formation.excludeSelf);
}
case SMART_TARGET_HOSTILE_SECOND_AGGRO:
case SMART_TARGET_HOSTILE_LAST_AGGRO:
case SMART_TARGET_HOSTILE_RANDOM:
case SMART_TARGET_HOSTILE_RANDOM_NOT_TOP:
return IsSAIBoolValid(e, e.target.hostileRandom.playerOnly);
case SMART_TARGET_FARTHEST:
return IsSAIBoolValid(e, e.target.farthest.playerOnly) &&
IsSAIBoolValid(e, e.target.farthest.isInLos);
break;
case SMART_TARGET_CLOSEST_CREATURE:
return IsSAIBoolValid(e, e.target.unitClosest.dead);
break;
case SMART_TARGET_CLOSEST_ENEMY:
return IsSAIBoolValid(e, e.target.closestAttackable.playerOnly);
break;
case SMART_TARGET_CLOSEST_FRIENDLY:
return IsSAIBoolValid(e, e.target.closestFriendly.playerOnly);
break;
case SMART_TARGET_OWNER_OR_SUMMONER:
return IsSAIBoolValid(e, e.target.owner.useCharmerOrOwner);
break;
case SMART_TARGET_STORED:
case SMART_TARGET_PLAYER_WITH_AURA:
case SMART_TARGET_RANDOM_POINT:
case SMART_TARGET_ROLE_SELECTION:
case SMART_TARGET_LOOT_RECIPIENTS:
case SMART_TARGET_VEHICLE_PASSENGER:
case SMART_EVENT_SUMMONED_UNIT_DIES:
case SMART_EVENT_SUMMONED_UNIT_EVADE:
case SMART_TARGET_PLAYER_RANGE:
case SMART_TARGET_CLOSEST_GAMEOBJECT:
case SMART_TARGET_SELF:
case SMART_TARGET_VICTIM:
case SMART_TARGET_POSITION:
case SMART_TARGET_NONE:
case SMART_TARGET_THREAT_LIST:
break;
default:
LOG_ERROR("sql.sql", "SmartAIMgr: Not handled target_type({}), Entry {} SourceType {} Event {} Action {}, skipped.", e.GetTargetType(), e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType());
return false;
}
if (!CheckUnusedTargetParams(e))
{
return false;
}
return true;
}
bool SmartAIMgr::CheckUnusedEventParams(SmartScriptHolder const& e)
{
std::size_t paramsStructSize = [&]() -> std::size_t
{
constexpr std::size_t NO_PARAMS = std::size_t(0);
switch (e.event.type)
{
case SMART_EVENT_UPDATE_IC: return sizeof(SmartEvent::minMaxRepeat);
case SMART_EVENT_UPDATE_OOC: return sizeof(SmartEvent::minMaxRepeat);
case SMART_EVENT_HEALTH_PCT: return sizeof(SmartEvent::minMaxRepeat);
case SMART_EVENT_MANA_PCT: return sizeof(SmartEvent::minMaxRepeat);
case SMART_EVENT_AGGRO: return NO_PARAMS;
case SMART_EVENT_KILL: return sizeof(SmartEvent::kill);
case SMART_EVENT_DEATH: return NO_PARAMS;
case SMART_EVENT_EVADE: return NO_PARAMS;
case SMART_EVENT_SPELLHIT: return sizeof(SmartEvent::spellHit);
case SMART_EVENT_RANGE: return sizeof(SmartEvent::minMaxRepeat);
case SMART_EVENT_OOC_LOS: return sizeof(SmartEvent::los);
case SMART_EVENT_RESPAWN: return sizeof(SmartEvent::respawn);
case SMART_EVENT_TARGET_HEALTH_PCT: return sizeof(SmartEvent::minMaxRepeat);
case SMART_EVENT_VICTIM_CASTING: return sizeof(SmartEvent::targetCasting);
case SMART_EVENT_FRIENDLY_HEALTH: return sizeof(SmartEvent::friendlyHealth);
case SMART_EVENT_FRIENDLY_IS_CC: return sizeof(SmartEvent::friendlyCC);
case SMART_EVENT_FRIENDLY_MISSING_BUFF: return sizeof(SmartEvent::missingBuff);
case SMART_EVENT_SUMMONED_UNIT: return sizeof(SmartEvent::summoned);
case SMART_EVENT_TARGET_MANA_PCT: return sizeof(SmartEvent::minMaxRepeat);
case SMART_EVENT_ACCEPTED_QUEST: return sizeof(SmartEvent::quest);
case SMART_EVENT_REWARD_QUEST: return sizeof(SmartEvent::quest);
case SMART_EVENT_REACHED_HOME: return NO_PARAMS;
case SMART_EVENT_RECEIVE_EMOTE: return sizeof(SmartEvent::emote);
case SMART_EVENT_HAS_AURA: return sizeof(SmartEvent::aura);
case SMART_EVENT_TARGET_BUFFED: return sizeof(SmartEvent::aura);
case SMART_EVENT_RESET: return NO_PARAMS;
case SMART_EVENT_IC_LOS: return sizeof(SmartEvent::los);
case SMART_EVENT_PASSENGER_BOARDED: return sizeof(SmartEvent::minMax);
case SMART_EVENT_PASSENGER_REMOVED: return sizeof(SmartEvent::minMax);
case SMART_EVENT_CHARMED: return sizeof(SmartEvent::charm);
case SMART_EVENT_CHARMED_TARGET: return NO_PARAMS;
case SMART_EVENT_SPELLHIT_TARGET: return sizeof(SmartEvent::spellHit);
case SMART_EVENT_DAMAGED: return sizeof(SmartEvent::minMaxRepeat);
case SMART_EVENT_DAMAGED_TARGET: return sizeof(SmartEvent::minMaxRepeat);
case SMART_EVENT_MOVEMENTINFORM: return sizeof(SmartEvent::movementInform);
case SMART_EVENT_SUMMON_DESPAWNED: return sizeof(SmartEvent::summoned);
case SMART_EVENT_CORPSE_REMOVED: return NO_PARAMS;
case SMART_EVENT_AI_INIT: return NO_PARAMS;
case SMART_EVENT_DATA_SET: return sizeof(SmartEvent::dataSet);
case SMART_EVENT_ESCORT_START: return sizeof(SmartEvent::waypoint);
case SMART_EVENT_ESCORT_REACHED: return sizeof(SmartEvent::waypoint);
case SMART_EVENT_TRANSPORT_ADDPLAYER: return NO_PARAMS;
case SMART_EVENT_TRANSPORT_ADDCREATURE: return sizeof(SmartEvent::transportAddCreature);
case SMART_EVENT_TRANSPORT_REMOVE_PLAYER: return NO_PARAMS;
case SMART_EVENT_TRANSPORT_RELOCATE: return sizeof(SmartEvent::transportRelocate);
case SMART_EVENT_INSTANCE_PLAYER_ENTER: return sizeof(SmartEvent::instancePlayerEnter);
case SMART_EVENT_AREATRIGGER_ONTRIGGER: return sizeof(SmartEvent::areatrigger);
case SMART_EVENT_QUEST_ACCEPTED: return NO_PARAMS;
case SMART_EVENT_QUEST_OBJ_COMPLETION: return NO_PARAMS;
case SMART_EVENT_QUEST_COMPLETION: return NO_PARAMS;
case SMART_EVENT_QUEST_REWARDED: return NO_PARAMS;
case SMART_EVENT_QUEST_FAIL: return NO_PARAMS;
case SMART_EVENT_TEXT_OVER: return sizeof(SmartEvent::textOver);
case SMART_EVENT_RECEIVE_HEAL: return sizeof(SmartEvent::minMaxRepeat);
case SMART_EVENT_JUST_SUMMONED: return NO_PARAMS;
case SMART_EVENT_ESCORT_PAUSED: return sizeof(SmartEvent::waypoint);
case SMART_EVENT_ESCORT_RESUMED: return sizeof(SmartEvent::waypoint);
case SMART_EVENT_ESCORT_STOPPED: return sizeof(SmartEvent::waypoint);
case SMART_EVENT_ESCORT_ENDED: return sizeof(SmartEvent::waypoint);
case SMART_EVENT_TIMED_EVENT_TRIGGERED: return sizeof(SmartEvent::timedEvent);
case SMART_EVENT_UPDATE: return sizeof(SmartEvent::minMaxRepeat);
case SMART_EVENT_LINK: return NO_PARAMS;
case SMART_EVENT_GOSSIP_SELECT: return sizeof(SmartEvent::gossip);
case SMART_EVENT_JUST_CREATED: return NO_PARAMS;
case SMART_EVENT_GOSSIP_HELLO: return sizeof(SmartEvent::gossipHello);
case SMART_EVENT_FOLLOW_COMPLETED: return NO_PARAMS;
case SMART_EVENT_EVENT_PHASE_CHANGE: return sizeof(SmartEvent::eventPhaseChange);
case SMART_EVENT_IS_BEHIND_TARGET: return sizeof(SmartEvent::minMaxRepeat);
case SMART_EVENT_IS_IN_MELEE_RANGE: return sizeof(SmartEvent::meleeRange);
case SMART_EVENT_GAME_EVENT_START: return sizeof(SmartEvent::gameEvent);
case SMART_EVENT_GAME_EVENT_END: return sizeof(SmartEvent::gameEvent);
case SMART_EVENT_GO_STATE_CHANGED: return sizeof(SmartEvent::goStateChanged);
case SMART_EVENT_GO_EVENT_INFORM: return sizeof(SmartEvent::eventInform);
case SMART_EVENT_ACTION_DONE: return sizeof(SmartEvent::doAction);
case SMART_EVENT_ON_SPELLCLICK: return NO_PARAMS;
case SMART_EVENT_FRIENDLY_HEALTH_PCT: return sizeof(SmartEvent::friendlyHealthPct);
case SMART_EVENT_DISTANCE_CREATURE: return sizeof(SmartEvent::distance);
case SMART_EVENT_DISTANCE_GAMEOBJECT: return sizeof(SmartEvent::distance);
case SMART_EVENT_COUNTER_SET: return sizeof(SmartEvent::counter);
//case SMART_EVENT_SCENE_START: return sizeof(SmartEvent::raw);
//case SMART_EVENT_SCENE_TRIGGER: return sizeof(SmartEvent::raw);
//case SMART_EVENT_SCENE_CANCEL: return sizeof(SmartEvent::raw);
//case SMART_EVENT_SCENE_COMPLETE: return sizeof(SmartEvent::raw);
case SMART_EVENT_SUMMONED_UNIT_DIES: return sizeof(SmartEvent::summoned);
case SMART_EVENT_NEAR_PLAYERS: return sizeof(SmartEvent::nearPlayer);
case SMART_EVENT_NEAR_PLAYERS_NEGATION: return sizeof(SmartEvent::nearPlayerNegation);
case SMART_EVENT_NEAR_UNIT: return sizeof(SmartEvent::nearUnit);
case SMART_EVENT_NEAR_UNIT_NEGATION: return sizeof(SmartEvent::nearUnitNegation);
case SMART_EVENT_AREA_CASTING: return sizeof(SmartEvent::minMaxRepeat);
case SMART_EVENT_AREA_RANGE: return sizeof(SmartEvent::minMaxRepeat);
case SMART_EVENT_SUMMONED_UNIT_EVADE: return sizeof(SmartEvent::summoned);
case SMART_EVENT_WAYPOINT_REACHED: return sizeof(SmartEvent::wpData);
case SMART_EVENT_WAYPOINT_ENDED: return sizeof(SmartEvent::wpData);
default:
LOG_WARN("sql.sql", "SmartAIMgr: entryorguid {} source_type {} id {} action_type {} is using an event {} with no unused params specified in SmartAIMgr::CheckUnusedEventParams(), please report this.",
e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType(), e.GetEventType());
return sizeof(SmartEvent::raw);
}
}();
static std::size_t rawCount = sizeof(SmartEvent::raw) / sizeof(uint32);
std::size_t paramsCount = paramsStructSize / sizeof(uint32);
bool valid = true;
for (std::size_t index = paramsCount; index < rawCount; index++)
{
uint32 value = ((uint32*)&e.event.raw)[index];
if (value != 0)
{
LOG_ERROR("sql.sql", "SmartAIMgr: entryorguid {} source_type {} id {} action_type {} has unused event_param{} with value {}, it must be 0, skipped.",
e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType(), index + 1, value);
valid = false;
}
}
return valid;
}
bool SmartAIMgr::CheckUnusedActionParams(SmartScriptHolder const& e)
{
std::size_t paramsStructSize = [&]() -> std::size_t
{
constexpr std::size_t NO_PARAMS = std::size_t(0);
switch (e.action.type)
{
case SMART_ACTION_NONE: return NO_PARAMS;
case SMART_ACTION_TALK: return sizeof(SmartAction::talk);
case SMART_ACTION_SET_FACTION: return sizeof(SmartAction::faction);
case SMART_ACTION_MORPH_TO_ENTRY_OR_MODEL: return sizeof(SmartAction::morphOrMount);
case SMART_ACTION_SOUND: return sizeof(SmartAction::sound);
case SMART_ACTION_PLAY_EMOTE: return sizeof(SmartAction::emote);
case SMART_ACTION_FAIL_QUEST: return sizeof(SmartAction::quest);
case SMART_ACTION_OFFER_QUEST: return sizeof(SmartAction::questOffer);
case SMART_ACTION_SET_REACT_STATE: return sizeof(SmartAction::react);
case SMART_ACTION_ACTIVATE_GOBJECT: return NO_PARAMS;
case SMART_ACTION_RANDOM_EMOTE: return sizeof(SmartAction::randomEmote);
case SMART_ACTION_CAST: return sizeof(SmartAction::cast);
case SMART_ACTION_SUMMON_CREATURE: return sizeof(SmartAction::summonCreature);
case SMART_ACTION_THREAT_SINGLE_PCT: return sizeof(SmartAction::threatPCT);
case SMART_ACTION_THREAT_ALL_PCT: return sizeof(SmartAction::threatPCT);
case SMART_ACTION_CALL_AREAEXPLOREDOREVENTHAPPENS: return sizeof(SmartAction::quest);
case SMART_ACTION_RESERVED_16: return sizeof(SmartAction::raw);
case SMART_ACTION_SET_EMOTE_STATE: return sizeof(SmartAction::emote);
case SMART_ACTION_SET_UNIT_FLAG: return sizeof(SmartAction::unitFlag);
case SMART_ACTION_REMOVE_UNIT_FLAG: return sizeof(SmartAction::unitFlag);
case SMART_ACTION_AUTO_ATTACK: return sizeof(SmartAction::autoAttack);
case SMART_ACTION_ALLOW_COMBAT_MOVEMENT: return sizeof(SmartAction::combatMove);
case SMART_ACTION_SET_EVENT_PHASE: return sizeof(SmartAction::setEventPhase);
case SMART_ACTION_INC_EVENT_PHASE: return sizeof(SmartAction::incEventPhase);
case SMART_ACTION_EVADE: return NO_PARAMS;
case SMART_ACTION_FLEE_FOR_ASSIST: return sizeof(SmartAction::flee);
case SMART_ACTION_CALL_GROUPEVENTHAPPENS: return sizeof(SmartAction::quest);
case SMART_ACTION_COMBAT_STOP: return NO_PARAMS;
case SMART_ACTION_REMOVEAURASFROMSPELL: return sizeof(SmartAction::removeAura);
case SMART_ACTION_FOLLOW: return sizeof(SmartAction::follow);
case SMART_ACTION_RANDOM_PHASE: return sizeof(SmartAction::randomPhase);
case SMART_ACTION_RANDOM_PHASE_RANGE: return sizeof(SmartAction::randomPhaseRange);
case SMART_ACTION_RESET_GOBJECT: return NO_PARAMS;
case SMART_ACTION_CALL_KILLEDMONSTER: return sizeof(SmartAction::killedMonster);
case SMART_ACTION_SET_INST_DATA: return sizeof(SmartAction::setInstanceData);
case SMART_ACTION_SET_INST_DATA64: return sizeof(SmartAction::setInstanceData64);
case SMART_ACTION_UPDATE_TEMPLATE: return sizeof(SmartAction::updateTemplate);
case SMART_ACTION_DIE: return sizeof(SmartAction::die);
case SMART_ACTION_SET_IN_COMBAT_WITH_ZONE: return NO_PARAMS;
case SMART_ACTION_CALL_FOR_HELP: return sizeof(SmartAction::callHelp);
case SMART_ACTION_SET_SHEATH: return sizeof(SmartAction::setSheath);
case SMART_ACTION_FORCE_DESPAWN: return sizeof(SmartAction::forceDespawn);
case SMART_ACTION_SET_INVINCIBILITY_HP_LEVEL: return sizeof(SmartAction::invincHP);
case SMART_ACTION_MOUNT_TO_ENTRY_OR_MODEL: return sizeof(SmartAction::morphOrMount);
case SMART_ACTION_SET_INGAME_PHASE_MASK: return sizeof(SmartAction::ingamePhaseMask);
case SMART_ACTION_SET_DATA: return sizeof(SmartAction::setData);
case SMART_ACTION_MOVE_FORWARD: return sizeof(SmartAction::moveRandom);
case SMART_ACTION_ATTACK_STOP: return NO_PARAMS;
case SMART_ACTION_SET_VISIBILITY: return sizeof(SmartAction::visibility);
case SMART_ACTION_SET_ACTIVE: return sizeof(SmartAction::setActive);
case SMART_ACTION_ATTACK_START: return NO_PARAMS;
case SMART_ACTION_SUMMON_GO: return sizeof(SmartAction::summonGO);
case SMART_ACTION_KILL_UNIT: return NO_PARAMS;
case SMART_ACTION_ACTIVATE_TAXI: return sizeof(SmartAction::taxi);
case SMART_ACTION_ESCORT_START: return sizeof(SmartAction::wpStart);
case SMART_ACTION_ESCORT_PAUSE: return sizeof(SmartAction::wpPause);
case SMART_ACTION_ESCORT_STOP: return sizeof(SmartAction::wpStop);
case SMART_ACTION_ADD_ITEM: return sizeof(SmartAction::item);
case SMART_ACTION_REMOVE_ITEM: return sizeof(SmartAction::item);
case SMART_ACTION_INSTALL_AI_TEMPLATE: return sizeof(SmartAction::installTtemplate);
case SMART_ACTION_SET_RUN: return sizeof(SmartAction::setRun);
case SMART_ACTION_SET_FLY: return sizeof(SmartAction::setFly);
case SMART_ACTION_SET_SWIM: return sizeof(SmartAction::setSwim);
case SMART_ACTION_TELEPORT: return sizeof(SmartAction::teleport);
case SMART_ACTION_SET_COUNTER: return sizeof(SmartAction::setCounter);
case SMART_ACTION_STORE_TARGET_LIST: return sizeof(SmartAction::storeTargets);
case SMART_ACTION_ESCORT_RESUME: return NO_PARAMS;
case SMART_ACTION_SET_ORIENTATION: return sizeof(SmartAction::orientation);
case SMART_ACTION_CREATE_TIMED_EVENT: return sizeof(SmartAction::timeEvent);
case SMART_ACTION_PLAYMOVIE: return sizeof(SmartAction::movie);
case SMART_ACTION_MOVE_TO_POS: return sizeof(SmartAction::moveToPos);
case SMART_ACTION_RESPAWN_TARGET: return sizeof(SmartAction::RespawnTarget);
case SMART_ACTION_EQUIP: return sizeof(SmartAction::equip);
case SMART_ACTION_CLOSE_GOSSIP: return NO_PARAMS;
case SMART_ACTION_TRIGGER_TIMED_EVENT: return sizeof(SmartAction::timeEvent);
case SMART_ACTION_REMOVE_TIMED_EVENT: return sizeof(SmartAction::timeEvent);
case SMART_ACTION_ADD_AURA: return sizeof(SmartAction::addAura);
case SMART_ACTION_OVERRIDE_SCRIPT_BASE_OBJECT: return NO_PARAMS;
case SMART_ACTION_RESET_SCRIPT_BASE_OBJECT: return NO_PARAMS;
case SMART_ACTION_CALL_SCRIPT_RESET: return NO_PARAMS;
case SMART_ACTION_SET_RANGED_MOVEMENT: return sizeof(SmartAction::setRangedMovement);
case SMART_ACTION_CALL_TIMED_ACTIONLIST: return sizeof(SmartAction::timedActionList);
case SMART_ACTION_SET_NPC_FLAG: return sizeof(SmartAction::flag);
case SMART_ACTION_ADD_NPC_FLAG: return sizeof(SmartAction::flag);
case SMART_ACTION_REMOVE_NPC_FLAG: return sizeof(SmartAction::flag);
case SMART_ACTION_SIMPLE_TALK: return sizeof(SmartAction::simpleTalk);
case SMART_ACTION_SELF_CAST: return sizeof(SmartAction::cast);
case SMART_ACTION_INVOKER_CAST: return sizeof(SmartAction::cast);
case SMART_ACTION_CROSS_CAST: return sizeof(SmartAction::crossCast);
case SMART_ACTION_CALL_RANDOM_TIMED_ACTIONLIST: return sizeof(SmartAction::randTimedActionList);
case SMART_ACTION_CALL_RANDOM_RANGE_TIMED_ACTIONLIST: return sizeof(SmartAction::randRangeTimedActionList);
case SMART_ACTION_RANDOM_MOVE: return sizeof(SmartAction::moveRandom);
case SMART_ACTION_SET_UNIT_FIELD_BYTES_1: return sizeof(SmartAction::setunitByte);
case SMART_ACTION_REMOVE_UNIT_FIELD_BYTES_1: return sizeof(SmartAction::delunitByte);
case SMART_ACTION_INTERRUPT_SPELL: return sizeof(SmartAction::interruptSpellCasting);
case SMART_ACTION_SEND_GO_CUSTOM_ANIM: return sizeof(SmartAction::sendGoCustomAnim);
case SMART_ACTION_SET_DYNAMIC_FLAG: return sizeof(SmartAction::flag);
case SMART_ACTION_ADD_DYNAMIC_FLAG: return sizeof(SmartAction::flag);
case SMART_ACTION_REMOVE_DYNAMIC_FLAG: return sizeof(SmartAction::flag);
case SMART_ACTION_JUMP_TO_POS: return sizeof(SmartAction::jump);
case SMART_ACTION_SEND_GOSSIP_MENU: return sizeof(SmartAction::sendGossipMenu);
case SMART_ACTION_GO_SET_LOOT_STATE: return sizeof(SmartAction::setGoLootState);
case SMART_ACTION_SEND_TARGET_TO_TARGET: return sizeof(SmartAction::sendTargetToTarget);
case SMART_ACTION_SET_HOME_POS: return sizeof(SmartAction::setHomePos);
case SMART_ACTION_SET_HEALTH_REGEN: return sizeof(SmartAction::setHealthRegen);
case SMART_ACTION_SET_ROOT: return sizeof(SmartAction::setRoot);
case SMART_ACTION_SET_GO_FLAG: return sizeof(SmartAction::goFlag);
case SMART_ACTION_ADD_GO_FLAG: return sizeof(SmartAction::goFlag);
case SMART_ACTION_REMOVE_GO_FLAG: return sizeof(SmartAction::goFlag);
case SMART_ACTION_SUMMON_CREATURE_GROUP: return sizeof(SmartAction::creatureGroup);
case SMART_ACTION_SET_POWER: return sizeof(SmartAction::power);
case SMART_ACTION_ADD_POWER: return sizeof(SmartAction::power);
case SMART_ACTION_REMOVE_POWER: return sizeof(SmartAction::power);
case SMART_ACTION_GAME_EVENT_STOP: return sizeof(SmartAction::gameEventStop);
case SMART_ACTION_GAME_EVENT_START: return sizeof(SmartAction::gameEventStart);
case SMART_ACTION_START_CLOSEST_WAYPOINT: return sizeof(SmartAction::startClosestWaypoint);
case SMART_ACTION_RISE_UP: return sizeof(SmartAction::moveRandom);
case SMART_ACTION_RANDOM_SOUND: return sizeof(SmartAction::randomSound);
case SMART_ACTION_SET_CORPSE_DELAY: return sizeof(SmartAction::corpseDelay);
case SMART_ACTION_DISABLE_EVADE: return sizeof(SmartAction::disableEvade);
case SMART_ACTION_GO_SET_GO_STATE: return sizeof(SmartAction::goState);
// case SMART_ACTION_SET_CAN_FLY: return sizeof(SmartAction::setFly);
// case SMART_ACTION_REMOVE_AURAS_BY_TYPE: return sizeof(SmartAction::auraType);
case SMART_ACTION_SET_SIGHT_DIST: return sizeof(SmartAction::sightDistance);
case SMART_ACTION_FLEE: return sizeof(SmartAction::flee);
case SMART_ACTION_ADD_THREAT: return sizeof(SmartAction::threat);
case SMART_ACTION_LOAD_EQUIPMENT: return sizeof(SmartAction::loadEquipment);
case SMART_ACTION_TRIGGER_RANDOM_TIMED_EVENT: return sizeof(SmartAction::randomTimedEvent);
case SMART_ACTION_REMOVE_ALL_GAMEOBJECTS: return NO_PARAMS;
// case SMART_ACTION_PAUSE_MOVEMENT: return sizeof(SmartAction::pauseMovement);
case SMART_ACTION_PLAY_ANIMKIT: return sizeof(SmartAction::raw);
case SMART_ACTION_SCENE_PLAY: return sizeof(SmartAction::raw);
case SMART_ACTION_SCENE_CANCEL: return sizeof(SmartAction::raw);
// case SMART_ACTION_SPAWN_SPAWNGROUP: return sizeof(SmartAction::groupSpawn);
// case SMART_ACTION_DESPAWN_SPAWNGROUP: return sizeof(SmartAction::groupSpawn);
// case SMART_ACTION_RESPAWN_BY_SPAWNID: return sizeof(SmartAction::respawnData);
case SMART_ACTION_PLAY_CINEMATIC: return sizeof(SmartAction::cinematic);
case SMART_ACTION_SET_MOVEMENT_SPEED: return sizeof(SmartAction::movementSpeed);
// case SMART_ACTION_PLAY_SPELL_VISUAL_KIT: return sizeof(SmartAction::raw);
// case SMART_ACTION_OVERRIDE_LIGHT: return sizeof(SmartAction::overrideLight);
// case SMART_ACTION_OVERRIDE_WEATHER: return sizeof(SmartAction::overrideWeather);
// case SMART_ACTION_SET_AI_ANIM_KIT: return sizeof(SmartAction::raw);
case SMART_ACTION_SET_HOVER: return sizeof(SmartAction::setHover);
case SMART_ACTION_SET_HEALTH_PCT: return sizeof(SmartAction::setHealthPct);
// case SMART_ACTION_CREATE_CONVERSATION: return sizeof(SmartAction::raw);
case SMART_ACTION_MOVE_TO_POS_TARGET: return sizeof(SmartAction::moveToPosTarget);
case SMART_ACTION_EXIT_VEHICLE: return NO_PARAMS;
case SMART_ACTION_SET_UNIT_MOVEMENT_FLAGS: return sizeof(SmartAction::movementFlag);
case SMART_ACTION_SET_COMBAT_DISTANCE: return sizeof(SmartAction::combatDistance);
case SMART_ACTION_FALL: return NO_PARAMS;
case SMART_ACTION_SET_EVENT_FLAG_RESET: return sizeof(SmartAction::setActive);
case SMART_ACTION_STOP_MOTION: return sizeof(SmartAction::stopMotion);
case SMART_ACTION_NO_ENVIRONMENT_UPDATE: return NO_PARAMS;
case SMART_ACTION_ZONE_UNDER_ATTACK: return NO_PARAMS;
case SMART_ACTION_LOAD_GRID: return NO_PARAMS;
case SMART_ACTION_MUSIC: return sizeof(SmartAction::music);
case SMART_ACTION_DO_ACTION: return sizeof(SmartAction::doAction);
case SMART_ACTION_SET_GUID: return sizeof(SmartAction::setGuid);
case SMART_ACTION_SCRIPTED_SPAWN: return sizeof(SmartAction::scriptSpawn);
case SMART_ACTION_SET_SCALE: return sizeof(SmartAction::setScale);
case SMART_ACTION_SUMMON_RADIAL: return sizeof(SmartAction::radialSummon);
case SMART_ACTION_PLAY_SPELL_VISUAL: return sizeof(SmartAction::spellVisual);
case SMART_ACTION_FOLLOW_GROUP: return sizeof(SmartAction::followGroup);
case SMART_ACTION_SET_ORIENTATION_TARGET: return sizeof(SmartAction::orientationTarget);
case SMART_ACTION_WAYPOINT_START: return sizeof(SmartAction::wpData);
case SMART_ACTION_WAYPOINT_DATA_RANDOM: return sizeof(SmartAction::wpDataRandom);
case SMART_ACTION_MOVEMENT_STOP: return NO_PARAMS;
case SMART_ACTION_MOVEMENT_PAUSE: return sizeof(SmartAction::move);
case SMART_ACTION_MOVEMENT_RESUME: return sizeof(SmartAction::move);
case SMART_ACTION_WORLD_SCRIPT: return sizeof(SmartAction::worldStateScript);
case SMART_ACTION_DISABLE_REWARD: return sizeof(SmartAction::reward);
case SMART_ACTION_SET_ANIM_TIER: return sizeof(SmartAction::animTier);
case SMART_ACTION_SET_GOSSIP_MENU: return sizeof(SmartAction::setGossipMenu);
case SMART_ACTION_SUMMON_GAMEOBJECT_GROUP: return sizeof(SmartAction::gameobjectGroup);
case SMART_ACTION_DISMOUNT: return NO_PARAMS;
default:
LOG_WARN("sql.sql", "SmartAIMgr: entryorguid {} source_type {} id {} action_type {} is using an action with no unused params specified in SmartAIMgr::CheckUnusedActionParams(), please report this.",
e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType());
return sizeof(SmartAction::raw);
}
}();
static std::size_t rawCount = sizeof(SmartAction::raw) / sizeof(uint32);
std::size_t paramsCount = paramsStructSize / sizeof(uint32);
bool valid = true;
for (std::size_t index = paramsCount; index < rawCount; index++)
{
uint32 value = ((uint32*)&e.action.raw)[index];
if (value != 0)
{
LOG_ERROR("sql.sql", "SmartAIMgr: entryorguid {} source_type {} id {} action_type {} has unused action_param{} with value {}, it must be 0, skipped.",
e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType(), index + 1, value);
valid = false;
}
}
return valid;
}
bool SmartAIMgr::CheckUnusedTargetParams(SmartScriptHolder const& e)
{
std::size_t paramsStructSize = [&]() -> std::size_t
{
constexpr std::size_t NO_PARAMS = std::size_t(0);
switch (e.target.type)
{
case SMART_TARGET_NONE: return NO_PARAMS;
case SMART_TARGET_SELF: return NO_PARAMS;
case SMART_TARGET_VICTIM: return NO_PARAMS;
case SMART_TARGET_HOSTILE_SECOND_AGGRO: return sizeof(SmartTarget::hostileRandom);
case SMART_TARGET_HOSTILE_LAST_AGGRO: return sizeof(SmartTarget::hostileRandom);
case SMART_TARGET_HOSTILE_RANDOM: return sizeof(SmartTarget::hostileRandom);
case SMART_TARGET_HOSTILE_RANDOM_NOT_TOP: return sizeof(SmartTarget::hostileRandom);
case SMART_TARGET_ACTION_INVOKER: return NO_PARAMS;
case SMART_TARGET_POSITION: return NO_PARAMS; //uses x,y,z,o
case SMART_TARGET_CREATURE_RANGE: return sizeof(SmartTarget::unitRange);
case SMART_TARGET_CREATURE_GUID: return sizeof(SmartTarget::unitGUID);
case SMART_TARGET_CREATURE_DISTANCE: return sizeof(SmartTarget::unitDistance);
case SMART_TARGET_STORED: return sizeof(SmartTarget::stored);
case SMART_TARGET_GAMEOBJECT_RANGE: return sizeof(SmartTarget::goRange);
case SMART_TARGET_GAMEOBJECT_GUID: return sizeof(SmartTarget::goGUID);
case SMART_TARGET_GAMEOBJECT_DISTANCE: return sizeof(SmartTarget::goDistance);
case SMART_TARGET_INVOKER_PARTY: return sizeof(SmartTarget::invokerParty);
case SMART_TARGET_PLAYER_RANGE: return sizeof(SmartTarget::playerRange);
case SMART_TARGET_PLAYER_DISTANCE: return sizeof(SmartTarget::playerDistance);
case SMART_TARGET_CLOSEST_CREATURE: return sizeof(SmartTarget::unitClosest);
case SMART_TARGET_CLOSEST_GAMEOBJECT: return sizeof(SmartTarget::goClosest);
case SMART_TARGET_CLOSEST_PLAYER: return sizeof(SmartTarget::playerDistance);
case SMART_TARGET_ACTION_INVOKER_VEHICLE: return NO_PARAMS;
case SMART_TARGET_OWNER_OR_SUMMONER: return sizeof(SmartTarget::owner);
case SMART_TARGET_THREAT_LIST: return sizeof(SmartTarget::threatList);
case SMART_TARGET_CLOSEST_ENEMY: return sizeof(SmartTarget::closestAttackable);
case SMART_TARGET_CLOSEST_FRIENDLY: return sizeof(SmartTarget::closestFriendly);
case SMART_TARGET_LOOT_RECIPIENTS: return NO_PARAMS;
case SMART_TARGET_FARTHEST: return sizeof(SmartTarget::farthest);
case SMART_TARGET_VEHICLE_PASSENGER: return sizeof(SmartTarget::vehicle);
// case SMART_TARGET_CLOSEST_UNSPAWNED_GAMEOBJECT: return sizeof(SmartTarget::goClosest);
case SMART_TARGET_PLAYER_WITH_AURA: return sizeof(SmartTarget::playerWithAura);
case SMART_TARGET_RANDOM_POINT: return sizeof(SmartTarget::randomPoint);
case SMART_TARGET_SUMMONED_CREATURES: return sizeof(SmartTarget::summonedCreatures);
case SMART_TARGET_INSTANCE_STORAGE: return sizeof(SmartTarget::instanceStorage);
case SMART_TARGET_FORMATION: return sizeof(SmartTarget::formation);
default:
LOG_WARN("sql.sql", "SmartAIMgr: entryorguid {} source_type {} id {} action_type {} is using a target {} with no unused params specified in SmartAIMgr::CheckUnusedTargetParams(), please report this.",
e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType(), e.GetTargetType());
return sizeof(SmartTarget::raw);
}
}();
static std::size_t rawCount = sizeof(SmartTarget::raw) / sizeof(uint32);
std::size_t paramsCount = paramsStructSize / sizeof(uint32);
bool valid = true;
for (std::size_t index = paramsCount; index < rawCount; index++)
{
uint32 value = ((uint32*)&e.target.raw)[index];
if (value != 0)
{
LOG_ERROR("sql.sql", "SmartAIMgr: entryorguid {} source_type {} id {} action_type {} has unused target_param{} with value {}, it must be 0, skipped.",
e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType(), index + 1, value);
valid = false;
}
}
return valid;
}
bool SmartAIMgr::IsEventValid(SmartScriptHolder& e)
{
if ((e.event.type >= SMART_EVENT_TC_END && e.event.type <= SMART_EVENT_AC_START) || e.event.type >= SMART_EVENT_AC_END)
{
LOG_ERROR("sql.sql", "SmartAIMgr: EntryOrGuid {} using event({}) has invalid event type ({}), skipped.", e.entryOrGuid, e.event_id, e.GetEventType());
return false;
}
// in SMART_SCRIPT_TYPE_TIMED_ACTIONLIST all event types are overriden by core
if (e.GetScriptType() != SMART_SCRIPT_TYPE_TIMED_ACTIONLIST && !(SmartAIEventMask[e.event.type][1] & SmartAITypeMask[e.GetScriptType()][1]))
{
LOG_ERROR("sql.sql", "SmartAIMgr: EntryOrGuid {}, event type {} can not be used for Script type {}", e.entryOrGuid, e.GetEventType(), e.GetScriptType());
return false;
}
if (e.action.type <= 0
|| (e.action.type >= SMART_ACTION_TC_END && e.action.type <= SMART_ACTION_AC_START)
|| e.action.type >= SMART_ACTION_AC_END)
{