annotate ObjectiveTracker/Data.lua @ 28:c33c17dd97e7

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