forked from belazor-wow/WorldQuestTab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dataprovider.lua
771 lines (646 loc) · 23.5 KB
/
Dataprovider.lua
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
local _, addon = ...
----------------------------
-- VARIABLES
----------------------------
local WQT = addon.WQT;
local _L = addon.L;
local _V = addon.variables;
local WQT_Utils = addon.WQT_Utils;
local _WFMLoaded = IsAddOnLoaded("WorldFlightMap");
local _azuriteID = C_CurrencyInfo.GetAzeriteCurrencyID();
----------------------------
-- LOCAL FUNCTIONS
----------------------------
local function UpdateAzerothZones(newLevel)
newLevel = newLevel or UnitLevel("player");
local expLevel = GetAccountExpansionLevel();
local worldTable = _V["WQT_ZONE_MAPCOORDS"][947]
wipe(worldTable);
-- world map continents depending on expansion level
worldTable[113] = {["x"] = 0.49, ["y"] = 0.13} -- Northrend
worldTable[424] = {["x"] = 0.46, ["y"] = 0.92} -- Pandaria
worldTable[12] = {["x"] = 0.19, ["y"] = 0.5} -- Kalimdor
worldTable[13] = {["x"] = 0.88, ["y"] = 0.56} -- Eastern Kingdom
-- Always take the highest expansion
if (expLevel >= LE_EXPANSION_BATTLE_FOR_AZEROTH and newLevel >= 50) then
worldTable[875] = {["x"] = 0.54, ["y"] = 0.61} -- Zandalar
worldTable[876] = {["x"] = 0.72, ["y"] = 0.49} -- Kul Tiras
elseif (expLevel >= LE_EXPANSION_LEGION and newLevel >= 50) then
worldTable[619] = {["x"] = 0.6, ["y"] = 0.41} -- Broken Isles
end
end
local function WipeQuestInfoRecursive(questInfo)
-- Clean out everthing that isn't a color
for k, v in pairs(questInfo) do
local objType = type(v);
if objType == "table" and not v.GetRGB then
WipeQuestInfoRecursive(v)
else
if (objType == "boolean" or objType == "number") then
questInfo[k] = nil;
elseif (objType == "string") then
questInfo[k] = "";
end
end
end
end
local function RewardSortFunc(a, b)
local aPassed = WQT_Utils:RewardTypePassesFilter(a.type);
local bPassed = WQT_Utils:RewardTypePassesFilter(b.type);
-- Rewards that pass the filters get priority
if (aPassed ~= bPassed) then
return aPassed and not bPassed;
end
if (a.quality == b.quality) then
if (a.quality == b.quality) then
if (a.id and b.id and a.id ~= b.id) then
return a.id > b.id;
end
if (a.amount == b.amount) then
return a.id < b.id;
end
return a.amount > b.amount;
end
return a.type < b.type;
end
return a.quality > b.quality;
end
local function ScanTooltipRewardForPattern(questID, pattern)
local result;
WQT_Utils:AddQuestRewardsToTooltip(WQT_ScrapeTooltip, questID, TOOLTIP_QUEST_REWARDS_STYLE_DEFAULT);
for i=2, 6 do
local line = _G["WQT_ScrapeTooltipTooltipTextLeft"..i];
if (not line) then break; end
local lineText = line:GetText() or "";
result = lineText:match(pattern);
if (result) then break; end
end
-- Force hide compare tooltips as they'd show up for people with alwaysCompareItems set to 1
for _, tooltip in ipairs(WQT_ScrapeTooltip.shoppingTooltips) do
tooltip:Hide();
end
return result;
end
local function ZonesByExpansionSort(a, b)
local expA = _V["WQT_ZONE_EXPANSIONS"][a];
local expB = _V["WQT_ZONE_EXPANSIONS"][b];
if (not expA or not expB or expA == expB) then
return b > a;
end
return expB > expA;
end
----------------------------
-- QuestInfoMixin
----------------------------
local QuestInfoMixin = {};
function WQT_Utils:QuestCreationFunc(questId)
local questInfo = CreateFromMixins(QuestInfoMixin);
questInfo:OnCreate();
local hasRewardData = false;
if (questId) then
hasRewardData = questInfo:Init(questId);
end
return questInfo, hasRewardData;
end
local function QuestResetFunc(pool, questInfo)
questInfo:Reset();
end
function QuestInfoMixin:Init(questId, isDaily, isCombatAllyQuest, alwaysHide, posX, posY)
self.questId = questId;
self.isDaily = isDaily;
self.isAllyQuest = isCombatAllyQuest;
self.alwaysHide = alwaysHide;
self:SetMapPos(posX, posY);
self.tagInfo = C_QuestLog.GetQuestTagInfo(questId);
self.isValid = HaveQuestData(self.questId);
self.time.seconds = WQT_Utils:GetQuestTimeString(self); -- To check if expired or never had a time limit
self.passedFilter = true;
-- quest type
self.typeBits = WQT_QUESTTYPE.normal;
if (isDaily) then self.typeBits = bit.bor(self.typeBits, WQT_QUESTTYPE.daily); end
if (C_QuestLog.IsThreatQuest(self.questId)) then self.typeBits = bit.bor(self.typeBits, WQT_QUESTTYPE.threat); end
if (C_QuestLog.IsQuestCalling(self.questId)) then self.typeBits = bit.bor(self.typeBits, WQT_QUESTTYPE.calling); end
if (isCombatAllyQuest) then self.typeBits = bit.bor(self.typeBits, WQT_QUESTTYPE.combatAlly); end
-- rewards
self:LoadRewards();
return self.hasRewardData;
end
function QuestInfoMixin:OnCreate()
self.time = {};
self.reward = {
["typeBits"] = WQT_REWARDTYPE.missing;
};
self.rewardList = {};
self.mapInfo = {};
self.hasRewardData = false;
end
function QuestInfoMixin:SetMapPos(posX, posY)
self.mapInfo.mapX = posX;
self.mapInfo.mapY = posY;
end
function QuestInfoMixin:Reset()
wipe(self.rewardList);
WipeQuestInfoRecursive(self);
-- Reset defaults
self.reward.typeBits = WQT_REWARDTYPE.missing;
self.typeBits = WQT_QUESTTYPE.normal;
self.hasRewardData = false;
self.isValid = false;
self.tagInfo = nil;
end
function QuestInfoMixin:LoadRewards(force)
-- If we already have our data, don't try again;
if (not force and self.hasRewardData) then return; end
wipe(self.rewardList);
local haveData = HaveQuestRewardData(self.questId);
if (haveData) then
self.reward.typeBits = WQT_REWARDTYPE.none;
-- Items
if (GetNumQuestLogRewards(self.questId) > 0) then
local _, texture, numItems, quality, _, rewardId, ilvl = GetQuestLogRewardInfo(1, self.questId);
if (rewardId) then
local price, typeID, subTypeID = select(11, GetItemInfo(rewardId));
if (C_Soulbinds.IsItemConduitByItemInfo(rewardId)) then
-- Conduits
-- Lovely yikes on getting the type
local conduitType = ScanTooltipRewardForPattern(self.questId, "(.+)") or "";
local subType = _V["CONDUIT_SUBTYPE"].endurance;
if(conduitType == CONDUIT_TYPE_FINESSE) then
subType = _V["CONDUIT_SUBTYPE"].finesse;
elseif(conduitType == CONDUIT_TYPE_POTENCY) then
subType = _V["CONDUIT_SUBTYPE"].potency;
end
self:AddReward(WQT_REWARDTYPE.conduit, ilvl, texture, quality, WQT_Utils:GetColor(_V["COLOR_IDS"].rewardRelic), rewardId, false, subType);
elseif (typeID == 4 or typeID == 2) then
-- Gear (4 = armor, 2 = weapon)
local canUpgrade = ScanTooltipRewardForPattern(self.questId, "(%d+%+)$") and true or false;
local rewardType = typeID == 4 and WQT_REWARDTYPE.equipment or WQT_REWARDTYPE.weapon;
local color = typeID == 4 and WQT_Utils:GetColor(_V["COLOR_IDS"].rewardArmor) or WQT_Utils:GetColor(_V["COLOR_IDS"].rewardWeapon);
self:AddReward(rewardType, ilvl, texture, quality, color, rewardId, canUpgrade);
elseif (typeID == 3 and subTypeID == 11) then
-- Relics
-- Find upgrade amount as C_ArtifactUI.GetItemLevelIncreaseProvidedByRelic doesn't scale
local numItems = tonumber(ScanTooltipRewardForPattern(self.questId, "^%+(%d+)"));
self:AddReward(WQT_REWARDTYPE.relic, numItems, texture, quality,WQT_Utils:GetColor(_V["COLOR_IDS"].rewardRelic), rewardId);
elseif(C_Item.IsAnimaItemByID(rewardId)) then
-- Anima
local value = ScanTooltipRewardForPattern(self.questId, " (%d+) ") or 1;
value = tonumber(value);
if (WQT.settings.general.sl_genericAnimaIcons) then
texture = 3528288;
if (value >= 250) then
texture = 3528287;
end
end
self:AddReward(WQT_REWARDTYPE.anima, numItems * value, texture, quality, WQT_Utils:GetColor(_V["COLOR_IDS"].rewardAnima), rewardId);
else
-- Normal items
if (texture == 894556) then
-- Bonus player xp item is counted as actual xp
self:AddReward(WQT_REWARDTYPE.xp, ilvl, texture, quality, WQT_Utils:GetColor(_V["COLOR_IDS"].rewardItem), rewardId);
elseif (typeID == 0 and subTypeID == 8 and price == 0 and ilvl > 100) then
-- Item converting into equipment
self:AddReward(WQT_REWARDTYPE.equipment, ilvl, texture, quality, WQT_Utils:GetColor(_V["COLOR_IDS"].rewardArmor), rewardId);
else
self:AddReward(WQT_REWARDTYPE.item, numItems, texture, quality, WQT_Utils:GetColor(_V["COLOR_IDS"].rewardItem), rewardId);
end
end
end
end
-- Spells
if (GetQuestLogRewardSpell(1, self.questId)) then
local texture, _, _, _, _, _, _, _, rewardId = GetQuestLogRewardSpell(1, self.questId);
self:AddReward(WQT_REWARDTYPE.spell, 1, texture, 1, WQT_Utils:GetColor(_V["COLOR_IDS"].rewardItem), rewardId);
end
-- Honor
if (GetQuestLogRewardHonor(self.questId) > 0) then
local numItems = GetQuestLogRewardHonor(self.questId);
self:AddReward(WQT_REWARDTYPE.honor, numItems, 1455894, 1, WQT_Utils:GetColor(_V["COLOR_IDS"].rewardHonor));
end
-- Gold
if (GetQuestLogRewardMoney(self.questId) > 0) then
local numItems = floor(abs(GetQuestLogRewardMoney(self.questId)))
self:AddReward(WQT_REWARDTYPE.gold, numItems, 133784, 1, WQT_Utils:GetColor(_V["COLOR_IDS"].rewardGold));
end
-- Currency
local numCurrencies = GetNumQuestLogRewardCurrencies(self.questId);
for i=1, numCurrencies do
local _, _, amount, currencyId = GetQuestLogRewardCurrencyInfo(i, self.questId);
if (currencyId) then
local currencyInfo = C_CurrencyInfo.GetCurrencyInfo(currencyId);
local isRep = C_CurrencyInfo.GetFactionGrantedByCurrency(currencyId) ~= nil;
local name, texture, _, quality = CurrencyContainerUtil.GetCurrencyContainerInfo(currencyId, amount, currencyInfo.name, currencyInfo.iconFileID, currencyInfo.quality);
local currType = currencyId == _azuriteID and WQT_REWARDTYPE.artifact or (isRep and WQT_REWARDTYPE.reputation or WQT_REWARDTYPE.currency);
local color = currType == WQT_REWARDTYPE.artifact and WQT_Utils:GetColor(_V["COLOR_IDS"].rewardArtiface) or WQT_Utils:GetColor(_V["COLOR_IDS"].rewardCurrency);
self:AddReward(currType, amount, texture, quality, color, currencyId);
end
end
-- Player experience
if (GetQuestLogRewardXP(self.questId) > 0) then
local numItems = GetQuestLogRewardXP(self.questId);
self:AddReward(WQT_REWARDTYPE.xp, numItems, 894556, 1, WQT_Utils:GetColor(_V["COLOR_IDS"].rewardXp));
end
self:ParseRewards();
end
self.hasRewardData = haveData;
end
function QuestInfoMixin:AddReward(rewardType, amount, texture, quality, color, id, canUpgrade, subType)
local index = #self.rewardList + 1;
-- Create reward
local rewardInfo = self.rewardList[index] or {};
rewardInfo.id = id or 0;
rewardInfo.type = rewardType;
rewardInfo.amount = amount;
rewardInfo.texture = texture;
rewardInfo.quality = quality;
rewardInfo.color, rewardInfo.textColor = WQT_Utils:GetRewardTypeColorIDs(rewardType);
rewardInfo.canUpgrade = canUpgrade;
rewardInfo.subType = subType;
self.rewardList[index] = rewardInfo;
-- Raise type flag
self.reward.typeBits = bit.bor(self.reward.typeBits, rewardType);
end
function QuestInfoMixin:ParseRewards()
table.sort(self.rewardList, RewardSortFunc);
end
function QuestInfoMixin:TryDressUpReward()
for k, rewardInfo in self:IterateRewards() do
if (bit.band(rewardInfo.type, WQT_REWARDTYPE.gear) > 0) then
local _, link = GetItemInfo(rewardInfo.id);
DressUpItemLink(link)
end
end
end
function QuestInfoMixin:IterateRewards()
return ipairs(self.rewardList);
end
function QuestInfoMixin:GetReward(index)
if (index < 1 or index > #self.rewardList) then
return nil;
end
return self.rewardList[index];
end
function QuestInfoMixin:IsExpired()
local timeLeftSeconds = C_TaskQuest.GetQuestTimeLeftSeconds(self.questId) or 0;
return self.time.seconds and self.time.seconds > 0 and timeLeftSeconds < 1;
end
function QuestInfoMixin:SetAsWaypoint()
local mapInfo = WQT_Utils:GetMapInfoForQuest(self.questId);
local x, y = WQT_Utils:GetQuestMapLocation(self.questId, mapInfo.mapID);
local wayPoint = UiMapPoint.CreateFromCoordinates(mapInfo.mapID, x, y);
C_Map.SetUserWaypoint(wayPoint);
end
-- Getters for the most important reward
function QuestInfoMixin:GetFirstNoneAzeriteType()
if (self.reward.typeBits == WQT_REWARDTYPE.none) then
return WQT_REWARDTYPE.none;
end
local hasAzerite = false;
for i = 1, #self.rewardList do
local reward = self.rewardList[i];
if (reward.type ~= WQT_REWARDTYPE.artifact) then
return reward.type, reward.subType;
else
hasAzerite = true;
end
end
return hasAzerite and WQT_REWARDTYPE.artifact or WQT_REWARDTYPE.missing;
end
function QuestInfoMixin:GetRewardType()
if (self.reward.typeBits == WQT_REWARDTYPE.none) then
return WQT_REWARDTYPE.none;
end
local reward = self.rewardList[1];
local rewardType = reward and reward.type or WQT_REWARDTYPE.missing;
local rewardSubType = reward and reward.subType;
return rewardType, rewardSubType;
end
function QuestInfoMixin:GetRewardId()
local reward = self.rewardList[1];
return reward and reward.id or 0;
end
function QuestInfoMixin:GetRewardAmount()
local reward = self.rewardList[1];
return reward and reward.amount or 0;
end
function QuestInfoMixin:GetRewardTexture()
if (self.reward.typeBits == WQT_REWARDTYPE.none) then
-- Dark empty texture
return "Interface/Garrison/GarrisonMissionUIInfoBoxBackgroundTile";
end
local reward = self.rewardList[1];
return reward and reward.texture or 134400;
end
function QuestInfoMixin:GetRewardQuality()
local reward = self.rewardList[1];
return reward and reward.quality or 1;
end
function QuestInfoMixin:GetRewardColor()
if (self.reward.typeBits == WQT_REWARDTYPE.none) then
return WQT_Utils:GetColor(_V["COLOR_IDS"].rewardNone);
end
local reward = self.rewardList[1];
return reward and reward.color or WQT_Utils:GetColor(_V["COLOR_IDS"].rewardMissing);
end
function QuestInfoMixin:GetRewardCanUpgrade()
local reward = self.rewardList[1];
return reward and reward.canUpgrade;
end
function QuestInfoMixin:IsCriteria(forceSingle)
local bountyBoard = WorldMapFrame.overlayFrames[_V["WQT_BOUNDYBOARD_OVERLAYID"]];
if (not bountyBoard) then return false; end
-- Try only selected
if (forceSingle) then
return bountyBoard:IsWorldQuestCriteriaForSelectedBounty(self.questId);
end
-- Try any of them
if (bountyBoard.bounties) then
for k, bounty in ipairs(bountyBoard.bounties) do
if (C_QuestLog.IsQuestCriteriaForBounty(self.questId, bounty.questID)) then
return true;
end
end
end
return false;
end
function QuestInfoMixin:GetTitle()
local title = C_TaskQuest.GetQuestInfoByQuestID(self.questId);
return title;
end
function QuestInfoMixin:GetTagInfo()
return self.tagInfo;
end
function QuestInfoMixin:IsDisliked()
return WQT_Utils:QuestIsDisliked(self.questId);
end
function QuestInfoMixin:DataIsValid()
return self.questId ~= nil;
end
function QuestInfoMixin:IsSpecialType()
return self.typeBits ~= WQT_QUESTTYPE.normal;
end
function QuestInfoMixin:IsQuestOfType(questType)
return bit.band(self.typeBits, questType) > 0;
end
----------------------------
-- MIXIN
----------------------------
-- Callbacks:
-- "BufferUpdated" (progress): % of buffered quests has changed. progress = 0-1
-- "QuestsLoaded" (): Buffer emptied
-- "WaitingRoom" (): Quest in the waiting room had data updated
WQT_DataProvider = CreateFromMixins(WQT_CallbackMixin);
function WQT_DataProvider:Init()
self.frame = CreateFrame("FRAME");
self.frame:SetScript("OnUpdate", function(frame, ...) self:OnUpdate(...); end);
self.frame:SetScript("OnEvent", function(frame, ...) self:OnEvent(...); end);
self.frame:RegisterEvent("QUEST_LOG_UPDATE");
self.frame:RegisterEvent("PLAYER_LEVEL_UP");
self.pool = CreateObjectPool(WQT_Utils.QuestCreationFunc, QuestResetFunc);
self.iterativeList = {};
self.keyList = {};
-- If we added a quest which we didn't have rewarddata for yet, it gets added to the waiting room
self.waitingRoomRewards = {};
self.bufferedZones = {};
hooksecurefunc(WorldMapFrame, "OnMapChanged", function()
-- If we change map, reset the CD, we want new quest info
self:LoadQuestsInZone(WorldMapFrame.mapID);
end);
UpdateAzerothZones();
self.updateCD = 0;
end
function WQT_DataProvider:OnEvent(event, ...)
if (event == "QUEST_LOG_UPDATE") then
-- If the last update was too recent, it's probably just quest data becoming available
if (self.updateCD > 0) then
self:UpdateWaitingRoom();
else
self:LoadQuestsInZone(WorldMapFrame.mapID);
end
elseif (event == "PLAYER_LEVEL_UP") then
local level = ...;
UpdateAzerothZones(level);
end
end
function WQT_DataProvider:OnUpdate(elapsed)
if (self.updateCD > 0) then
self.updateCD = max(0, self.updateCD - elapsed);
end
if (#self.bufferedZones > 0) then
-- Figure out how many zoned to check each frame
local numQuests = #self.bufferedZones;
local num = 10;
num = min (numQuests, num);
local questsAdded = false;
-- Load quests
for i = numQuests, numQuests - num + 1, -1 do
local zoneId = self.bufferedZones[i];
local zoneInfo = WQT_Utils:GetCachedMapInfo(zoneId);
local hadQuests = self:AddQuestsInZone(zoneId, zoneInfo.parentMapID);
questsAdded = questsAdded or hadQuests;
tremove(self.bufferedZones, i);
self.numZonesProcessed = self.numZonesProcessed + 1;
end
self:UpdateBufferProgress();
if (#self.bufferedZones == 0) then
self.isUpdating = false;
self:TriggerCallback("QuestsLoaded");
end
end
end
function WQT_DataProvider:ClearData()
self.pool:ReleaseAll();
wipe(self.iterativeList);
wipe(self.keyList);
wipe(self.waitingRoomRewards);
wipe(self.bufferedZones);
self.numZonesProcessed = 0;
end
function WQT_DataProvider:UpdateWaitingRoom()
local questInfo;
local updatedData = false;
for i = #self.waitingRoomRewards, 1, -1 do
questInfo = self.waitingRoomRewards[i];
if ( questInfo.questId and HaveQuestRewardData(questInfo.questId)) then
questInfo:LoadRewards(true);
table.remove(self.waitingRoomRewards, i);
updatedData = true;
end
end
if (updatedData) then
self:TriggerCallback("WaitingRoom");
end
end
function WQT_DataProvider:AddContinentMapQuests(continentZones, continentId)
if continentZones then
for zoneID in pairs(continentZones) do
self:AddZoneToBuffer(zoneID);
end
end
end
function WQT_DataProvider:AddWorldMapQuests(worldContinents)
if worldContinents then
for contID in pairs(worldContinents) do
-- Every ID is a continent, get every zone on every continent
local continentZones = _V["WQT_ZONE_MAPCOORDS"][contID];
self:AddContinentMapQuests(continentZones, contID)
end
end
end
function WQT_DataProvider:AddZoneToBuffer(zoneID)
tinsert(self.bufferedZones, zoneID);
-- Check for subzones and add those as well
local subZones = _V["ZONE_SUBZONES"][zoneID];
if (subZones) then
for k, subID in ipairs(subZones) do
tinsert(self.bufferedZones, subID);
end
end
end
function WQT_DataProvider:LoadQuestsInZone(zoneID)
self.isUpdating = true;
self:ClearData();
zoneID = zoneID or self.latestZoneId or C_Map.GetBestMapForUnit("player");
if (not zoneID) then return end;
self.updateCD = 0.5;
self.latestZoneId = zoneID
-- If the flight map is open, we want all quests no matter what
if ((FlightMapFrame and FlightMapFrame:IsShown()) ) then
local taxiId = GetTaxiMapID()
zoneID = (taxiId and taxiId > 0) and taxiId or zoneID;
-- World Flight Map add-on overwrite
if (_WFMLoaded) then
zoneID = WorldMapFrame.mapID;
end
end
local currentMapInfo = WQT_Utils:GetCachedMapInfo(zoneID);
if not currentMapInfo then return end;
if (WQT.settings.list.alwaysAllQuests ) then
local expLevel = _V["WQT_ZONE_EXPANSIONS"][zoneID];
if (not expLevel or expLevel == 0) then
expLevel = GetAccountExpansionLevel();
end
-- Gather quests for all zones either matching current zone's expansion, or matching no expansion (i.e. Stranglethorn fishing quest)
local count = 0;
for zoneID, expId in pairs(_V["WQT_ZONE_EXPANSIONS"])do
if (expId == 0 or expId == expLevel) then
self:AddZoneToBuffer(zoneID);
end
count = count + 1;
end
else
local continentZones = _V["WQT_ZONE_MAPCOORDS"][zoneID];
if (currentMapInfo.mapType == Enum.UIMapType.World) then
self:AddWorldMapQuests(continentZones);
elseif (continentZones) then -- Zone with multiple subzones
self:AddContinentMapQuests(continentZones);
else
self:AddZoneToBuffer(zoneID);
end
end
-- Sort current expansion to front, they are more likely to have quests
table.sort(self.bufferedZones, ZonesByExpansionSort);
self:UpdateBufferProgress();
if (self.bufferedZones == 0) then
self.isUpdating = false;
end
self:TriggerCallback("QuestsLoaded");
end
function WQT_DataProvider:AddQuestsInZone(zoneID, continentId)
local questsById = C_TaskQuest.GetQuestsForPlayerByMapID(zoneID, continentId);
local hadQuests;
if (questsById) then
for k, info in ipairs(questsById) do
if (info.mapID == zoneID) then
self:AddQuest(info);
end
end
hadQuests = #questsById > 0;
end
return hadQuests;
end
function WQT_DataProvider:AddQuest(qInfo)
-- Setting to filter daily world quests
if (not WQT.settings.list.includeDaily and qInfo.isDaily) then
return true;
end
local duplicate = self:FindDuplicate(qInfo.questId);
-- If there is a duplicate, we don't want to go through all the info again
if (duplicate) then
-- Check if the new zone is the 'official' zone, if so, use that one instead
if (qInfo.mapID == C_TaskQuest.GetQuestZoneID(qInfo.questId) ) then
duplicate:SetMapPos(qInfo.x, qInfo.y);
end
return duplicate;
end
local questInfo = self.pool:Acquire();
local alwaysHide = not MapUtil.ShouldShowTask(qInfo.mapID, qInfo);
local posX, posY = WQT_Utils:GetQuestMapLocation(qInfo.questId, qInfo.mapID);
local haveRewardData = questInfo:Init(qInfo.questId, qInfo.isDaily, qInfo.isCombatAllyQuest, alwaysHide, posX, posY);
-- If we have no data for the quest, don't include them in the waiting room, they are probably messed up
-- Worst case we do get their data at a later point, it will cause everything to refresh anyway
if (not haveRewardData and HaveQuestData(qInfo.questId)) then
C_TaskQuest.RequestPreloadRewardData(qInfo.questId);
tinsert(self.waitingRoomRewards, questInfo);
return false;
end;
return true;
end
function WQT_DataProvider:FindDuplicate(questId)
for questInfo, v in self.pool:EnumerateActive() do
if (questInfo.questId == questId) then
return questInfo;
end
end
return nil;
end
function WQT_DataProvider:GetIterativeList()
wipe(self.iterativeList);
for questInfo in self.pool:EnumerateActive() do
table.insert(self.iterativeList, questInfo);
end
return self.iterativeList;
end
function WQT_DataProvider:GetKeyList()
for id in pairs(self.keyList) do
self.keyList[id] = nil;
end
for questInfo, v in self.pool:EnumerateActive() do
self.keyList[questInfo.questId] = questInfo;
end
return self.keyList;
end
function WQT_DataProvider:GetQuestById(id)
for questInfo in self.pool:EnumerateActive() do
if questInfo.questId == id then return questInfo; end
end
return nil;
end
function WQT_DataProvider:ListContainsEmissary()
for questInfo, v in self.pool:EnumerateActive() do
if (questInfo:IsCriteria(WQT.settings.general.bountySelectedOnly)) then return true; end
end
return false
end
function WQT_DataProvider:HasNoQuests()
if (self:IsBuffereingQuests()) then return false; end
if (self.pool:GetNumActive() > 0) then return false; end
return true;
end
function WQT_DataProvider:IsBuffereingQuests()
return #self.bufferedZones > 0;
end
function WQT_DataProvider:UpdateBufferProgress()
local total = #self.bufferedZones + self.numZonesProcessed;
local progress = 1-(#self.bufferedZones / total);
self:TriggerCallback("BufferUpdated", progress);
end
function WQT_DataProvider:ReloadQuestRewards()
for questInfo, v in self.pool:EnumerateActive() do
questInfo:LoadRewards(true);
end
self:TriggerCallback("QuestsLoaded");
end
function WQT_DataProvider:IsUpdating()
return self.isUpdating or #self.bufferedZones > 0 or #self.waitingRoomRewards > 0;
end