/
ScriptMgr.cpp
3299 lines (2983 loc) · 122 KB
/
ScriptMgr.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* MaNGOS is a full featured server for World of Warcraft, supporting
* the following clients: 1.12.x, 2.4.3, 3.3.5a, 4.3.4a and 5.4.8
*
* Copyright (C) 2005-2023 MaNGOS <https://getmangos.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* World of Warcraft, and all World of Warcraft or Warcraft art, images,
* and lore are copyrighted by Blizzard Entertainment, Inc.
*/
#include "ScriptMgr.h"
#include "Policies/Singleton.h"
#include "Log.h"
#include "ProgressBar.h"
#include "ObjectMgr.h"
#include "WaypointManager.h"
#include "World.h"
#include <DBCStores.h>
#include "GridNotifiers.h"
#include "GridNotifiersImpl.h"
#include "Cell.h"
#include "CellImpl.h"
#include "SQLStorages.h"
#include "BattleGround/BattleGround.h"
#include "OutdoorPvP/OutdoorPvP.h"
#include "WaypointMovementGenerator.h"
#include "Mail.h"
#if defined(CLASSIC)
#include "LFGMgr.h"
#endif
#ifdef ENABLE_ELUNA
#include "LuaEngine.h"
#endif /* ENABLE_ELUNA */
#ifdef ENABLE_SD3
#include "system/ScriptDevMgr.h"
#endif
#include <cstring> /* std::strcmp */
INSTANTIATE_SINGLETON_1(ScriptMgr);
ScriptMgr::ScriptMgr() : m_scheduledScripts(0), m_lock(0)
{
m_dbScripts.resize(DBS_END);
ScriptChainMap emptyMap;
for (int t = DBS_START; t < DBS_END; ++t)
{
m_dbScripts[t] = emptyMap;
}
}
ScriptMgr::~ScriptMgr()
{
m_dbScripts.clear();
}
ScriptChainMap const* ScriptMgr::GetScriptChainMap(DBScriptType type)
{
ACE_GUARD_RETURN(ACE_Thread_Mutex, _guard, m_lock, NULL)
if ((type != DBS_INTERNAL) && type < DBS_END)
{
return &m_dbScripts[type];
}
return NULL;
}
// /////////////////////////////////////////////////////////
// DB SCRIPTS (loaders of static data)
// /////////////////////////////////////////////////////////
// returns priority (0 == can not start script)
uint8 GetSpellStartDBScriptPriority(SpellEntry const* spellinfo, SpellEffectIndex effIdx)
{
#if defined (CATA)
SpellEffectEntry const* spellEffect = spellinfo->GetSpellEffect(effIdx);
if (!spellEffect)
{
return 0;
}
#endif
#if defined (CATA)
if (spellEffect->Effect == SPELL_EFFECT_SCRIPT_EFFECT)
#else
if (spellinfo->Effect[effIdx] == SPELL_EFFECT_SCRIPT_EFFECT)
#endif
{
return 10;
}
#if defined (CATA)
if (spellEffect->Effect == SPELL_EFFECT_DUMMY)
#else
if (spellinfo->Effect[effIdx] == SPELL_EFFECT_DUMMY)
#endif
{
return 9;
}
// NonExisting triggered spells can also start DB-Spell-Scripts
#if defined (CATA)
if (spellEffect->Effect == SPELL_EFFECT_TRIGGER_SPELL && !sSpellStore.LookupEntry(spellEffect->EffectTriggerSpell))
#else
if (spellinfo->Effect[effIdx] == SPELL_EFFECT_TRIGGER_SPELL && !sSpellStore.LookupEntry(spellinfo->EffectTriggerSpell[effIdx]))
#endif
{
return 5;
}
// NonExisting trigger missile spells can also start DB-Spell-Scripts
#if defined (CATA)
if (spellEffect->Effect == SPELL_EFFECT_TRIGGER_MISSILE && !sSpellStore.LookupEntry(spellEffect->EffectTriggerSpell))
#else
if (spellinfo->Effect[effIdx] == SPELL_EFFECT_TRIGGER_MISSILE && !sSpellStore.LookupEntry(spellinfo->EffectTriggerSpell[effIdx]))
#endif
{
return 4;
}
// Can not start script
return 0;
}
// Priorize: SCRIPT_EFFECT before DUMMY before Non-Existing triggered spell, for same priority the first effect with the priority triggers
bool ScriptMgr::CanSpellEffectStartDBScript(SpellEntry const* spellinfo, SpellEffectIndex effIdx)
{
uint8 priority = GetSpellStartDBScriptPriority(spellinfo, effIdx);
if (!priority)
{
return false;
}
for (int i = 0; i < MAX_EFFECT_INDEX; ++i)
{
uint8 currentPriority = GetSpellStartDBScriptPriority(spellinfo, SpellEffectIndex(i));
if (currentPriority < priority) // lower priority, continue checking
{
continue;
}
if (currentPriority > priority) // take other index with higher priority
{
return false;
}
if (i < effIdx) // same priority at lower index
{
return false;
}
}
return true;
}
void ScriptMgr::LoadScripts(DBScriptType type)
{
if (IsScriptScheduled()) // function don't must be called in time scripts use.
{
return;
}
m_dbScripts[type].clear(); // need for reload support
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
QueryResult* result = WorldDatabase.PQuery("SELECT `id`, `delay`, `command`, `datalong`, `datalong2`, `buddy_entry`, `search_radius`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o` FROM `db_scripts` WHERE `script_type` = %d ORDER BY `script_guid` ASC", type);
uint32 count = 0;
if (!result)
{
BarGoLink bar(1);
bar.step();
sLog.outString(">> Loaded %u script definitions from `db_scripts [type %d]` table", count, type);
sLog.outString();
return;
}
BarGoLink bar(result->GetRowCount());
do
{
bar.step();
Field* fields = result->Fetch();
ScriptInfo tmp;
tmp.id = fields[0].GetUInt32();
tmp.delay = fields[1].GetUInt32();
tmp.command = fields[2].GetUInt32();
tmp.raw.data[0] = fields[3].GetUInt32();
tmp.raw.data[1] = fields[4].GetUInt32();
tmp.buddyEntry = fields[5].GetUInt32();
tmp.searchRadiusOrGuid = fields[6].GetUInt32();
tmp.data_flags = fields[7].GetUInt8();
tmp.textId[0] = fields[8].GetInt32();
tmp.textId[1] = fields[9].GetInt32();
tmp.textId[2] = fields[10].GetInt32();
tmp.textId[3] = fields[11].GetInt32();
tmp.x = fields[12].GetFloat();
tmp.y = fields[13].GetFloat();
tmp.z = fields[14].GetFloat();
tmp.o = fields[15].GetFloat();
// generic command args check
if (tmp.buddyEntry && !(tmp.data_flags & SCRIPT_FLAG_BUDDY_BY_GUID))
{
if (tmp.IsCreatureBuddy() && !ObjectMgr::GetCreatureTemplate(tmp.buddyEntry))
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has buddyEntry = %u in command %u for script id %u, but this creature_template does not exist, skipping.", type, tmp.buddyEntry, tmp.command, tmp.id);
continue;
}
else if (!tmp.IsCreatureBuddy() && !ObjectMgr::GetGameObjectInfo(tmp.buddyEntry))
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has buddyEntry = %u in command %u for script id %u, but this gameobject_template does not exist, skipping.", type, tmp.buddyEntry, tmp.command, tmp.id);
continue;
}
if (!tmp.searchRadiusOrGuid)
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has searchRadius = 0 in command %u for script id %u for buddy %u, skipping.", type, tmp.command, tmp.id, tmp.buddyEntry);
continue;
}
}
if (tmp.data_flags) // Check flags
{
if (tmp.data_flags & ~MAX_SCRIPT_FLAG_VALID)
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has invalid data_flags %u in command %u for script id %u, skipping.", type, tmp.data_flags, tmp.command, tmp.id);
continue;
}
if (!tmp.HasAdditionalScriptFlag() && tmp.data_flags & SCRIPT_FLAG_COMMAND_ADDITIONAL)
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has invalid data_flags %u in command %u for script id %u, skipping.", type, tmp.data_flags, tmp.command, tmp.id);
continue;
}
if (tmp.data_flags & SCRIPT_FLAG_BUDDY_AS_TARGET && ! tmp.buddyEntry)
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has buddy required in data_flags %u in command %u for script id %u, but no buddy defined, skipping.", type, tmp.data_flags, tmp.command, tmp.id);
continue;
}
if (tmp.data_flags & SCRIPT_FLAG_BUDDY_BY_GUID) // Check guid
{
if (tmp.IsCreatureBuddy())
{
CreatureData const* data = sObjectMgr.GetCreatureData(tmp.searchRadiusOrGuid);
if (!data)
{
sLog.outErrorDb("Table `db_scripts [type = %d]`, script %u has buddy defined by guid (SCRIPT_FLAG_BUDDY_BY_GUID %u set) but no npc spawned with guid %u, skipping.", type, tmp.id, SCRIPT_FLAG_BUDDY_BY_GUID, tmp.searchRadiusOrGuid);
continue;
}
if (data->id != tmp.buddyEntry)
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has buddy defined by guid (SCRIPT_FLAG_BUDDY_BY_GUID %u set) but spawned npc with guid %u has entry %u, expected buddy_entry is %u, skipping.", type, SCRIPT_FLAG_BUDDY_BY_GUID, tmp.searchRadiusOrGuid, data->id, tmp.buddyEntry);
continue;
}
}
else
{
GameObjectData const* data = sObjectMgr.GetGOData(tmp.searchRadiusOrGuid);
if (!data)
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has go-buddy defined by guid (SCRIPT_FLAG_BUDDY_BY_GUID %u set) but no go spawned with guid %u, skipping.", type, SCRIPT_FLAG_BUDDY_BY_GUID, tmp.searchRadiusOrGuid);
continue;
}
if (data->id != tmp.buddyEntry)
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has go-buddy defined by guid (SCRIPT_FLAG_BUDDY_BY_GUID %u set) but spawned go with guid %u has entry %u, expected buddy_entry is %u, skipping.", type, SCRIPT_FLAG_BUDDY_BY_GUID, tmp.searchRadiusOrGuid, data->id, tmp.buddyEntry);
continue;
}
}
}
}
switch (tmp.command)
{
case SCRIPT_COMMAND_TALK: // 0
{
if (tmp.textId[0] == 0)
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has invalid talk text id (dataint = %i) in SCRIPT_COMMAND_TALK for script id %u", type, tmp.textId[0], tmp.id);
continue;
}
for (int i = 0; i < MAX_TEXT_ID; ++i)
{
if (tmp.textId[i] && (tmp.textId[i] < MIN_DB_SCRIPT_STRING_ID || tmp.textId[i] >= MAX_DB_SCRIPT_STRING_ID))
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has out of range text_id%u (dataint = %i expected %u-%u) in SCRIPT_COMMAND_TALK for script id %u", type, i + 1, tmp.textId[i], MIN_DB_SCRIPT_STRING_ID, MAX_DB_SCRIPT_STRING_ID, tmp.id);
continue;
}
}
// if (!GetMangosStringLocale(tmp.dataint)) will be checked after db_script_string loading
break;
}
case SCRIPT_COMMAND_EMOTE: // 1
{
if (!sEmotesStore.LookupEntry(tmp.emote.emoteId))
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has invalid emote id (datalong = %u) in SCRIPT_COMMAND_EMOTE for script id %u", type, tmp.emote.emoteId, tmp.id);
continue;
}
for (int i = 0; i < MAX_TEXT_ID; ++i)
{
if (tmp.textId[i] && !sEmotesStore.LookupEntry(tmp.textId[i]))
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has invalid emote id (text_id%u = %u) in SCRIPT_COMMAND_EMOTE for script id %u", type, i + 1, tmp.textId[i], tmp.id);
continue;
}
}
break;
}
case SCRIPT_COMMAND_FIELD_SET: // 2
case SCRIPT_COMMAND_MOVE_TO: // 3
case SCRIPT_COMMAND_FLAG_SET: // 4
case SCRIPT_COMMAND_FLAG_REMOVE: // 5
break;
case SCRIPT_COMMAND_TELEPORT_TO: // 6
{
if (!sMapStore.LookupEntry(tmp.teleportTo.mapId))
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has invalid map (Id: %u) in SCRIPT_COMMAND_TELEPORT_TO for script id %u", type, tmp.teleportTo.mapId, tmp.id);
continue;
}
if (!MaNGOS::IsValidMapCoord(tmp.x, tmp.y, tmp.z, tmp.o))
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has invalid coordinates (X: %f Y: %f) in SCRIPT_COMMAND_TELEPORT_TO for script id %u", type, tmp.x, tmp.y, tmp.id);
continue;
}
break;
}
case SCRIPT_COMMAND_QUEST_EXPLORED: // 7
{
Quest const* quest = sObjectMgr.GetQuestTemplate(tmp.questExplored.questId);
if (!quest)
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has invalid quest (ID: %u) in SCRIPT_COMMAND_QUEST_EXPLORED in `datalong` for script id %u", type, tmp.questExplored.questId, tmp.id);
continue;
}
if (!quest->HasSpecialFlag(QUEST_SPECIAL_FLAG_EXPLORATION_OR_EVENT))
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has quest (ID: %u) in SCRIPT_COMMAND_QUEST_EXPLORED in `datalong` for script id %u, but quest not have flag QUEST_SPECIAL_FLAG_EXPLORATION_OR_EVENT in quest flags. Script command or quest flags wrong. Quest modified to require objective.", type, tmp.questExplored.questId, tmp.id);
// this will prevent quest completing without objective
const_cast<Quest*>(quest)->SetSpecialFlag(QUEST_SPECIAL_FLAG_EXPLORATION_OR_EVENT);
// continue; - quest objective requirement set and command can be allowed
}
if (float(tmp.questExplored.distance) > DEFAULT_VISIBILITY_DISTANCE)
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has too large distance (%u) for exploring objective complete in `datalong2` in SCRIPT_COMMAND_QUEST_EXPLORED in `datalong` for script id %u",
type, tmp.questExplored.distance, tmp.id);
continue;
}
if (tmp.questExplored.distance && float(tmp.questExplored.distance) > DEFAULT_VISIBILITY_DISTANCE)
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has too large distance (%u) for exploring objective complete in `datalong2` in SCRIPT_COMMAND_QUEST_EXPLORED in `datalong` for script id %u, max distance is %f or 0 for disable distance check",
type, tmp.questExplored.distance, tmp.id, DEFAULT_VISIBILITY_DISTANCE);
continue;
}
if (tmp.questExplored.distance && float(tmp.questExplored.distance) < INTERACTION_DISTANCE)
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has too small distance (%u) for exploring objective complete in `datalong2` in SCRIPT_COMMAND_QUEST_EXPLORED in `datalong` for script id %u, min distance is %f or 0 for disable distance check",
type, tmp.questExplored.distance, tmp.id, INTERACTION_DISTANCE);
continue;
}
break;
}
case SCRIPT_COMMAND_KILL_CREDIT: // 8
{
if (tmp.killCredit.creatureEntry && !ObjectMgr::GetCreatureTemplate(tmp.killCredit.creatureEntry))
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has invalid creature (Entry: %u) in SCRIPT_COMMAND_KILL_CREDIT for script id %u", type, tmp.killCredit.creatureEntry, tmp.id);
continue;
}
break;
}
case SCRIPT_COMMAND_RESPAWN_GO: // 9
{
uint32 goEntry;
if (!tmp.GetGOGuid())
{
if (!tmp.buddyEntry)
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has no gameobject nor buddy defined in SCRIPT_COMMAND_RESPAWN_GO for script id %u", type, tmp.id);
continue;
}
goEntry = tmp.buddyEntry;
}
else
{
GameObjectData const* data = sObjectMgr.GetGOData(tmp.GetGOGuid());
if (!data)
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has invalid gameobject (GUID: %u) in SCRIPT_COMMAND_RESPAWN_GO for script id %u", type, tmp.GetGOGuid(), tmp.id);
continue;
}
goEntry = data->id;
}
GameObjectInfo const* info = ObjectMgr::GetGameObjectInfo(goEntry);
if (!info)
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has gameobject with invalid entry (GUID: %u Entry: %u) in SCRIPT_COMMAND_RESPAWN_GO for script id %u", type, tmp.GetGOGuid(), goEntry, tmp.id);
continue;
}
if (info->type == GAMEOBJECT_TYPE_FISHINGNODE ||
info->type == GAMEOBJECT_TYPE_FISHINGHOLE ||
info->type == GAMEOBJECT_TYPE_DOOR)
{
sLog.outErrorDb("Table `db_scripts [type = %d]` have gameobject type (%u) unsupported by command SCRIPT_COMMAND_RESPAWN_GO for script id %u", type, info->type, tmp.id);
continue;
}
break;
}
case SCRIPT_COMMAND_TEMP_SUMMON_CREATURE: // 10
{
if (!MaNGOS::IsValidMapCoord(tmp.x, tmp.y, tmp.z, tmp.o))
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has invalid coordinates (X: %f Y: %f) in SCRIPT_COMMAND_TEMP_SUMMON_CREATURE for script id %u", type, tmp.x, tmp.y, tmp.id);
continue;
}
if (!ObjectMgr::GetCreatureTemplate(tmp.summonCreature.creatureEntry))
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has invalid creature (Entry: %u) in SCRIPT_COMMAND_TEMP_SUMMON_CREATURE for script id %u", type, tmp.summonCreature.creatureEntry, tmp.id);
continue;
}
break;
}
case SCRIPT_COMMAND_OPEN_DOOR: // 11
case SCRIPT_COMMAND_CLOSE_DOOR: // 12
{
uint32 goEntry;
if (!tmp.GetGOGuid())
{
if (!tmp.buddyEntry)
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has no gameobject nor buddy defined in %s for script id %u", type, (tmp.command == SCRIPT_COMMAND_OPEN_DOOR ? "SCRIPT_COMMAND_OPEN_DOOR" : "SCRIPT_COMMAND_CLOSE_DOOR"), tmp.id);
continue;
}
goEntry = tmp.buddyEntry;
}
else
{
GameObjectData const* data = sObjectMgr.GetGOData(tmp.GetGOGuid());
if (!data)
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has invalid gameobject (GUID: %u) in %s for script id %u", type, tmp.GetGOGuid(), (tmp.command == SCRIPT_COMMAND_OPEN_DOOR ? "SCRIPT_COMMAND_OPEN_DOOR" : "SCRIPT_COMMAND_CLOSE_DOOR"), tmp.id);
continue;
}
goEntry = data->id;
}
GameObjectInfo const* info = ObjectMgr::GetGameObjectInfo(goEntry);
if (!info)
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has gameobject with invalid entry (GUID: %u Entry: %u) in %s for script id %u", type, tmp.GetGOGuid(), goEntry, (tmp.command == SCRIPT_COMMAND_OPEN_DOOR ? "SCRIPT_COMMAND_OPEN_DOOR" : "SCRIPT_COMMAND_CLOSE_DOOR"), tmp.id);
continue;
}
if (info->type != GAMEOBJECT_TYPE_DOOR)
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has gameobject type (%u) non supported by command %s for script id %u", type, info->id, (tmp.command == SCRIPT_COMMAND_OPEN_DOOR ? "SCRIPT_COMMAND_OPEN_DOOR" : "SCRIPT_COMMAND_CLOSE_DOOR"), tmp.id);
continue;
}
break;
}
case SCRIPT_COMMAND_ACTIVATE_OBJECT: // 13
break;
case SCRIPT_COMMAND_REMOVE_AURA: // 14
{
if (!sSpellStore.LookupEntry(tmp.removeAura.spellId))
{
sLog.outErrorDb("Table `db_scripts [type = %d]` using nonexistent spell (id: %u) in SCRIPT_COMMAND_REMOVE_AURA or SCRIPT_COMMAND_CAST_SPELL for script id %u",
type, tmp.removeAura.spellId, tmp.id);
continue;
}
break;
}
case SCRIPT_COMMAND_CAST_SPELL: // 15
{
if (!sSpellStore.LookupEntry(tmp.castSpell.spellId))
{
sLog.outErrorDb("Table `db_scripts [type = %d]` using nonexistent spell (id: %u) in SCRIPT_COMMAND_REMOVE_AURA or SCRIPT_COMMAND_CAST_SPELL for script id %u",
type, tmp.castSpell.spellId, tmp.id);
continue;
}
bool hasErrored = false;
for (uint8 i = 0; i < MAX_TEXT_ID; ++i)
{
if (tmp.textId[i] && !sSpellStore.LookupEntry(uint32(tmp.textId[i])))
{
sLog.outErrorDb("Table `db_scripts [type = %d]` using nonexistent spell (id: %u) in SCRIPT_COMMAND_CAST_SPELL for script id %u, dataint%u",
type, uint32(tmp.textId[i]), tmp.id, i + 1);
hasErrored = true;
}
}
if (hasErrored)
{
continue;
}
break;
}
case SCRIPT_COMMAND_PLAY_SOUND: // 16
{
if (!sSoundEntriesStore.LookupEntry(tmp.playSound.soundId))
{
sLog.outErrorDb("Table `db_scripts [type = %d]` using nonexistent sound (id: %u) in SCRIPT_COMMAND_PLAY_SOUND for script id %u",
type, tmp.playSound.soundId, tmp.id);
continue;
}
// bitmask: 0/1=target-player, 0/2=with distance dependent, 0/4=map wide, 0/8=zone wide
if (tmp.playSound.flags & ~(1 | 2 | 4 | 8))
{
sLog.outErrorDb("Table `db_scripts [type = %d]` using unsupported sound flags (datalong2: %u) in SCRIPT_COMMAND_PLAY_SOUND for script id %u, unsupported flags will be ignored", type, tmp.playSound.flags, tmp.id);
}
if ((tmp.playSound.flags & (1 | 2)) > 0 && (tmp.playSound.flags & (4 | 8)) > 0)
{
sLog.outErrorDb("Table `db_scripts [type = %d]` uses sound flags (datalong2: %u) in SCRIPT_COMMAND_PLAY_SOUND for script id %u, combining (1|2) with (4|8) makes no sense", type, tmp.playSound.flags, tmp.id);
}
break;
}
case SCRIPT_COMMAND_CREATE_ITEM: // 17
{
if (!ObjectMgr::GetItemPrototype(tmp.createItem.itemEntry))
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has nonexistent item (entry: %u) in SCRIPT_COMMAND_CREATE_ITEM for script id %u",
type, tmp.createItem.itemEntry, tmp.id);
continue;
}
if (!tmp.createItem.amount)
{
sLog.outErrorDb("Table `db_scripts [type = %d]` SCRIPT_COMMAND_CREATE_ITEM but amount is %u for script id %u",
type, tmp.createItem.amount, tmp.id);
continue;
}
break;
}
case SCRIPT_COMMAND_DESPAWN_SELF: // 18
{
// for later, we might consider despawn by database guid, and define in datalong2 as option to despawn self.
break;
}
case SCRIPT_COMMAND_PLAY_MOVIE: // 19
{
#if defined(CLASSIC)
sLog.outErrorDb("Table `db_scripts [type = %d]` use unsupported SCRIPT_COMMAND_PLAY_MOVIE for script id %u",
type, tmp.id);
continue;
#else
if (!sMovieStore.LookupEntry(tmp.playMovie.movieId))
{
sLog.outErrorDb("Table `db_scripts [type = %d]` use non-existing movie_id (id: %u) in SCRIPT_COMMAND_PLAY_MOVIE for script id %u",
type, tmp.playMovie.movieId, tmp.id);
continue;
}
break;
#endif
}
case SCRIPT_COMMAND_MOVEMENT: // 20
{
if (tmp.movement.movementType >= MAX_DB_MOTION_TYPE)
{
sLog.outErrorDb("Table `db_scripts [type = %d]` SCRIPT_COMMAND_MOVEMENT has invalid MovementType %u for script id %u",
type, tmp.movement.movementType, tmp.id);
continue;
}
break;
}
case SCRIPT_COMMAND_SET_ACTIVEOBJECT: // 21
break;
case SCRIPT_COMMAND_SET_FACTION: // 22
{
if (tmp.faction.factionId && !sFactionTemplateStore.LookupEntry(tmp.faction.factionId))
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has datalong = %u in SCRIPT_COMMAND_SET_FACTION for script id %u, but this faction-template does not exist.", type, tmp.faction.factionId, tmp.id);
continue;
}
break;
}
case SCRIPT_COMMAND_MORPH_TO_ENTRY_OR_MODEL: // 23
{
if (tmp.data_flags & SCRIPT_FLAG_COMMAND_ADDITIONAL)
{
if (tmp.morph.creatureOrModelEntry && !sCreatureDisplayInfoStore.LookupEntry(tmp.morph.creatureOrModelEntry))
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has datalong = %u in SCRIPT_COMMAND_MORPH_TO_ENTRY_OR_MODEL for script id %u, but this model does not exist.", type, tmp.morph.creatureOrModelEntry, tmp.id);
continue;
}
}
else
{
if (tmp.morph.creatureOrModelEntry && !ObjectMgr::GetCreatureTemplate(tmp.morph.creatureOrModelEntry))
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has datalong = %u in SCRIPT_COMMAND_MORPH_TO_ENTRY_OR_MODEL for script id %u, but this creature_template does not exist.", type, tmp.morph.creatureOrModelEntry, tmp.id);
continue;
}
}
break;
}
case SCRIPT_COMMAND_MOUNT_TO_ENTRY_OR_MODEL: // 24
{
if (tmp.data_flags & SCRIPT_FLAG_COMMAND_ADDITIONAL)
{
if (tmp.mount.creatureOrModelEntry && !sCreatureDisplayInfoStore.LookupEntry(tmp.mount.creatureOrModelEntry))
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has datalong = %u in SCRIPT_COMMAND_MOUNT_TO_ENTRY_OR_MODEL for script id %u, but this model does not exist.", type, tmp.mount.creatureOrModelEntry, tmp.id);
continue;
}
}
else
{
if (tmp.mount.creatureOrModelEntry && !ObjectMgr::GetCreatureTemplate(tmp.mount.creatureOrModelEntry))
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has datalong = %u in SCRIPT_COMMAND_MOUNT_TO_ENTRY_OR_MODEL for script id %u, but this creature_template does not exist.", type, tmp.mount.creatureOrModelEntry, tmp.id);
continue;
}
}
break;
}
case SCRIPT_COMMAND_SET_RUN: // 25
case SCRIPT_COMMAND_ATTACK_START: // 26
break;
case SCRIPT_COMMAND_GO_LOCK_STATE: // 27
{
if (// lock(0x01) and unlock(0x02) together
((tmp.goLockState.lockState & 0x01) && (tmp.goLockState.lockState & 0x02)) ||
// non-interact (0x4) and interact (0x08) together
((tmp.goLockState.lockState & 0x04) && (tmp.goLockState.lockState & 0x08)) ||
// no setting
!tmp.goLockState.lockState ||
// invalid number
tmp.goLockState.lockState >= 0x10)
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has invalid lock state (datalong = %u) in SCRIPT_COMMAND_GO_LOCK_STATE for script id %u.", type, tmp.goLockState.lockState, tmp.id);
continue;
}
break;
}
case SCRIPT_COMMAND_STAND_STATE: // 28
{
if (tmp.standState.stand_state >= MAX_UNIT_STAND_STATE)
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has invalid stand state (datalong = %u) in SCRIPT_COMMAND_STAND_STATE for script id %u", type, tmp.standState.stand_state, tmp.id);
continue;
}
break;
}
case SCRIPT_COMMAND_MODIFY_NPC_FLAGS: // 29
break;
case SCRIPT_COMMAND_SEND_TAXI_PATH: // 30
{
if (!sTaxiPathStore.LookupEntry(tmp.sendTaxiPath.taxiPathId))
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has datalong = %u in SCRIPT_COMMAND_SEND_TAXI_PATH for script id %u, but this taxi path does not exist.", type, tmp.sendTaxiPath.taxiPathId, tmp.id);
continue;
}
// Check if this taxi path can be triggered with a spell
if (!sLog.HasLogFilter(LOG_FILTER_DB_STRICTED_CHECK))
{
uint32 taxiSpell = 0;
for (uint32 i = 1; i < sSpellStore.GetNumRows() && taxiSpell == 0; ++i)
{
if (SpellEntry const* spell = sSpellStore.LookupEntry(i))
for (int j = 0; j < MAX_EFFECT_INDEX; ++j)
{
#if defined (CATA)
SpellEffectEntry const* spellEffect = spell->GetSpellEffect(SpellEffectIndex(j));
if (!spellEffect)
{
continue;
}
if (spellEffect->Effect == SPELL_EFFECT_SEND_TAXI && spellEffect->EffectMiscValue == tmp.sendTaxiPath.taxiPathId)
#else
if (spell->Effect[j] == SPELL_EFFECT_SEND_TAXI && spell->EffectMiscValue[j] == int32(tmp.sendTaxiPath.taxiPathId))
#endif
{
taxiSpell = i;
break;
}
}
}
if (taxiSpell)
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has datalong = %u in SCRIPT_COMMAND_SEND_TAXI_PATH for script id %u, but this taxi path can be triggered by spell %u.", type, tmp.sendTaxiPath.taxiPathId, tmp.id, taxiSpell);
continue;
}
}
break;
}
case SCRIPT_COMMAND_TERMINATE_SCRIPT: // 31
{
if (tmp.terminateScript.npcEntry && !ObjectMgr::GetCreatureTemplate(tmp.terminateScript.npcEntry))
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has datalong = %u in SCRIPT_COMMAND_TERMINATE_SCRIPT for script id %u, but this npc entry does not exist.", type, tmp.sendTaxiPath.taxiPathId, tmp.id);
continue;
}
break;
}
case SCRIPT_COMMAND_PAUSE_WAYPOINTS: // 32
break;
case SCRIPT_COMMAND_JOIN_LFG: // 33
//Only currently used in Zero
break;
case SCRIPT_COMMAND_TERMINATE_COND: // 34
{
if (!sConditionStorage.LookupEntry<PlayerCondition>(tmp.terminateCond.conditionId))
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has datalong = %u in SCRIPT_COMMAND_TERMINATE_COND for script id %u, but this condition_id does not exist.", type, tmp.terminateCond.conditionId, tmp.id);
continue;
}
if (tmp.terminateCond.failQuest && !sObjectMgr.GetQuestTemplate(tmp.terminateCond.failQuest))
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has datalong2 = %u in SCRIPT_COMMAND_TERMINATE_COND for script id %u, but this questId does not exist.", type, tmp.terminateCond.failQuest, tmp.id);
continue;
}
break;
}
case SCRIPT_COMMAND_SEND_AI_EVENT_AROUND: // 35
{
if (tmp.sendAIEvent.eventType >= MAXIMAL_AI_EVENT_EVENTAI)
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has invalid AI event (datalong = %u) in SCRIPT_COMMAND_SEND_AI_EVENT for script id %u", type, tmp.sendAIEvent.eventType, tmp.id);
continue;
}
break;
}
case SCRIPT_COMMAND_TURN_TO: // 36
break;
case SCRIPT_COMMAND_MOVE_DYNAMIC: // 37
{
if (tmp.moveDynamic.maxDist < tmp.moveDynamic.minDist)
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has invalid min-dist (datalong2 = %u) less than max-dist (datalon = %u) in SCRIPT_COMMAND_MOVE_DYNAMIC for script id %u", type, tmp.moveDynamic.minDist, tmp.moveDynamic.maxDist, tmp.id);
continue;
}
break;
}
case SCRIPT_COMMAND_SEND_MAIL: // 38
{
if (!sMailTemplateStore.LookupEntry(tmp.sendMail.mailTemplateId))
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has invalid mailTemplateId (datalong = %u) in SCRIPT_COMMAND_SEND_MAIL for script id %u", type, tmp.sendMail.mailTemplateId, tmp.id);
continue;
}
if (tmp.sendMail.altSender && !ObjectMgr::GetCreatureTemplate(tmp.sendMail.altSender))
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has invalid alternativeSender (datalong2 = %u) in SCRIPT_COMMAND_SEND_MAIL for script id %u", type, tmp.sendMail.altSender, tmp.id);
continue;
}
break;
}
case SCRIPT_COMMAND_CHANGE_ENTRY: // 39
{
if (tmp.changeEntry.creatureEntry && !ObjectMgr::GetCreatureTemplate(tmp.changeEntry.creatureEntry))
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has datalong = %u in SCRIPT_COMMAND_CHANGE_ENTRY for script id %u, but this creature_template does not exist.", type, tmp.changeEntry.creatureEntry, tmp.id);
continue;
}
break;
}
case SCRIPT_COMMAND_DESPAWN_GO: // 40
{
if (!tmp.despawnGo.goGuid)
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has no gameobject defined in SCRIPT_COMMAND_DESPAWN_GO for script id %u", type, tmp.id);
continue;
}
GameObjectData const* data = sObjectMgr.GetGOData(tmp.despawnGo.goGuid);
if (!data)
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has invalid gameobject (GUID: %u) in SCRIPT_COMMAND_RESPAWN_GO for script id %u", type, tmp.despawnGo.goGuid, tmp.id);
continue;
}
break;
}
case SCRIPT_COMMAND_RESPAWN: // 41
break;
case SCRIPT_COMMAND_SET_EQUIPMENT_SLOTS: // 42
{
if (tmp.textId[0] < 0 || tmp.textId[1] < 0 || tmp.textId[2] < 0)
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has invalid equipment slot (dataint = %u, dataint2 = %u dataint3 = %u) in SCRIPT_COMMAND_SET_EQUIPMENT_SLOTS for script id %u", type, tmp.textId[0], tmp.textId[1], tmp.textId[2], tmp.id);
continue;
}
break;
}
case SCRIPT_COMMAND_RESET_GO: // 43
break;
case SCRIPT_COMMAND_UPDATE_TEMPLATE: // 44
{
#if defined(CLASSIC) || defined(TBC) || defined(WOTLK)
if (tmp.updateTemplate.entry && !ObjectMgr::GetCreatureTemplate(tmp.updateTemplate.entry))
#else
if (!sCreatureStorage.LookupEntry<CreatureInfo>(tmp.updateTemplate.entry))
#endif
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has datalong = %u in SCRIPT_COMMAND_UPDATE_TEMPLATE for script id %u, but this creature_template does not exist.", type, tmp.updateTemplate.entry, tmp.id);
continue;
}
#if defined(CLASSIC) || defined(TBC) || defined(WOTLK)
if (tmp.updateTemplate.faction > 1)
#else
if (tmp.updateTemplate.faction != 0 && tmp.updateTemplate.faction != 1)
#endif
{
sLog.outErrorDb("Table `db_scripts [type = %d]` uses invalid faction team (datalong2 = %u, must be 0 or 1) in SCRIPT_COMMAND_UPDATE_TEMPLATE for script id %u", type, tmp.updateTemplate.faction, tmp.id);
continue;
}
break;
}
case SCRIPT_COMMAND_XP_USER: // 53
{
break;
}
case SCRIPT_COMMAND_SET_FLY: // 59
{
break;
}
default:
{
sLog.outErrorDb("Table `db_scripts [type = %d]` uses unknown command %u, skipping.", type, tmp.command);
continue;
}
}
if (m_dbScripts[type].find(tmp.id) == m_dbScripts[type].end())
{
ScriptChain emptyVec;
m_dbScripts[type][tmp.id] = emptyVec;
}
m_dbScripts[type][tmp.id].push_back(tmp);
++count;
}
while (result->NextRow());
delete result;
sLog.outString(">> Loaded %u script definitions from `db_scripts [type = %d]` table", count, type);
sLog.outString();
}
void ScriptMgr::LoadDbScripts(DBScriptType t)
{
std::set<uint32> eventIds; // Store possible event ids
if (t == DBS_ON_EVENT)
{
CollectPossibleEventIds(eventIds);
}
{
ACE_GUARD(ACE_Thread_Mutex, _g, m_lock)
LoadScripts(t);
}
ScriptChainMap& scm = m_dbScripts[t];
for (ScriptChainMap::const_iterator itr = scm.begin(); itr != scm.end(); ++itr)
{
switch (t)
{
case DBS_ON_QUEST_START:
case DBS_ON_QUEST_END:
if (!sObjectMgr.GetQuestTemplate(itr->first))
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has not existing quest (Id: %u) as script id", t, itr->first);
}
break;
case DBS_ON_CREATURE_DEATH:
if (!sObjectMgr.GetCreatureTemplate(itr->first))
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has not existing creature (Entry: %u) as script id", t, itr->first);
}
break;
case DBS_ON_SPELL:
{
SpellEntry const* spellInfo = sSpellStore.LookupEntry(itr->first);
if (!spellInfo)
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has not existing spell (Id: %u) as script id", t, itr->first);
continue;
}
// check for correct spellEffect
bool found = false;
for (int i = 0; i < MAX_EFFECT_INDEX; ++i)
{
if (GetSpellStartDBScriptPriority(spellInfo, SpellEffectIndex(i)))
{
found = true;
break;
}
}
if (!found)
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has unsupported spell (Id: %u)", t, itr->first);
}
break;
}
case DBS_ON_GO_USE:
if (!sObjectMgr.GetGOData(itr->first))
{
sLog.outErrorDb("Table `db_scripts [type = %d]`, has not existing gameobject (GUID: %u) as script id", t, itr->first);
}
break;
case DBS_ON_GOT_USE:
if (!sObjectMgr.GetGameObjectInfo(itr->first))
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has not existing gameobject (Entry: %u) as script id", t, itr->first);
}
break;
case DBS_ON_EVENT:
{
std::set<uint32>::const_iterator itr2 = eventIds.find(itr->first);
if (itr2 == eventIds.end())
{
sLog.outErrorDb("Table `db_scripts [type = %d]` has script (Id: %u) not referring to any fitting gameobject_template or any spell effect %u or path taxi node data", t, itr->first, SPELL_EFFECT_SEND_EVENT);
}
break;
}
default:
break;
}
}
}
void ScriptMgr::LoadDbScriptStrings()
{
sObjectMgr.LoadMangosStrings(WorldDatabase, "db_script_string", MIN_DB_SCRIPT_STRING_ID, MAX_DB_SCRIPT_STRING_ID, true);
std::set<int32> ids;
for (int32 i = MIN_DB_SCRIPT_STRING_ID; i < MAX_DB_SCRIPT_STRING_ID; ++i)
if (sObjectMgr.GetMangosStringLocale(i))
{
ids.insert(i);
}
CheckScriptTexts(ids);
sWaypointMgr.CheckTextsExistance(ids);
for (std::set<int32>::const_iterator itr = ids.begin(); itr != ids.end(); ++itr)
{
sLog.outErrorDb("Table `db_script_string` has unused string id %u", *itr);
}
}
void ScriptMgr::CheckScriptTexts(std::set<int32>& ids)
{
for (int t = DBS_START; t < DBS_END; ++t)
{
for (ScriptChainMap::const_iterator itrCM = m_dbScripts[t].begin(); itrCM != m_dbScripts[t].end(); ++itrCM)
{
for (ScriptChain::const_iterator itrC = itrCM->second.begin(); itrC != itrCM->second.end(); ++itrC)
{
if (itrC->command == SCRIPT_COMMAND_TALK)
{
for (int i = 0; i < MAX_TEXT_ID; ++i)
{
if (itrC->textId[i] && !sObjectMgr.GetMangosStringLocale(itrC->textId[i]))