2 local OptionHouse
= LibStub("OptionHouse-1.1")
5 local myfaction
= UnitFactionGroup("player")
7 TourGuide
= DongleStub("Dongle-1.0"):New("TourGuide")
8 if tekDebug
then TourGuide
:EnableDebug(10, tekDebug
:GetFrame("TourGuide")) end
10 TourGuide
.guidelist
= {}
11 TourGuide
.nextzones
= {}
14 TourGuide
.icons
= setmetatable({
15 ACCEPT
= "Interface\\GossipFrame\\AvailableQuestIcon",
16 COMPLETE
= "Interface\\Icons\\Ability_DualWield",
17 TURNIN
= "Interface\\GossipFrame\\ActiveQuestIcon",
18 RUN
= "Interface\\Icons\\Ability_Tracking",
19 MAP
= "Interface\\Icons\\Ability_Spy",
20 FLY
= "Interface\\Icons\\Ability_Druid_FlightForm",
21 TRAIN
= "Interface\\GossipFrame\\trainerGossipIcon",
22 SETHEARTH
= "Interface\\Icons\\Spell_Holy_ElunesGrace",
23 HEARTH
= "Interface\\Icons\\INV_Misc_Rune_01",
24 NOTE
= "Interface\\Icons\\INV_Misc_Note_01",
25 GRIND
= "Interface\\Icons\\INV_Stone_GrindingStone_05",
26 USE
= "Interface\\Icons\\INV_Misc_Bag_08",
27 BUY
= "Interface\\Icons\\INV_Misc_Coin_01",
28 BOAT
= "Interface\\Icons\\Spell_Frost_SummonWaterElemental",
29 GETFLIGHTPOINT
= "Interface\\Icons\\Spell_Nature_GiftoftheWaterSpirit",
30 }, {__index
= function() return "Interface\\Icons\\INV_Misc_QuestionMark" end})
51 function TourGuide
:Initialize()
52 self
.db
= self
:InitializeDB("TourGuideAlphaDB", {
58 self
.turnedin
= self
.db
.char
.turnedin
59 self
.cachedturnins
= self
.db
.char
.cachedturnins
61 self
.db
.char
.currentguide
= self
.db
.char
.currentguide
or self
.guidelist
[1]
62 self
:LoadGuide(self
.db
.char
.currentguide
)
63 self
:PositionStatusFrame()
67 function TourGuide
:Enable()
68 local _
, title
= GetAddOnInfo("TourGuide")
69 local author
, version
= GetAddOnMetadata("TourGuide", "Author"), GetAddOnMetadata("TourGuide", "Version")
70 local oh
= OptionHouse
:RegisterAddOn("Tour Guide", title
, author
, version
)
71 oh
:RegisterCategory("Guides", TourGuide
, "CreateGuidesPanel")
72 oh
:RegisterCategory("Objectives", TourGuide
, "CreateObjectivePanel")
74 for _
,event
in pairs(self
.TrackEvents
) do self
:RegisterEvent(event
) end
75 self
:RegisterEvent("QUEST_COMPLETE", "UpdateStatusFrame")
76 self
:RegisterEvent("QUEST_DETAIL", "UpdateStatusFrame")
77 self
.TrackEvents
= nil
78 self
:UpdateStatusFrame()
82 function TourGuide
:RegisterGuide(name
, nextzone
, faction
, sequencefunc
)
83 if faction
~= myfaction
then return end
84 self
.guides
[name
] = sequencefunc
85 self
.nextzones
[name
] = nextzone
86 table.insert(self
.guidelist
, name
)
90 function TourGuide
:LoadGuide(name
)
91 if not name
then return end
93 self
.db
.char
.currentguide
= name
94 if not self
.guides
[name
] then self
.db
.char
.currentguide
= self
.guidelist
[1] end
95 self
:DebugF(1, "Loading guide: %s", name
)
96 self
.guidechanged
= true
97 self
:ParseObjectives(self
.guides
[self
.db
.char
.currentguide
]())
101 function TourGuide
:LoadNextGuide()
102 local name
= self
.nextzones
[self
.db
.char
.currentguide
]
103 if not name
then return end
105 for i
,quest
in ipairs(self
.quests
) do self
.turnedin
[quest
] = nil end -- Clean out old completed objectives, to avoid conflicts
108 self
:UpdateGuidesPanel()
113 function TourGuide
:GetQuestLogIndexByName(name
)
114 name
= name
or self
.quests
[self
.current
]
115 name
= name
:gsub("%s%(Part %d+%)", "")
116 for i
=1,GetNumQuestLogEntries() do
117 if GetQuestLogTitle(i
) == name
then return i
end
121 function TourGuide
:GetQuestDetails(name
)
122 if not name
then return end
124 local i
= self
:GetQuestLogIndexByName(name
)
125 local complete
= i
and select(7, GetQuestLogTitle(i
)) == 1
130 function TourGuide
:FindBagSlot(itemid
)
132 for slot
=1,GetContainerNumSlots(bag
) do
133 local item
= GetContainerItemLink(bag
, slot
)
134 if item
and string.find(item
, "item:"..itemid
) then return bag
, slot
end
140 function TourGuide
:GetObjectiveInfo(i
)
141 i
= i
or self
.current
142 if not self
.actions
[i
] then return end
144 return self
.actions
[i
], self
.quests
[i
]:gsub("@.*@", ""), self
.quests
[i
] -- Action, display name, full name
148 function TourGuide
:GetObjectiveStatus(i
)
149 i
= i
or self
.current
150 if not self
.actions
[i
] then return end
152 return self
.turnedin
[self
.quests
[i]]
, self
:GetQuestDetails(self
.quests
[i
]) -- turnedin, logi, complete
156 function TourGuide
:GetObjectiveTag(tag, i
)
157 self
:Debug(11, "GetObjectiveTag", tag, i
)
158 i
= i
or self
.current
159 if tag == "LV" then return self
.levels
[i
]
160 elseif tag == "N" then return self
.notes
[i
]
161 elseif tag == "U" then return self
.useitems
[i
]
162 elseif tag == "O" then return self
.optional
[i
]
163 elseif tag == "L" then
164 local _
, _
, lootitem
, lootqty
= string.find(self
.lootitems
[i
] or "", "(%d+)%s?(%d*)")
165 lootqty
= tonumber(lootqty
) or 1
167 return lootitem
, lootqty
172 local myclass
= UnitClass("player")
173 local titlematches
= {"For", "A", "The", "Or", "In", "Then", "From", "To"}
174 local function ParseQuests(...)
175 local accepts
, turnins
, completes
= {}, {}, {}
177 local actions
, notes
, quests
, useitems
, optionals
, lootitems
, levels
= {}, {}, {}, {}, {}, {}, {}
180 for j
=1,select("#", ...) do
181 local text
= select(j
, ...)
182 local _
, _
, class
= text
:find("|C|([^|]+)|")
184 if text
~= "" and (not class
or class
== myclass
) then
185 local _
, _
, action
, quest
= text
:find("^(%a) ([^|]*)")
186 assert(actiontypes
[action
], "Unknown action: "..text
)
188 if not (action
== "A" or action
=="C" or action
=="T") then
189 quest
= quest
.."@"..uniqueid
.."@"
190 uniqueid
= uniqueid
+ 1
193 actions
[i
], quests
[i
] = actiontypes
[action
], quest
195 local _
, _
, note
= string.find(text
, "|N|([^|]+)|")
196 if note
then notes
[i
] = note
end
198 local _
, _
, level
= string.find(text
, "|LV|(%d+)|")
199 if level
then levels
[i
] = tonumber(level
) end
201 local _
, _
, useitem
= string.find(text
, "|U|(%d+)|")
202 if useitem
then useitems
[i
] = useitem
end
204 local _
, _
, lootitem
= string.find(text
, "|L|(%d+%s?%d*)|")
205 if lootitem
then lootitems
[i
] = lootitem
end
207 if string.find(text
, "|O|") then optionals
[i
] = true end
212 if action
== "A" then accepts
[quest
] = true
213 elseif action
== "T" then turnins
[quest
] = true
214 elseif action
== "C" then completes
[quest
] = true end
216 if action
== "A" or action
== "C" or action
== "T" then
217 -- Catch bad Title Case
218 for _
,word
in pairs(titlematches
) do
219 if quest
:find("[^:]%s"..word
.."%s") or quest
:find("[^:]%s"..word
.."$") or quest
:find("[^:]%s"..word
.."@") then
220 TourGuide
:DebugF(1, "%s %s -- Contains bad title case", action
, quest
)
224 local _
, _
, comment
= string.find(text
, "(|.|[^|]+)$")
225 if comment
then TourGuide
:Debug(1, "Unclosed comment: ".. comment
) end
230 for quest
in pairs(accepts
) do if not turnins
[quest
] then TourGuide
:DebugF(1, "Quest has no 'turnin' objective: %s", quest
) end end
231 for quest
in pairs(turnins
) do if not accepts
[quest
] then TourGuide
:DebugF(1, "Quest has no 'accept' objective: %s", quest
) end end
232 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
234 return actions
, notes
, quests
, useitems
, optionals
, lootitems
, levels
238 function TourGuide
:ParseObjectives(text
)
239 self
.actions
, self
.notes
, self
.quests
, self
.useitems
, self
.optional
, self
.lootitems
, self
.levels
= ParseQuests(string.split("\n", text
))
243 function TourGuide
:SetTurnedIn(i
, value
, noupdate
)
249 if value
then value
= true else value
= nil end -- Cleanup to minimize savedvar data
251 self
.turnedin
[self
.quests
[i]]
= value
252 self
:DebugF(1, "Set turned in %q = %s", self
.quests
[i
], tostring(value
))
253 if not noupdate
then self
:UpdateStatusFrame()
254 else self
.updatedelay
= true end
258 function TourGuide
:CompleteQuest(name
, noupdate
)
259 local i
= self
.current
262 action
, quest
= self
:GetObjectiveInfo(i
)
263 if action
== "TURNIN" and not self
:GetObjectiveStatus(i
) and name
== quest
:gsub("%s%(Part %d+%)", "") then
264 self
:DebugF(1, "Saving quest turnin %q", quest
)
265 return self
:SetTurnedIn(i
, true, noupdate
)
269 self
:DebugF(1, "Quest %q not found!", name
)