public
Description: WoW Powerleveling addon
Homepage: http://www.tekkub.net/
Clone URL: git://github.com/tekkub/tourguide.git
Click here to lend your support to: tourguide and make a donation at www.pledgie.com !
tourguide / Parser.lua
100644 189 lines (144 sloc) 5.802 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
 
 
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",
  P = "PET",
}
 
 
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 == "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 function DumpQuestDebug(accepts, turnins, completes)
  for quest in pairs(accepts) do if not turnins[quest] then TourGuide:DebugF(1, "Quest has no 'turnin' objective: %s", quest) end end
  for quest in pairs(turnins) do if not accepts[quest] then TourGuide:DebugF(1, "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:DebugF(1, "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:DebugF(1, "%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 quest:find("[^:]%s"..word.."%s") or quest:find("[^:]%s"..word.."$") or quest:find("[^:]%s"..word.."@") then
        TourGuide:DebugF(1, "%s %s -- Contains bad title case", action, quest)
        haserrors = true
      end
    end
  end
 
  if text:find("[“”’]") then
    TourGuide:DebugF(1, "%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(1, "Unclosed comment: ".. comment)
    haserrors = true
  end
 
  return haserrors
end
 
 
local myclass, myrace = UnitClass("player"), UnitRace("player")
local function ParseQuests(...)
  local accepts, turnins, completes = {}, {}, {}
  local uniqueid = 1
  local actions, quests, tags = {}, {}, {}
  local i, haserrors = 1, false
 
  for j=1,select("#", ...) do
    local text = select(j, ...)
    local _, _, class = text:find("|C|([^|]+)|")
    local _, _, race = text:find("|R|([^|]+)|")
 
    if text ~= "" and (not class or class == myclass) and (not race or race == 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
 
      haserrors = DebugQuestObjective(text, action, quest, accepts, turnins, completes) or haserrors
    end
  end
 
  DumpQuestDebug(accepts, turnins, completes)
 
  if haserrors and TourGuide:IsDebugEnabled() 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)/#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:find("^(.*) %(.*%)$")
  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
 
 
function TourGuide:DebugGuideSequence(dumpquests)
  local accepts, turnins, completes = {}, {}, {}
  local function DebugParse(...)
    local uniqueid, haserrors = 1
 
    for j=1,select("#", ...) do
      local text = select(j, ...)
 
      if text ~= "" then
        local _, _, action, quest, tag = text:find("^(%a) ([^|]*)(.*)")
        if not actiontypes[action] then TourGuide:Debug(1, "Unknown action: "..text) end
        quest = quest:trim()
        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(1, "------ Begin Full Debug ------")
 
  local name, lastzone = self.db.char.currentguide
  repeat
    if not self.guides[name] then
      self:DebugF(1, "Cannot find guide %q", name)
      name, lastzone = nil, name
    elseif DebugParse(string.split("\n", self.guides[name]())) then
      self:DebugF(1, "Errors in guide: %s", name)
      self:Debug(1, "---------------------------")
    end
    name, lastzone = self.nextzones[name], name
  until not name
 
  if dumpquests then
    self:Debug(1, "------ Quest Continuity Debug ------")
    DumpQuestDebug(accepts, turnins, completes)
  end
  self:Debug(1, "Last zone loaded:", lastzone)
  self:Debug(1, "------ End Full Debug ------")
end