tekkub / tourguide_recorder

WoW Addon - TourGuide guide making helper

This URL has Read+Write access

tourguide_recorder / TourGuide_Recorder.lua
100644 116 lines (89 sloc) 3.189 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
local al = DongleStub("Astrolabe-0.4")
local currentquests, oldquests, currentboards, oldboards, titles, firstscan, abandoning, db = {}, {}, {}, {}, {}, true
local qids = setmetatable({}, {
__index = function(t,i)
local v = tonumber(i:match("|Hquest:(%d+):"))
t[i] = v
return v
end,
})
 
 
local function Debug(msg) ChatFrame6:AddMessage(tostring(msg)) end
 
local f = CreateFrame("frame")
f:SetScript("OnEvent", function(self, event, ...) if self[event] then return self[event](self, event, ...) end end)
f:RegisterEvent("ADDON_LOADED")
 
 
function f:ADDON_LOADED(event, addon)
if addon ~= "TourGuide_Recorder" then return end
 
TourGuide_RecorderDB = TourGuide_RecorderDB or ""
 
self:UnregisterEvent("ADDON_LOADED")
self.ADDON_LOADED = nil
 
self:RegisterEvent("QUEST_LOG_UPDATE")
end
 
 
local function Save(val)
TourGuide_RecorderDB = TourGuide_RecorderDB..val
Debug(val:gsub("|", "||"):gsub("\n", ""))
end
 
function f:QUEST_LOG_UPDATE()
--~ Debug("QUEST_LOG_UPDATE")
currentquests, oldquests = oldquests, currentquests
currentboards, oldboards = oldboards, currentboards
for i in pairs(currentquests) do currentquests[i] = nil end
for i in pairs(currentboards) do currentboards[i] = nil end
 
for i=1,GetNumQuestLogEntries() do
local link = GetQuestLink(i)
local qid = link and qids[link]
if qid then
currentquests[qid] = true
titles[qid] = GetQuestLogTitle(i)
 
for j=1,GetNumQuestLeaderBoards(i) do
local text, objtype, finished = GetQuestLogLeaderBoard(j, i)
if finished then
currentboards[qid.."."..j] = text
end
end
end
end
 
if firstscan then
firstscan = nil
return
end
 
local _, _, x, y = al:GetCurrentPlayerPosition()
 
for qidboard,text in pairs(currentboards) do
if not oldboards[qidboard] then
Save(string.format("\n- |QID|%s| |QO|%s| |N|%s, %s (%.2f, %.2f)|", qidboard, text, GetZoneText(), GetSubZoneText(), x*100, y*100))
end
end
 
for qid in pairs(oldquests) do
if not currentquests[qid] then
local action = abandoning and "Abandoned quest" or "Turned in quest"
if not abandoning then Save(string.format("\nT %s |QID|%s| |N|%s, %s (%.2f, %.2f)|", titles[qid], qid, GetZoneText(), GetSubZoneText(), x*100, y*100)) end
abandoning = nil
return
end
end
 
for qid in pairs(currentquests) do
if not oldquests[qid] then
Save(string.format("\nA %s |QID|%s| |N|%s, %s (%.2f, %.2f)|", titles[qid], qid, GetZoneText(), GetSubZoneText(), x*100, y*100))
return
end
end
end
 
 
local orig = AbandonQuest
function AbandonQuest(...)
abandoning = true
return orig(...)
end
 
 
local used = {}
hooksecurefunc("UseContainerItem", function(bag, slot, ...)
if MerchantFrame:IsVisible() then return end
local link = GetContainerItemLink(bag, slot)
if link and not used[link] then
used[link] = true
local _, _, x, y = al:GetCurrentPlayerPosition()
Save(string.format("\nU %s |N|%s, %s (%.2f, %.2f)|", link, GetZoneText(), GetSubZoneText(), x*100, y*100))
end
end)
 
 
SLASH_TGR1 = "/tgr"
function SlashCmdList.TGR(msg)
local _, _, x, y = al:GetCurrentPlayerPosition()
Save(string.format("\nN %s |N|%s, %s (%.2f, %.2f)|", msg or "No note", GetZoneText(), GetSubZoneText(), x*100, y*100))
end