Zariel (author)
Wed Jan 28 04:40:16 -0800 2009
commit  48289936ff384ac0993ffa6cc8e6799143ee5949
tree    f8367d790ed9d36aa7cf1d6fc40008fb5b050db1
parent  423499cc967251f23c2066cf3d5d723a538bc979
tourguide / Parser.lua
100644 95 lines (72 sloc) 2.631 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
local actiontypes = {
A = "ACCEPT",
C = "COMPLETE",
T = "TURNIN",
K = "KILL",
R = "RUN",
H = "HEARTH",
h = "SETHEARTH",
F = "FLY",
f = "GETFLIGHTPOINT",
N = "NOTE",
B = "BUY",
b = "BOAT",
U = "USE",
}
 
 
function TourGuide:GetObjectiveTag(tag, i)
self:Debug(11, "GetObjectiveTag", tag, i)
i = i or self.current
local tags = self.tags[i]
if not tags then return end
 
if tag == "O" then return tags:find("|O|")
elseif tag == "T" then return tags:find("|T|")
elseif tag == "QID" then return tonumber((tags:match("|QID|(%d+)|")))
elseif tag == "L" then
local _, _, lootitem, lootqty = tags:find("|L|(%d+)%s?(%d*)|")
lootqty = tonumber(lootqty) or 1
 
return lootitem, lootqty
end
 
return select(3, tags:find("|"..tag.."|([^|]*)|?"))
end
 
 
local myclass, myrace = UnitClass("player"), UnitRace("player")
local function ParseQuests(...)
local accepts, turnins, completes = {}, {}, {}
local uniqueid = 1
local actions, quests, tags = {}, {}, {}
local i = 1
 
for j=1,select("#", ...) do
local text = select(j, ...)
local _, _, classes = text:find("|C|([^|]+)|")
local _, _, races = text:find("|R|([^|]+)|")
 
if text ~= "" and (not classes or classes:find(myclass)) and (not races or races:find(myrace)) then
local _, _, action, quest, tag = text:find("^(%a) ([^|]*)(.*)")
assert(actiontypes[action], "Unknown action: "..text)
quest = quest:trim()
if not (action == "A" or action =="C" or action =="T") then
quest = quest.."@"..uniqueid.."@"
uniqueid = uniqueid + 1
end
 
actions[i], quests[i], tags[i] = actiontypes[action], quest, tag
 
i = i + 1
end
end
 
-- Query |U| items so they're cached when we actually need them
for _,vals in pairs(tags) do
local useitem = tonumber(vals:match("|U|(%d+)|"))
if useitem and not GetItemInfo(useitem) then GameTooltip:SetHyperlink("item:"..useitem) end
end
 
return actions, quests, tags
end
 
 
function TourGuide:LoadGuide(name, complete)
if not name then return end
 
if complete then self.db.char.completion[self.db.char.currentguide] = 1
elseif self.actions then self.db.char.completion[self.db.char.currentguide] = (self.current-1)/#self.actions end
 
self.db.char.currentguide = self.guides[name] and name or self.guidelist[1]
self:DebugF(1, "Loading guide: %s", name)
self.guidechanged = true
local zonename = name:match("%s*([^]]+) %(.*%)$")
self.zonename = zonename
self.actions, self.quests, self.tags = ParseQuests(string.split("\n", self.guides[self.db.char.currentguide]()))
 
if not self.db.char.turnins[name] then self.db.char.turnins[name] = {} end
self.turnedin = self.db.char.turnins[name]
end