22 function TourGuide
:GetObjectiveTag(tag, i
)
23 self
:Debug(11, "GetObjectiveTag", tag, i
)
25 local tags
= self
.tags
[i
]
26 if not tags
then return end
28 if tag == "O" then return tags
:find("|O|")
29 elseif tag == "L" then
30 local _
, _
, lootitem
, lootqty
= tags
:find("|L|(%d+)%s?(%d*)|")
31 lootqty
= tonumber(lootqty
) or 1
33 return lootitem
, lootqty
36 return select(3, tags
:find("|"..tag.."|([^|]*)|?"))
40 local myclass
= UnitClass("player")
41 local titlematches
= {"For", "A", "The", "Or", "In", "Then", "From", "To"}
42 local function ParseQuests(...)
43 local accepts
, turnins
, completes
= {}, {}, {}
45 local actions
, quests
, tags
= {}, {}, {}
46 local i
, haserrors
= 1, false
48 for j
=1,select("#", ...) do
49 local text
= select(j
, ...)
50 local _
, _
, class
= text
:find("|C|([^|]+)|")
52 if text
~= "" and (not class
or class
== myclass
) then
53 local _
, _
, action
, quest
, tag = text
:find("^(%a) ([^|]*)(.*)")
54 assert(actiontypes
[action
], "Unknown action: "..text
)
56 if not (action
== "A" or action
=="C" or action
=="T") then
57 quest
= quest
.."@"..uniqueid
.."@"
58 uniqueid
= uniqueid
+ 1
61 actions
[i
], quests
[i
], tags
[i
] = actiontypes
[action
], quest
, tag
66 if not string.find(text
, "|NODEBUG|") then
67 if action
== "A" then accepts
[quest
] = true
68 elseif action
== "T" then turnins
[quest
] = true
69 elseif action
== "C" then completes
[quest
] = true end
71 if action
== "A" or action
== "C" or action
== "T" then
72 -- Catch bad Title Case
73 for _
,word
in pairs(titlematches
) do
74 if quest
:find("[^:]%s"..word
.."%s") or quest
:find("[^:]%s"..word
.."$") or quest
:find("[^:]%s"..word
.."@") then
75 TourGuide
:DebugF(1, "%s %s -- Contains bad title case", action
, quest
)
80 if quest
:find("[“”’]") then
81 TourGuide
:DebugF(1, "%s %s -- Contains bad char", action
, quest
)
86 local _
, _
, comment
= string.find(text
, "(|[NLUC]V?|[^|]+)$") or string.find(text
, "(|[NLUC]V?|[^|]+) |[NLUC]V?|")
88 TourGuide
:Debug(1, "Unclosed comment: ".. comment
)
96 for quest
in pairs(accepts
) do if not turnins
[quest
] then TourGuide
:DebugF(1, "Quest has no 'turnin' objective: %s", quest
) end end
97 for quest
in pairs(turnins
) do if not accepts
[quest
] then TourGuide
:DebugF(1, "Quest has no 'accept' objective: %s", quest
) end end
98 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
100 if haserrors
and TourGuide
:IsDebugEnabled() then TourGuide
:Print("This guide contains errors") end
102 return actions
, quests
, tags
106 function TourGuide
:LoadGuide(name
)
107 if not name
then return end
109 self
.db
.char
.currentguide
= name
110 if not self
.guides
[name
] then self
.db
.char
.currentguide
= self
.guidelist
[1] end
111 self
:DebugF(1, "Loading guide: %s", name
)
112 self
.guidechanged
= true
113 local _
, _
, zonename
= name
:find("^(.*) %(.*%)$")
114 self
.zonename
= zonename
115 self
.actions
, self
.quests
, self
.tags
= ParseQuests(string.split("\n", self
.guides
[self
.db
.char
.currentguide
]()))