annotate ObjectiveTracker/BonusObjectives.lua @ 33:64f2a9bbea79

- implementing structural revisions in bonus objectives - prevent instances of nil arithmetic - decide on where to keep style values - start widgets with dummy values for operability
author Nenue
date Fri, 15 Apr 2016 17:01:06 -0400
parents a3afe6c3771e
children 9856ebc63fa4
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@33 11 local iprint = B.print('Info')
Nenue@29 12 local Bonus = T.Bonus
Nenue@27 13
Nenue@29 14 local UnitName, GetRealmName, GetQuestObjectiveInfo, GetTasksTable, GetTaskInfo = UnitName, GetRealmName, GetQuestObjectiveInfo, GetTasksTable, GetTaskInfo
Nenue@29 15 local GetMapNameByID, GetCurrentMapAreaID = GetMapNameByID, GetCurrentMapAreaID
Nenue@29 16 local tinsert, ipairs, pairs, tostring = tinsert, ipairs, pairs, tostring
Nenue@29 17 local GetQuestProgressBarPercent, PERCENTAGE_STRING, GetTime = GetQuestProgressBarPercent, PERCENTAGE_STRING, GetTime
Nenue@33 18 local STICKY_TASKS = true
Nenue@29 19
Nenue@29 20 --- Returns a tasks table modified to include recently completed objectives
Nenue@29 21 local InternalGetTasksTable = function()
Nenue@29 22 local savedTasks = T.Conf.TasksLog
Nenue@29 23 local char = UnitName("player")
Nenue@29 24 local realm = GetRealmName()
Nenue@29 25 local tasks = GetTasksTable()
Nenue@29 26
Nenue@29 27 for questID, data in pairs(Bonus.Info) do
Nenue@29 28
Nenue@29 29 print(' -- questID:', questID, #data.objectives)
Nenue@29 30 for i, o in ipairs(data.objectives) do
Nenue@29 31 print(' --', i, o.text)
Nenue@29 32 end
Nenue@29 33
Nenue@29 34 end
Nenue@29 35
Nenue@29 36
Nenue@29 37 for questID, data in pairs(savedTasks) do
Nenue@29 38 if questID > 0 then
Nenue@29 39 local found = false
Nenue@29 40 for i = 1, #tasks do
Nenue@29 41 if tasks[i] == questID then
Nenue@29 42 found = true
Nenue@29 43 break
Nenue@29 44 end
Nenue@29 45 end
Nenue@29 46 -- if it's not part of the current table, then try to insert it where it was last found
Nenue@29 47 if not found then
Nenue@29 48 if data.watchIndex < #tasks then
Nenue@29 49 tinsert(tasks, data.watchIndex, data)
Nenue@29 50 else
Nenue@29 51 tinsert(tasks, data)
Nenue@29 52 end
Nenue@29 53 end
Nenue@29 54 end
Nenue@29 55 end
Nenue@29 56 return tasks
Nenue@29 57 end
Nenue@29 58
Nenue@29 59 --- Returns an entry from the composed tasks table if possible, otherwise makes an API pull
Nenue@29 60 local InternalGetTaskInfo = function(questID)
Nenue@29 61 local completedTasks = T.Conf.TasksLog
Nenue@29 62 if completedTasks[questID] then
Nenue@29 63 return true, true, #completedTasks[questID].objectives
Nenue@29 64 else
Nenue@29 65 return GetTaskInfo(questID)
Nenue@29 66 end
Nenue@29 67 end
Nenue@29 68
Nenue@29 69 --- Same as above but for the objective entries
Nenue@29 70 local InternalGetQuestObjectiveInfo = function(questID, objectiveIndex)
Nenue@29 71 local completedTasks = T.Conf.TasksLog
Nenue@29 72 if ( completedTasks[questID] ) then
Nenue@29 73 print('using internal data')
Nenue@29 74 return completedTasks[questID].objectives[objectiveIndex], completedTasks[questID].objectiveType, true;
Nenue@29 75 else
Nenue@29 76 return GetQuestObjectiveInfo(questID, objectiveIndex, false);
Nenue@29 77 end
Nenue@29 78 end
Nenue@29 79
Nenue@29 80 --- end redundant copy of silliness
Nenue@29 81 ------------------------------------------------------------------------------------------
Nenue@29 82
Nenue@29 83 Bonus.Completed = {}
Nenue@29 84 Bonus.POI = {}
Nenue@29 85 Bonus.Scenario = {}
Nenue@29 86 Bonus.QuestBlock = {}
Nenue@29 87 Bonus.WatchInfo = {}
Nenue@29 88 function Bonus:GetNumWatched ()
Nenue@33 89 local print = iprint
Nenue@29 90 print(self.name, self)
Nenue@29 91
Nenue@29 92 local tasks = InternalGetTasksTable()
Nenue@29 93 local numWatched = 0
Nenue@29 94 local numAll = 0
Nenue@33 95 local existingTasks = {}
Nenue@29 96 self.WatchInfo = {}
Nenue@29 97 print('|cFFFFFF00Bonus.GetNumWatched()|r', #tasks)
Nenue@29 98 print(' TasksTable pull:')
Nenue@29 99 for i, questID in ipairs(tasks) do
Nenue@29 100 local isInArea, isOnMap, numObjectives = InternalGetTaskInfo(questID)
Nenue@29 101 local existingTask = self.QuestBlock[questID]
Nenue@29 102 local displayObjectiveHeader = false;
Nenue@29 103 local test = (isInArea or (isOnMap and existingTask))
Nenue@29 104 --local test = true
Nenue@29 105 if test then
Nenue@29 106 self.Info[questID] = self.Info[questID] or {}
Nenue@29 107
Nenue@29 108 local t = self.Info[questID]
Nenue@33 109 if (isOnMap or isInArea) and existingTask then
Nenue@33 110 t.areaID = GetCurrentMapAreaID()
Nenue@33 111 local _
Nenue@33 112 t.mapName, _, _, t.isMicroDungeon, t.microDungeonMapName = GetMapInfo()
Nenue@33 113 print('|cFF00FF00scooping map info (questID '..questID..'):|r', t.areaID, t.mapName)
Nenue@33 114 end
Nenue@29 115
Nenue@29 116 local taskTitle
Nenue@33 117 t.objectives = {}
Nenue@29 118 local taskFinished = true;
Nenue@29 119 for objectiveIndex = 1, numObjectives do
Nenue@29 120 local text, objectiveType, finished, displayAsObjective = InternalGetQuestObjectiveInfo(questID, objectiveIndex, false);
Nenue@29 121 displayObjectiveHeader = displayObjectiveHeader or displayAsObjective;
Nenue@29 122 if not taskTitle then
Nenue@29 123 if objectiveType == 'progressbar' and not text:match('^%d%+\\%d+') then
Nenue@29 124 taskTitle = text
Nenue@29 125 text = ''
Nenue@29 126 end
Nenue@29 127 end
Nenue@29 128
Nenue@29 129
Nenue@29 130 print(' --', text, objectiveType, finished, displayAsObjective)
Nenue@29 131 t.objectives[objectiveIndex] = t.objectives[objectiveIndex] or {}
Nenue@29 132 local o = t.objectives[objectiveIndex]
Nenue@29 133
Nenue@29 134 o.objectiveIndex = objectiveIndex
Nenue@29 135 o.text = text
Nenue@29 136 o.objectiveType = objectiveType
Nenue@29 137 o.finished = finished
Nenue@29 138 o.displayAsObjective = displayAsObjective
Nenue@29 139 print(' |cFF00FF88*', objectiveIndex, text)
Nenue@29 140 end
Nenue@29 141
Nenue@33 142 T.SetRewards(t, questID)
Nenue@33 143
Nenue@29 144 -- didn't get a name from progress bar? what about area name
Nenue@29 145 if not taskTitle then
Nenue@29 146 if isInArea then
Nenue@29 147 taskTitle = GetMapNameByID(GetCurrentMapAreaID())
Nenue@29 148 end
Nenue@29 149 end
Nenue@33 150
Nenue@33 151 t.isInArea = isInArea
Nenue@33 152 t.isOnMap = isOnMap
Nenue@33 153 t.existingTask = existingTask
Nenue@33 154 t.questID = questID
Nenue@33 155 t.id = questID
Nenue@33 156 t.taskIndex = i
Nenue@29 157 t.title = taskTitle
Nenue@33 158 self.WatchInfo[i] = t
Nenue@29 159 end
Nenue@29 160
Nenue@29 161 print (' |cFF00FF88#', i, 'questID', questID, 'inArea', isInArea, 'onMap', isOnMap, 'existing', (existingTask and 'Y' or 'N'), (test and '|cFF00FF00show|r' or '|cFFFF0088hide|r'))
Nenue@29 162 end
Nenue@29 163
Nenue@29 164
Nenue@29 165 self.numAll = #tasks
Nenue@29 166 self.numWatched = #self.WatchInfo
Nenue@29 167 print(' stats:', self.numAll, 'active tasks,', self.numWatched, 'nearby or animating')
Nenue@29 168 --return #tasks
Nenue@29 169 return #self.WatchInfo
Nenue@29 170 end
Nenue@29 171
Nenue@29 172 --- info cleanup done when turn-ins are detected
Nenue@33 173 Bonus.OnTurnIn = function(self, block, questID, xp, money)
Nenue@33 174 local info = self.Info[questID]
Nenue@33 175 if info.rewardInfo and #info.rewardInfo >= 1 then
Nenue@33 176 for i, reward in ipairs(info.rewardInfo) do
Nenue@29 177 --[[
Nenue@29 178 type = 'item',
Nenue@29 179 index = i ,
Nenue@29 180 name = name,
Nenue@29 181 texture = texture,
Nenue@29 182 count = count,
Nenue@29 183 quality = quality,
Nenue@29 184 isUsable = isUsable
Nenue@29 185 ]]
Nenue@29 186 print(' reward ', i, ' ', reward.type, reward.name, reward.count)
Nenue@29 187
Nenue@29 188 end
Nenue@29 189 end
Nenue@29 190
Nenue@33 191 print('|cFFFF8800'..block.name..':OnTurnIn call', questID, xp, money)
Nenue@29 192 local savedTasks = B.Conf.TasksLog
Nenue@29 193
Nenue@33 194 info.completedTime = GetTime()
Nenue@33 195 info.animate = true
Nenue@33 196 T.SetAnimate(handler.watchReasonModule)
Nenue@33 197 savedTasks[questID] = info
Nenue@33 198
Nenue@33 199 print('adding', info.title, 'to cache')
Nenue@29 200 end
Nenue@29 201
Nenue@29 202 Bonus.GetInfo = function(self, taskIndex)
Nenue@29 203 print(self.name, self)
Nenue@29 204 return self.WatchInfo[taskIndex]
Nenue@29 205 end
Nenue@29 206
Nenue@29 207
Nenue@29 208
Nenue@29 209 --- Update hooks
Nenue@27 210 Bonus.UpdateObjectives = function(handler, block)
Nenue@27 211 Default.UpdateObjectives(handler, block)
Nenue@27 212 end
Nenue@27 213
Nenue@33 214 Bonus.UpdateLine = function(handler, block, line, data)
Nenue@27 215 local info = block.info
Nenue@27 216 local print = lprint
Nenue@31 217 local text, attachment = '', nil
Nenue@27 218 line.displayColor = 'FFFFFF'
Nenue@27 219 print(' ', data.objectiveIndex,'|cFFFF0088-|r', data.objectiveType, data.text)
Nenue@27 220 if data.objectiveType == 'progressbar' then
Nenue@27 221 print(' |cFFFF44DDpercent='..tostring(GetQuestProgressBarPercent(info.questID)))
Nenue@33 222 local percent = 100
Nenue@31 223 attachment = T.SetWidget(line, data, 'ProgressBar', info.questID..'-'..data.objectiveIndex)
Nenue@33 224 if not data.finished then
Nenue@33 225 percent = GetQuestProgressBarPercent(info.questID)
Nenue@33 226 end
Nenue@33 227 attachment.value = percent
Nenue@33 228 attachment.maxValue = 100
Nenue@31 229 attachment:SetPoint('TOP', line, 'TOP', 0, 0)
Nenue@33 230 attachment.status:SetFormattedText(PERCENTAGE_STRING, (percent / 100))
Nenue@27 231 print(' |cFFFF0022** text:|r', data.text, '|cFFFF0022value:|r', data.value, '|cFFFF0022max:|r', data.maxValue)
Nenue@27 232 else
Nenue@31 233 text = data.text
Nenue@27 234 end
Nenue@31 235 return text, attachment
Nenue@27 236 end
Nenue@27 237
Nenue@33 238 Bonus.Select = function(handler, block)
Nenue@33 239 print(handler, block)
Nenue@33 240 handler:OnTurnIn(block, block.info.questID)
Nenue@27 241 end
Nenue@27 242 Bonus.Remove = function(self)
Nenue@27 243
Nenue@27 244 end