-
Notifications
You must be signed in to change notification settings - Fork 1
/
CheckQuestThreadUnit.pas
822 lines (765 loc) · 26.3 KB
/
CheckQuestThreadUnit.pas
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
unit CheckQuestThreadUnit;
interface
uses
System.SysUtils,
System.Types,
System.UITypes,
System.Classes,
System.Variants,
System.IniFiles,
Data.DB,
FMX.Types,
FMX.Controls,
FMX.Forms,
FMX.Dialogs,
FMX.Objects,
FMX.Menus,
FMX.Grid,
FMX.ExtCtrls,
FMX.ListBox,
FMX.TreeView,
FMX.Memo,
FMX.TabControl,
FMX.Layouts,
FMX.Edit,
FMX.Platform,
FMX.Bind.DBEngExt,
FMX.Bind.Editors,
FMX.Bind.DBLinks,
FMX.Bind.Navigator,
Data.Bind.EngExt,
Data.Bind.Components,
Data.Bind.DBScope,
Data.Bind.DBLinks,
Datasnap.DBClient,
Fmx.Bind.Grid,
System.Rtti,
System.Bindings.Outputs,
Data.Bind.Grid,
Fmx.StdCtrls,
FMX.Header,
FMX.Graphics,
MyDataModule;
type
TCheckQuestThread = class(TThread)
private
cq: integer;
FQuestList: TList;
Report: TStringList;
MyQuery: TFDQuery;
MyTempQuery: TFDQuery;
MyLootQuery: TFDQuery;
ErrorStr: string;
function CheckQuestLog(qId: integer): string;
procedure UpdateCaption2;
procedure UpdateCaption3;
procedure SetQuestList(const Value: TList);
protected
procedure Execute; override;
public
procedure Prepare(Connection : TFDConnection);
property QuestList: TList read FQuestList write SetQuestList;
constructor Create(Connection: TFDConnection; List: TList; CreateSuspended: boolean);
procedure MyTerminate(Sender: TObject);
procedure HandleThreadException;
end;
implementation
uses Math, Functions, checkUnit;
{ Important: Methods and properties of objects in visual components can only be
used in a method called using Synchronize, for example,
Synchronize(UpdateCaption);
and UpdateCaption could look like,
procedure TCheckQuestThread.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }
{ TCheckQuestThread }
{.$DEFINE QUICK}
procedure TCheckQuestThread.Execute;
var
i: integer;
begin
for i:=0 to FQuestList.Count - 1 do
begin
if Terminated then
Exit
else
begin
try
cq:=integer(FQuestList[i]);
CheckQuestLog(cq);
Synchronize(UpdateCaption3);
except
on E: Exception do
begin
ErrorStr:=E.Message;
if not(ExceptObject is EAbort) then
Synchronize(HandleThreadException);
end;
end;
end;
end;
end;
procedure TCheckQuestThread.MyTerminate(Sender: TObject);
begin
MyQuery.Free;
MyTempQuery.Free;
MyLootQuery.Free;
Report.Free;
FQuestList.Free;
end;
function TCheckQuestThread.CheckQuestLog(qId: integer): string;
var
Log, fname: string;
cid, i, j: integer;
ErrCount: integer;
WarnCount: integer;
List: TWideStringList;
ItemQuestGiver: integer;
QuestGiverOtherCount: integer;
QuestTakerOtherCount: integer;
procedure Add(typ: integer; S: string; const Args: array of const); overload;
begin
Report.Add(Format(S,Args));
if typ=1 then Inc(ErrCount);
if typ=2 then Inc(WarnCount);
end;
procedure Add(typ: integer; S: string); overload;
begin
Report.Add(S);
if typ=1 then Inc(ErrCount);
if typ=2 then Inc(WarnCount);
end;
begin
//
Synchronize(UpdateCaption2); if Terminated then Exit;
//
Add(0, dmMain.Text[24], [qid]); //'quest = %d'
ItemQuestGiver:=0;
ErrCount:=0;
WarnCount:=0;
QuestGiverOtherCount:=0;
QuestTakerOtherCount:=0;
if qid<=0 then
begin
Add(1, dmMain.Text[25], [qid]); //'Fatal Error: Wrong quest id (%d)'
Exit;
end;
MyQuery.Close;
MyTempQuery.Close;
MyLootQuery.Close;
MyQuery.SQL.Text:=Format('SELECT * FROM `quest_template` WHERE `Id`=%d',[qid]);
MyQuery.Open;
if MyQuery.Eof then
begin
Add(1, dmMain.Text[26], [qid]); //'Fatal Error: Quest with entry = %d not found'
Exit;
end;
//
Synchronize(UpdateCaption2); if Terminated then Exit;
//
// quest giver creature check
MyQuery.Close;
MyQuery.SQL.Text:=Format('SELECT * FROM `creature_queststarter` WHERE `quest` = %d',[qid]);
MyQuery.Open;
if not MyQuery.Eof then
begin
inc(QuestGiverOtherCount);
if MyQuery.RecordCount>1 then
begin
Add(2, dmMain.Text[27]); //'Warning: There more than one quest giver:'
while not MyQuery.Eof do
begin
Add(0,'-----> creature, entry = %d',[MyQuery.FieldByName('id').AsInteger]);
MyQuery.Next;
end;
end
else
begin
// one rec only
cid := MyQuery.FieldByName('id').AsInteger;
MyQuery.Close;
MyQuery.SQL.Text:=Format('SELECT * FROM `creature_template` WHERE `entry`=%d ',[cid]);
MyQuery.Open;
if not MyQuery.Eof then
begin
if (MyQuery.FieldByName('npcflag').AsInteger and 2) <> 2 then
Add(1, dmMain.Text[28], [cid]); //'Error: quest giver is creature with entry = %d, but (`npcflag` & 2) <> 2 '
MyQuery.Close;
MyQuery.SQL.Text:=Format('SELECT * FROM `creature` WHERE `id`=%d',[cid]);
MyQuery.Open;
if not MyQuery.Eof then
begin
if MyQuery.RecordCount>1 then
Add(2, dmMain.Text[29], [cid]); //'Warning: There more than one location for quest giver (id=%d) in table `creature`'
end
else
Add(1, dmMain.Text[30], [cid]); //'Error: Location for quest giver (id=%d) not found in table `creature`'
end
else
Add(1, dmMain.Text[31], [cid]); //'Error: quest giver is creature with entry = %d, but there is no one record in `creature_template` with entry = %0:d'
end;
end;
//
Synchronize(UpdateCaption2); if Terminated then Exit;
//
// quest giver gameobject check
MyQuery.Close;
MyQuery.SQL.Text:=Format('SELECT * FROM `gameobject_queststarter` WHERE `quest` = %d',[qid]);
MyQuery.Open;
if not MyQuery.Eof then
begin
inc(QuestGiverOtherCount);
if MyQuery.RecordCount>1 then
begin
Add(2,dmMain.Text[27]);
while not MyQuery.Eof do
begin
Add(0,'-----> gameobject, entry = %d',[MyQuery.FieldByName('id').AsInteger]);
MyQuery.Next;
end;
end
else
begin
// one rec only
cid := MyQuery.FieldByName('id').AsInteger;
MyQuery.Close;
MyQuery.SQL.Text:=Format('SELECT * FROM `gameobject_template` WHERE `entry`=%d ',[cid]);
MyQuery.Open;
if not MyQuery.Eof then
begin
MyQuery.Close;
MyQuery.SQL.Text:=Format('SELECT * FROM `gameobject` WHERE `id`=%d',[cid]);
MyQuery.Open;
if not MyQuery.Eof then
begin
if MyQuery.RecordCount>1 then
Add(2, dmMain.Text[32], [cid]); //'Warning: There more than one location for quest giver (id=%d) in table `gameobject`'
end
else
Add(1, dmMain.Text[33], [cid]); //'Error: Location for quest giver (id=%d) not found in table `gameobject`'
end
else
Add(1, dmMain.Text[76], [cid]); //'Error: quest giver is gameobject with entry = %d, but there is no one record in `gameobject_template` with entry = %0:d'
end;
end;
//
Synchronize(UpdateCaption2); if Terminated then Exit;
//
// item quest giver check
MyQuery.Close;
{$IFNDEF QUICK}
MyQuery.SQL.Text:=Format('SELECT `entry` FROM `item_template` WHERE `startquest` = %d',[qid]);
MyQuery.Open;
{$ENDIF}
//
Synchronize(UpdateCaption2); if Terminated then Exit;
//
if not MyQuery.Eof then
begin
inc(QuestGiverOtherCount);
if MyQuery.RecordCount>1 then
begin
Add(2,dmMain.Text[27]);
while not MyQuery.Eof do
begin
Add(0,'-----> item, entry = %d',[MyQuery.FieldByName('entry').AsInteger]);
MyQuery.Next;
end;
end
else
begin
// one rec only
cid := MyQuery.FieldByName('entry').AsInteger;
ItemQuestGiver:=cid;
MyQuery.Close;
MyQuery.SQL.Text:=Format('SELECT * FROM `creature_loot_template` WHERE `item`=%d ',[cid]);
MyQuery.Open;
//
Synchronize(UpdateCaption2); if Terminated then Exit;
//
if MyQuery.Eof then
begin
MyQuery.Close;
MyQuery.SQL.Text:=Format('SELECT * FROM `gameobject_loot_template` WHERE `item`=%d ',[cid]);
MyQuery.Open;
//
Synchronize(UpdateCaption2); if Terminated then Exit;
//
if MyQuery.Eof then
begin
MyQuery.Close;
MyQuery.SQL.Text:=Format('SELECT * FROM `item_loot_template` WHERE `item`=%d ',[cid]);
MyQuery.Open;
//
Synchronize(UpdateCaption2); if Terminated then Exit;
//
if MyQuery.Eof then
begin
MyQuery.Close;
MyQuery.SQL.Text:=Format('SELECT * FROM `pickpocketing_loot_template` WHERE `item`=%d ',[cid]);
MyQuery.Open;
//
Synchronize(UpdateCaption2); if Terminated then Exit;
//
if MyQuery.Eof then
begin
MyQuery.Close;
MyQuery.SQL.Text:=Format('SELECT * FROM `skinning_loot_template` WHERE `item`=%d ',[cid]);
MyQuery.Open;
//
Synchronize(UpdateCaption2); if Terminated then Exit;
//
if MyQuery.Eof then
begin
MyQuery.Close;
MyQuery.SQL.Text:=Format('SELECT * FROM `disenchant_loot_template` WHERE `item`=%d ',[cid]);
MyQuery.Open;
//
Synchronize(UpdateCaption2); if Terminated then Exit;
//
if MyQuery.Eof then
begin
MyQuery.Close;
MyQuery.SQL.Text:=Format('SELECT * FROM `npc_vendor` WHERE `item`=%d ',[cid]);
MyQuery.Open;
//
Synchronize(UpdateCaption2); if Terminated then Exit;
//
if MyQuery.Eof then
begin
Add(2, dmMain.Text[34], [cid]); //'Warning: quest giver is item (id=%d), but there is no one loot in tables *_loot_template and npc_vendor. May be it is not error, just item need to be rewarded or gived from other quest.'
end;
end;
end;
end;
end;
end;
end;
end;
end;
// creature quest taker check
MyQuery.Close;
MyQuery.SQL.Text:=Format('SELECT * FROM `creature_questender` WHERE `quest` = %d',[qid]);
MyQuery.Open;
if not MyQuery.Eof then
begin
inc(QuestTakerOtherCount);
if MyQuery.RecordCount>1 then
begin
Add(2, dmMain.Text[35]); //'Warning: There more than one quest taker: '
while not MyQuery.Eof do
begin
Add(0,'-----> creature, entry = %d',[MyQuery.FieldByName('id').AsInteger]);
MyQuery.Next;
end;
end
else
begin
// one rec only
cid := MyQuery.FieldByName('id').AsInteger;
MyQuery.Close;
MyQuery.SQL.Text:=Format('SELECT * FROM `creature_template` WHERE `entry`=%d ',[cid]);
MyQuery.Open;
if not MyQuery.Eof then
begin
if (MyQuery.FieldByName('npcflag').AsInteger and 2) <> 2 then
begin
Add(1, dmMain.Text[36], [cid]); //'Error: quest taker is creature with entry = %d, but (`npcflag` & 2) <> 2 '
end;
MyQuery.Close;
MyQuery.SQL.Text:=Format('SELECT * FROM `creature` WHERE `id`=%d',[cid]);
MyQuery.Open;
if not MyQuery.Eof then
begin
if MyQuery.RecordCount>1 then
Add(2, dmMain.Text[37], [cid]); //'Warning: There more than one location for quest taker (id=%d) in table `creature`'
end
else
Add(1, dmMain.Text[38], [cid]); //'Error: Location for quest taker (id=%d) not found in table `creature`'
end
else
Add(1, dmMain.Text[39], [cid]); //'Error: quest taker is creature with entry = %d, but there is no one record in `creature_template` with entry = %0:d'
end;
end;
//
Synchronize(UpdateCaption2); if Terminated then Exit;
//
// quest taker gameobject check
MyQuery.Close;
MyQuery.SQL.Text:=Format('SELECT * FROM `gameobject_questender` WHERE `quest` = %d',[qid]);
MyQuery.Open;
if not MyQuery.Eof then
begin
inc(QuestTakerOtherCount);
if MyQuery.RecordCount>1 then
begin
Add(2,dmMain.Text[35]);
while not MyQuery.Eof do
begin
Add(0,'-----> gameobject, entry = %d',[MyQuery.FieldByName('id').AsInteger]);
MyQuery.Next;
end;
end
else
begin
// one rec only
cid := MyQuery.FieldByName('id').AsInteger;
MyQuery.Close;
MyQuery.SQL.Text:=Format('SELECT * FROM `gameobject_template` WHERE `entry`=%d ',[cid]);
MyQuery.Open;
if not MyQuery.Eof then
begin
MyQuery.Close;
MyQuery.SQL.Text:=Format('SELECT * FROM `gameobject` WHERE `id`=%d',[cid]);
MyQuery.Open;
if not MyQuery.Eof then
begin
if MyQuery.RecordCount>1 then
Add(2, dmMain.Text[40], [cid]); //'Warning: There more than one location for quest taker (id=%d) in table `gameobject`'
end
else
Add(1, dmMain.Text[41], [cid]); // 'Error: Location for quest taker (id=%d) not found in table `gameobject`'
end
else
Add(1, dmMain.Text[42], [cid]); // 'Error: quest taker is gameobject with entry = %d, but there is no one record in `gameobject_template` with entry = %0:d'
end;
end;
//
Synchronize(UpdateCaption2); if Terminated then Exit;
//
if QuestGiverOtherCount=0 then Add(1, dmMain.Text[43]); //'Error: quest giver not found'
if QuestTakerOtherCount=0 then Add(1, dmMain.Text[44]); //'Error: quest taker not found'
// 'Warning: There is more than one different type quest giver (quest giver count=%d)'
if QuestGiverOtherCount>1 then Add(2, dmMain.Text[45], [QuestGiverOtherCount]);
// 'Warning: There is more than one different type quest taker (quest taker count=%d)'
if QuestTakerOtherCount>1 then Add(2, dmMain.Text[46], [QuestTakerOtherCount]);
// quest check begin
MyQuery.Close;
MyQuery.SQL.Text:=Format('SELECT * FROM `quest_template` WHERE `Id` = %d',[qid]);
MyQuery.Open;
// prev quest id check
cid:=MyQuery.FieldByName('PrevQuestId').AsInteger;
if cid>0 then
begin
MyTempQuery.SQL.Text:=Format('SELECT * FROM `quest_template` WHERE `Id` = %d', [cid]);
MyTempQuery.Open;
if MyTempQuery.Eof then
Add(1, dmMain.Text[47], [cid]); //'Error: PrevQuestId=%d, but quest with this id is not exists'
MyTempQuery.Close;
end;
//
Synchronize(UpdateCaption2); if Terminated then Exit;
//
// next quest id check
cid:=MyQuery.FieldByName('NextQuestId').AsInteger;
if cid>0 then
begin
MyTempQuery.SQL.Text:=Format('SELECT * FROM `quest_template` WHERE `Id` = %d',[cid]);
MyTempQuery.Open;
if MyTempQuery.Eof then
Add(1, dmMain.Text[48], [cid]); //'Error: NextQuestId=%d, but quest with this id is not exists'
MyTempQuery.Close;
end;
//
Synchronize(UpdateCaption2); if Terminated then Exit;
//
List:=TWideStringList.Create;
try
// Type check
cid:=MyQuery.FieldByName('Type').AsInteger;
if cid>0 then
begin
LoadSimpleIDListFromDBCFile(List, 'QuestInfo');
i:=List.IndexOf(IntToStr(cid));
if i=-1 then
Add(1, dmMain.Text[49], [cid]); //'Error: Type = %d, but Type with this id is not exists'
end;
// factions check
for i:=0 to MyQuery.Fields.Count - 1 do
begin
if Pos(LowerCase('Faction'), LowerCase(MyQuery.Fields[i].FieldName))>0 then
begin
cid := MyQuery.Fields[i].AsInteger;
if cid>0 then
begin
LoadSimpleIDListFromDBCFile(List, 'Faction');
j:=List.IndexOf(IntToStr(cid));
if j=-1 then
Add(1, dmMain.Text[50],[MyQuery.Fields[i].FieldName, cid]);
//'Error: %s = %d, but Faction with this id is not exists'
end;
end;
end;
// ZoneID check
cid:=MyQuery.FieldByName('ZoneOrSort').AsInteger;
if cid>0 then
begin
LoadSimpleIDListFromDBCFile(List, 'AreaTable');
i:=List.IndexOf(IntToStr(cid));
if i=-1 then
Add(1, dmMain.Text[51], [cid]); //'Error: ZoneOrSort = %d, but ZoneId with this id is not exists'
end
else
if cid<0 then
begin
LoadSimpleIDListFromDBCFile(List, 'QuestSort');
i:=List.IndexOf(IntToStr(-cid));
if i=-1 then
Add(1, dmMain.Text[52], [cid]); //'Error: ZoneOrSort = %d, but QuestSort with this id is not exists'
end;
finally
List.Free;
end;
// quest level check
if MyQuery.FieldByName('MinLevel').AsInteger>MyQuery.FieldByName('QuestLevel').AsInteger then
// 'Error: MinLevel (%d) > QuestLevel (%d)'
Add(1,dmMain.Text[53],[MyQuery.FieldByName('MinLevel').AsInteger,
MyQuery.FieldByName('QuestLevel').AsInteger]);
//
Synchronize(UpdateCaption2); if Terminated then Exit;
//
// LimitTime check
cid := MyQuery.FieldByName('LimitTime').AsInteger;
if cid>0 then
begin
if cid<60 then Add(2, 'Warning: LimitTime = %d seconds',[cid]);
{ if MyQuery.FieldByName('QuestFlags').AsInteger and 16 <> 16 then
Add(2, dmMain.Text[58], [cid]); //'Warning: LimitTime = %d seconds, but QuestFlags is not set to TIMED'
} end;
// items check
for i:=0 to MyQuery.Fields.Count - 1 do
begin
fname := MyQuery.Fields[i].FieldName;
if Pos(LowerCase('ItemId'), LowerCase(fname))>0 then // item field;
begin
cid := MyQuery.Fields[i].AsInteger;
// if cid <> MyQuery.FieldByName('SrcItemId').AsInteger then
begin
if cid>0 then
begin
MyTempQuery.SQL.Text:=Format('SELECT `entry` FROM `item_template` WHERE `entry` = %d',[cid]);
MyTempQuery.Open;
if MyTempQuery.Eof then
Add(1, dmMain.Text[62],[MyQuery.Fields[i].FieldName, cid]) // 'Error: %s = %d, but item with this id is not exists'
else
begin
// check loot
if (Pos('rewchoiceitemid',lowercase(fname))<>1) and (Pos('rewitemid',lowercase(fname))<>1) and
(cid<>ItemQuestGiver) and (cid<>MyQuery.FieldByName('SrcItemId').AsInteger) then
begin
MyTempQuery.Close;
MyTempQuery.SQL.Text:=Format('SELECT `entry` FROM `creature_loot_template` WHERE `item`=%d ',[cid]);
MyTempQuery.Open;
if MyTempQuery.Eof then
begin
MyTempQuery.Close;
MyTempQuery.SQL.Text:=Format('SELECT `entry` FROM `gameobject_loot_template` WHERE `item`=%d ',[cid]);
MyTempQuery.Open;
if MyTempQuery.Eof then
begin
MyTempQuery.Close;
MyTempQuery.SQL.Text:=Format('SELECT `entry` FROM `item_loot_template` WHERE `item`=%d ',[cid]);
MyTempQuery.Open;
if MyTempQuery.Eof then
begin
MyTempQuery.Close;
MyTempQuery.SQL.Text:=Format('SELECT `entry` FROM `pickpocketing_loot_template` WHERE `item`=%d ',[cid]);
MyTempQuery.Open;
if MyTempQuery.Eof then
begin
MyTempQuery.Close;
MyTempQuery.SQL.Text:=Format('SELECT `entry` FROM `skinning_loot_template` WHERE `item`=%d ',[cid]);
MyTempQuery.Open;
if MyTempQuery.Eof then
begin
MyTempQuery.Close;
MyTempQuery.SQL.Text:=Format('SELECT `entry` FROM `disenchant_loot_template` WHERE `item`=%d ',[cid]);
MyTempQuery.Open;
if MyTempQuery.Eof then
begin
MyTempQuery.Close;
MyTempQuery.SQL.Text:=Format('SELECT `entry` FROM `npc_vendor` WHERE `item`=%d ',[cid]);
MyTempQuery.Open;
if MyTempQuery.Eof then
begin
// 'Warning: %s = %d, but there is no one loot in
// tables *_loot_template and npc_vendor.
// May be it is not error, just item need to be
// created or rewarded from other quest.'
Add(2, dmMain.Text[63], [fname, cid]);
end;
end;
end;
end;
end;
end
else
begin
if (Pos('reqitemid', lowercase(fname))=1) or (Pos('reqsourceid', lowercase(fname))=1) then
begin
while not MyTempQuery.Eof do
begin
MyLootQuery.SQL.Text:=Format('SELECT `guid` FROM `gameobject` WHERE `id` = %d',[
MyTempQuery.FieldByName('entry').AsInteger]);
MyLootQuery.Open;
if MyLootQuery.Eof then
// 'Error: %s = %d. Loot for this item is
// gameobject_loot_template.entry = %d, but gameobject
// with this id not found in `gameobject` table'
Add(1, dmMain.Text[64], [fname, cid, MyTempQuery.FieldByName('entry').AsInteger]);
MyLootQuery.Close;
MyTempQuery.Next;
end;
MyTempQuery.Close;
end;
end;
end
else
begin
if (Pos('reqitemid', lowercase(fname))=1) or (Pos('reqsourceid', lowercase(fname))=1) then
begin
while not MyTempQuery.Eof do
begin
MyLootQuery.SQL.Text:=Format('SELECT `guid` FROM `creature` WHERE `id` = %d',[
MyTempQuery.FieldByName('entry').AsInteger]);
MyLootQuery.Open;
if MyLootQuery.Eof then
//'Error: %s = %d. Loot for this item is
// creature_loot_template.entry = %d, but creature with
// this id not found in `creature` table'
Add(1, dmMain.Text[65], [fname, cid, MyTempQuery.FieldByName('entry').AsInteger]);
MyLootQuery.Close;
MyTempQuery.Next;
end;
MyTempQuery.Close;
end;
end;
end;
end;
end;
end;
end;
end;
//
Synchronize(UpdateCaption2); if Terminated then Exit;
//
{ //* reqsource check
for i:=1 to 4 do
begin
cid:=MyQuery.FieldByName(Format('ReqSourceRef%d',[i])).AsInteger;
if cid>0 then
begin
if cid>4 then Add(1, dmMain.Text[66], [i]); // 'Error: ReqSourceRef%d > 4'
if MyQuery.FieldByName(Format('ReqSourceId%d',[i])).AsInteger=0 then
Add(1, dmMain.Text[67], [i, cid]); // 'Error: ReqSourceId%d=0, but ReqSourceRef%0:d=%1:d '
if MyQuery.FieldByName(Format('ReqItemId%d',[cid])).AsInteger=0 then
Add(1, dmMain.Text[68],[i, cid]); //'Error: ReqItemId%1:d=0, but ReqSourceRef%0:d=%1:d '
end;
end;
//
Synchronize(UpdateCaption2); if Terminated then Exit;
//
}
//creature or go check
for i:=1 to 4 do
begin
cid:=MyQuery.FieldByName(Format('ReqCreatureOrGOId%d',[i])).AsInteger;
if cid>0 then
begin
MyTempQuery.SQL.Text:=Format('SELECT entry FROM `creature_template` WHERE `entry` = %d',[cid]);
MyTempQuery.Open;
if MyTempQuery.Eof then
Add(1, dmMain.Text[69], [i,cid]) //'Error: ReqCreatureOrGOId%d = %d, but creature with this id is not exists'
else
begin
// location check
MyTempQuery.Close;
MyTempQuery.SQL.Text:=Format('SELECT `guid` FROM `creature` WHERE `id`=%d',[cid]);
MyTempQuery.Open;
if MyTempQuery.Eof then
Add(1, dmMain.Text[70], [i, cid]); //'Error: ReqCreatureOrGOId%d = %d, Location for creature not exists'
end;
MyTempQuery.Close;
end;
if cid<0 then
begin
MyTempQuery.SQL.Text:=Format('SELECT entry FROM `gameobject_template` WHERE `entry` = %d',[abs(cid)]);
MyTempQuery.Open;
if MyTempQuery.Eof then
Add(1, dmMain.Text[71], [i,cid]) //'Error: ReqCreatureOrGOId%d = %d, but gameobject with this id is not exists'
else
begin
/// location check
MyTempQuery.Close;
MyTempQuery.SQL.Text:=Format('SELECT `guid` FROM `gameobject` WHERE `id`=%d',[abs(cid)]);
MyTempQuery.Open;
if MyTempQuery.Eof then
Add(1, dmMain.Text[72], [i, cid]); //'Error: ReqCreatureOrGOId%d = %d, Location for gameobject not exists'
end;
MyTempQuery.Close;
end;
end;
Synchronize(UpdateCaption2); if Terminated then Exit;
// quest check end!
MyQuery.Close;
Add(0, '---------------------------------------------------');
//'Check complete: %d errors, %d warnings'
Add(0, dmMain.Text[73], [ErrCount, WarnCount]);
Add(0, '');
end;
procedure TCheckQuestThread.SetQuestList(const Value: TList);
begin
FQuestList := Value;
end;
procedure TCheckQuestThread.Prepare(Connection : TFDConnection);
begin
MyQuery := TFDQuery.Create(nil);
MyTempQuery := TFDQuery.Create(nil);
MyLootQuery := TFDQuery.Create(nil);
Report := TStringList.Create;
MyQuery.Connection := Connection;
MyTempQuery.Connection := Connection;
MyLootQuery.Connection := Connection;
end;
procedure TCheckQuestThread.HandleThreadException;
begin
CheckForm.Memo.Lines.Add(ErrorStr);
CheckForm.Memo.Lines.Add('');
CheckForm.Memo.SelStart := CheckForm.Memo.Perform(EM_LINEINDEX, CheckForm.Memo.Lines.Count, 0);
CheckForm.Memo.Perform(EM_SCROLLCARET, 0, 0);
end;
constructor TCheckQuestThread.Create(Connection: TFDConnection;
List: TList; CreateSuspended: boolean);
begin
inherited Create(CreateSuspended);
Prepare(Connection);
FQuestList:=List;
OnTerminate := MyTerminate;
end;
procedure TCheckQuestThread.UpdateCaption2;
begin
CheckForm.pbCheckQuest.StepIt;
// 'Check quest (%d) : %d%%'
CheckForm.Label1.Caption:=Format(dmMain.Text[74], [cq, Round((CheckForm.pbCheckQuest.Position*100)/CheckForm.pbCheckQuest.Max)]);
if Report.Count > 0 then
begin
CheckForm.Memo.Lines.AddStrings(Report);
CheckForm.Memo.SelStart := CheckForm.Memo.Perform(EM_LINEINDEX, CheckForm.Memo.Lines.Count, 0);
CheckForm.Memo.Perform(EM_SCROLLCARET, 0, 0);
Report.Clear;
end;
end;
procedure TCheckQuestThread.UpdateCaption3;
begin
if Report.Count > 0 then
begin
CheckForm.Memo.Lines.AddStrings(Report);
CheckForm.Memo.SelStart := CheckForm.Memo.Perform(EM_LINEINDEX, CheckForm.Memo.Lines.Count, 0);
CheckForm.Memo.Perform(EM_SCROLLCARET, 0, 0);
Report.Clear;
end;
CheckForm.pbCheckQuest.Position:=0;
CheckForm.Label1.Caption:=dmMain.Text[75]; //'Check quest colmpete'
end;
end.