TourGuide: i hate to rework my text, but it had to. ie. Beached Sea Creatures and...
[WoW-TourGuide.git] / TourGuide.lua
blob9300e2d030630a5003a967cf3db162f51e3b1e50
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
9 TourGuide.guides = {}
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 KILL = "Interface\\Icons\\Ability_Creature_Cursed_02",
19 RUN = "Interface\\Icons\\Ability_Tracking",
20 MAP = "Interface\\Icons\\Ability_Spy",
21 FLY = "Interface\\Icons\\Ability_Druid_FlightForm",
22 TRAIN = "Interface\\GossipFrame\\trainerGossipIcon",
23 SETHEARTH = "Interface\\AddOns\\TourGuide\\resting.tga",
24 HEARTH = "Interface\\Icons\\INV_Misc_Rune_01",
25 NOTE = "Interface\\Icons\\INV_Misc_Note_01",
26 GRIND = "Interface\\Icons\\INV_Stone_GrindingStone_05",
27 USE = "Interface\\Icons\\INV_Misc_Bag_08",
28 BUY = "Interface\\Icons\\INV_Misc_Coin_01",
29 BOAT = "Interface\\Icons\\Spell_Frost_SummonWaterElemental",
30 GETFLIGHTPOINT = "Interface\\Icons\\Ability_Hunter_EagleEye",
31 }, {__index = function() return "Interface\\Icons\\INV_Misc_QuestionMark" end})
34 function TourGuide:Initialize()
35 self.db = self:InitializeDB("TourGuideAlphaDB", {
36 char = {
37 turnedin = {},
38 cachedturnins = {},
41 self.turnedin = self.db.char.turnedin
42 self.cachedturnins = self.db.char.cachedturnins
44 self.db.char.currentguide = self.db.char.currentguide or self.guidelist[1]
45 self:LoadGuide(self.db.char.currentguide)
46 self:PositionStatusFrame()
47 end
50 function TourGuide:Enable()
51 local _, title = GetAddOnInfo("TourGuide")
52 local author, version = GetAddOnMetadata("TourGuide", "Author"), GetAddOnMetadata("TourGuide", "Version")
53 local oh = OptionHouse:RegisterAddOn("Tour Guide", title, author, version)
54 oh:RegisterCategory("Guides", TourGuide, "CreateGuidesPanel")
55 oh:RegisterCategory("Objectives", TourGuide, "CreateObjectivePanel")
57 for _,event in pairs(self.TrackEvents) do self:RegisterEvent(event) end
58 self:RegisterEvent("QUEST_COMPLETE", "UpdateStatusFrame")
59 self:RegisterEvent("QUEST_DETAIL", "UpdateStatusFrame")
60 self.TrackEvents = nil
61 self:UpdateStatusFrame()
62 end
65 function TourGuide:RegisterGuide(name, nextzone, faction, sequencefunc)
66 if faction ~= myfaction then return end
67 self.guides[name] = sequencefunc
68 self.nextzones[name] = nextzone
69 table.insert(self.guidelist, name)
70 end
73 function TourGuide:LoadNextGuide()
74 local name = self.nextzones[self.db.char.currentguide]
75 if not name then return end
77 for i,quest in ipairs(self.quests) do self.turnedin[quest] = nil end -- Clean out old completed objectives, to avoid conflicts
79 self:LoadGuide(name)
80 self:UpdateGuidesPanel()
81 return true
82 end
85 function TourGuide:GetQuestLogIndexByName(name)
86 name = name or self.quests[self.current]
87 name = name:gsub("%s%(Part %d+%)", "")
88 for i=1,GetNumQuestLogEntries() do
89 if GetQuestLogTitle(i) == name then return i end
90 end
91 end
93 function TourGuide:GetQuestDetails(name)
94 if not name then return end
96 local i = self:GetQuestLogIndexByName(name)
97 local complete = i and select(7, GetQuestLogTitle(i)) == 1
98 return i, complete
99 end
102 function TourGuide:FindBagSlot(itemid)
103 for bag=0,4 do
104 for slot=1,GetContainerNumSlots(bag) do
105 local item = GetContainerItemLink(bag, slot)
106 if item and string.find(item, "item:"..itemid) then return bag, slot end
112 function TourGuide:GetObjectiveInfo(i)
113 i = i or self.current
114 if not self.actions[i] then return end
116 return self.actions[i], self.quests[i]:gsub("@.*@", ""), self.quests[i] -- Action, display name, full name
120 function TourGuide:GetObjectiveStatus(i)
121 i = i or self.current
122 if not self.actions[i] then return end
124 return self.turnedin[self.quests[i]], self:GetQuestDetails(self.quests[i]) -- turnedin, logi, complete
128 function TourGuide:SetTurnedIn(i, value, noupdate)
129 if not i then
130 i = self.current
131 value = true
134 if value then value = true else value = nil end -- Cleanup to minimize savedvar data
136 self.turnedin[self.quests[i]] = value
137 self:DebugF(1, "Set turned in %q = %s", self.quests[i], tostring(value))
138 if not noupdate then self:UpdateStatusFrame()
139 else self.updatedelay = true end
143 function TourGuide:CompleteQuest(name, noupdate)
144 if not self.current then
145 self:DebugF(1, "Cannot complete %q, no guide loaded", name)
146 return
149 local i = self.current
150 local action, quest
151 repeat
152 action, quest = self:GetObjectiveInfo(i)
153 if action == "TURNIN" and not self:GetObjectiveStatus(i) and name == quest:gsub("%s%(Part %d+%)", "") then
154 self:DebugF(1, "Saving quest turnin %q", quest)
155 return self:SetTurnedIn(i, true, noupdate)
157 i = i + 1
158 until not action
159 self:DebugF(1, "Quest %q not found!", name)