-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdb-extra.lua
More file actions
767 lines (757 loc) · 18.9 KB
/
db-extra.lua
File metadata and controls
767 lines (757 loc) · 18.9 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
--[[--
by ALA
CREDIT shagu/pfQuest(MIT LICENSE) @ https://github.com/shagu
--]]--
local __addon, __private = ...;
local MT = __private.MT;
local CT = __private.CT;
local VT = __private.VT;
local DT = __private.DT;
--> upvalue
local collectgarbage = collectgarbage;
local date = date;
local setmetatable = setmetatable;
local next = next;
local strfind = string.find;
local _G = _G;
-->
local DataAgent = DT.DB;
local l10n = CT.l10n;
-->
MT.BuildEnv("db-extra");
--> predef
-->
local chain_prev_quest = { };
DataAgent.chain_prev_quest = chain_prev_quest;
local item_related_quest = { };
DataAgent.item_related_quest = item_related_quest;
local avl_quest_list = { };
local avl_quest_hash = { };
DataAgent.avl_quest_list = avl_quest_list;
DataAgent.avl_quest_hash = avl_quest_hash;
-->
--> db-extra
local function check(tbl, key, str)
if tbl.U then
for _, unit in next, tbl.U do
local uinfo = DataAgent.unit[unit];
if uinfo ~= nil and uinfo[key] ~= -1 then
return true;
end
end
end
if tbl.O then
for _, obj in next, tbl.O do
local oinfo = DataAgent.object[obj];
if oinfo ~= nil then
local fac = oinfo['fac'];
if fac == nil or strfind(fac, str) then
return true;
end
end
end
end
return false;
end
local EmptyInfo = {
unit = { ["coords"] = { }, },
item = {},
object = { ["coords"] = { }, },
refloot = {},
event = { ["coords"] = { }, },
};
local function MarkItemRelation(quest, item)
local v = item_related_quest[item];
if v == nil then
v = { };
item_related_quest[item] = v;
end
local num = #v;
for i = 1, num do
if v[i] == quest then
return;
end
end
v[num + 1] = quest;
end
local MarkUnit, MarkItem, MarkObject, MarkRefloot, MarkEvent;
local HashUnit, HashItem, HashObject, HashRefloot, HashEvent = { }, { }, { }, { }, { };
local Hash = { unit = HashUnit, item = HashItem, object = HashObject, refloot = HashRefloot, event = HashEvent, };
function MarkUnit(quest, unit)
-- if HashUnit[unit] == nil then
HashUnit[unit] = 1;
local info = DataAgent.unit[unit];
if info ~= nil then
local spawn = info.spawn;
if spawn ~= nil then
if spawn.U ~= nil then
for unit, _ in next, spawn.U do
MarkUnit(quest, unit);
end
end
if spawn.O ~= nil then
for object, _ in next, spawn.O do
MarkObject(quest, object);
end
end
if spawn.I ~= nil then
for item, _ in next, spawn.I do
MarkItem(quest, item);
end
end
end
end
-- end
end
function MarkItem(quest, item, spawned)
-- if HashItem[item] == nil then
HashItem[item] = 1;
local info = DataAgent.item[item];
if info ~= nil then
if info.U ~= nil then
for unit, _ in next, info.U do
MarkUnit(quest, unit);
end
end
if info.O ~= nil then
for object, _ in next, info.O do
MarkObject(quest, object);
end
end
if info.I ~= nil then
for item, _ in next, info.I do
MarkItem(quest, item);
end
end
if info.R ~= nil then
for ref, _ in next, info.R do
MarkRefloot(quest, ref);
end
end
if info.V ~= nil then
for unit, _ in next, info.V do
MarkUnit(quest, unit);
end
end
end
-- end
if spawned == nil or spawned < 2 then
MarkItemRelation(quest, item);
end
end
function MarkObject(quest, object)
-- if HashObject[object] == nil then
HashObject[object] = 1;
local info = DataAgent.object[object];
if info ~= nil then
local spawn = info.spawn;
if spawn ~= nil then
if spawn.U ~= nil then
for unit, _ in next, spawn.U do
MarkUnit(quest, unit);
end
end
if spawn.O ~= nil then
for object, _ in next, spawn.O do
MarkObject(quest, object);
end
end
if spawn.I ~= nil then
for item, _ in next, spawn.I do
MarkItem(quest, item);
end
end
end
end
-- end
end
function MarkRefloot(quest, ref)
-- if HashRefloot[ref] == nil then
local info = DataAgent.refloot[ref];
if info ~= nil then
if info.U ~= nil then
for unit, _ in next, info.U do
MarkUnit(quest, unit);
end
end
if info.O ~= nil then
for object, _ in next, info.O do
MarkObject(quest, object);
end
end
end
-- end
end
function MarkEvent(quest, event)
HashEvent[event] = 1;
local info = DataAgent.event[event];
if info ~= nil then
local spawn = info.spawn;
if spawn ~= nil then
if spawn.U ~= nil then
for unit, _ in next, spawn.U do
MarkUnit(quest, unit);
end
end
if spawn.O ~= nil then
for object, _ in next, spawn.O do
MarkObject(quest, object);
end
end
if spawn.I ~= nil then
for item, _ in next, spawn.I do
MarkItem(quest, item);
end
end
end
end
end
local function VerifyData()
MT.Debug("|cffff7f00Start|r |cffff0000VerifyData|r");
local vitem, vobject, vunit, vrefloot;
local VI, VO, VU, VR = { }, { }, { }, { };
function vitem(t, k, id, hu, hi, ho, path)
if DataAgent.blacklist_item[id] or VI[id] then
return;
end
path = path .. " item:" .. id;
local spawn = DataAgent.item[id];
if spawn ~= nil then
if hi[id] then
return MT.Print("|cffff0000SpawnError|r", path, hi[id]);
end
hi[id] = true;
if spawn.U ~= nil then
for unit, _ in next, spawn.U do
vunit(t, k, unit, hu, hi, ho, path);
end
end
if spawn.O ~= nil then
for object, _ in next, spawn.O do
vobject(t, k, object, hu, hi, ho, path);
end
end
if spawn.I ~= nil then
for item, _ in next, spawn.I do
vitem(t, k, item, hu, hi, ho, path);
end
end
hi[id] = nil;
end
VI[id] = true;
end
function vobject(t, k, id, hu, hi, ho, path)
if VO[id] then
return;
end
path = path .. " object:" .. id;
local info = DataAgent.object[id];
if info ~= nil then
local spawn = info.spawn;
if spawn ~= nil then
if ho[id] then
return MT.Print("|cffff0000SpawnError|r", path, ho[id]);
end
ho[id] = true;
if spawn.U ~= nil then
for unit, _ in next, spawn.U do
vunit(t, k, unit, hu, hi, ho, path);
end
end
if spawn.O ~= nil then
for object, _ in next, spawn.O do
vobject(t, k, object, hu, hi, ho, path);
end
end
if spawn.I ~= nil then
for item, _ in next, spawn.I do
vitem(t, k, item, hu, hi, ho, path);
end
end
ho[id] = nil;
end
end
VO[id] = true;
end
function vunit(t, k, id, hu, hi, ho, path)
if VU[id] then
return;
end
path = path .. " unit:" .. id;
local info = DataAgent.unit[id];
if info ~= nil then
local spawn = info.spawn;
if spawn ~= nil then
if hu[id] then
return MT.Print("|cffff0000SpawnError|r", path, hu[id]);
end
hu[id] = true;
if spawn.U ~= nil then
for unit, _ in next, spawn.U do
vunit(t, k, unit, hu, hi, ho, path);
end
end
if spawn.O ~= nil then
for object, _ in next, spawn.O do
vobject(t, k, object, hu, hi, ho, path);
end
end
if spawn.I ~= nil then
for item, _ in next, spawn.I do
vitem(t, k, item, hu, hi, ho, path);
end
end
hu[id] = nil;
end
end
VU[id] = true;
end
function vrefloot(t, k, id, hu, hi, ho, path)
if VR[id] then
return;
end
path = path .. " refloot:" .. id;
local info = DataAgent.refloot[id];
if info ~= nil then
if info.U ~= nil then
for unit, _ in next, info.U do
vunit(t, k, unit, hu, hi, ho, path);
end
end
if info.O ~= nil then
for object, _ in next, info.O do
vobject(t, k, object, hu, hi, ho, path);
end
end
end
VR[id] = true;
end
for unit, info in next, DataAgent.unit do
vunit('unit', unit, unit, { }, { }, { }, "");
end
for item, info in next, DataAgent.item do
vitem('item', item, item, { }, { }, { }, "");
end
for object, info in next, DataAgent.object do
vobject('object', object, object, { }, { }, { }, "");
end
MT.Debug("|cff00ff00Finish|r |cffff0000VerifyData|r");
end
MT.RegisterOnLogin("db-extra", function(LoggedIn)
--> patch
local function patchDB(fix)
for key, patch in next, fix do
local db = DataAgent[key];
if db ~= nil then
for id, val in next, patch do
local t = db[id];
if t ~= nil then
for k, v in next, val do
if v == "_NIL" then
t[k] = nil;
else
t[k] = v;
end
end
else
db[id] = val;
end
end
end
end
end
patchDB(DataAgent.fix);
if CT.SELFFACTION == "Alliance" then
patchDB(DataAgent.fix_alliance);
else
patchDB(DataAgent.fix_horde);
end
if DataAgent.override ~= nil then
for key, patch in next, DataAgent.override do
local db = DataAgent[key];
if db ~= nil then
for id, val in next, patch do
db[id] = val;
end
end
end
end
for id, val in next, DataAgent.waypoints do
local waypoints = { };
for _, tbl in next, val do
for _, p in next, tbl do
waypoints[#waypoints + 1] = p;
end
end
DataAgent.unit[id] = DataAgent.unit[id] or { };
DataAgent.unit[id].waypoints = waypoints;
end
--> Misc
if VT.__is_dev then
VerifyData();
end
for quest, info in next, DataAgent.quest do
local _next = info.next;
if _next ~= nil then
chain_prev_quest[_next] = quest;
end
end
local today = date("*t");
local year, month, day, wday = today.year, today.month, today.day, today.wday;
-- if CT.TOCVERSION >= 30000 and C_Calendar and C_Calendar.GetHolidayInfo then
-- else
-- end
for event, limits in next, DataAgent.worldeventperiod do
local limit = limits[year] or limits["*"];
if limit == nil or
(limit[1] <= limit[3] and (month < limit[1] or month > limit[3])) or
(month < limit[1] and month > limit[3]) or
(month == limit[1] and day < limit[2]) or
(month == limit[3] and day > limit[4])
then
local eventquests = DataAgent.worldevent[event];
for _, quest in next, eventquests do
DataAgent.blacklist_quest[quest] = true;
end
else
local eventquests = DataAgent.worldevent[event];
for _, quest in next, eventquests do
DataAgent.blacklist_quest[quest] = nil;
end
end
end
--> faction quest list
local key = CT.SELFFACTION == "Alliance" and "facA" or "facH";
local str = CT.SELFFACTION == "Alliance" and "A" or "H";
for quest, info in next, DataAgent.quest do
if DataAgent.blacklist_quest[quest] == nil then
local info = DataAgent.quest[quest];
local race = info.race;
local class = info.class;
if (race == nil or MT.CheckSelfRace(race)) and (class == nil or MT.CheckSelfClass(class)) then
local _start = info['start'];
local _end = info['end'];
if (_start and check(_start, key, str)) or (_end and check(_end, key, str)) then
avl_quest_list[#avl_quest_list + 1] = quest;
avl_quest_hash[quest] = 1;
end
end
end
end
-->
--> Delete Unused
--> cache
for quest, info in next, DataAgent.quest do
local _obj = info['obj'];
if _obj ~= nil then
if _obj.U ~= nil then
for _, unit in next, _obj.U do
MarkUnit(quest, unit);
end
end
if _obj.I ~= nil then
for _, item in next, _obj.I do
MarkItem(quest, item);
end
end
if _obj.IR ~= nil then
for _, item in next, _obj.IR do
-- HashItem[item] = 1;
MarkItemRelation(quest, item);
end
end
if _obj.O ~= nil then
for _, object in next, _obj.O do
MarkObject(quest, object);
end
end
if _obj.E ~= nil then
for _, event in next, _obj.E do
MarkEvent(quest, event);
end
end
end
local _start = info['start'];
if _start ~= nil then
if _start.U ~= nil then
for _, unit in next, _start.U do
MarkUnit(quest, unit);
end
end
if _start.I ~= nil then
for _, item in next, _start.I do
MarkItem(quest, item);
end
end
if _start.O ~= nil then
for _, object in next, _start.O do
MarkObject(quest, object);
end
end
end
local _end = info['end'];
if _end ~= nil then
if _end.U ~= nil then
for _, unit in next, _end.U do
MarkUnit(quest, unit);
end
end
if _end.O ~= nil then
for _, object in next, _end.O do
MarkObject(quest, object);
end
end
end
local _extra = info['extra'];
if _extra ~= nil then
if _extra.U ~= nil then
for unit in next, _extra.U do
MarkUnit(quest, unit);
end
end
if _extra.I ~= nil then
for item in next, _extra.I do
MarkItem(quest, item);
end
end
if _extra.IR ~= nil then
for item in next, _extra.IR do
-- HashItem[item] = 1;
MarkItemRelation(quest, item);
end
end
if _extra.O ~= nil then
for object in next, _extra.O do
MarkObject(quest, object);
end
end
if _extra.E ~= nil then
for event in next, _extra.E do
MarkEvent(quest, event);
end
end
end
end
--> proc db
-- local M = {};
-- local LO = l10n.object;
-- for object in next, HashObject do
-- if LO[object] == nil then
-- M[#M + 1] = object;
-- end
-- end
-- _G.table.sort(M);
-- VT.ObjectMissLocale = M;
-- CodexLiteSV.ObjectMissLocale=__ala_meta__.quest.VT.ObjectMissLocale
-->
local i18n = CT.i18n;
for which, hash in next, Hash do
local info = EmptyInfo[which];
local db = DataAgent[which];
local loc = l10n[which];
local def = i18n and i18n[which] or { };
if loc == nil then
for id, _ in next, hash do
db[id] = db[id] or info;
end
else
for id, _ in next, loc do
if hash[id] == nil then
loc[id] = nil;
end
end
for id, _ in next, hash do
db[id] = db[id] or info;
end
if which == "quest" then
for id, _ in next, hash do
local v = loc[id];
if v == nil then
v = { };
loc[id] = v;
end
local d = def[id];
v[1] = v[1] or d[1] or "quest:" .. id;
v[2] = nil;
v[3] = v[3] or v[2] or d[3] or d[2];
-- def[id] = nil;
end
else
for id, _ in next, hash do
loc[id] = loc[id] or def[id] or which .. ":" .. id;
-- def[id] = nil;
end
end
end
for id, _ in next, db do
if hash[id] == nil then
db[id] = nil;
end
end
if loc ~= def then
setmetatable(def, { __mode = "kv", });
end
end
if l10n ~= i18n then
setmetatable(i18n, { __mode = "kv", });
end
-->
MarkUnit, MarkItem, MarkObject, MarkRefloot, MarkEvent = nil;
HashUnit, HashItem, HashObject, HashRefloot, HashEvent = nil;
Hash = nil;
-->
CT.i18n = nil;
-->
--[==[
local i18n = CT.i18n;
if i18nn then
for _, which in next, { "unit", "item", "object", "refloot", "event", } do
local loc = l10n[which];
local def = i18n[which] or { };
for key, val in next, def do
if loc[key] == nil then
loc[key] = val;
end
end
end
CT.i18n = nil;
end
--]==]
--> item-drop
for iid, info in next, DataAgent.item do
if info.U ~= nil then
local throttle = false;
local U = info.U;
local O = info.O;
if O ~= nil then
for oid, r in next, O do
if r >= 25 then
throttle = true;
break;
end
end
end
if not throttle then
for uid, r in next, U do
if r >= 25 then
throttle = true;
break;
end
end
end
if throttle then
for uid, r in next, U do
if r <= 2 then
U[uid] = nil;
end
end
if O ~= nil then
for oid, r in next, O do
if r <= 2 then
O[oid] = nil;
end
end
end
end
end
end
-->
--> Large Pin
for quest, info in next, DataAgent.quest do
local _obj = info['obj'];
if _obj ~= nil then
if _obj.U ~= nil then
for _, unit in next, _obj.U do
local uinfo = DataAgent.unit[unit];
if uinfo ~= nil and uinfo.waypoints == nil and uinfo.coords ~= nil and #uinfo.coords == 1 then
DataAgent.large_pin[quest] = DataAgent.large_pin[quest] or { };
DataAgent.large_pin[quest].unit = DataAgent.large_pin[quest].unit or { };
DataAgent.large_pin[quest].unit[unit] = 1;
end
end
end
if _obj.O ~= nil then
for _, object in next, _obj.O do
local oinfo = DataAgent.object[object];
if oinfo ~= nil and oinfo.coords ~= nil and #oinfo.coords == 1 then
DataAgent.large_pin[quest] = DataAgent.large_pin[quest] or { };
DataAgent.large_pin[quest].object = DataAgent.large_pin[quest].object or { };
DataAgent.large_pin[quest].object[object] = 1;
end
end
end
if _obj.I ~= nil then
for _, item in next, _obj.I do
local iinfo = DataAgent.item[item];
if iinfo ~= nil then
local num = 0;
local type = nil;
local id = nil;
if iinfo.U ~= nil then
for unit, rate in next, iinfo.U do
if rate >= 1 then
local uinfo = DataAgent.unit[unit];
if uinfo ~= nil and uinfo.coords ~= nil then
local n = #uinfo.coords;
if n == 1 then
type = 'unit';
id = unit;
end
num = num +n;
if num > 1 then break; end
end
end
end
end
if num <= 1 then
if iinfo.V ~= nil then
for unit, _ in next, iinfo.V do
local uinfo = DataAgent.unit[unit];
if uinfo ~= nil and uinfo.coords ~= nil then
local n = #uinfo.coords;
if n == 1 then
type = 'unit';
id = unit;
end
num = num + n;
if num > 1 then break; end
end
end
end
end
if num <= 1 then
if iinfo.O ~= nil then
for object, rate in next, iinfo.O do
if rate >= 1 then
local oinfo = DataAgent.object[object];
if oinfo ~= nil and oinfo.coords ~= nil then
local n = #oinfo.coords;
if n == 1 then
type = 'object';
id = object;
end
num = num + n;
if num > 1 then break; end
end
end
end
end
end
if num == 1 then
DataAgent.large_pin[quest] = DataAgent.large_pin[quest] or { };
DataAgent.large_pin[quest].item = DataAgent.large_pin[quest].item or { };
DataAgent.large_pin[quest].item[item] = 1;
DataAgent.large_pin[quest][type] = DataAgent.large_pin[quest][type] or { };
DataAgent.large_pin[quest][type][id] = 1;
end
end
end
end
end
end
-->
--> Locale
-->
collectgarbage('collect');
end);
-->