Mercurial > wow > buffalo2
diff ObjectiveTracker/BonusObjectives.lua @ 29:adcd7c328d07
code collation cleaning
author | Nenue |
---|---|
date | Wed, 13 Apr 2016 21:53:24 -0400 |
parents | c3aa94bc6be2 |
children | 7583684becf4 |
line wrap: on
line diff
--- a/ObjectiveTracker/BonusObjectives.lua Wed Apr 13 20:19:37 2016 -0400 +++ b/ObjectiveTracker/BonusObjectives.lua Wed Apr 13 21:53:24 2016 -0400 @@ -5,30 +5,250 @@ -- Created: 4/13/2016 7:48 PM local B = select(2,...).frame local T = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame') -local _G, ipairs, max, min, unpack, floor, pairs, tostring, type, band = _G, ipairs, max, min, unpack, floor, pairs, tostring, type, bit.band -local GetAutoQuestPopUp, GetQuestLogCompletionText = GetAutoQuestPopUp, GetQuestLogCompletionText local Default, Quest = T.DefaultHandler, T.Quest -local format = format local print = B.print('Tracker') local lprint = B.print('Line') -local iprint = B.print('Info') -local Bonus = mod.Bonus +local Bonus = T.Bonus +local UnitName, GetRealmName, GetQuestObjectiveInfo, GetTasksTable, GetTaskInfo = UnitName, GetRealmName, GetQuestObjectiveInfo, GetTasksTable, GetTaskInfo +local GetMapNameByID, GetCurrentMapAreaID = GetMapNameByID, GetCurrentMapAreaID +local tinsert, ipairs, pairs, tostring = tinsert, ipairs, pairs, tostring +local GetNumQuestLogRewardCurrencies, GetQuestLogRewardCurrencyInfo = GetNumQuestLogRewardCurrencies, GetQuestLogRewardCurrencyInfo +local GetNumQuestLogRewards, GetQuestLogRewardInfo = GetNumQuestLogRewards, GetQuestLogRewardInfo +local GetQuestLogRewardMoney, GetMoneyString = GetQuestLogRewardMoney, GetMoneyString +local GetQuestProgressBarPercent, PERCENTAGE_STRING, GetTime = GetQuestProgressBarPercent, PERCENTAGE_STRING, GetTime ---- Module-specific data wrangling that has to happen during UpdateBlock() --- Most of this is sculpting objectives data into a parsible list. --- Some of it is additional block manipulation that doesn't quite fit with the other modules.. +local DoQuestRewards = function(t, questID) + local rewards = {} + t.numCurrencies = GetNumQuestLogRewardCurrencies(questID) + for i = 1, t.numCurrencies do + local name, texture, count = GetQuestLogRewardCurrencyInfo(i, questID) + tinsert(rewards,{ + type = 'currency', + index = i, + name = name, + texture = texture, + count = count + }); + end + -- items + t.numItems = GetNumQuestLogRewards(questID) + for i = 1, t.numItems do + local name, texture, count, quality, isUsable = GetQuestLogRewardInfo(i, questID) + tinsert(rewards, { + type = 'item', + index = i , + name = name, + texture = texture, + count = count, + quality = quality, + isUsable = isUsable + }); + end + -- money + + local money = GetQuestLogRewardMoney(questID) + if ( money > 0 ) then + tinsert(rewards, { + type = 'money', + name = GetMoneyString(money), + texture = "Interface\\Icons\\inv_misc_coin_01", + count = 0, + }); + end + + if #rewards >= 1 then + t.rewardInfo = rewards + end +end + +--- Returns a tasks table modified to include recently completed objectives +local InternalGetTasksTable = function() + local savedTasks = T.Conf.TasksLog + local char = UnitName("player") + local realm = GetRealmName() + local tasks = GetTasksTable() + + for questID, data in pairs(Bonus.Info) do + + print(' -- questID:', questID, #data.objectives) + for i, o in ipairs(data.objectives) do + print(' --', i, o.text) + end + + end + + + for questID, data in pairs(savedTasks) do + if questID > 0 then + local found = false + for i = 1, #tasks do + if tasks[i] == questID then + found = true + break + end + end + -- if it's not part of the current table, then try to insert it where it was last found + if not found then + if data.watchIndex < #tasks then + tinsert(tasks, data.watchIndex, data) + else + tinsert(tasks, data) + end + end + end + end + return tasks +end + +--- Returns an entry from the composed tasks table if possible, otherwise makes an API pull +local InternalGetTaskInfo = function(questID) + local completedTasks = T.Conf.TasksLog + if completedTasks[questID] then + return true, true, #completedTasks[questID].objectives + else + return GetTaskInfo(questID) + end +end + +--- Same as above but for the objective entries +local InternalGetQuestObjectiveInfo = function(questID, objectiveIndex) + local completedTasks = T.Conf.TasksLog + if ( completedTasks[questID] ) then + print('using internal data') + return completedTasks[questID].objectives[objectiveIndex], completedTasks[questID].objectiveType, true; + else + return GetQuestObjectiveInfo(questID, objectiveIndex, false); + end +end + +--- end redundant copy of silliness +------------------------------------------------------------------------------------------ + +Bonus.Completed = {} +Bonus.POI = {} +Bonus.Scenario = {} +Bonus.QuestBlock = {} +Bonus.WatchInfo = {} +function Bonus:GetNumWatched () + print(self.name, self) + + local tasks = InternalGetTasksTable() + local numWatched = 0 + local numAll = 0 + self.WatchInfo = {} + print('|cFFFFFF00Bonus.GetNumWatched()|r', #tasks) + print(' TasksTable pull:') + for i, questID in ipairs(tasks) do + local isInArea, isOnMap, numObjectives = InternalGetTaskInfo(questID) + local existingTask = self.QuestBlock[questID] + local displayObjectiveHeader = false; + local test = (isInArea or (isOnMap and existingTask)) + --local test = true + if test then + self.Info[questID] = self.Info[questID] or {} + + local t = self.Info[questID] + self.WatchInfo[i] = t + t.isInArea = isInArea + t.isOnMap = isOnMap + t.existingTask = existingTask + t.questID = questID + t.objectives = {} + t.taskIndex = i + + + DoQuestRewards(t, questID) + + local taskTitle + local taskFinished = true; + for objectiveIndex = 1, numObjectives do + local text, objectiveType, finished, displayAsObjective = InternalGetQuestObjectiveInfo(questID, objectiveIndex, false); + displayObjectiveHeader = displayObjectiveHeader or displayAsObjective; + if not taskTitle then + if objectiveType == 'progressbar' and not text:match('^%d%+\\%d+') then + taskTitle = text + text = '' + end + end + + + print(' --', text, objectiveType, finished, displayAsObjective) + t.objectives[objectiveIndex] = t.objectives[objectiveIndex] or {} + local o = t.objectives[objectiveIndex] + + o.objectiveIndex = objectiveIndex + o.text = text + o.objectiveType = objectiveType + o.finished = finished + o.displayAsObjective = displayAsObjective + print(' |cFF00FF88*', objectiveIndex, text) + end + + -- didn't get a name from progress bar? what about area name + if not taskTitle then + if isInArea then + taskTitle = GetMapNameByID(GetCurrentMapAreaID()) + end + end + t.title = taskTitle + end + + print (' |cFF00FF88#', i, 'questID', questID, 'inArea', isInArea, 'onMap', isOnMap, 'existing', (existingTask and 'Y' or 'N'), (test and '|cFF00FF00show|r' or '|cFFFF0088hide|r')) + end + + + self.numAll = #tasks + self.numWatched = #self.WatchInfo + print(' stats:', self.numAll, 'active tasks,', self.numWatched, 'nearby or animating') + --return #tasks + return #self.WatchInfo +end + +--- info cleanup done when turn-ins are detected +Bonus.OnTurnIn = function(self, questID, xp, money) + + if #self.info.rewardInfo >= 1 then + for i, reward in ipairs(self.info.rewardInfo) do + --[[ + type = 'item', + index = i , + name = name, + texture = texture, + count = count, + quality = quality, + isUsable = isUsable + ]] + print(' reward ', i, ' ', reward.type, reward.name, reward.count) + + end + end + + print('|cFFFF8800'..self.name..':OnTurnIn call', questID, xp, money) + local savedTasks = B.Conf.TasksLog + + self.Info[questID].completedTime = GetTime() + self.Info[questID].animate = true + T.SetAnimate(self.watchReasonModule) + savedTasks[questID] = self.Info[questID] +end + +Bonus.GetInfo = function(self, taskIndex) + print(self.name, self) + return self.WatchInfo[taskIndex] +end + + + +--- Update hooks Bonus.UpdateObjectives = function(handler, block) Default.UpdateObjectives(handler, block) end - - Bonus.UpdateLine = function(handler, block, line, data) local info = block.info local print = lprint - line.displayColor = 'FFFFFF' line.displayText = data.text line.progress = 0 @@ -58,7 +278,6 @@ end Bonus.Select = function(self) - Bonus:OnTurnIn(self.info.questID) end Bonus.Remove = function(self)