-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathParser.lua
180 lines (148 loc) · 6.05 KB
/
Parser.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
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
local actiontypes = {
A = "ACCEPT",
C = "COMPLETE",
T = "TURNIN",
K = "KILL",
R = "RUN",
H = "HEARTH",
h = "SETHEARTH",
G = "GRIND",
F = "FLY",
f = "GETFLIGHTPOINT",
N = "NOTE",
B = "BUY",
b = "BOAT",
U = "USE",
P = "PET",
D = "DIE",
}
function TourGuide:GetObjectiveTag(tag, i)
--self:Debug( "GetObjectiveTag", tag, i)
i = i or self.current
local tags = self.tags[i]
if not tags then return end
if tag == "O" then return string.find(tags,"|O|")
elseif tag == "T" then return string.find(tags,"|T|")
elseif tag == "S" then return string.find(tags,"|S|")
elseif tag == "QID" then return self.select(3, string.find(tags, "|QID|(%d+)|"))
elseif tag == "L" then
local _, _, lootitem, lootqty = string.find(tags,"|L|(%d+)%s?(%d*)|")
lootqty = tonumber(lootqty) or 1
return lootitem, lootqty
end
return self.select(3, string.find(tags,"|"..tag.."|([^|]*)|?"))
end
local function DumpQuestDebug(accepts, turnins, completes)
for quest in pairs(accepts) do if not turnins[quest] then TourGuide:Debug( string.format("Quest has no 'turnin' objective: %s", quest)) end end
for quest in pairs(turnins) do if not accepts[quest] then TourGuide:Debug( string.format("Quest has no 'accept' objective: %s", quest)) end end
for quest in pairs(completes) do if not accepts[quest] and not turnins[quest] then TourGuide:Debug( string.format("Quest has no 'accept' and 'turnin' objectives: %s", quest)) end end
end
local titlematches = {"For", "A", "The", "Or", "In", "Then", "From", "To"}
local function DebugQuestObjective(text, action, quest, accepts, turnins, completes)
local haserrors
if (action == "A" and accepts[quest] or action == "T" and turnins[quest] or action == "C" and completes[quest]) and not string.find(text, "|NODEBUG|") then
TourGuide:Debug( string.format("%s %s -- Duplicate objective", action, quest))
haserrors = true
end
if action == "A" then accepts[quest] = true
elseif action == "T" then turnins[quest] = true
elseif action == "C" then completes[quest] = true end
if string.find(text, "|NODEBUG|") then return haserrors end
if action == "A" or action == "C" or action == "T" then
-- Catch bad Title Case
for _,word in pairs(titlematches) do
if string.find(quest,"[^:]%s"..word.."%s") or string.find(quest,"[^:]%s"..word.."$") or string.find(quest,"[^:]%s"..word.."@") then
TourGuide:Debug( string.format("%s %s -- Contains bad title case", action, quest))
haserrors = true
end
end
end
if string.find(text,"[���]") then
TourGuide:Debug( string.format("%s %s -- Contains bad char", action, quest))
haserrors = true
end
local _, _, comment = string.find(text, "(|[NLUC]V?|[^|]+)$") or string.find(text, "(|[NLUC]V?|[^|]+) |[NLUC]V?|")
if comment then
TourGuide:Debug( "Unclosed comment: ".. comment)
haserrors = true
end
return haserrors
end
local myclass, myrace = UnitClass("player"), UnitRace("player")
local function StepParse(guide)
local accepts, turnins, completes = {}, {}, {}
local uniqueid = 1
local actions, quests, tags = {}, {}, {}
local i, haserrors = 1, false
local guidet = TourGuide.split("\r\n", guide)
for _,text in pairs(guidet) do
local _, _, class = string.find(text,"|C|([^|]+)|")
local _, _, race = string.find(text,"|R|([^|]+)|")
if text ~= "" and (not class or string.find(class, myclass)) and (not race or string.find(race,myrace)) then
local _, _, action, quest, tag = string.find(text,"^(%a) ([^|]*)(.*)")
assert(actiontypes[action], "Unknown action: "..text)
quest = TourGuide.trim(quest)
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
haserrors = DebugQuestObjective(text, action, quest, accepts, turnins, completes) or haserrors
end
end
DumpQuestDebug(accepts, turnins, completes)
if haserrors and TourGuide:IsDebugging() then TourGuide:Print("This guide contains errors") 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)/table.getn(self.actions) end
self.db.char.currentguide = self.guides[name] and name or self.guidelist[1]
self:Debug( string.format("Loading guide: %s", name))
self.guidechanged = true
local _, _, zonename = string.find(name,"^(.*) %(.*%)$")
self.zonename = zonename
self.actions, self.quests, self.tags = StepParse(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
function TourGuide:DebugGuideSequence(dumpquests)
local accepts, turnins, completes = {}, {}, {}
local function DebugParse(guide)
local uniqueid, haserrors = 1
local guidet = TourGuide.split("\n", guide)
for _,text in pairs(guidet) do
if text ~= "" then
local _, _, action, quest, tag = string.find(text,"^(%a) ([^|]*)(.*)")
if not actiontypes[action] then TourGuide:Debug( "Unknown action: "..text) end
quest = TourGuide.trim(quest)
if not (action == "A" or action =="C" or action =="T") then
quest = quest.."@"..uniqueid.."@"
uniqueid = uniqueid + 1
end
haserrors = DebugQuestObjective(text, action, quest, accepts, turnins, completes) or haserrors
end
end
return haserrors
end
self:Debug( "------ Begin Full Debug ------")
local name, lastzone = self.db.char.currentguide
repeat
if not self.guides[name] then
self:Debug( string.format("Cannot find guide %q", name))
name, lastzone = nil, name
elseif DebugParse(self.guides[name]()) then
self:Debug( string.format("Errors in guide: %s", name))
self:Debug( "---------------------------")
end
name, lastzone = self.nextzones[name], name
until not name
if dumpquests then
self:Debug( "------ Quest Continuity Debug ------")
DumpQuestDebug(accepts, turnins, completes)
end
self:Debug( "Last zone loaded:", lastzone)
self:Debug( "------ End Full Debug ------")
end