-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAutoTurnIn.lua
executable file
·121 lines (98 loc) · 3.47 KB
/
AutoTurnIn.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
local addonName, ATOM = ...
local Module = ATOM:NewModule('AutoTurnIn')
local activeInteraction
local QuestFrame_OnShow
function Module:OnEnable()
self:RegisterEvent('GOSSIP_CLOSED', 'CharacterInteraction')
self:RegisterEvent('GOSSIP_SHOW', 'CharacterInteraction')
self:RegisterEvent('QUEST_COMPLETE', 'CharacterInteraction')
self:RegisterEvent('QUEST_DETAIL', 'CharacterInteraction')
self:RegisterEvent('QUEST_FINISHED', 'CharacterInteraction')
self:RegisterEvent('QUEST_GREETING', 'CharacterInteraction')
self:RegisterEvent('QUEST_PROGRESS', 'CharacterInteraction')
QuestFrame:HookScript('OnShow', QuestFrame_OnShow)
end
function Module:OnDisable()
self:UnregisterEvent('GOSSIP_CLOSED', 'CharacterInteraction')
self:UnregisterEvent('GOSSIP_SHOW', 'CharacterInteraction')
self:UnregisterEvent('QUEST_COMPLETE', 'CharacterInteraction')
self:UnregisterEvent('QUEST_DETAIL', 'CharacterInteraction')
self:UnregisterEvent('QUEST_FINISHED', 'CharacterInteraction')
self:UnregisterEvent('QUEST_GREETING', 'CharacterInteraction')
self:UnregisterEvent('QUEST_PROGRESS', 'CharacterInteraction')
end
function QuestFrame_OnShow()
-- Some quest givers don't fire GOSSIP_SHOW, QUEST_GREETING and QUEST_DETAIL
-- and immediately display the quest with accept and decline buttons
if not activeInteraction and QuestFrameAcceptButton:IsVisible() then
if IsControlKeyDown() then
activeInteraction = true
Module:QUEST_DETAIL()
end
end
end
function Module:CharacterInteraction(event, ...)
activeInteraction = IsControlKeyDown()
if activeInteraction then
self[event](self, ...)
end
end
function Module:QUEST_GREETING()
for i = 1, GetNumAvailableQuests() do
SelectAvailableQuest(i)
end
for i = 1, GetNumActiveQuests() do
local title, isComplete = GetActiveTitle(i)
if isComplete then
SelectActiveQuest(i)
end
end
end
function Module:GOSSIP_SHOW()
local availableQuests = C_GossipInfo.GetAvailableQuests()
for i, quest in ipairs(availableQuests) do
C_GossipInfo.SelectAvailableQuest(quest.questID)
end
-- check for quests to complete
local activeQuests = C_GossipInfo.GetActiveQuests()
for i, quest in ipairs(activeQuests) do
if quest.isComplete then
C_GossipInfo.SelectActiveQuest(quest.questID)
end
end
-- check for lone gossip option and no available/active quests
local gossipOptions = C_GossipInfo.GetOptions()
if gossipOptions and #gossipOptions == 1 and C_GossipInfo.GetNumAvailableQuests() == 0 and C_GossipInfo.GetNumActiveQuests() == 0 then
C_GossipInfo.SelectOption(gossipOptions[1].gossipOptionID)
end
end
function Module:GOSSIP_CLOSED()
ATOM:Wait(function()
activeInteraction = nil
end)
end
function Module:QUEST_DETAIL()
if not QuestGetAutoAccept() then
AcceptQuest()
end
end
function Module:QUEST_PROGRESS()
if IsQuestCompletable() then
CompleteQuest()
end
end
function Module:QUEST_COMPLETE()
if not GetQuestID() or GetNumQuestChoices() > 1 then
return
end
QuestDetailAcceptButton_OnClick()
if tonumber(QuestInfoFrame.itemChoice or 0) <= 0 then
GetQuestReward(max(QuestInfoFrame.itemChoice or 1, 1))
end
end
function Module:QUEST_FINISHED()
self:GOSSIP_CLOSED()
end
function Module:QuestCompleted(questID)
ATOM:Dump(C_QuestLog.IsQuestFlaggedCompleted(questID))
end