comparison ObjectiveTracker/ObjectiveInfo.lua @ 23:e837384ac363

Separating objective tracker module
author Nenue
date Sun, 10 Apr 2016 04:35:32 -0400
parents ObjectiveInfo.lua@9b3fa734abff
children 4b3da1b221de
comparison
equal deleted inserted replaced
22:9b3fa734abff 23:e837384ac363
1 local B = select(2,...).frame
2 local wipe, pairs, ipairs, min, max, unpack = table.wipe, pairs, ipairs, min, max, unpack
3 local tinsert, tostring, format, mod = tinsert, tostring, format, mod
4 local GetQuestTagInfo, GetQuestLogTitle = GetQuestTagInfo, GetQuestLogTitle
5 local GetNumQuestLogEntries, GetNumQuestWatches, GetQuestLogCompletionText, IsQuestWatched, IsQuestHardWatched, GetQuestLogSpecialItemInfo, GetQuestLogSpecialItemCooldown = GetNumQuestLogEntries, GetNumQuestWatches, GetQuestLogCompletionText, IsQuestWatched, IsQuestHardWatched, GetQuestLogSpecialItemInfo, GetQuestLogSpecialItemCooldown
6 local GetNumAutoQuestPopUps, GetAutoQuestPopUp, GetTasksTable, GetNumQuestLogTasks, GetTaskInfo, GetQuestObjectiveInfo = GetNumAutoQuestPopUps, GetAutoQuestPopUp, GetTasksTable, GetNumQuestLogTasks, GetTaskInfo, GetQuestObjectiveInfo
7 local GetNumQuestLogRewardCurrencies, GetQuestLogRewardCurrencyInfo, GetNumQuestLogRewards, GetQuestLogRewardInfo, GetQuestLogRewardMoney, GetMoneyString = GetNumQuestLogRewardCurrencies, GetQuestLogRewardCurrencyInfo, GetNumQuestLogRewards, GetQuestLogRewardInfo, GetQuestLogRewardMoney, GetMoneyString
8 local GetNumQuestLeaderBoards, GetAchievementNumCriteria, GetQuestLogLeaderBoard, GetAchievementCriteriaInfo = GetNumQuestLeaderBoards, GetAchievementNumCriteria, GetQuestLogLeaderBoard, GetAchievementCriteriaInfo
9 local GetQuestWatchIndex, GetQuestLogIndexByID, GetSuperTrackedQuestID, SetSuperTrackedQuestID, GetQuestWatchInfo = GetQuestWatchIndex, GetQuestLogIndexByID, GetSuperTrackedQuestID, SetSuperTrackedQuestID, GetQuestWatchInfo
10 local QuestHasPOIInfo, GetDistanceSqToQuest, GetQuestFactionGroup = QuestHasPOIInfo, GetDistanceSqToQuest, GetQuestFactionGroup
11 local GetTrackedAchievements, GetNumTrackedAchievements, GetAchievementInfo = GetTrackedAchievements, GetNumTrackedAchievements, GetAchievementInfo
12 local GetMoney, floor = GetMoney, floor
13 local T = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame')
14 local print = B.print('Info')
15 local QUEST_TAG_DUNGEON = QUEST_TAG_DUNGEON
16 local QUEST_TAG_GROUP = QUEST_TAG_GROUP
17 local QUEST_TAG_ACCOUNT = QUEST_TAG_ACCOUNT
18 local QUEST_TAG_TCOORDS = QUEST_TAG_TCOORDS
19 local LE_QUEST_FREQUENCY_DAILY = LE_QUEST_FREQUENCY_DAILY
20 local LE_QUEST_FREQUENCY_WEEKLY = LE_QUEST_FREQUENCY_WEEKLY
21 local FACTION_ALLIANCE, LE_QUEST_FACTION_HORDE, FACTION_HORDE, LE_QUEST_FACTION_HORDE = FACTION_ALLIANCE, LE_QUEST_FACTION_HORDE, FACTION_HORDE, LE_QUEST_FACTION_HORDE
22
23 local Tracker, Bonus, AutoQuest, Quest, Cheevs = T.DefaultTracker, T.Bonus, T.AutoQuest, T.Quest, T.Cheevs
24 --------------------------------------------------------------------
25 --- Tracker-specific data retrieval functions
26 --------------------------------------------------------------------
27
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
73
74 -----------------------------
75 --- 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(questIndex)
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 -----------------------------
111 --- BONUS OBJECTIVE
112 -- 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.
114 -- Blizzard deal with this fact by caching any task data collected during session and masking out whatever gets completed.
115 -- For the addon's module structure to work, GetNumWatched method also invokes a tasks table scan.
116 -- That composes the table searched by GetInfo().
117
118 ------------------------------------------------------------------------------------------
119 --- These functions are copied from Blizzard_BonusObjectiveTracker.lua;
120 -- It's kind of dumb, but this avoids the risk of code taint.
121
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 print('|cFFFF8800'..self.name..':OnTurnIn call', questID, xp, money)
269 local savedTasks = B.Conf.TasksLog
270
271 self.Info[questID].completedTime = GetTime()
272 self.Info[questID].animate = true
273 T.SetAnimate(self.watchReason)
274 savedTasks[questID] = self.Info[questID]
275 end
276
277 Bonus.GetInfo = function(self, taskIndex)
278 print(self.name, self)
279 return self.WatchInfo[taskIndex]
280 end
281
282
283
284 Cheevs.GetNumWatched = function(self)
285 print('|cFF00FF00' .. GetTime())
286 Cheevs.trackedCheevs = {GetTrackedAchievements()}
287 return GetNumTrackedAchievements()
288 end
289 Cheevs.GetInfo = function(self, index)
290 local cheevID = Cheevs.trackedCheevs[index]
291 local id, name, points, completed, month, day, year, description, flags, icon, rewardText, isGuildAch, wasEarnedByMe, earnedBy = GetAchievementInfo(cheevID)
292
293 self.Info[cheevID] = {}
294 local c = self.Info[cheevID]
295 c.type = 'Cheevs'
296 c.watchIndex = index
297 c.cheevID = cheevID
298 c.title = name
299 c.points, c.completed, c.month, c.day, c.year, c.description, c.flags, c.icon, c.rewardText, c.isGuildAch, c.wasEarnedByMe, c.earnedBy =
300 points, completed, month, day, year, description, flags, icon, rewardText, isGuildAch, wasEarnedByMe, earnedBy
301 c.numObjectives = GetAchievementNumCriteria(cheevID)
302 c.objectives = {}
303 for i = 1, c.numObjectives do
304 local description, type, completed, quantity, requiredQuantity, characterName, flags, assetID, quantityString, criteriaID = GetAchievementCriteriaInfo(cheevID, i)
305 c.objectives[i] = {
306 objectiveIndex = i,
307 cheevID = cheevID,
308 text = description,
309 type = type,
310 finished = completed,
311 value = quantity,
312 maxValue = requiredQuantity,
313 characterName = characterName,
314 flags = flags,
315 assetID = assetID,
316 quantityString = quantityString,
317 criteriaID = criteriaID,
318 }
319 end
320 print('Cheevs.|cFF0088FFGetInfo|r('..index..')', 'obj:', GetAchievementNumCriteria(cheevID), name, description)
321
322 self.WatchInfo[index] = c
323 return self.Info[cheevID]
324 end