Mercurial > wow > buffalo2
comparison ObjectiveTracker/Quests.lua @ 28:c33c17dd97e7
file renames
author | Nenue |
---|---|
date | Wed, 13 Apr 2016 20:19:37 -0400 |
parents | |
children | adcd7c328d07 |
comparison
equal
deleted
inserted
replaced
27:c3aa94bc6be2 | 28:c33c17dd97e7 |
---|---|
1 local B = select(2,...).frame | |
2 local T = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame') | |
3 local _G, ipairs, max, min, unpack, floor, pairs, tostring, type, band = _G, ipairs, max, min, unpack, floor, pairs, tostring, type, bit.band | |
4 local GetAutoQuestPopUp, GetQuestLogCompletionText = GetAutoQuestPopUp, GetQuestLogCompletionText | |
5 local Default, Quest = T.DefaultHandler, T.Quest | |
6 local format = format | |
7 local print = B.print('Tracker') | |
8 local lprint = B.print('Line') | |
9 local iprint = B.print('Info') | |
10 | |
11 local colors = T.colors | |
12 | |
13 local tprint = B.print('Tracker') | |
14 Quest.Update = function(self, reason, ...) | |
15 local print = tprint | |
16 print('QuestTracker:Update() received') | |
17 T.UpdateActionButtons() | |
18 Default.Update(self, reason, ...) | |
19 end | |
20 | |
21 T.Quest.numButtons = 0 | |
22 local usedButtons = T.Quest.itemButtons | |
23 local freeButtons = T.Quest.freeButtons | |
24 | |
25 Quest.UpdateObjectives = function(handler, block) | |
26 local print = lprint | |
27 print('|cFF00FFFFUpdateObjectives()') | |
28 local info = block.info | |
29 | |
30 local titlebg, textbg = colors.default.titlebg, colors.default.textbg | |
31 print((info.isAccount and 'isAccount' or ''), (info.isFaction and 'isFaction' or ''), (info.isDaily and 'isDaily' or ''), (info.isWeekly and 'isWeekly' or ''), info.tagID, info.tagName) | |
32 | |
33 if info.isAccount then | |
34 if info.isFaction then | |
35 print(' faction', info.tagID) | |
36 titlebg, textbg = colors['faction_'..info.tagID].titlebg, colors.default.textbg | |
37 else | |
38 print(' account', info.isAccount, info.isFaction) | |
39 titlebg, textbg = colors.account.titlebg, colors.account.textbg | |
40 end | |
41 elseif info.isDaily then | |
42 print(' daily', info.frequency) | |
43 titlebg, textbg = colors.daily.titlebg, colors.daily.textbg | |
44 elseif info.isWeekly then | |
45 print(' weekly', info.frequency) | |
46 titlebg, textbg = colors.weekly.titlebg, colors.weekly.textbg | |
47 end | |
48 | |
49 block.titlebg:SetGradientAlpha(unpack(titlebg)) | |
50 block.statusbg:SetGradientAlpha(unpack(textbg)) | |
51 | |
52 local completionText | |
53 if info.isComplete then | |
54 if info.isAutoComplete then | |
55 local questID, popupType = GetAutoQuestPopUp(info.questLogIndex) | |
56 if popupType == 'COMPLETE' then | |
57 print(' :: auto-complete quest :: set the message') | |
58 info.completionText = T.strings.CLICK_TO_COMPLETE | |
59 end | |
60 else | |
61 if not completionText or info.completionText then | |
62 info.completionText = GetQuestLogCompletionText(info.questLogIndex) | |
63 end | |
64 end | |
65 print(' :: complete quest :: show instruction: "'.. tostring(info.completionText) .. '"') | |
66 end | |
67 | |
68 Default.UpdateObjectives(handler, block) | |
69 end | |
70 | |
71 Quest.UpdateLine = function(handler, block, line, data) | |
72 local print = lprint | |
73 local objectiveType = data.type | |
74 local r, g, b, a = 0, 1, 1, 1 | |
75 | |
76 line.progress = 0 | |
77 if data.finished then | |
78 line.progress = 2 | |
79 r, g, b, a = 0, 1, 0, 1 | |
80 elseif objectiveType == 'monster' then | |
81 r, g, b, a = 1, .55, .2, 1 | |
82 elseif objectiveType == 'item' then | |
83 r, g, b, a = .8, .8, .8, 1 | |
84 elseif objectiveType == 'object' then | |
85 r, g, b, a = 1, 1, 1, 1 | |
86 elseif objectiveType == 'player' then | |
87 r, g, b, a = 0, 0.8, 1, 1 | |
88 end | |
89 print(format(' |cFF%02X%02X%02X%0.1f, %0.1f, %0.1f|r', (r * 255), g * 255, b * 255, r, g, b)) | |
90 | |
91 line.displayColor = {r, g, b, a} | |
92 line.status:SetTextColor(r, g, b, a) | |
93 line.displayText = data.text | |
94 | |
95 return line | |
96 end | |
97 | |
98 ----------------------------- | |
99 --- QUEST | |
100 Quest.POI = {} | |
101 Quest.QuestBlock = {} | |
102 Quest.LogBlock = {} | |
103 Quest.LogInfo = {} | |
104 | |
105 function Quest:GetNumWatched () | |
106 print(self.name, self) | |
107 self.numAll = GetNumQuestLogEntries() | |
108 self.numWatched = GetNumQuestWatches() | |
109 return self.numWatched, self.numAll | |
110 end | |
111 Quest.GetInfo = function (self, watchIndex) | |
112 local print = iprint | |
113 print('|cFF00DDFFQuest|r.|cFF0088FFGetInfo(|r'.. tostring(watchIndex)..'|r)') | |
114 local questID, title, questIndex, numObjectives, requiredMoney, _, | |
115 _, isAutoComplete, failureTime, timeElapsed, questType, _, _, _, _ = GetQuestWatchInfo(watchIndex) | |
116 | |
117 if not questIndex then | |
118 return | |
119 end | |
120 | |
121 | |
122 local _, level, suggestedGroup, isHeader, isCollapsed, isComplete, frequency, _, startEvent, displayQuestID, isOnMap, hasLocalPOI, isTask, isStory = GetQuestLogTitle(questIndex) | |
123 | |
124 | |
125 if not questID then | |
126 return | |
127 end | |
128 Quest.Info[questID] = Quest.Info[questID] or {} | |
129 | |
130 local q = Quest.Info[questID] | |
131 q.watchIndex = watchIndex | |
132 q.type = 'Quest' | |
133 q.questID = questID | |
134 q.title = title | |
135 q.level = level | |
136 q.displayQuestID = displayQuestID | |
137 q.suggestedGroup = suggestedGroup | |
138 q.questLogIndex = questIndex | |
139 q.numObjectives = numObjectives | |
140 q.requiredMoney = requiredMoney | |
141 q.isComplete = isComplete | |
142 q.startEvent = startEvent | |
143 q.isAutoComplete = isAutoComplete | |
144 q.failureTime = failureTime | |
145 q.timeElapsed = timeElapsed | |
146 q.questType = questType | |
147 q.isTask = isTask | |
148 q.isStory = isStory | |
149 q.isOnMap = isOnMap | |
150 q.hasLocalPOI = hasLocalPOI | |
151 q.frequency = frequency | |
152 q.isComplete = isComplete | |
153 q.isStory = isStory | |
154 q.isTask = isTask | |
155 | |
156 --- resolve icon type and template | |
157 local questTagID, tagName = GetQuestTagInfo(questID) | |
158 local tagID | |
159 | |
160 local factionGroup = GetQuestFactionGroup(questID); | |
161 if( questTagID and questTagID == QUEST_TAG_ACCOUNT ) then | |
162 if( factionGroup ) then | |
163 tagID = "ALLIANCE"; | |
164 if ( factionGroup == LE_QUEST_FACTION_HORDE ) then | |
165 tagID = "HORDE"; | |
166 end | |
167 q.isFaction = true | |
168 else | |
169 tagID = QUEST_TAG_ACCOUNT; | |
170 q.isAccount = true | |
171 end | |
172 q.typeTag = QUEST_TAG_TCOORDS[tagID] | |
173 elseif ( factionGroup) then | |
174 tagID = "ALLIANCE"; | |
175 if ( factionGroup == LE_QUEST_FACTION_HORDE ) then | |
176 tagID = "HORDE"; | |
177 end | |
178 q.isFaction = true | |
179 end | |
180 | |
181 if( frequency == LE_QUEST_FREQUENCY_DAILY and (not isComplete or isComplete == 0) ) then | |
182 tagID = "DAILY"; | |
183 q.frequencyTag = QUEST_TAG_TCOORDS["DAILY"] | |
184 q.isDaily = true | |
185 elseif( frequency == LE_QUEST_FREQUENCY_WEEKLY and (not isComplete or isComplete == 0) )then | |
186 tagID = "WEEKLY"; | |
187 q.frequencyTag = QUEST_TAG_TCOORDS["WEEKLY"] | |
188 q.isWeekly = true | |
189 elseif( questTagID ) then | |
190 tagID = questTagID; | |
191 end | |
192 | |
193 if ( isComplete and isComplete < 0 ) then | |
194 q.completionTag = QUEST_TAG_TCOORDS["FAILED"] | |
195 q.isFailed = true | |
196 elseif isComplete then | |
197 q.completionTag = QUEST_TAG_TCOORDS["COMPLETED"] | |
198 end | |
199 | |
200 | |
201 q.tagID = questTagID | |
202 q.tagName = tagName | |
203 --q.isBreadCrumb = isBreadCrumb | |
204 q.completionText= GetQuestLogCompletionText(questIndex) | |
205 q.numObjectives = GetNumQuestLeaderBoards(questIndex) | |
206 q.objectives = {} | |
207 for i = 1, q.numObjectives do | |
208 local text, type, finished = GetQuestLogLeaderBoard(i, questIndex) | |
209 print(format(' #%d %s %s %s', i, tostring(type), tostring(text), tostring(finished))) | |
210 q.objectives[i] = { | |
211 index = i, | |
212 type = type, | |
213 text = text, | |
214 finished = finished | |
215 } | |
216 if type == 'event' then | |
217 elseif type == 'monster' then | |
218 elseif type == 'object' then | |
219 elseif type == 'reputation' then | |
220 elseif type == 'item' then | |
221 end | |
222 end | |
223 | |
224 if requiredMoney >= 1 then | |
225 local money = GetMoney() | |
226 local moneyText = money | |
227 local requiredSilver, requiredCopper | |
228 local requiredGold = (requiredMoney > 10000) and (floor(requiredMoney/10000)) or nil | |
229 if mod(requiredMoney, 10000) ~= 0 then | |
230 requiredSilver = (requiredMoney > 100) and (mod(requiredMoney, 10000) / 100) or nil | |
231 if mod(requiredMoney, 100) ~= 0 then | |
232 requiredCopper = mod(requiredMoney, 100) | |
233 end | |
234 end | |
235 | |
236 -- round the money value down | |
237 if requiredMoney > 9999 and not (requiredSilver or requiredCopper) then | |
238 moneyText = floor(money/10000) | |
239 elseif requiredMoney < 10000 and mod(requiredMoney,100) == 0 then | |
240 moneyText = floor(money/100) | |
241 end | |
242 | |
243 local text = moneyText | |
244 local index = #q.objectives + 1 | |
245 local finished = (GetMoney() >= requiredMoney) | |
246 | |
247 if not finished then | |
248 text = text .. ' / ' .. GetCoinTextureString(requiredMoney, 12) | |
249 else | |
250 text = '' .. GetCoinTextureString(requiredMoney, 12) | |
251 end | |
252 q.objectives[index] = { | |
253 index = index, | |
254 type = 'progressbar', | |
255 quantity = money, | |
256 requiredQuantity = requiredMoney, | |
257 text = text, | |
258 finished = finished | |
259 } | |
260 print(format(' #%d %s %s %s', index, 'money', text, tostring(finished))) | |
261 end | |
262 | |
263 | |
264 local link, icon, charges = GetQuestLogSpecialItemInfo(questIndex) | |
265 local start, duration, enable = GetQuestLogSpecialItemCooldown(questIndex) | |
266 if link or icon or charges then | |
267 q.specialItem = { | |
268 questID = questID, | |
269 questIndex = questIndex, | |
270 link = link, | |
271 charges = charges, | |
272 icon = icon, | |
273 start = start, | |
274 duration = duration, | |
275 enable = enable, | |
276 } | |
277 end | |
278 | |
279 if QuestHasPOIInfo(questID) then | |
280 local distance, onContinent = GetDistanceSqToQuest(questIndex) | |
281 if distance ~= nil and distance > 0 then | |
282 self.POI[questIndex] = { | |
283 questIndex = questIndex, | |
284 questID = questID, | |
285 distance = distance, | |
286 onContinent = onContinent | |
287 } | |
288 end | |
289 end | |
290 | |
291 | |
292 q.selected = (questID == GetSuperTrackedQuestID()) -- call directly so artifact data doesn't become an issue | |
293 self.WatchInfo[watchIndex] = q | |
294 self.LogInfo[questIndex] = q | |
295 print('- logIndex =', questIndex, 'title =', title) | |
296 for k,v in pairs(q) do | |
297 print('|cFFFFFF00'..k..'|r:', v) | |
298 end | |
299 return q | |
300 end | |
301 | |
302 Quest.GetClosest = function() | |
303 local minID, minTitle | |
304 local minDist = math.huge | |
305 local numQuests = GetNumQuestLogEntries() | |
306 for questIndex = 1, numQuests do | |
307 local distance, onContinent = GetDistanceSqToQuest(questIndex) | |
308 local title, level, _, _, _, _, _, _, questID = GetQuestLogTitle(questIndex) | |
309 if onContinent and distance < minDist then | |
310 minDist = distance | |
311 minTitle = title | |
312 minID = questID | |
313 end | |
314 end | |
315 | |
316 print('nearest quest is', minTitle, 'by', math.sqrt(minDist)) | |
317 return minID, minTitle, minDist | |
318 end | |
319 | |
320 Quest.OnTurnIn = function(self, questID, xp, money) | |
321 | |
322 end | |
323 | |
324 | |
325 Quest.Select = function(self) | |
326 | |
327 if self.info.isAutoComplete and self.info.isComplete then | |
328 ShowQuestComplete(self.info.questLogIndex) | |
329 else | |
330 SetSuperTrackedQuestID(self.info.questID) | |
331 end | |
332 end | |
333 | |
334 Quest.Link = function(self) | |
335 | |
336 local questLink = GetQuestLink(self.info.questLogIndex); | |
337 if ( questLink ) then | |
338 ChatEdit_InsertLink(questLink); | |
339 end | |
340 end | |
341 | |
342 Quest.Open = function(self) | |
343 | |
344 QuestMapFrame_OpenToQuestDetails(self.info.questID) | |
345 end | |
346 | |
347 Quest.Remove = function(self) | |
348 | |
349 print('removing', self.info.questLogIndex, 'from watcher') | |
350 RemoveQuestWatch(self.info.questLogIndex) | |
351 end |