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