Nenue@27: --- ${PACKAGE_NAME} Nenue@27: -- @file-author@ Nenue@27: -- @project-revision@ @project-hash@ Nenue@27: -- @file-revision@ @file-hash@ Nenue@27: -- Created: 4/13/2016 7:48 PM Nenue@27: local B = select(2,...).frame Nenue@27: local T = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame') Nenue@27: local Default, Quest = T.DefaultHandler, T.Quest Nenue@27: local print = B.print('Tracker') Nenue@27: local lprint = B.print('Line') Nenue@29: local Bonus = T.Bonus Nenue@27: Nenue@29: local UnitName, GetRealmName, GetQuestObjectiveInfo, GetTasksTable, GetTaskInfo = UnitName, GetRealmName, GetQuestObjectiveInfo, GetTasksTable, GetTaskInfo Nenue@29: local GetMapNameByID, GetCurrentMapAreaID = GetMapNameByID, GetCurrentMapAreaID Nenue@29: local tinsert, ipairs, pairs, tostring = tinsert, ipairs, pairs, tostring Nenue@29: local GetNumQuestLogRewardCurrencies, GetQuestLogRewardCurrencyInfo = GetNumQuestLogRewardCurrencies, GetQuestLogRewardCurrencyInfo Nenue@29: local GetNumQuestLogRewards, GetQuestLogRewardInfo = GetNumQuestLogRewards, GetQuestLogRewardInfo Nenue@29: local GetQuestLogRewardMoney, GetMoneyString = GetQuestLogRewardMoney, GetMoneyString Nenue@29: local GetQuestProgressBarPercent, PERCENTAGE_STRING, GetTime = GetQuestProgressBarPercent, PERCENTAGE_STRING, GetTime Nenue@27: Nenue@29: local DoQuestRewards = function(t, questID) Nenue@29: local rewards = {} Nenue@29: t.numCurrencies = GetNumQuestLogRewardCurrencies(questID) Nenue@29: for i = 1, t.numCurrencies do Nenue@29: local name, texture, count = GetQuestLogRewardCurrencyInfo(i, questID) Nenue@29: tinsert(rewards,{ Nenue@29: type = 'currency', Nenue@29: index = i, Nenue@29: name = name, Nenue@29: texture = texture, Nenue@29: count = count Nenue@29: }); Nenue@29: end Nenue@29: -- items Nenue@29: t.numItems = GetNumQuestLogRewards(questID) Nenue@29: for i = 1, t.numItems do Nenue@29: local name, texture, count, quality, isUsable = GetQuestLogRewardInfo(i, questID) Nenue@29: tinsert(rewards, { Nenue@29: type = 'item', Nenue@29: index = i , Nenue@29: name = name, Nenue@29: texture = texture, Nenue@29: count = count, Nenue@29: quality = quality, Nenue@29: isUsable = isUsable Nenue@29: }); Nenue@29: end Nenue@29: -- money Nenue@29: Nenue@29: local money = GetQuestLogRewardMoney(questID) Nenue@29: if ( money > 0 ) then Nenue@29: tinsert(rewards, { Nenue@29: type = 'money', Nenue@29: name = GetMoneyString(money), Nenue@29: texture = "Interface\\Icons\\inv_misc_coin_01", Nenue@29: count = 0, Nenue@29: }); Nenue@29: end Nenue@29: Nenue@29: if #rewards >= 1 then Nenue@29: t.rewardInfo = rewards Nenue@29: end Nenue@29: end Nenue@29: Nenue@29: --- Returns a tasks table modified to include recently completed objectives Nenue@29: local InternalGetTasksTable = function() Nenue@29: local savedTasks = T.Conf.TasksLog Nenue@29: local char = UnitName("player") Nenue@29: local realm = GetRealmName() Nenue@29: local tasks = GetTasksTable() Nenue@29: Nenue@29: for questID, data in pairs(Bonus.Info) do Nenue@29: Nenue@29: print(' -- questID:', questID, #data.objectives) Nenue@29: for i, o in ipairs(data.objectives) do Nenue@29: print(' --', i, o.text) Nenue@29: end Nenue@29: Nenue@29: end Nenue@29: Nenue@29: Nenue@29: for questID, data in pairs(savedTasks) do Nenue@29: if questID > 0 then Nenue@29: local found = false Nenue@29: for i = 1, #tasks do Nenue@29: if tasks[i] == questID then Nenue@29: found = true Nenue@29: break Nenue@29: end Nenue@29: end Nenue@29: -- if it's not part of the current table, then try to insert it where it was last found Nenue@29: if not found then Nenue@29: if data.watchIndex < #tasks then Nenue@29: tinsert(tasks, data.watchIndex, data) Nenue@29: else Nenue@29: tinsert(tasks, data) Nenue@29: end Nenue@29: end Nenue@29: end Nenue@29: end Nenue@29: return tasks Nenue@29: end Nenue@29: Nenue@29: --- Returns an entry from the composed tasks table if possible, otherwise makes an API pull Nenue@29: local InternalGetTaskInfo = function(questID) Nenue@29: local completedTasks = T.Conf.TasksLog Nenue@29: if completedTasks[questID] then Nenue@29: return true, true, #completedTasks[questID].objectives Nenue@29: else Nenue@29: return GetTaskInfo(questID) Nenue@29: end Nenue@29: end Nenue@29: Nenue@29: --- Same as above but for the objective entries Nenue@29: local InternalGetQuestObjectiveInfo = function(questID, objectiveIndex) Nenue@29: local completedTasks = T.Conf.TasksLog Nenue@29: if ( completedTasks[questID] ) then Nenue@29: print('using internal data') Nenue@29: return completedTasks[questID].objectives[objectiveIndex], completedTasks[questID].objectiveType, true; Nenue@29: else Nenue@29: return GetQuestObjectiveInfo(questID, objectiveIndex, false); Nenue@29: end Nenue@29: end Nenue@29: Nenue@29: --- end redundant copy of silliness Nenue@29: ------------------------------------------------------------------------------------------ Nenue@29: Nenue@29: Bonus.Completed = {} Nenue@29: Bonus.POI = {} Nenue@29: Bonus.Scenario = {} Nenue@29: Bonus.QuestBlock = {} Nenue@29: Bonus.WatchInfo = {} Nenue@29: function Bonus:GetNumWatched () Nenue@29: print(self.name, self) Nenue@29: Nenue@29: local tasks = InternalGetTasksTable() Nenue@29: local numWatched = 0 Nenue@29: local numAll = 0 Nenue@29: self.WatchInfo = {} Nenue@29: print('|cFFFFFF00Bonus.GetNumWatched()|r', #tasks) Nenue@29: print(' TasksTable pull:') Nenue@29: for i, questID in ipairs(tasks) do Nenue@29: local isInArea, isOnMap, numObjectives = InternalGetTaskInfo(questID) Nenue@29: local existingTask = self.QuestBlock[questID] Nenue@29: local displayObjectiveHeader = false; Nenue@29: local test = (isInArea or (isOnMap and existingTask)) Nenue@29: --local test = true Nenue@29: if test then Nenue@29: self.Info[questID] = self.Info[questID] or {} Nenue@29: Nenue@29: local t = self.Info[questID] Nenue@29: self.WatchInfo[i] = t Nenue@29: t.isInArea = isInArea Nenue@29: t.isOnMap = isOnMap Nenue@29: t.existingTask = existingTask Nenue@29: t.questID = questID Nenue@29: t.objectives = {} Nenue@29: t.taskIndex = i Nenue@29: Nenue@29: Nenue@29: DoQuestRewards(t, questID) Nenue@29: Nenue@29: local taskTitle Nenue@29: local taskFinished = true; Nenue@29: for objectiveIndex = 1, numObjectives do Nenue@29: local text, objectiveType, finished, displayAsObjective = InternalGetQuestObjectiveInfo(questID, objectiveIndex, false); Nenue@29: displayObjectiveHeader = displayObjectiveHeader or displayAsObjective; Nenue@29: if not taskTitle then Nenue@29: if objectiveType == 'progressbar' and not text:match('^%d%+\\%d+') then Nenue@29: taskTitle = text Nenue@29: text = '' Nenue@29: end Nenue@29: end Nenue@29: Nenue@29: Nenue@29: print(' --', text, objectiveType, finished, displayAsObjective) Nenue@29: t.objectives[objectiveIndex] = t.objectives[objectiveIndex] or {} Nenue@29: local o = t.objectives[objectiveIndex] Nenue@29: Nenue@29: o.objectiveIndex = objectiveIndex Nenue@29: o.text = text Nenue@29: o.objectiveType = objectiveType Nenue@29: o.finished = finished Nenue@29: o.displayAsObjective = displayAsObjective Nenue@29: print(' |cFF00FF88*', objectiveIndex, text) Nenue@29: end Nenue@29: Nenue@29: -- didn't get a name from progress bar? what about area name Nenue@29: if not taskTitle then Nenue@29: if isInArea then Nenue@29: taskTitle = GetMapNameByID(GetCurrentMapAreaID()) Nenue@29: end Nenue@29: end Nenue@29: t.title = taskTitle Nenue@29: end Nenue@29: Nenue@29: print (' |cFF00FF88#', i, 'questID', questID, 'inArea', isInArea, 'onMap', isOnMap, 'existing', (existingTask and 'Y' or 'N'), (test and '|cFF00FF00show|r' or '|cFFFF0088hide|r')) Nenue@29: end Nenue@29: Nenue@29: Nenue@29: self.numAll = #tasks Nenue@29: self.numWatched = #self.WatchInfo Nenue@29: print(' stats:', self.numAll, 'active tasks,', self.numWatched, 'nearby or animating') Nenue@29: --return #tasks Nenue@29: return #self.WatchInfo Nenue@29: end Nenue@29: Nenue@29: --- info cleanup done when turn-ins are detected Nenue@29: Bonus.OnTurnIn = function(self, questID, xp, money) Nenue@29: Nenue@29: if #self.info.rewardInfo >= 1 then Nenue@29: for i, reward in ipairs(self.info.rewardInfo) do Nenue@29: --[[ Nenue@29: type = 'item', Nenue@29: index = i , Nenue@29: name = name, Nenue@29: texture = texture, Nenue@29: count = count, Nenue@29: quality = quality, Nenue@29: isUsable = isUsable Nenue@29: ]] Nenue@29: print(' reward ', i, ' ', reward.type, reward.name, reward.count) Nenue@29: Nenue@29: end Nenue@29: end Nenue@29: Nenue@29: print('|cFFFF8800'..self.name..':OnTurnIn call', questID, xp, money) Nenue@29: local savedTasks = B.Conf.TasksLog Nenue@29: Nenue@29: self.Info[questID].completedTime = GetTime() Nenue@29: self.Info[questID].animate = true Nenue@29: T.SetAnimate(self.watchReasonModule) Nenue@29: savedTasks[questID] = self.Info[questID] Nenue@29: end Nenue@29: Nenue@29: Bonus.GetInfo = function(self, taskIndex) Nenue@29: print(self.name, self) Nenue@29: return self.WatchInfo[taskIndex] Nenue@29: end Nenue@29: Nenue@29: Nenue@29: Nenue@29: --- Update hooks Nenue@27: Bonus.UpdateObjectives = function(handler, block) Nenue@27: Default.UpdateObjectives(handler, block) Nenue@27: end Nenue@27: Nenue@27: Bonus.UpdateLine = function(handler, block, line, data) Nenue@27: local info = block.info Nenue@27: local print = lprint Nenue@27: Nenue@27: line.displayColor = 'FFFFFF' Nenue@27: line.displayText = data.text Nenue@27: line.progress = 0 Nenue@27: print(' ', data.objectiveIndex,'|cFFFF0088-|r', data.objectiveType, data.text) Nenue@27: if data.objectiveType == 'progressbar' then Nenue@27: line.widgetType = 'ProgressBar' Nenue@27: print(' |cFFFF44DDpercent='..tostring(GetQuestProgressBarPercent(info.questID))) Nenue@27: data.value = GetQuestProgressBarPercent(info.questID) or 0 Nenue@27: data.maxValue = 100 Nenue@27: if data.value >= data.maxValue then Nenue@27: line.progress = 1 Nenue@27: elseif data.value > 0 then Nenue@27: line.progress = 2 Nenue@27: end Nenue@27: line.format = PERCENTAGE_STRING Nenue@27: local widget = T.SetWidget(line, data, 'ProgressBar', info.questID..'-'..data.objectiveIndex) Nenue@27: print(' |cFFFF0022** text:|r', data.text, '|cFFFF0022value:|r', data.value, '|cFFFF0022max:|r', data.maxValue) Nenue@27: widget:SetPoint('TOP', line, 'TOP', 0, 0) Nenue@27: Nenue@27: line.widget = widget Nenue@27: line.height = widget.height Nenue@27: else Nenue@27: line.displayText = data.text Nenue@27: line.widget = nil Nenue@27: end Nenue@27: return line Nenue@27: end Nenue@27: Nenue@27: Bonus.Select = function(self) Nenue@27: Bonus:OnTurnIn(self.info.questID) Nenue@27: end Nenue@27: Bonus.Remove = function(self) Nenue@27: Nenue@27: end