annotate ObjectiveTracker/BonusObjectives.lua @ 29:adcd7c328d07

code collation cleaning
author Nenue
date Wed, 13 Apr 2016 21:53:24 -0400
parents c3aa94bc6be2
children 7583684becf4
rev   line source
Nenue@27 1 --- ${PACKAGE_NAME}
Nenue@27 2 -- @file-author@
Nenue@27 3 -- @project-revision@ @project-hash@
Nenue@27 4 -- @file-revision@ @file-hash@
Nenue@27 5 -- Created: 4/13/2016 7:48 PM
Nenue@27 6 local B = select(2,...).frame
Nenue@27 7 local T = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame')
Nenue@27 8 local Default, Quest = T.DefaultHandler, T.Quest
Nenue@27 9 local print = B.print('Tracker')
Nenue@27 10 local lprint = B.print('Line')
Nenue@29 11 local Bonus = T.Bonus
Nenue@27 12
Nenue@29 13 local UnitName, GetRealmName, GetQuestObjectiveInfo, GetTasksTable, GetTaskInfo = UnitName, GetRealmName, GetQuestObjectiveInfo, GetTasksTable, GetTaskInfo
Nenue@29 14 local GetMapNameByID, GetCurrentMapAreaID = GetMapNameByID, GetCurrentMapAreaID
Nenue@29 15 local tinsert, ipairs, pairs, tostring = tinsert, ipairs, pairs, tostring
Nenue@29 16 local GetNumQuestLogRewardCurrencies, GetQuestLogRewardCurrencyInfo = GetNumQuestLogRewardCurrencies, GetQuestLogRewardCurrencyInfo
Nenue@29 17 local GetNumQuestLogRewards, GetQuestLogRewardInfo = GetNumQuestLogRewards, GetQuestLogRewardInfo
Nenue@29 18 local GetQuestLogRewardMoney, GetMoneyString = GetQuestLogRewardMoney, GetMoneyString
Nenue@29 19 local GetQuestProgressBarPercent, PERCENTAGE_STRING, GetTime = GetQuestProgressBarPercent, PERCENTAGE_STRING, GetTime
Nenue@27 20
Nenue@29 21 local DoQuestRewards = function(t, questID)
Nenue@29 22 local rewards = {}
Nenue@29 23 t.numCurrencies = GetNumQuestLogRewardCurrencies(questID)
Nenue@29 24 for i = 1, t.numCurrencies do
Nenue@29 25 local name, texture, count = GetQuestLogRewardCurrencyInfo(i, questID)
Nenue@29 26 tinsert(rewards,{
Nenue@29 27 type = 'currency',
Nenue@29 28 index = i,
Nenue@29 29 name = name,
Nenue@29 30 texture = texture,
Nenue@29 31 count = count
Nenue@29 32 });
Nenue@29 33 end
Nenue@29 34 -- items
Nenue@29 35 t.numItems = GetNumQuestLogRewards(questID)
Nenue@29 36 for i = 1, t.numItems do
Nenue@29 37 local name, texture, count, quality, isUsable = GetQuestLogRewardInfo(i, questID)
Nenue@29 38 tinsert(rewards, {
Nenue@29 39 type = 'item',
Nenue@29 40 index = i ,
Nenue@29 41 name = name,
Nenue@29 42 texture = texture,
Nenue@29 43 count = count,
Nenue@29 44 quality = quality,
Nenue@29 45 isUsable = isUsable
Nenue@29 46 });
Nenue@29 47 end
Nenue@29 48 -- money
Nenue@29 49
Nenue@29 50 local money = GetQuestLogRewardMoney(questID)
Nenue@29 51 if ( money > 0 ) then
Nenue@29 52 tinsert(rewards, {
Nenue@29 53 type = 'money',
Nenue@29 54 name = GetMoneyString(money),
Nenue@29 55 texture = "Interface\\Icons\\inv_misc_coin_01",
Nenue@29 56 count = 0,
Nenue@29 57 });
Nenue@29 58 end
Nenue@29 59
Nenue@29 60 if #rewards >= 1 then
Nenue@29 61 t.rewardInfo = rewards
Nenue@29 62 end
Nenue@29 63 end
Nenue@29 64
Nenue@29 65 --- Returns a tasks table modified to include recently completed objectives
Nenue@29 66 local InternalGetTasksTable = function()
Nenue@29 67 local savedTasks = T.Conf.TasksLog
Nenue@29 68 local char = UnitName("player")
Nenue@29 69 local realm = GetRealmName()
Nenue@29 70 local tasks = GetTasksTable()
Nenue@29 71
Nenue@29 72 for questID, data in pairs(Bonus.Info) do
Nenue@29 73
Nenue@29 74 print(' -- questID:', questID, #data.objectives)
Nenue@29 75 for i, o in ipairs(data.objectives) do
Nenue@29 76 print(' --', i, o.text)
Nenue@29 77 end
Nenue@29 78
Nenue@29 79 end
Nenue@29 80
Nenue@29 81
Nenue@29 82 for questID, data in pairs(savedTasks) do
Nenue@29 83 if questID > 0 then
Nenue@29 84 local found = false
Nenue@29 85 for i = 1, #tasks do
Nenue@29 86 if tasks[i] == questID then
Nenue@29 87 found = true
Nenue@29 88 break
Nenue@29 89 end
Nenue@29 90 end
Nenue@29 91 -- if it's not part of the current table, then try to insert it where it was last found
Nenue@29 92 if not found then
Nenue@29 93 if data.watchIndex < #tasks then
Nenue@29 94 tinsert(tasks, data.watchIndex, data)
Nenue@29 95 else
Nenue@29 96 tinsert(tasks, data)
Nenue@29 97 end
Nenue@29 98 end
Nenue@29 99 end
Nenue@29 100 end
Nenue@29 101 return tasks
Nenue@29 102 end
Nenue@29 103
Nenue@29 104 --- Returns an entry from the composed tasks table if possible, otherwise makes an API pull
Nenue@29 105 local InternalGetTaskInfo = function(questID)
Nenue@29 106 local completedTasks = T.Conf.TasksLog
Nenue@29 107 if completedTasks[questID] then
Nenue@29 108 return true, true, #completedTasks[questID].objectives
Nenue@29 109 else
Nenue@29 110 return GetTaskInfo(questID)
Nenue@29 111 end
Nenue@29 112 end
Nenue@29 113
Nenue@29 114 --- Same as above but for the objective entries
Nenue@29 115 local InternalGetQuestObjectiveInfo = function(questID, objectiveIndex)
Nenue@29 116 local completedTasks = T.Conf.TasksLog
Nenue@29 117 if ( completedTasks[questID] ) then
Nenue@29 118 print('using internal data')
Nenue@29 119 return completedTasks[questID].objectives[objectiveIndex], completedTasks[questID].objectiveType, true;
Nenue@29 120 else
Nenue@29 121 return GetQuestObjectiveInfo(questID, objectiveIndex, false);
Nenue@29 122 end
Nenue@29 123 end
Nenue@29 124
Nenue@29 125 --- end redundant copy of silliness
Nenue@29 126 ------------------------------------------------------------------------------------------
Nenue@29 127
Nenue@29 128 Bonus.Completed = {}
Nenue@29 129 Bonus.POI = {}
Nenue@29 130 Bonus.Scenario = {}
Nenue@29 131 Bonus.QuestBlock = {}
Nenue@29 132 Bonus.WatchInfo = {}
Nenue@29 133 function Bonus:GetNumWatched ()
Nenue@29 134 print(self.name, self)
Nenue@29 135
Nenue@29 136 local tasks = InternalGetTasksTable()
Nenue@29 137 local numWatched = 0
Nenue@29 138 local numAll = 0
Nenue@29 139 self.WatchInfo = {}
Nenue@29 140 print('|cFFFFFF00Bonus.GetNumWatched()|r', #tasks)
Nenue@29 141 print(' TasksTable pull:')
Nenue@29 142 for i, questID in ipairs(tasks) do
Nenue@29 143 local isInArea, isOnMap, numObjectives = InternalGetTaskInfo(questID)
Nenue@29 144 local existingTask = self.QuestBlock[questID]
Nenue@29 145 local displayObjectiveHeader = false;
Nenue@29 146 local test = (isInArea or (isOnMap and existingTask))
Nenue@29 147 --local test = true
Nenue@29 148 if test then
Nenue@29 149 self.Info[questID] = self.Info[questID] or {}
Nenue@29 150
Nenue@29 151 local t = self.Info[questID]
Nenue@29 152 self.WatchInfo[i] = t
Nenue@29 153 t.isInArea = isInArea
Nenue@29 154 t.isOnMap = isOnMap
Nenue@29 155 t.existingTask = existingTask
Nenue@29 156 t.questID = questID
Nenue@29 157 t.objectives = {}
Nenue@29 158 t.taskIndex = i
Nenue@29 159
Nenue@29 160
Nenue@29 161 DoQuestRewards(t, questID)
Nenue@29 162
Nenue@29 163 local taskTitle
Nenue@29 164 local taskFinished = true;
Nenue@29 165 for objectiveIndex = 1, numObjectives do
Nenue@29 166 local text, objectiveType, finished, displayAsObjective = InternalGetQuestObjectiveInfo(questID, objectiveIndex, false);
Nenue@29 167 displayObjectiveHeader = displayObjectiveHeader or displayAsObjective;
Nenue@29 168 if not taskTitle then
Nenue@29 169 if objectiveType == 'progressbar' and not text:match('^%d%+\\%d+') then
Nenue@29 170 taskTitle = text
Nenue@29 171 text = ''
Nenue@29 172 end
Nenue@29 173 end
Nenue@29 174
Nenue@29 175
Nenue@29 176 print(' --', text, objectiveType, finished, displayAsObjective)
Nenue@29 177 t.objectives[objectiveIndex] = t.objectives[objectiveIndex] or {}
Nenue@29 178 local o = t.objectives[objectiveIndex]
Nenue@29 179
Nenue@29 180 o.objectiveIndex = objectiveIndex
Nenue@29 181 o.text = text
Nenue@29 182 o.objectiveType = objectiveType
Nenue@29 183 o.finished = finished
Nenue@29 184 o.displayAsObjective = displayAsObjective
Nenue@29 185 print(' |cFF00FF88*', objectiveIndex, text)
Nenue@29 186 end
Nenue@29 187
Nenue@29 188 -- didn't get a name from progress bar? what about area name
Nenue@29 189 if not taskTitle then
Nenue@29 190 if isInArea then
Nenue@29 191 taskTitle = GetMapNameByID(GetCurrentMapAreaID())
Nenue@29 192 end
Nenue@29 193 end
Nenue@29 194 t.title = taskTitle
Nenue@29 195 end
Nenue@29 196
Nenue@29 197 print (' |cFF00FF88#', i, 'questID', questID, 'inArea', isInArea, 'onMap', isOnMap, 'existing', (existingTask and 'Y' or 'N'), (test and '|cFF00FF00show|r' or '|cFFFF0088hide|r'))
Nenue@29 198 end
Nenue@29 199
Nenue@29 200
Nenue@29 201 self.numAll = #tasks
Nenue@29 202 self.numWatched = #self.WatchInfo
Nenue@29 203 print(' stats:', self.numAll, 'active tasks,', self.numWatched, 'nearby or animating')
Nenue@29 204 --return #tasks
Nenue@29 205 return #self.WatchInfo
Nenue@29 206 end
Nenue@29 207
Nenue@29 208 --- info cleanup done when turn-ins are detected
Nenue@29 209 Bonus.OnTurnIn = function(self, questID, xp, money)
Nenue@29 210
Nenue@29 211 if #self.info.rewardInfo >= 1 then
Nenue@29 212 for i, reward in ipairs(self.info.rewardInfo) do
Nenue@29 213 --[[
Nenue@29 214 type = 'item',
Nenue@29 215 index = i ,
Nenue@29 216 name = name,
Nenue@29 217 texture = texture,
Nenue@29 218 count = count,
Nenue@29 219 quality = quality,
Nenue@29 220 isUsable = isUsable
Nenue@29 221 ]]
Nenue@29 222 print(' reward ', i, ' ', reward.type, reward.name, reward.count)
Nenue@29 223
Nenue@29 224 end
Nenue@29 225 end
Nenue@29 226
Nenue@29 227 print('|cFFFF8800'..self.name..':OnTurnIn call', questID, xp, money)
Nenue@29 228 local savedTasks = B.Conf.TasksLog
Nenue@29 229
Nenue@29 230 self.Info[questID].completedTime = GetTime()
Nenue@29 231 self.Info[questID].animate = true
Nenue@29 232 T.SetAnimate(self.watchReasonModule)
Nenue@29 233 savedTasks[questID] = self.Info[questID]
Nenue@29 234 end
Nenue@29 235
Nenue@29 236 Bonus.GetInfo = function(self, taskIndex)
Nenue@29 237 print(self.name, self)
Nenue@29 238 return self.WatchInfo[taskIndex]
Nenue@29 239 end
Nenue@29 240
Nenue@29 241
Nenue@29 242
Nenue@29 243 --- Update hooks
Nenue@27 244 Bonus.UpdateObjectives = function(handler, block)
Nenue@27 245 Default.UpdateObjectives(handler, block)
Nenue@27 246 end
Nenue@27 247
Nenue@27 248 Bonus.UpdateLine = function(handler, block, line, data)
Nenue@27 249 local info = block.info
Nenue@27 250 local print = lprint
Nenue@27 251
Nenue@27 252 line.displayColor = 'FFFFFF'
Nenue@27 253 line.displayText = data.text
Nenue@27 254 line.progress = 0
Nenue@27 255 print(' ', data.objectiveIndex,'|cFFFF0088-|r', data.objectiveType, data.text)
Nenue@27 256 if data.objectiveType == 'progressbar' then
Nenue@27 257 line.widgetType = 'ProgressBar'
Nenue@27 258 print(' |cFFFF44DDpercent='..tostring(GetQuestProgressBarPercent(info.questID)))
Nenue@27 259 data.value = GetQuestProgressBarPercent(info.questID) or 0
Nenue@27 260 data.maxValue = 100
Nenue@27 261 if data.value >= data.maxValue then
Nenue@27 262 line.progress = 1
Nenue@27 263 elseif data.value > 0 then
Nenue@27 264 line.progress = 2
Nenue@27 265 end
Nenue@27 266 line.format = PERCENTAGE_STRING
Nenue@27 267 local widget = T.SetWidget(line, data, 'ProgressBar', info.questID..'-'..data.objectiveIndex)
Nenue@27 268 print(' |cFFFF0022** text:|r', data.text, '|cFFFF0022value:|r', data.value, '|cFFFF0022max:|r', data.maxValue)
Nenue@27 269 widget:SetPoint('TOP', line, 'TOP', 0, 0)
Nenue@27 270
Nenue@27 271 line.widget = widget
Nenue@27 272 line.height = widget.height
Nenue@27 273 else
Nenue@27 274 line.displayText = data.text
Nenue@27 275 line.widget = nil
Nenue@27 276 end
Nenue@27 277 return line
Nenue@27 278 end
Nenue@27 279
Nenue@27 280 Bonus.Select = function(self)
Nenue@27 281 Bonus:OnTurnIn(self.info.questID)
Nenue@27 282 end
Nenue@27 283 Bonus.Remove = function(self)
Nenue@27 284
Nenue@27 285 end