Mercurial > wow > buffalo2
comparison ObjectiveTracker/Data.lua @ 29:adcd7c328d07
code collation cleaning
author | Nenue |
---|---|
date | Wed, 13 Apr 2016 21:53:24 -0400 |
parents | c33c17dd97e7 |
children |
comparison
equal
deleted
inserted
replaced
28:c33c17dd97e7 | 29:adcd7c328d07 |
---|---|
24 -------------------------------------------------------------------- | 24 -------------------------------------------------------------------- |
25 --- Tracker-specific data retrieval functions | 25 --- Tracker-specific data retrieval functions |
26 -------------------------------------------------------------------- | 26 -------------------------------------------------------------------- |
27 | 27 |
28 | 28 |
29 local DoQuestRewards= function(t, questID) | |
30 local rewards = {} | |
31 t.numCurrencies = GetNumQuestLogRewardCurrencies(questID) | |
32 for i = 1, t.numCurrencies do | |
33 local name, texture, count = GetQuestLogRewardCurrencyInfo(i, questID) | |
34 tinsert(rewards,{ | |
35 type = 'currency', | |
36 index = i, | |
37 name = name, | |
38 texture = texture, | |
39 count = count | |
40 }); | |
41 end | |
42 -- items | |
43 t.numItems = GetNumQuestLogRewards(questID) | |
44 for i = 1, t.numItems do | |
45 local name, texture, count, quality, isUsable = GetQuestLogRewardInfo(i, questID) | |
46 tinsert(rewards, { | |
47 type = 'item', | |
48 index = i , | |
49 name = name, | |
50 texture = texture, | |
51 count = count, | |
52 quality = quality, | |
53 isUsable = isUsable | |
54 }); | |
55 end | |
56 -- money | |
57 | |
58 local money = GetQuestLogRewardMoney(questID) | |
59 if ( money > 0 ) then | |
60 tinsert(rewards, { | |
61 type = 'money', | |
62 name = GetMoneyString(money), | |
63 texture = "Interface\\Icons\\inv_misc_coin_01", | |
64 count = 0, | |
65 }); | |
66 end | |
67 | |
68 if #rewards >= 1 then | |
69 t.rewardInfo = rewards | |
70 end | |
71 end | |
72 | 29 |
73 | 30 |
74 ----------------------------- | 31 ----------------------------- |
75 --- AUTO_QUEST | 32 --- AUTO_QUEST |
76 AutoQuest.LogInfo = {} | |
77 AutoQuest.LogBlock = {} | |
78 AutoQuest.QuestBlock = {} | |
79 AutoQuest.WatchBlock = {} | |
80 function AutoQuest:GetNumWatched () | |
81 print(self.name, self) | |
82 Quest:GetNumWatched() | |
83 self.numWatched = GetNumAutoQuestPopUps() | |
84 | |
85 return self.numWatched | |
86 end | |
87 AutoQuest.GetInfo = function(self, popupIndex) | |
88 | |
89 | |
90 local questID, type = GetAutoQuestPopUp(popupIndex) | |
91 local questLogIndex = GetQuestLogIndexByID(questID) | |
92 local title, level, suggestedGroup, isHeader, isCollapsed, isComplete, frequency, questID, startEvent, displayQuestID, isOnMap, hasLocalPOI, isTask, isStory = GetQuestLogTitle(questLogIndex) | |
93 | |
94 self.Info[questID] = self.Info[questID] or {} | |
95 local popup = self.Info[questID] | |
96 popup.title = title | |
97 popup.description = type | |
98 popup.popupType = type | |
99 popup.questID = questID | |
100 popup.questLogIndex = questLogIndex | |
101 popup.popupIndex = popupIndex | |
102 | |
103 self.Info[questID] = popup | |
104 self.WatchInfo[popupIndex] = popup | |
105 | |
106 | |
107 return self.Info[questID] | |
108 end | |
109 | |
110 ----------------------------- | 33 ----------------------------- |
111 --- BONUS OBJECTIVE | 34 --- BONUS OBJECTIVE |
112 -- The default UI pops them up as you enter their relevant areas, but the data is actually available at all times. | 35 -- The default UI pops them up as you enter their relevant areas, but the data is actually available at all times. |
113 -- The only requirement is that you've been to said area and progressed any of the objectives. | 36 -- The only requirement is that you've been to said area and progressed any of the objectives. |
114 -- Blizzard deal with this fact by caching any task data collected during session and masking out whatever gets completed. | 37 -- Blizzard deal with this fact by caching any task data collected during session and masking out whatever gets completed. |
117 | 40 |
118 ------------------------------------------------------------------------------------------ | 41 ------------------------------------------------------------------------------------------ |
119 --- These functions are copied from Blizzard_BonusObjectiveTracker.lua; | 42 --- These functions are copied from Blizzard_BonusObjectiveTracker.lua; |
120 -- It's kind of dumb, but this avoids the risk of code taint. | 43 -- It's kind of dumb, but this avoids the risk of code taint. |
121 | 44 |
122 --- Returns a tasks table modified to include recently completed objectives | |
123 local UnitName, GetRealmName = UnitName, GetRealmName | |
124 local InternalGetTasksTable = function() | |
125 local savedTasks = T.Conf.TasksLog | |
126 local char = UnitName("player") | |
127 local realm = GetRealmName() | |
128 local tasks = GetTasksTable() | |
129 | |
130 for questID, data in pairs(Bonus.Info) do | |
131 | |
132 print(' -- questID:', questID, #data.objectives) | |
133 for i, o in ipairs(data.objectives) do | |
134 print(' --', i, o.text) | |
135 end | |
136 | |
137 end | |
138 | |
139 | |
140 for questID, data in pairs(savedTasks) do | |
141 if questID > 0 then | |
142 local found = false | |
143 for i = 1, #tasks do | |
144 if tasks[i] == questID then | |
145 found = true | |
146 break | |
147 end | |
148 end | |
149 -- if it's not part of the current table, then try to insert it where it was last found | |
150 if not found then | |
151 if data.watchIndex < #tasks then | |
152 tinsert(tasks, data.watchIndex, data) | |
153 else | |
154 tinsert(tasks, data) | |
155 end | |
156 end | |
157 end | |
158 end | |
159 return tasks | |
160 end | |
161 | |
162 --- Returns an entry from the composed tasks table if possible, otherwise makes an API pull | |
163 local InternalGetTaskInfo = function(questID) | |
164 local completedTasks = T.Conf.TasksLog | |
165 if completedTasks[questID] then | |
166 return true, true, #completedTasks[questID].objectives | |
167 else | |
168 return GetTaskInfo(questID) | |
169 end | |
170 end | |
171 | |
172 --- Same as above but for the objective entries | |
173 local InternalGetQuestObjectiveInfo = function(questID, objectiveIndex) | |
174 local completedTasks = T.Conf.TasksLog | |
175 if ( completedTasks[questID] ) then | |
176 print('using internal data') | |
177 return completedTasks[questID].objectives[objectiveIndex], completedTasks[questID].objectiveType, true; | |
178 else | |
179 return GetQuestObjectiveInfo(questID, objectiveIndex, false); | |
180 end | |
181 end | |
182 | |
183 --- end redundant copy of silliness | |
184 ------------------------------------------------------------------------------------------ | |
185 | |
186 Bonus.Completed = {} | |
187 Bonus.POI = {} | |
188 Bonus.Scenario = {} | |
189 Bonus.QuestBlock = {} | |
190 Bonus.WatchInfo = {} | |
191 function Bonus:GetNumWatched () | |
192 print(self.name, self) | |
193 | |
194 local tasks = InternalGetTasksTable() | |
195 local numWatched = 0 | |
196 local numAll = 0 | |
197 self.WatchInfo = {} | |
198 print('|cFFFFFF00Bonus.GetNumWatched()|r', #tasks) | |
199 print(' TasksTable pull:') | |
200 for i, questID in ipairs(tasks) do | |
201 local isInArea, isOnMap, numObjectives = InternalGetTaskInfo(questID) | |
202 local existingTask = self.QuestBlock[questID] | |
203 local displayObjectiveHeader = false; | |
204 local test = (isInArea or (isOnMap and existingTask)) | |
205 --local test = true | |
206 if test then | |
207 self.Info[questID] = self.Info[questID] or {} | |
208 | |
209 local t = self.Info[questID] | |
210 self.WatchInfo[i] = t | |
211 t.isInArea = isInArea | |
212 t.isOnMap = isOnMap | |
213 t.existingTask = existingTask | |
214 t.questID = questID | |
215 t.objectives = {} | |
216 t.taskIndex = i | |
217 | |
218 | |
219 DoQuestRewards(t, questID) | |
220 | |
221 local taskTitle | |
222 local taskFinished = true; | |
223 for objectiveIndex = 1, numObjectives do | |
224 local text, objectiveType, finished, displayAsObjective = InternalGetQuestObjectiveInfo(questID, objectiveIndex, false); | |
225 displayObjectiveHeader = displayObjectiveHeader or displayAsObjective; | |
226 if not taskTitle then | |
227 if objectiveType == 'progressbar' and not text:match('^%d%+\\%d+') then | |
228 taskTitle = text | |
229 text = '' | |
230 end | |
231 end | |
232 | |
233 | |
234 print(' --', text, objectiveType, finished, displayAsObjective) | |
235 t.objectives[objectiveIndex] = t.objectives[objectiveIndex] or {} | |
236 local o = t.objectives[objectiveIndex] | |
237 | |
238 o.objectiveIndex = objectiveIndex | |
239 o.text = text | |
240 o.objectiveType = objectiveType | |
241 o.finished = finished | |
242 o.displayAsObjective = displayAsObjective | |
243 print(' |cFF00FF88*', objectiveIndex, text) | |
244 end | |
245 | |
246 -- didn't get a name from progress bar? what about area name | |
247 if not taskTitle then | |
248 if isInArea then | |
249 taskTitle = GetMapNameByID(GetCurrentMapAreaID()) | |
250 end | |
251 end | |
252 t.title = taskTitle | |
253 end | |
254 | |
255 print (' |cFF00FF88#', i, 'questID', questID, 'inArea', isInArea, 'onMap', isOnMap, 'existing', (existingTask and 'Y' or 'N'), (test and '|cFF00FF00show|r' or '|cFFFF0088hide|r')) | |
256 end | |
257 | |
258 | |
259 self.numAll = #tasks | |
260 self.numWatched = #self.WatchInfo | |
261 print(' stats:', self.numAll, 'active tasks,', self.numWatched, 'nearby or animating') | |
262 --return #tasks | |
263 return #self.WatchInfo | |
264 end | |
265 | |
266 --- info cleanup done when turn-ins are detected | |
267 Bonus.OnTurnIn = function(self, questID, xp, money) | |
268 | |
269 if #self.info.rewardInfo >= 1 then | |
270 for i, reward in ipairs(self.info.rewardInfo) do | |
271 --[[ | |
272 type = 'item', | |
273 index = i , | |
274 name = name, | |
275 texture = texture, | |
276 count = count, | |
277 quality = quality, | |
278 isUsable = isUsable | |
279 ]] | |
280 print(' reward ', i, ' ', reward.type, reward.name, reward.count) | |
281 | |
282 end | |
283 end | |
284 | |
285 print('|cFFFF8800'..self.name..':OnTurnIn call', questID, xp, money) | |
286 local savedTasks = B.Conf.TasksLog | |
287 | |
288 self.Info[questID].completedTime = GetTime() | |
289 self.Info[questID].animate = true | |
290 T.SetAnimate(self.watchReasonModule) | |
291 savedTasks[questID] = self.Info[questID] | |
292 end | |
293 | |
294 Bonus.GetInfo = function(self, taskIndex) | |
295 print(self.name, self) | |
296 return self.WatchInfo[taskIndex] | |
297 end | |
298 | |
299 | |
300 | |
301 Cheevs.GetNumWatched = function(self) | |
302 print('|cFF00FF00' .. GetTime()) | |
303 Cheevs.trackedCheevs = {GetTrackedAchievements()} | |
304 return GetNumTrackedAchievements() | |
305 end | |
306 Cheevs.GetInfo = function(self, index) | |
307 local cheevID = Cheevs.trackedCheevs[index] | |
308 local id, name, points, completed, month, day, year, description, flags, icon, rewardText, isGuildAch, wasEarnedByMe, earnedBy = GetAchievementInfo(cheevID) | |
309 | |
310 self.Info[cheevID] = {} | |
311 local c = self.Info[cheevID] | |
312 c.type = 'Cheevs' | |
313 c.watchIndex = index | |
314 c.cheevID = cheevID | |
315 c.title = name | |
316 c.points, c.completed, c.month, c.day, c.year, c.description, c.flags, c.icon, c.rewardText, c.isGuildAch, c.wasEarnedByMe, c.earnedBy = | |
317 points, completed, month, day, year, description, flags, icon, rewardText, isGuildAch, wasEarnedByMe, earnedBy | |
318 c.numObjectives = GetAchievementNumCriteria(cheevID) | |
319 c.objectives = {} | |
320 for i = 1, c.numObjectives do | |
321 local description, type, completed, quantity, requiredQuantity, characterName, flags, assetID, quantityString, criteriaID = GetAchievementCriteriaInfo(cheevID, i) | |
322 c.objectives[i] = { | |
323 objectiveIndex = i, | |
324 cheevID = cheevID, | |
325 text = description, | |
326 type = type, | |
327 finished = completed, | |
328 value = quantity, | |
329 maxValue = requiredQuantity, | |
330 characterName = characterName, | |
331 flags = flags, | |
332 assetID = assetID, | |
333 quantityString = quantityString, | |
334 criteriaID = criteriaID, | |
335 } | |
336 end | |
337 print('Cheevs.|cFF0088FFGetInfo|r('..index..')', 'obj:', GetAchievementNumCriteria(cheevID), name, description) | |
338 | |
339 self.WatchInfo[index] = c | |
340 return self.Info[cheevID] | |
341 end |