-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathfunctions.lua
More file actions
8355 lines (7595 loc) · 277 KB
/
Copy pathfunctions.lua
File metadata and controls
8355 lines (7595 loc) · 277 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local addonName, addon = ...
local localizedClass, class = UnitClass("player")
local gameVersion = select(4, GetBuildInfo())
local fmt, tinsert = string.format,tinsert
local LoadAddOn = C_AddOns and C_AddOns.LoadAddOn or _G.LoadAddOn
local IsAddOnLoaded = C_AddOns and C_AddOns.IsAddOnLoaded or _G.IsAddOnLoaded
local GetItemInfo = C_Item and C_Item.GetItemInfo or _G.GetItemInfo
local GetSpellTexture = C_Spell and C_Spell.GetSpellTexture or _G.GetSpellTexture
local GetSpellSubtext = C_Spell and C_Spell.GetSpellSubtext or _G.GetSpellSubtext
local IsCurrentSpell = C_Spell and C_Spell.IsCurrentSpell or _G.IsCurrentSpell
local IsSpellKnown = C_SpellBook and C_SpellBook.IsSpellKnown or _G.IsSpellKnown
local IsPlayerSpell = C_Spell and C_Spell.IsPlayerSpell or _G.IsPlayerSpell
local GetSpellInfo = C_Spell and C_Spell.GetSpellInfo and addon.GetSpellInfo or _G.GetSpellInfo
local GetMerchantItemInfo = C_MerchantFrame and C_MerchantFrame.GetItemInfo or _G.GetMerchantItemInfo
local UnitName = addon.GetUnitName
-- start, duration, enabled, modRate = GetSpellCooldown(spell)
local GetSpellCooldown = _G.GetSpellCooldown or function(spellIdentifier)
if C_Spell and C_Spell.GetSpellCooldown then
local info = C_Spell.GetSpellCooldown(spellIdentifier)
return info.startTime, info.start, info.duration, info.enabled, info.modRate
end
end
addon.GetFactionInfoByID = _G.GetFactionInfoByID or function(factionID)
local name, description, standingID, barMin, barMax, barValue
local factionData = C_Reputation.GetFactionDataByID(factionID);
name = factionData.name
standingID = factionData.reaction
barValue = factionData.currentStanding
barMin = factionData.currentReactionThreshold
barMax = factionData.nextReactionThreshold
return name, description, standingID, barMin, barMax, barValue
end
if not (UnitAura and UnitBuff and UnitDebuff) then
addon.UnitAura = function(unitToken, index, filter)
if C_Secrets and C_Secrets.ShouldAurasBeSecret() then
return
end
local auraData = C_UnitAuras.GetAuraDataByIndex(unitToken, index, filter);
if not auraData then
return nil;
end
return AuraUtil.UnpackAuraData(auraData);
end
addon.UnitBuff = function(unitToken, index, filter)
if C_Secrets and C_Secrets.ShouldAurasBeSecret() then
return
end
local auraData = C_UnitAuras.GetBuffDataByIndex(unitToken, index, filter);
if not auraData then
return nil;
end
return AuraUtil.UnpackAuraData(auraData);
end
addon.UnitDebuff = function(unitToken, index, filter)
if C_Secrets and C_Secrets.ShouldAurasBeSecret() then
return
end
local auraData = C_UnitAuras.GetDebuffDataByIndex(unitToken, index, filter);
if not auraData then
return nil;
end
return AuraUtil.UnpackAuraData(auraData);
end
end
local UnitAura = addon.UnitAura or _G.UnitAura
local UnitBuff = addon.UnitBuff or _G.UnitBuff
local UnitDebuff = addon.UnitDebuff or _G.UnitDebuff
local GetItemCount = C_Item and C_Item.GetItemCount or _G.GetItemCount
local function LoremasterEnabled()
local loremaster
if addon.gameVersion < 50000 then
loremaster = addon.game == "WOTLK" and addon.settings.profile.northrendLM or
addon.game == "CATA" and addon.settings.profile.loremasterMode
elseif addon.gameVersion < 60000 then
loremaster = addon.settings.profile.loremasterMode or UnitLevel('player') == addon.player.maxlevel
elseif addon.gameVersion < 50000 then
loremaster = addon.settings.profile.loremasterMode
end
return loremaster
end
--local RXPGuides = addon.RXPGuides
local L = addon.locale.Get
addon.functions.__index = addon.functions
local events = {}
local UNIT_QUEST_LOG_CHANGED
if C_EventUtils and C_EventUtils.IsEventValid("UNIT_QUEST_LOG_CHANGED") then
UNIT_QUEST_LOG_CHANGED = "UNIT_QUEST_LOG_CHANGED"
end
addon.stepUpdateList = {}
addon.functions.events = events
events.collect = {"BAG_UPDATE_DELAYED", "QUEST_LOG_UPDATE", "MERCHANT_SHOW","CHAT_MSG_LOOT",UNIT_QUEST_LOG_CHANGED}
events.collectmultiple = events.collect
events.destroy = events.collect
events.buy = events.collect
events.accept = {"QUEST_ACCEPTED", "QUEST_TURNED_IN", "QUEST_REMOVED"}
events.turnin = {"QUEST_TURNED_IN","QUEST_LOG_UPDATE", UNIT_QUEST_LOG_CHANGED}
if C_EventUtils and C_EventUtils.IsEventValid("STOP_MOVIE") then
events.complete = {"QUEST_LOG_UPDATE", "CINEMATIC_STOP", "STOP_MOVIE", UNIT_QUEST_LOG_CHANGED}
else
events.complete = {"QUEST_LOG_UPDATE", "CINEMATIC_STOP", UNIT_QUEST_LOG_CHANGED}
end
events.fp = {"UI_INFO_MESSAGE", "UI_ERROR_MESSAGE", "TAXIMAP_OPENED", "GOSSIP_SHOW", "TAXIMAP_CLOSED"}
events.hs = "UNIT_SPELLCAST_SUCCEEDED"
events.home = {"HEARTHSTONE_BOUND","CONFIRM_BINDER","GOSSIP_SHOW"}
events.bindlocation = events.home
events.fly = {"PLAYER_CONTROL_LOST", "TAXIMAP_OPENED", "ZONE_CHANGED", "GOSSIP_SHOW"}
events.deathskip = {"CONFIRM_XP_LOSS","GOSSIP_SHOW"}
events.xp = {"PLAYER_XP_UPDATE", "PLAYER_LEVEL_UP"}
events.reputation = "UPDATE_FACTION"
events.vendor = {"MERCHANT_SHOW", "MERCHANT_CLOSED"}
events.trainer = {"TRAINER_SHOW", "TRAINER_CLOSED"}
events.stable = {"PET_STABLE_SHOW", "PET_STABLE_CLOSED"}
events.tame = {"UNIT_SPELLCAST_SUCCEEDED", "UNIT_SPELLCAST_START"}
events.money = "PLAYER_MONEY"
events.train = {
"TRAINER_SHOW", "CHAT_MSG_SYSTEM", "SKILL_LINES_CHANGED", "TRAINER_UPDATE"
}
events.istrained = events.train
events.spellmissing = events.train
local zoneEvents = {"ZONE_CHANGED_NEW_AREA","ZONE_CHANGED","NEW_WMO_CHUNK","PLAYER_ENTERING_WORLD"}
events.zone = zoneEvents
events.zoneskip = zoneEvents
events.subzone = zoneEvents
events.subzoneskip = zoneEvents
events.bankdeposit = {"BANKFRAME_OPENED", "BAG_UPDATE_DELAYED"}
local gossipConfirm
local PI_Hide
local LSIT
if C_EventUtils then
if C_EventUtils.IsEventValid("ZONE_CHANGED_INDOORS") then
tinsert(zoneEvents,"ZONE_CHANGED_INDOORS")
end
if C_EventUtils.IsEventValid("GOSSIP_CONFIRM") then
gossipConfirm = "GOSSIP_CONFIRM"
end
if C_EventUtils.IsEventValid("GOSSIP_CONFIRM") then
PI_Hide = "PLAYER_INTERACTION_MANAGER_FRAME_HIDE"
end
if C_EventUtils.IsEventValid("LEARNED_SPELL_IN_TAB") then
LSIT = "LEARNED_SPELL_IN_TAB"
end
end
events.skipgossip = {"GOSSIP_SHOW", "GOSSIP_CLOSED", "GOSSIP_CONFIRM_CANCEL", "GOSSIP_CONFIRM"}
events.gossip = {"GOSSIP_SHOW", PI_Hide, gossipConfirm}
events.isQuestOffered = events.gossip
events.gossipoption = events.skipgossip
events.skipgossipid = {"GOSSIP_SHOW",gossipConfirm}
events.vehicle = {"UNIT_ENTERING_VEHICLE", "VEHICLE_UPDATE", "UNIT_EXITING_VEHICLE"}
events.exitvehicle = events.vehicle
events.skill = {"SKILL_LINES_CHANGED", LSIT}
events.emote = "PLAYER_TARGET_CHANGED"
events.collectmount = {"COMPANION_LEARNED", "COMPANION_UNLEARNED", "COMPANION_UPDATE", "NEW_PET_ADDED"}
events.collecttoy = "TOYS_UPDATED"
events.collectcurrency = "CURRENCY_DISPLAY_UPDATE"
events.collectpet = {"COMPANION_LEARNED", "COMPANION_UNLEARNED", "COMPANION_UPDATE", "NEW_PET_ADDED"}
events.tradeskill = events.train
events.cooldown = "SPELL_UPDATE_COOLDOWN"
events.mob = {"UNIT_TARGET","QUEST_TURNED_IN","QUEST_ACCEPTED"}
events.unitscan = events.mob
events.target = events.mob
events.bankwithdraw = events.bankdeposit
events.abandon = events.complete
--[[
events.isQuestComplete = events.complete
events.isOnQuest = events.complete
events.isQuestTurnedIn = events.complete
events.isQuestAvailable = events.isQuestTurnedIn
]]
events.cast = {"UNIT_SPELLCAST_SUCCEEDED","UNIT_SPELLCAST_FAILED_QUIET"}
events.blastedLands = events.collect
events.daily = events.accept
events.dailyturnin = events.turnin
events.acceptmultiple = events.accept
events.turninmultiple = events.turnin
local function GetIcon(path,index,size)
local coords = _G.GetPOITextureCoords or C_Minimap.GetPOITextureCoords
local x1, x2, y1, y2 = coords(index)
return format("|T%s:0:0:0:0:%d:%d:%d:%d:%d:%d|t", path, size, size, x1*size, x2*size, y1*size, y2*size)
end
addon.GetIcon = GetIcon
addon.icons = {
accept = "|TInterface/GossipFrame/AvailableQuestIcon:0|t",
daily = "|TInterface/GossipFrame/DailyQuestIcon:0|t",
dailyturnin = "|TInterface/GossipFrame/DailyActiveQuestIcon:0|t",
turnin = "|TInterface/GossipFrame/ActiveQuestIcon:0|t",
collect = "|TInterface/GossipFrame/VendorGossipIcon:0|t",
collectmultiple = "|TInterface/GossipFrame/VendorGossipIcon:0|t",
equip = "|TInterface/GossipFrame/VendorGossipIcon:0|t",
combat = "|TInterface/GossipFrame/BattleMasterGossipIcon:0|t",
complete = "|TInterface/GossipFrame/HealerGossipIcon:0|t",
vendor = "|TInterface/GossipFrame/BankerGossipIcon:0|t",
reputation = "|TInterface/GossipFrame/WorkOrderGossipIcon:0|t",
fly = "|TInterface/GossipFrame/TaxiGossipIcon:0|t",
fp = "|TInterface/AddOns/" .. addonName .. "/Textures/fp:0|t", --TODO themes, load issue
gossip = "|TInterface/GossipFrame/GossipGossipIcon:0|t",
hs = "|TInterface/MINIMAP/TRACKING/Innkeeper:0|t",
trainer = "|TInterface/GossipFrame/TrainerGossipIcon:0|t",
train = "|TInterface/GossipFrame/TrainerGossipIcon:0|t",
arrow = "|TInterface/MINIMAP/MinimapArrow:0|t",
marker = "|TInterface/WORLDSTATEFRAME/ColumnIcon-FlagCapture2:0|t",
xp = "|TInterface/PETBATTLES/BattleBar-AbilityBadge-Strong-Small:0|t",
stable = "|TInterface/MINIMAP/TRACKING/StableMaster:0|t",
tame = "|TInterface/ICONS/Ability_Hunter_BeastTaming:0|t",
abandon = "|TInterface/GossipFrame/IncompleteQuestIcon:0|t",
link = "|TInterface/FriendsFrame/UI-FriendsFrame-Link:0|t",
error = "|TInterface/Buttons/UI-GroupLoot-Pass-Up:0|t",
clock = "|TInterface/ICONS/INV_Misc_PocketWatch_02:0|t",
engrave = "|T134419:0|t",
clicknext = "|TInterface/Tooltips/ReforgeGreenArrow:0|t",
}
if addon.gameVersion > 50000 then
addon.icons["goto"] = "|TInterface/MINIMAP/POIICONS:0:0:0:0:128:128:63:72:0:4|t"
addon.icons["home"] = "|TInterface/MINIMAP/POIICONS:0:0:0:0:128:128:45:54:0:4|t"
addon.icons["deathskip"] = "|TInterface/MINIMAP/POIICONS:0:0:0:0:128:128:72:81:0:4|t"
elseif addon.gameVersion > 30000 then
addon.icons["goto"] = "|TInterface/MINIMAP/POIICONS:0:0:0:0:128:128:63:72:0:9|t"
addon.icons["home"] = "|TInterface/MINIMAP/POIICONS:0:0:0:0:128:128:45:54:0:9|t"
addon.icons["deathskip"] = "|TInterface/MINIMAP/POIICONS:0:0:0:0:128:128:72:81:0:9|t"
else
addon.icons["goto"] = "|TInterface/MINIMAP/POIICONS:0:0:0:0:128:128:96:112:0:16|t"
addon.icons["home"] = "|TInterface/MINIMAP/POIICONS:0:0:0:0:128:128:64:80:0:16|t"
addon.icons["deathskip"] = "|TInterface/MINIMAP/POIICONS:0:0:0:0:128:128:112:128:0:16|t"
end
--GetIcon("Interface/MINIMAP/POIICONS",5,128)
addon.icons.groundgoto = addon.icons["goto"]
addon.icons.flygoto = addon.icons["goto"]
addon.icons.acceptmultiple = addon.icons.accept
addon.icons.turninmultiple = addon.icons.turnin
addon.icons.xpto60 = addon.icons.xp
function addon.error(text, arg1)
if type(text) ~= "string" then
text = ""
end
if arg1 then
addon.comms.PrettyPrint("%s %s: %s\n%s", L("Error parsing guide"), addon.currentGuideName, arg1, text)
else
addon.comms.PrettyPrint(text)
end
end
local _G = _G
local GetNumQuests = C_QuestLog.GetNumQuestLogEntries or
_G.GetNumQuestLogEntries
local GetQuestLogTitle = _G.GetQuestLogTitle
local GetNumDayEvents = _G.C_Calendar and _G.C_Calendar.GetNumDayEvents
local GetDayEvent = _G.C_Calendar and _G.C_Calendar.GetDayEvent
local GetCurrentCalendarTime = _G.C_DateAndTime.GetCurrentCalendarTime
--local OpenCalendar = _G.C_Calendar and _G.C_Calendar.OpenCalendar
local GossipSelectOption = _G.SelectGossipOption
local GossipGetOptions = C_GossipInfo and C_GossipInfo.GetOptions or _G.GetGossipOptions
local PickupContainerItem = C_Container and C_Container.PickupContainerItem or _G.PickupContainerItem
local GetContainerNumFreeSlots = C_Container and C_Container.GetContainerNumFreeSlots or _G.GetContainerNumFreeSlots
local GetContainerNumSlots = C_Container and C_Container.GetContainerNumSlots or _G.GetContainerNumSlots
local GetContainerItemID = C_Container and C_Container.GetContainerItemID or _G.GetContainerItemID
local GetContainerItemInfo = C_Container and C_Container.GetContainerItemInfo or _G.GetContainerItemInfo
local GetItemCooldown = addon.GetItemCooldown
addon.recentTurnIn = {}
addon.recentAccept = {}
function addon.ExpandQuestHeaders()
for i = 1, GetNumQuests() do
local isCollapsed
if GetQuestLogTitle then
_, _, _, _, isCollapsed = GetQuestLogTitle(i)
else
local qInfo = C_QuestLog.GetInfo(i)
isCollapsed = qInfo and qInfo.isCollapsed
end
if isCollapsed then
_G.ExpandQuestHeader(0)
return
end
end
end
if C_GossipInfo and C_GossipInfo.SelectOptionByIndex then
GossipSelectOption = function(index)
local gossipOptions = C_GossipInfo.GetOptions()
if not gossipOptions or not gossipOptions[index] then
return
end
local gossipOptionID = gossipOptions[index].gossipOptionID
if gossipOptionID then
C_GossipInfo.SelectOption(gossipOptionID,"",true)
return
end
local orderIndex = gossipOptions[index].orderIndex
if orderIndex then
C_GossipInfo.SelectOptionByIndex(orderIndex,"",true)
end
end
end
local SetRecentTurnIn = function(id)
addon.recentTurnIn[id] = GetTime()
end
local GetRecentTurnIn = function(id)
return addon.recentTurnIn[id]
end
addon.ImportQuestTurnInList = {}
function addon.ParseCompletedQuests(str)
str = str or addon.settings.profile.debugQuestImport or ""
addon.ImportQuestTurnInList = {}
if not addon.settings.profile.debug and str then return end
for quest in str:gmatch("%d+") do
local id = tonumber(quest)
addon.ImportQuestTurnInList[id] = true
end
end
local IsTurnedIn = C_QuestLog.IsQuestFlaggedCompleted or
_G.IsQuestFlaggedCompleted or
function(id) return _G.GetQuestsCompleted()[id] end
local IsQuestTurnedIn = function(id,accountWide)
if not id then return end
local recentTurnIn = GetRecentTurnIn(id)
local turnedIn
if accountWide and C_QuestLog.IsQuestFlaggedCompletedOnAccount then
turnedIn = C_QuestLog.IsQuestFlaggedCompletedOnAccount(id)
addon.comms.PrettyDebug("CompletedOnAccount(%d) = %s", id, tostring(turnedIn))
else
turnedIn = IsTurnedIn(id)
end
if addon.settings.profile.debug and next(addon.ImportQuestTurnInList)
and addon.ImportQuestTurnInList[id] then
--print('ok1',id)
return true
end
if turnedIn then
addon.recentTurnIn[id] = nil
return true
elseif recentTurnIn and GetTime() - recentTurnIn < 5 then
return true
end
--if recent then print(7,recent,id) end
end
--QT = IsQuestTurnedIn
function addon.IsQuestComplete(id)
if not id then return end
if C_QuestLog.IsComplete then
return C_QuestLog.IsComplete(id)
else
addon.ExpandQuestHeaders()
for i = 1, GetNumQuests() do
local _, _, _, _, _,
isComplete, _, questID = GetQuestLogTitle(i);
if questID == id then
return isComplete
end
end
end
end
local IsQuestComplete = addon.IsQuestComplete
local function IsOnQuest(id)
local quest = C_QuestLog.IsOnQuest(id)
local recent = addon.recentAccept[id]
if quest then
addon.recentAccept[id] = nil
elseif recent and GetTime()-recent < 2 then
return true
end
return quest
end
function addon.GetLogIndexForQuestID(questID)
if C_QuestLog.GetLogIndexForQuestID then
return C_QuestLog.GetLogIndexForQuestID(questID),C_QuestLog.IsPushableQuest(questID)
else
addon.ExpandQuestHeaders()
for i = 1, GetNumQuests() do
local _, _, _, _, _, _, _, id = GetQuestLogTitle(i);
if questID == id then
_G.SelectQuestLogEntry(i)
return i,_G.GetQuestLogPushable()
end
end
end
end
addon.IsOnQuest = IsOnQuest
addon.IsQuestTurnedIn = IsQuestTurnedIn
addon.IsQuestComplete = IsQuestComplete
local function GetQuestId(src,guide,checkMirror)
if type(guide) ~= "table" then
guide = addon.currentGuide or addon.guide
end
if not (src and guide) then
return src
end
function ConvertID(quest,guidetable)
guidetable = guidetable.questConversion
if guidetable and guidetable[quest] then
--print(1,src,guide[src])
return guidetable[quest]
elseif addon.questConversion[quest] then
--print(1,src,addon.questConversion[src])
return addon.questConversion[quest]
else
return quest
end
end
local id = ConvertID(src,guide)
local mirror = checkMirror and guide.mirrorID and guide.mirrorID[id]
if mirror then
for _,quest in pairs(mirror) do
if IsOnQuest(quest) then
return quest
end
end
end
return id
end
addon.GetQuestId = GetQuestId
local timer = GetTime()
local nrequests = 0
local requests = {}
addon.requestQuestInfo = requests
local db
if _G.QuestieLoader then db = _G.QuestieLoader:ImportModule("QuestieDB") end
addon.questieDB = db
function addon.FormatNumber(number, precision)
if type(number) ~= "number" then
return "-1"
end
precision = precision or 0
local integer = math.floor(number)
local decimal = math.floor((number - integer) * 10 ^ precision + 0.5)
if decimal > 0 then
decimal = '.' .. tostring(decimal)
else
decimal = ""
end
integer = tostring(integer)
local i = #integer % 3
if i == 0 then i = 3 end
local suffix = string.sub(integer, i + 1)
integer = string.sub(integer, 1, i)
for n in string.gmatch(suffix, "%d%d%d") do integer = integer .. "," .. n end
return integer .. decimal
end
function addon.Round(number, precision)
if not number then return end
precision = precision and 10 ^ precision or 1
local integer = math.floor(number)
return integer + math.floor((number - integer) * precision + 0.5)/precision
end
function addon.ClearQuestCache()
local questObjectivesCache = RXPCData.questObjectivesCache
if not addon.currentGuide or questObjectivesCache[0] < 100 then
return
end
local questNameCache = RXPCData.questNameCache
local guideQuests = {}
for i,step in pairs(addon.currentGuide.steps) do
for j,element in pairs(step.elements or {}) do
if element.tag == "complete" then
local id = element.questId
guideQuests[id] = bit.bor(guideQuests[id] or 0,0x1)
elseif element.tag == "accept" then
local id = element.questId
guideQuests[id] = bit.bor(guideQuests[id] or 0,0x2)
end
end
end
for id in pairs(questObjectivesCache) do
if not (guideQuests[id] and guideQuests[id] % 2 == 1 or id == 0) then
questObjectivesCache[id] = nil
questObjectivesCache[0] = questObjectivesCache[0] - 1
end
end
for id in pairs(questNameCache) do
if not (guideQuests[id] and guideQuests[id] > 1) then
questNameCache[id] = nil
end
end
return true
end
local function CacheQuest(id,data,remove)
local questObjectivesCache = RXPCData.questObjectivesCache
if not id or id == 0 then
return
elseif data and not (remove or questObjectivesCache[id]) then
data.finished = false
questObjectivesCache[0] = questObjectivesCache[0] + 1
questObjectivesCache[id] = data
elseif remove and questObjectivesCache[id] then
questObjectivesCache[0] = questObjectivesCache[0] - 1
questObjectivesCache[id] = nil
end
end
local REQUEST_TIMER = 1.5
local N_REQUESTS = 3
local function RequestQuestData(id)
local questObjectivesCache = RXPCData.questObjectivesCache
local ctime = GetTime()
if ctime - timer > REQUEST_TIMER then
timer = ctime
nrequests = 0
end
if nrequests < N_REQUESTS or requests[id] == 0 then
local isLoaded
--[[if C_QuestLog.RequestLoadQuestByID and not requests[id] then
C_QuestLog.RequestLoadQuestByID(id)
requests[id] = GetTime()
end]]
if (not requests[id] or ctime - requests[id] > 3) then
isLoaded = HaveQuestData(id)
end
if isLoaded then
requests[id] = 0
-- print(id,GetTime()-base)
local questInfo = C_QuestLog.GetQuestObjectives(id)
local incomplete
if (#questInfo == 1 and
(questInfo[1].type == "" or not questInfo[1].type)) or
#questInfo == 0 then
questInfo[1] = {
text = L("Objective Complete"),
type = "event",
numRequired = 1,
numFulfilled = 0,
finished = false,
generated = true,
}
else
for _,obj in pairs(questInfo) do
if obj.type == "progressbar" and not obj.finished then
obj.numFulfilled = 0
obj.numRequired = 100
end
if not obj.text or obj.text:sub(1,1) == " " then
incomplete = true
--print(id,_)
end
end
end
if incomplete then
CacheQuest(id,questInfo,true)
else
CacheQuest(id,questInfo)
end
return questInfo
elseif not requests[id] then
requests[id] = GetTime()
elseif ctime - requests[id] <= 3 then
return questObjectivesCache[id]
else
requests[id] = GetTime()
end
-- print(id,GetTime()-base)
nrequests = nrequests + 1
end
return questObjectivesCache[id]
end
function addon.GetQuestName(id)
local questNameCache = RXPCData.questNameCache
local keepData
local grp = addon.currentGuide.group
local QuestDB = addon.QuestDB[grp] or addon.QuestDBLegacy
if QuestDB and QuestDB[id] then
keepData = true
end
if type(id) ~= "number" then return end
id = GetQuestId(id)
local name
if db and type(db.QueryQuest) == "function" and type(db.GetQuest) ==
"function" then
local quest = db:GetQuest(id)
if quest and quest.name then return quest.name end
end
local function CacheQuestName(id,name)
if name then
if keepData then
RXPData.questNames[id] = name
else
questNameCache[id] = name
end
end
end
local function GetCachedName(id)
return RXPData.questNames[id] or RXPCData.questNameCache[id]
end
if IsOnQuest(id) then
if GetQuestLogTitle then
addon.ExpandQuestHeaders()
for i = 1, GetNumQuests() do
local questLogTitleText, _, _, _, _, _, _, questID =
GetQuestLogTitle(i);
if questID == id then
name = questLogTitleText
CacheQuestName(id,name)
return name
end
end
else
local name = C_QuestLog.GetTitleForQuestID(id)
CacheQuestName(id,name)
return name
end
else
local ctime = GetTime()
if ctime - timer > REQUEST_TIMER then
timer = ctime
nrequests = 0
end
if nrequests < N_REQUESTS or requests[id] == 0 then
local isLoaded
--[[if C_QuestLog.RequestLoadQuestByID and not requests[id] then
C_QuestLog.RequestLoadQuestByID(id)
requests[id] = GetTime()
end]]
if (not requests[id] or ctime - requests[id] > 3) then
isLoaded = HaveQuestData(id)
end
if isLoaded then
requests[id] = 0
if C_QuestLog.GetQuestInfo then
name = C_QuestLog.GetQuestInfo(id)
CacheQuestName(id,name)
return GetCachedName(id)
else
name = C_QuestLog.GetTitleForQuestID(id)
CacheQuestName(id,name)
return GetCachedName(id)
end
elseif not requests[id] then
requests[id] = GetTime()
elseif ctime - requests[id] <= 3 then
return GetCachedName(id)
else
requests[id] = GetTime()
end
nrequests = nrequests + 1
end
return GetCachedName(id)
end
end
function addon.GetQuestObjectives(id, step, useCache)
id = GetQuestId(id,nil,true)
if not id then return end
local stepdiff = step and math.abs(RXPCData.currentStep - step) or 0
local questObjectivesCache = RXPCData.questObjectivesCache
local err = false
if IsOnQuest(id) then
local questInfo = {}
local questFound
addon.ExpandQuestHeaders()
for i = 1, GetNumQuests() do
local isComplete, questID
if GetQuestLogTitle then
_, _, _, _, _, isComplete, _, questID = GetQuestLogTitle(i);
else
local qInfo = C_QuestLog.GetInfo(i) or {}
questID = qInfo.questID
if questID then
isComplete = C_QuestLog.IsComplete(questID)
end
end
local nObj = 0
if questID == id then
questFound = true
for j = 1, GetNumQuestLeaderBoards(i) do
local description, objectiveType, isCompleted =
GetQuestLogLeaderBoard(j, i)
if description then
nObj = nObj + 1
local fulfilled, required
if objectiveType == "progressbar" then
fulfilled = GetQuestProgressBarPercent(id) or 0
required = 100
else
fulfilled, required = description:match(
"(%d+)/(%d+)")
if fulfilled then
required = tonumber(required)
fulfilled = tonumber(fulfilled)
else
required = 1
if isCompleted then
fulfilled = 1
else
fulfilled = 0
end
end
end
questInfo[j] = {
text = description,
type = objectiveType,
numRequired = required,
numFulfilled = fulfilled,
finished = isCompleted
}
else
err = true
break
end
end
if (err or nObj == 0) and GetNumQuestLeaderBoards(i) <= 1 then
local fulfilled = 0
if isComplete then fulfilled = 1 end
questInfo[1] = {
text = L("Objective Complete"),
type = "event",
numRequired = 1,
numFulfilled = fulfilled,
finished = isComplete,
generated = true,
}
CacheQuest(id,questInfo)
return questInfo
else
CacheQuest(id,questInfo)
return questInfo
end
end
end
if not questFound then
addon.ExpandQuestHeaders()
end
elseif (stepdiff > 4 or useCache) and questObjectivesCache[id] then
return questObjectivesCache[id]
elseif db and type(db.QueryQuest) == "function" and
(stepdiff > 4 or useCache) and type(db.GetQuest) == "function" then
local qInfo = {}
local q = db:GetQuest(id)
-- print(type(q))
local objectives
if q and q.ObjectiveData then
objectives = q.ObjectiveData
else
err = true
end
local nObj
if objectives then
nObj = 0
for i, quest in pairs(objectives) do
nObj = nObj + 1
local qType = quest.Type
local objId = quest.Id
qInfo[i] = {type = qType, finished = false, questie = true}
if qType == "monster" then
local npc = db:GetNPC(objId)
if npc and npc.name then
qInfo[i].text = npc.name
else
qInfo[i].text = ""
end
elseif qType == "item" then
qInfo[i].text = db:GetItem(objId).name
elseif quest.Text then
qInfo[i].text = quest.Text
else
err = true
break
end
end
end
if not err then
if nObj == 0 then
qInfo[1] = {
text = L("Objective Complete"),
type = "event",
numRequired = 1,
numFulfilled = 0,
finished = false,
generated = true,
}
end
return qInfo
end
end
if (not IsOnQuest(id) or err) and not useCache then
return RequestQuestData(id)
end
end
local NPCNames = {}
function addon.GetNpcName(id)
local npc = NPCNames[id]
if type(id) ~= "number" then
return
elseif type(npc) == "string" then
return npc
elseif not npc or GetTime()-npc > 1.5 then
GameTooltip:SetOwner(WorldFrame, "ANCHOR_BOTTOMRIGHT")
GameTooltip:ClearLines()
GameTooltip:SetHyperlink(string.format("unit:Creature-0-0-0-0-%d",id))
local name
if GameTooltip:IsShown() then
name = GameTooltipTextLeft1:GetText()
--DevTools_Dump(name)
name = name:match("^|c%x%x%x%x%x%x%x%x(.*)|") or name
NPCNames[id] = name
end
GameTooltip:Hide()
if name then
return name
else
NPCNames[id] = GetTime()
return
end
else
return
end
end
function addon.ReplaceNpcIds(textLine,element)
textLine = textLine:gsub("npc:(.-):(%d+)",function(name,id)
if not element or element.step.active then
return addon.GetNpcName(tonumber(id)) or name
else
return id
end
end)
if element and not element.step.active then
return textLine:gsub("::%d+","")
end
for name,npcId in string.gmatch(textLine, "|c%x%x%x%x%x%x%x%x([^|:]+)::(%d+)|r") do
--local newName
--if addon.player.lang ~= "en" then
local newName = addon.GetNpcName(tonumber(npcId))
--end
newName = newName or name
textLine = textLine:gsub(name.."::%d+",newName)
end
return textLine
end
function addon.GetItemName(id)
id = id or false
id = tonumber(id)
if not id then return end
local name = GetItemInfo(id)
if not name then addon.itemQueryList[id] = true end
return name
end
function addon.SetElementComplete(self, disable, skipIfInactive)
local element
if not self.element and self.tag then
element = self
else
element = self.element
end
if not element then return end
local active = element.step.active
if skipIfInactive and not active then
return
end
if element.timer and active and not element.completed and not element.textOnly and not element.tag == "countdown" then
addon.StartTimer(element.timer,element.timerText)
end
element.completed = true
element.skip = true
addon.updateSteps = true
addon.UpdateMap()
if active and GetTime() - addon.lastStepUpdate > 1 then
addon:QueueMessage("RXP_OBJECTIVE_COMPLETE",element,addon.currentGuide)
end
if element.OnComplete and active then
--print('onc',element.step.index)
element.OnComplete(element)
end
if self.button then
-- print('----ok',disable)
self.button:SetChecked(true)
if disable then self.button:Disable() end
end
end
function addon.SetElementIncomplete(self)
if self.element.completed and not self.element.textOnly then
self.element.completed = false
addon.UpdateMap()
end
if self.button then
self.button:Enable()
if not self.element.skip then self.button:SetChecked(false) end
end
end
addon.functions.noop = function() end
addon.labels = {}
addon.functions.label = function(self,text,label)
if type(self) == "string" and label then
addon.labels["*"..label] = addon.step
end
end
function addon.UpdateStepText(self)
local index
if not self.step then
return
elseif self.step.tip then
addon.updateTipWindow = true
addon.updateStepText = true
return
elseif not self.step.index then
return
elseif type(self) == "number" then
index = self
else
index = self.step.index
end
addon.updateStepText = true
if index then
addon.stepUpdateList[index] = true
else
addon.updateTipWindow = true
end
end
function addon.GetNpcId(unit, isGuid)
if not unit then
if isGuid then
return
else
unit = "target"
end
end
local guid
if isGuid then