-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathAutoTurnIn.lua
More file actions
1440 lines (1324 loc) · 46.6 KB
/
Copy pathAutoTurnIn.lua
File metadata and controls
1440 lines (1324 loc) · 46.6 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
--[[
Feel free to use this source code for any purpose ( except developing nuclear weapon! :)
Please keep original author statement.
@author Alex Shubert (alex.shubert@gmail.com)
]]--
local addonName, ptable = ...
local L, C = ptable.L, ptable.CONST
local Q_DAILY, Q_EXCEPTDAILY = 2, 3
local questNPCName = nil
AutoTurnIn = LibStub("AceAddon-3.0"):NewAddon("AutoTurnIn", "AceEvent-3.0", "AceConsole-3.0")
-- TODO: REFACTOR INTO A SINGLE 'OPTION' OBJECT
AutoTurnIn.ldb, AutoTurnIn.allowed = nil, nil
AutoTurnIn.funcList = {[1] = function() return false end, [2]=IsAltKeyDown, [3]=IsControlKeyDown, [4]=IsShiftKeyDown}
AutoTurnIn.autoEquipList={}
AutoTurnIn.questCache={} -- daily quest cache. Initially is built from player's quest log
AutoTurnIn.knownGossips={}
AutoTurnIn.ERRORVALUE = nil
AutoTurnIn.IgnoreButton = {["quest"] = nil, ["gossip"] = nil}
AutoTurnIn.defer = {
questLog = false,
watch = false,
ignore = {["quest"] = false, ["gossip"] = false},
merchant = {sell = false, repair = false},
cinematic = false,
movieId = nil,
acceptQuest = false,
completeQuest = false,
getQuestRewardIndex = nil,
}
--[[
INIT: INITIALIZE
--]]
local db
local defaults = CopyTable(ptable.defaults)
local function makeWeaponToggle(index, _order)
return {
type = "toggle",
name = C.weapon[index],
arg = ("weapon;".. C.weapon[index]),
order = _order,
}
end
local function createToggle(_name, _arg, _order)
return {
type = "toggle",
name = _name,
arg = _arg,
order = _order,
}
end
local options = {
type = "group",
name = "AutoTurnIn",
desc = C_AddOns.GetAddOnMetadata(addonName, "Notes-" .. GetLocale()) or C_AddOns.GetAddOnMetadata(addonName, "Notes"),
args = {
enabled = {
type = "toggle",
name = L["enabled"].." (version "..C_AddOns.GetAddOnMetadata(addonName, "Version") .. ")",
desc = L["usage1"],
order = 1,
width = 1.5,
get = function(_) return db.enabled end,
set = function(_, v)
db.enabled = v
AutoTurnIn:SetEnabled(v)
end,
disabled = false,
},
debug = {
type = "toggle",
name = L["debug"],
arg = "debug",
width = "double",
order = 2,
hidden = function() return not db.admin end,
get = function(_) return db.debug end,
set = function(_, v) db.debug = v end,
},
overall_settings = {
type = "group",
name = L["global settings"],
order = 10,
disabled = function() return not db.enabled end,
get = function(info) return db[info.arg] end,
set = function(info, v) db[info.arg] = v end,
args = {
q_title = {
type = "header",
name = "General Settings",
order = 1
},
QuestDropDown = {
type = "select",
style = "dropdown",
name = L["questTypeLabel"],
values = {[1] = L["questTypeAll"], [2]=L["questTypeList"],[3]=L["questTypeExceptDaily"]},
arg = "all",
width = "double",
order = 10,
},
trivial = {
type = "toggle",
name = L["TrivialQuests"],
arg = "trivial",
width = "double",
order = 20,
},
completeonly = {
type = "toggle",
name = L["CompleteOnly"],
arg = "completeonly",
width = "double",
order = 30,
},
ToggleKeyDropDown = {
type = "select",
style = "dropdown",
name = L["togglekey"],
values = {[1]=NONE_KEY, [2]=ALT_KEY, [3]=CTRL_KEY, [4]=SHIFT_KEY},
arg = "togglekey",
width = "double",
order = 40,
},
reward_title = {
type = "header",
name = "Rewards",
order = 45
},
LootDropDown = {
type = "select",
style = "dropdown",
name = L["lootTypeLabel"],
values = {[1]=L["lootTypeFalse"], [2]=L["lootTypeGreed"], [3]=L["lootTypeNeed"]},
arg = "lootreward",
width = "double",
order = 50,
},
rewardtext = {
type = "toggle",
name = L["rewardtext"],
arg = "showrewardtext",
width = "full",
order = 60,
},
autoequip = {
type = "toggle",
name = L["autoequip"],
arg = "autoequip",
order = 70,
},
TournamentDropDown = {
type = "select",
style = "dropdown",
name = L["tournamentLabel"],
values = {[1]=L["tournamentWrit"], [2]=L["tournamentPurse"]},
arg = "tournament",
width = "double",
order = 80,
},
gossip_opts = {
type = "group",
name = "Gossips",
desc = "Gossip options",
order = 100,
args = {
darkmoon_title = {
type = "header",
name = "Darkmoon",
order = 1
},
todarkmoon = {
type = "toggle",
name = L["ToDarkmoonLabel"],
arg = "todarkmoon",
width = "full",
order = 140,
},
darkmoonteleport = {
type = "toggle",
name = L["DarkmoonTeleLabel"],
arg = "darkmoonteleport",
width = "full",
order = 150,
},
darkmoonautostart = {
type = "toggle",
name = L["DarkmoonAutoLabel"],
arg = "darkmoonautostart",
width = "full",
order = 160,
},
batllepets_title = {
type = "header",
name = "Battle pets",
order = 165
},
reviveBattlePet = {
type = "toggle",
name = L["ReviveBattlePetLabel"],
arg = "reviveBattlePet",
width = "full",
order = 170,
},
shadowlands_title = {
type = "header",
name = "Shadowlands",
order = 175
},
dismisskyriansteward = {
type = "toggle",
name = L["DismissKyrianStewardLabel"],
arg = "dismisskyriansteward",
width = "full",
order = 180,
},
covenantswapgossipcompletion = {
type = "toggle",
name = L["CovenantSwapGossipCompletion"],
arg = "covenantswapgossipcompletion",
width = "full",
order = 190,
},
}
},
ui_opts = {
type = "group",
name = "UI addons",
desc = "UI tweaks",
order = 120,
args = {
questlevel = {
type = "toggle",
name = L["questlevel"],
arg = "questlevel",
width = "full",
order = 10,
},
watchlevel = {
type = "toggle",
name = L["watchlevel"],
arg = "watchlevel",
width = "full",
order = 20,
confirm = function() return "This thing taints the UI. Use on your own risk" end,
},
questshare = {
type = "toggle",
name = L["ShareQuestsLabel"],
arg = "questshare",
width = "full",
order = 30,
},
sell_junk = {
type = "select",
name = "Sell junk functionality",
values = {[1]=L["Don't do anything"], [2]=L["Autosell junk"], [3]=L["Add sell button"]},
width = "full",
get = function(info) return db[info.arg] end,
set = function(info, v) AutoTurnIn:SwitchSellJunk(v); db[info.arg] = v end,
arg = "sell_junk",
order = 40,
},
auto_repair = {
type = "toggle",
name = "Auto repair",
width = "full",
arg = "auto_repair",
order = 50,
},
skip_cinematics = {
type = "select",
name = "Skip cinematics",
values = {[1]=L["Do not skip"], [2]=L["Skip in instances only"], [3]=L["Skip everywhere"]},
width = "full",
arg = "skip_cinematics",
order = 60,
},
skip_movies = {
type = "select",
name = "Skip movies",
values = {[1]=L["Do not skip"], [2]=L["Skip in instances only"], [3]=L["Skip everywhere"]},
width = "full",
arg = "skip_movies",
order = 60,
},
map_coords = {
type = "toggle",
name = "Display player coordinates on world map",
arg = "map_coords",
width = "full",
get = function(info) return db[info.arg] end,
set = function(info, v) AutoTurnIn:SwitchMapCoords(v); db[info.arg] = v end,
order = 70,
},
minimap_coords = {
type = "toggle",
name = "Display player coordinates under minimap",
arg = "minimap_coords",
width = "full",
get = function(info) return db[info.arg] end,
set = function(info, v) AutoTurnIn:SwitchMiniMapCoords(v); db[info.arg] = v end,
order = 80,
},
-- unsafe_item_wipe = {
-- type = "toggle",
-- name = "Wipe item in the bag by ALT + Click",
-- arg = "unsafe_item_wipe",
-- confirm = function() return "Wiping ANY item in your bag if clicked with ALT key pressed" end,
-- width = "full",
-- order = 200,
-- },
}
},
relic_opts = {
type = "group",
name = "Relic/Artifact",
order = 130,
args = {
relictoggle = {
type = "toggle",
name = L["relictoggle"],
arg = "relictoggle",
width = "full",
order = 130,
},
artifactpowertoggle = {
type = "toggle",
name = L["artifactpowertoggle"],
arg = "artifactpowertoggle",
width = "full",
order = 140,
}
}
},
rewards = {
type = "group",
name = "Rewards",
desc = L["rewardlootoptions"],
order = 2000,
hidden = function() return db.lootreward~=3 end,
get = function(info) local t,st = strsplit(";", info.arg) local v = db[t][st] return v == nil and false or v end,
set = function(info, v) local t,st = strsplit(";", info.arg) db[t][st] = (v or nil) end,
args = {
greedifnothing = {
type = "toggle",
name = L["greedifnothing"],
get = function(info) return db.greedifnothingfound end,
set = function(info,val) db.greedifnothingfound = val end,
order = 10,
},
weapon_title = {
type = "header",
name = C.WEAPONLABEL,
order = 20
},
wp1 = makeWeaponToggle(0, 30),
wp2 = makeWeaponToggle(1, 31),
wp3 = makeWeaponToggle(4, 32),
wp4 = makeWeaponToggle(5, 33),
wp7 = makeWeaponToggle(7, 34),
wp6 = makeWeaponToggle(8, 35),
wp5 = makeWeaponToggle(6, 36),
wp8 = makeWeaponToggle(9, 37),
wp10 = makeWeaponToggle(10, 39),
wp11 = makeWeaponToggle(15, 40),
-- TODO INVTYPE_RANGED
wp13 = createToggle(string.format("%s, %s, %s", C.weapon[2], C.weapon[3], C.weapon[18]), "weapon;Ranged", 42),
armor_title = {
type = "header",
name = C.ARMORLABEL,
order = 50
},
armor_reward = {
type = "select",
style = "dropdown",
name = "",
values = {[-1] = NONE_KEY, [1]=C.armor[1], [2]=C.armor[2], [3]=C.armor[3], [4]=C.armor[4]},
get = function() return db["armorType"] end,
set = function(_, v) db["armorType"] = v end,
width = "double",
order = 60,
},
armor7 = createToggle(C.armor[6], "armor;SHIELD", 61),
armor8 = createToggle(L['Jewelry'], "armor;Jewelry", 62),
armor9 = createToggle(INVTYPE_HOLDABLE, "armor;HOLDABLE", 63),
armor10 = createToggle(INVTYPE_CLOAK, "armor;CLOAK", 64),
-- STATS
stat_title = {
type = "header",
name = STAT_CATEGORY_ATTRIBUTES,
order = 70
},
stat1 = createToggle(SPELL_STAT1_NAME, "stat;ITEM_MOD_STRENGTH_SHORT", 71),
stat2 = createToggle(SPELL_STAT2_NAME, "stat;ITEM_MOD_AGILITY_SHORT", 72),
stat3 = createToggle(SPELL_STAT4_NAME, "stat;ITEM_MOD_INTELLECT_SHORT", 73),
sec_stat_title = {
type = "header",
name = STAT_CATEGORY_ENHANCEMENTS,
order = 80
},
secstat1 = createToggle(ITEM_MOD_CRIT_RATING_SHORT, "secondary;ITEM_MOD_CRIT_RATING_SHORT", 81),
secstat2 = createToggle(ITEM_MOD_CR_LIFESTEAL_SHORT, "secondary;ITEM_MOD_CR_LIFESTEAL_SHORT", 82),
secstat3 = createToggle(ITEM_MOD_HASTE_RATING_SHORT, "secondary;ITEM_MOD_HASTE_RATING_SHORT", 83),
secstat4 = createToggle(ITEM_MOD_CR_MULTISTRIKE_SHORT, "secondary;ITEM_MOD_CR_MULTISTRIKE_SHORT", 84),
secstat5 = createToggle(ITEM_MOD_MASTERY_RATING_SHORT, "secondary;ITEM_MOD_MASTERY_RATING_SHORT", 85),
secstat6 = createToggle(ITEM_MOD_VERSATILITY, "secondary;ITEM_MOD_VERSATILITY", 86),
secstat7 = createToggle(ITEM_MOD_SPELL_POWER_SHORT, "secondary;ITEM_MOD_SPELL_POWER_SHORT", 85),
-- secstat8 = createToggle(ITEM_MOD_SPIRIT_SHORT, "secondary;ITEM_MOD_SPIRIT_SHORT", 86),
},
},
}
},
},
}
-- Option DB https://www.wowace.com/projects/ace3/pages/ace-db-3-0-tutorial
-- Option GUI https://www.wowace.com/projects/ace3/pages/ace-config-3-0-options-tables
function AutoTurnIn:OnInitialize()
-- set up options db
self.db = LibStub("AceDB-3.0"):New("AutoTurnInDB", defaults)
self.db.RegisterCallback(self, "OnProfileChanged", "OnProfileChanged")
self.db.RegisterCallback(self, "OnProfileCopied", "OnProfileChanged")
self.db.RegisterCallback(self, "OnProfileReset", "OnProfileChanged")
db = self.db.profile
LibStub("AceConfigRegistry-3.0"):RegisterOptionsTable("AutoTurnIn", options)
_, self.optionCategory = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("AutoTurnIn", "AutoTurnIn")
options.args.profiles = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db)
self:RegisterChatCommand("au", "ShowOptions")
self:LibDataStructure()
self:CinematickHooks()
-- See no way tp fix taint issues with quest special items.
-- TODO : THE WAR WITHIN HAS BROKEN BOTH THINGS
-- hooksecurefunc("ObjectiveTracker_Update", AutoTurnIn.ShowQuestLevelInWatchFrame)
-- hooksecurefunc("QuestLogQuests_Update", AutoTurnIn.ShowQuestLevelInLog)
end
function AutoTurnIn:OnProfileChanged(event, database, newProfileKey)
db = database.profile
end
-- reuse :Enable() / :Disable() ? https://www.wowace.com/projects/ace3/pages/api/ace-addon-3-0
function AutoTurnIn:SetEnabled(enabled)
db.enabled = not not enabled
if self.ldb then
self.ldb.text = (db.enabled) and '|cff00ff00on|r' or '|cffff0000off|r'
end
if (db.enabled) then
self:SwitchMapCoords(db.enabled and db.map_coords)
self:SwitchMiniMapCoords(db.enabled and db.minimap_coords)
self:SwitchSellJunk(db.enabled and db.sell_junk)
self:RegisterForEvents()
else
self:UnregisterAllEvents()
end
end
--[[
INIT: ENABLE quest autocomplete handlers and functions
--]]
function AutoTurnIn:OnEnable()
self:SetEnabled(db.enabled)
end
-- actually never called, but still
function AutoTurnIn:OnDisable()
db.enabled = false
self:SetEnabled(db.enabled)
end
--[[
INIT: Register for events
--]]
function AutoTurnIn:RegisterForEvents()
self:RegisterEvent("QUEST_GREETING")
self:RegisterEvent("GOSSIP_SHOW")
self:RegisterEvent("QUEST_DETAIL")
self:RegisterEvent("QUEST_PROGRESS")
self:RegisterEvent("QUEST_COMPLETE")
self:RegisterEvent("QUEST_LOG_UPDATE")
self:RegisterEvent("QUEST_ACCEPTED")
if db.reviveBattlePet --[[ and select(2, UnitClass("player")) == "HUNTER" ]] then
self:RegisterEvent("GOSSIP_CONFIRM")
end
self:RegisterGossipOptionClicker()
end
function AutoTurnIn:RegisterGossipOptionClicker()
local function __getGossipId(index)
-- SOmetimes quest comletition removes the options. SelectOption does not throws exception on unavailable index
return #C_GossipInfo.GetOptions() > 0 and C_GossipInfo.GetOptions()[index].gossipOptionID or -1
end
local gossipFunc1 = function()
C_GossipInfo.SelectOption( __getGossipId(1) )
end
local gossipFunc2 = function()
if (C_GossipInfo.GetNumOptions and C_GossipInfo.GetNumOptions() == 2) then C_GossipInfo.SelectOption(__getGossipId(1)) end
end
local gossipFunc3 = function()
if (db.todarkmoon and GetRealZoneText() ~= L["Darkmoon Island"] and C_GossipInfo.GetNumAvailableQuests() == 0) then
--accept available quest first, then teleport
AutoTurnIn:Print("Teleporting to " .. L["Darkmoon Island"])
C_GossipInfo.SelectOption(__getGossipId(1))
StaticPopup1Button1:Click()
end
end
local gossipFunc4 = function()
if db.darkmoonteleport then
AutoTurnIn:Print("Teleporting to cannon")
C_GossipInfo.SelectOption(__getGossipId(1))
StaticPopup1Button1:Click()
end
end
local gossipFunc5 = function()
if db.dismisskyriansteward then
AutoTurnIn:Print(L["ivechosenfive"])
C_GossipInfo.SelectOption(__getGossipId(5))
end
end
local gossipFunc6 = function()
if db.covenantswapgossipcompletion then
C_GossipInfo.SelectOption(__getGossipId(1))
C_GossipInfo.SelectOption(__getGossipId(1))
StaticPopup1Button1:Click()
end
end
AutoTurnIn.knownGossips = {
["171787"]=gossipFunc6, -- Polemarch Adrestes (Kyrian)
["171795"]=gossipFunc6, -- Lady Moonberry (Night Fae)
["171589"]=gossipFunc6, -- General Draven (Venthyr)
["171821"]=gossipFunc6, -- Secutor Mevix (Necrolord)
["93188"]=gossipFunc1, -- Mongar
["96782"]=gossipFunc1, -- Lucian Trias
["97004"]=gossipFunc1, -- "Red" Jack Findle
["55267"]=gossipFunc1, -- YoungPandaren
["79815"]=gossipFunc2, -- Grunlek, free seals Alliance
["77377"]=gossipFunc2, -- Kristen Stoneforge, free seals Horde
["54334"]=gossipFunc3, -- travel to Darkmoon
["55382"]=gossipFunc3, -- travel to Darkmoon
["57850"]=gossipFunc4, -- DarkmoonFaireTeleportologist
["166663"]=gossipFunc5, -- Kyrian Steward
["20142"]=gossipFunc1, -- Caverns of Time:Steward of Time
["42391"]=gossipFunc1, -- West Plains Drifter [Lieutenant Horatio Laine]
["42384"]=gossipFunc1, -- Homeless Stormwind [Lieutenant Horatio Laine]
["42383"]=gossipFunc1, -- Transient [Lieutenant Horatio Laine]
}
end
function AutoTurnIn:QUEST_LOG_UPDATE()
if ( C_QuestLog.GetNumQuestLogEntries() > 0 ) then
for index=1, C_QuestLog.GetNumQuestLogEntries() do
local questInfo = C_QuestLog.GetInfo(index)
if (questInfo and not questInfo.isHeader and self:_isDaily(questInfo)) then
self.questCache[questInfo.title] = true
end
end
self:UnregisterEvent("QUEST_LOG_UPDATE")
end
end
function AutoTurnIn:_isDaily(questInfo)
return questInfo and
(questInfo.frequency == Enum.QuestFrequency.Daily or
questInfo.frequency == Enum.QuestFrequency.Weekly or
questInfo.repeatable)
end
-- Available check requires cache
-- Active check query API function Returns true if quest matches options
function AutoTurnIn:isAppropriateQuest(questname, byCache)
local daily
if byCache then
daily = (not not self.questCache[questname])
else
-- for some reason questInfo in gossip table return data different from one from QuestCache
local questID = GetQuestID()
local qn = questname or (questID and QuestCache:Get(questID).title or "");
daily = QuestIsDaily() or QuestIsWeekly() or (not not self.questCache[qn])
end
return self:_isAppropriate(daily)
end
-- 'private' function
function AutoTurnIn:_isAppropriate(daily)
if daily then
return (db.all ~= Q_EXCEPTDAILY)
else
return (db.all ~= Q_DAILY)
end
end
-- caches offered by gossip quest as daily
function AutoTurnIn:CacheAsDaily(questname)
self.questCache[questname] = true
end
function AutoTurnIn:IsIgnoredQuest(quest, questId)
local function startsWith(str,template)
return (string.len(str) >= string.len(template)) and (string.sub(str,1,string.len(template))==template)
end
if db.IGNORED_QUEST[questId] then return true end
for q in pairs(L.ignoreList) do
if (startsWith(quest, q)) then
return true
end
end
return false
end
-- returns specified item count on player character. It may be some sort of currency or present in inventory as real items.
function AutoTurnIn:GetItemAmount(isCurrency, item)
local amount = isCurrency and C_CurrencyInfo.GetCurrencyInfo(item).quantity or GetItemCount(item, nil, true)
return amount and amount or 0
end
-- returns set 'self.allowed' to true if addon is allowed to handle current gossip conversation
-- Cases when it may not : (addon is enabled and toggle key was pressed) or (addon is disabled and toggle key is not pressed)
-- 'forcecheck' does what it name says: forces check
function AutoTurnIn:AllowedToHandle(forcecheck)
-- workaround for https://zygorguides.com/forum/forum/technical-support/zygor-guide-viewer/190851-new-lua-error-addon_action-blocked
-- Currently, blizzard UI fails to properly check in-combat. This is to enforce the checks (hopefully)
-- TODO: it is not clear why would I need global "self.allowed"
if ( InCombatLockdown() ) then
return false
end
if ( self.allowed == nil or forcecheck ) then
-- Double 'not' converts possible 'nil' to boolean representation
local IsModifiedClick = not not self.funcList[db.togglekey]()
-- it's a simple xor implementation (a ~= b)
self.allowed = (not not db.enabled) ~= (IsModifiedClick)
end
return self.allowed and (not AutoTurnIn:IsIgnoredNPC())
end
-- Old 'Quest NPC' interaction system. See http://wowprogramming.com/docs/events/QUEST_GREETING
function AutoTurnIn:QUEST_GREETING()
if (not self:AllowedToHandle(true)) then
return
end
for index=1, GetNumActiveQuests() do
local quest, isComplete = GetActiveTitle(index)
if isComplete and (self:isAppropriateQuest(quest, true)) then
SelectActiveQuest(index)
end
end
if not db.completeonly then
for index=1, GetNumAvailableQuests() do
local isTrivial, isDaily, isRepeatable, isIgnored = GetAvailableQuestInfo(index)
if (isIgnored) then return end -- Legion functionality
local triviaAndAllowedOrNotTrivia = (not isTrivial) or db.trivial
local title = GetAvailableTitle(index)
local quest = L.quests[title]
local notBlackListed = not (quest and (quest.donotaccept or AutoTurnIn:IsIgnoredQuest(title, nil)))
-- isDaily was a boolean, but is a number now. but maybe it's still a boolean somewhere
if (type(isDaily) == "number" and isDaily ~= 0) then isDaily = true else isDaily = false end
if isDaily then
self:CacheAsDaily(GetAvailableTitle(index))
end
if (triviaAndAllowedOrNotTrivia and notBlackListed and self:_isAppropriate(isDaily)) then
if quest and quest.amount then
if self:GetItemAmount(quest.currency, quest.item) >= quest.amount then
SelectAvailableQuest(index)
end
else
SelectAvailableQuest(index)
end
end
end
end
end
function AutoTurnIn:VarArgForActiveQuests(gossipInfos)
for _, questInfo in ipairs(gossipInfos) do
if (questInfo.isComplete) then
local questname = questInfo.title
if self:isAppropriateQuest(questname, true) then
local quest = L.quests[questname]
if quest and quest.amount then
if self:GetItemAmount(quest.currency, quest.item) >= quest.amount then
C_GossipInfo.SelectActiveQuest(questInfo.questID)
self.DarkmoonAllowToProceed = false
end
else
C_GossipInfo.SelectActiveQuest(questInfo.questID)
self.DarkmoonAllowToProceed = false
end
end
end
end
end
function AutoTurnIn:VarArgForAvailableQuests(gossipInfos)
for i,questInfo in ipairs(gossipInfos) do
local triviaAndAllowedOrNotTrivial = (not questInfo.isTrivial) or db.trivial
local quest = L.quests[questInfo.title] -- this quest exists in addons quest DB. There are mostly daily quests
local notBlackListed = not (quest and (quest.donotaccept or AutoTurnIn:IsIgnoredQuest(questInfo.title, questInfo.questID)))
local isDaily = self:_isDaily(questInfo)
-- for unknown reason the questInfo is different from what is seen in QuestCache:Get(questID);
if isDaily then
self:CacheAsDaily(questInfo.title)
end
-- Quest is appropriate if: (it is trivial and trivial are accepted) and (any quest accepted or (it is daily quest that is not in ignore list))
if (triviaAndAllowedOrNotTrivial and notBlackListed and self:_isAppropriate(isDaily)) then
if quest and quest.amount then
if self:GetItemAmount(quest.currency, quest.item) >= quest.amount then
C_GossipInfo.SelectAvailableQuest(questInfo.questID)
end
else
C_GossipInfo.SelectAvailableQuest(questInfo.questID)
end
end
end
end
-- Extracts GUID from the NPC which dialog window is currenty displayed
function AutoTurnIn:GetNPCGUID()
local a = UnitGUID("npc")
if not a then return nil end
-- Use pcall to safely handle tainted/secret strings from protected NPCs
local success, _, _, _, _, _, guid = pcall(string.find, a, "Creature%-(%d+)%-(%d+)%-(%d+)%-(%d+)%-(%d+)%-")
if success and guid then
return guid
end
return nil
end
function AutoTurnIn:isDarkmoonAndAllowed(questCount)
return (self.DarkmoonAllowToProceed and questCount) and
db.darkmoonautostart and
(GetZoneText() == L["Darkmoon Island"])
end
function AutoTurnIn:GOSSIP_CONFIRM(event, _, message, cost)
if message == L["ReviveBattlePetA"] and cost == 1000 then
local dialog = StaticPopup_FindVisible("GOSSIP_CONFIRM")
if dialog then
StaticPopup_OnClick(dialog, 1)
end
end
end
function AutoTurnIn:GOSSIP_SHOW()
self:DebugPrint("GOSSIP_SHOW")
if (not self:AllowedToHandle(true)) then
return
end
-- darkmoon fairy gossip sometime turns in quest too fast so I can't relay only on quest number count. It often lie.
-- this flag is set in VarArgForActiveQuests if any quest may be turned in
self.DarkmoonAllowToProceed = true
local questCount = C_GossipInfo.GetNumActiveQuests() > 0
self:VarArgForActiveQuests(C_GossipInfo.GetActiveQuests())
if not db.completeonly then
self:VarArgForAvailableQuests(C_GossipInfo.GetAvailableQuests())
end
if self:isDarkmoonAndAllowed(questCount) then
local options = C_GossipInfo.GetOptions()
for _, gossipInfo in ipairs(options) do
if ((gossipInfo.type == "gossip") and strfind(gossipInfo.name, "|cFF0008E8%(")) then
return C_GossipInfo.SelectOption(gossipInfo.gossipOptionID)
end
end
end
self:HandleGossip()
end
local trivialNoText = {}
function AutoTurnIn:QUEST_DETAIL()
if (QuestIsDaily() or QuestIsWeekly()) then
self:CacheAsDaily(GetTitleText())
end
if QuestGetAutoAccept() then
CloseQuest()
else
if self:AllowedToHandle() and self:isAppropriateQuest() and (not db.completeonly) then
--ignore trivial quests
if (not C_QuestLog.IsQuestTrivial(GetQuestID()) or db.trivial) then
QuestInfoDescriptionText:SetAlphaGradient(0, 5000)
QuestInfoDescriptionText:SetAlpha(1)
AcceptQuest()
return
end
end
--quest level on detail frame
if db.questlevel then
local qid = GetQuestID()
local level = C_QuestLog.GetQuestDifficultyLevel(qid)
--sometimes it returns 0, but that's wrong
if level and level > 0 then
local text = QuestInfoTitleHeader:GetText()
if text then -- there are reports (unconfirmed) that some trivial quests return nil for text
local levelFormat = "[%d] %s"
--trivial display
if C_QuestLog.IsQuestTrivial(qid) then text = TRIVIAL_QUEST_DISPLAY:format(text) end
QuestInfoTitleHeader:SetText(levelFormat:format(level, text))
else
if (not not trivialNoText[qid]) then
trivialNoText[qid] = true
self:Print("[AutoTurnIn] Quest has nil title [" .. qid .. "]. Could you please report it to AutoTurnIn author?")
end
end
end
end
end
end
-- TODO: needs testing with another player
function AutoTurnIn:QUEST_ACCEPTED(event, index)
if db.questshare and C_QuestLog.IsPushableQuest(index) and GetNumGroupMembers() >= 1 then
C_QuestLog.SetSelectedQuest(index);
QuestLogPushQuest();
end
end
function AutoTurnIn:QUEST_PROGRESS()
if (self:AllowedToHandle() and IsQuestCompletable() and (self:isAppropriateQuest() or self:IsWantedQuest(GetQuestID()))) then
CompleteQuest()
end
end
function AutoTurnIn:HandleGossip()
local guid = AutoTurnIn:GetNPCGUID()
local func = AutoTurnIn.knownGossips[guid]
if func then
func()
else
-- https://www.wowinterface.com/forums/showthread.php?t=49210 adaptation
if db.reviveBattlePet then
local options = C_GossipInfo.GetOptions()
for _, gossipInfo in ipairs(options) do
if gossipInfo.name == L["ReviveBattlePetQ"] then
return C_GossipInfo.SelectOption(gossipInfo.gossipOptionID)
end
end
end
end
end
-- return true if an item is of `Jewelry` type and is suitable with current options
function AutoTurnIn:IsJewelryAndRequired(equipSlot)
return db.armor['Jewelry'] and (C.JEWELRY[equipSlot])
end
-- initiated in AutoTurnIn:TurnInQuest PLAYER_LEAVE_COMBAT ? PLAYER_REGEN_ENABLED ?
AutoTurnIn.delayFrame = CreateFrame('Frame')
AutoTurnIn.delayFrame:Hide()
AutoTurnIn.delayFrame:SetScript('OnUpdate', function()
if not next(AutoTurnIn.autoEquipList) then
AutoTurnIn:DebugPrint("AutoEquip has no registered items to equip")
AutoTurnIn.delayFrame:Hide()
return
end
if (InCombatLockdown()) then
return
end
if (time() < AutoTurnIn.delayFrame.delay) then
return
end
for bag=0, NUM_BAG_SLOTS do
for slot=1, ContainerFrame_GetContainerNumSlots(bag), 1 do
local link = C_Container.GetContainerItemLink (bag, slot)
if ( link ) then
local name = GetItemInfo(link)
if ( name and AutoTurnIn.autoEquipList[name] ) then
AutoTurnIn:Print(L["equipping reward"], link)
EquipItemByName(name, AutoTurnIn.autoEquipList[name])
AutoTurnIn.autoEquipList[name]=nil
end
end
end
end
end)
-- return 0 if itemlink is null, item level is math.huge if the item is heirloom
function AutoTurnIn:ItemLevel(itemLink)
if (not itemLink) then
return 0
end
-- 7 for heirloom https://wowpedia.fandom.com/wiki/Enum.ItemQuality
local invQuality, invLevel = select(3, GetItemInfo(itemLink))
return (invQuality == 7) and math.huge or invLevel
end
function AutoTurnIn:swapEquip(itemLink)
local name = GetItemInfo(itemLink)
if (self.autoEquipList[name]) then
self.delayFrame.delay = time() + 2
self.delayFrame:Show()
end
end
-- rewardIndex is calculated in AutoTurnIn:QUEST_COMPLETE, ot just '1' if there is just a single reward
-- turns in the quest and prints reward text if `showrewardtext` option is set.
-- equips received reward if such option selected
function AutoTurnIn:TurnInQuest(rewardIndex)
if (db.showrewardtext) then
self:Print((UnitName("target") and UnitName("target") or '')..'\n', GetRewardText())
end
if (self.forceGreed) then
if (GetNumQuestChoices() > 1) then
self:Print(L["gogreedy"])
end
else
if db.autoequip then
-- this is a 'CHOICE'
local itemLink1 = GetQuestItemLink("choice", (GetNumQuestChoices() == 1) and 1 or rewardIndex)
-- this is 'REWARD' - the unconditional item given for quest completition, it is different from the 'CHOICE'
local itemLink2 = GetNumQuestRewards() > 0 and GetQuestItemLink("reward", 1) or nil
-- if we have 2 items for same slot check which one is better
if (not not itemLink1 and (not not itemLink2)) then
local lootLevel1, _, _, _, _, equipSlot1 = select(4, GetItemInfo(itemLink1))
local lootLevel2, _, _, _, _, equipSlot2 = select(4, GetItemInfo(itemLink2))
if (equipSlot1 == equipSlot2) then
if lootLevel1 > lootLevel2 then
itemLink2 = nil
else
itemLink1 = nil
end
end
end
-- 'CHOICE' item is preferred
if (not not itemLink1) then
-- Could be already added to the equip frame by the AutoTurnIn:COMPLETE_QUEST funciton
local name = GetItemInfo(itemLink1)
if (self.autoEquipList[name] or (not not self:isSuitableItem(itemLink1))) then
self:DebugPrint("register item for Auto-Equip", itemLink1)
-- side effect, may register the item as non-equipable
self:swapEquip(itemLink1)
end
end
if (not not itemLink2 and not not self:isSuitableItem(itemLink2)) then
self:swapEquip(itemLink2)
end
end
end
if (db.debug) then
local link = GetQuestItemLink("choice", rewardIndex)
if (link) then
self:DebugPrint("Looting item: ", link)
elseif (GetNumQuestChoices() == 0) then
self:DebugPrint("turning quest in, no choice required")
end
else
GetQuestReward(rewardIndex)
end
end
function AutoTurnIn:LootMostExpensive()
local index, money = 0, 0;
self:DebugPrint("looting most expensive")
for i=1, GetNumQuestChoices() do
local link = GetQuestItemLink("choice", i)
if ( link == nil ) then
return
end
local m = select(11, GetItemInfo(link))
if m > money then
money = m
index = i
end
end
if money > 0 then -- some quests, like tournament ones, offer reputation rewards and they have no cost.
self.forceGreed = true
self:TurnInQuest(index)
end