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@33: local iprint = B.print('Info') 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 GetQuestProgressBarPercent, PERCENTAGE_STRING, GetTime = GetQuestProgressBarPercent, PERCENTAGE_STRING, GetTime Nenue@33: local STICKY_TASKS = true 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@37: if true then return 0, 0, nil end Nenue@33: local print = iprint Nenue@29: print(self.name, self) Nenue@29: Nenue@29: local tasks = InternalGetTasksTable() Nenue@29: local numWatched = 0 Nenue@29: local numAll = 0 Nenue@33: local existingTasks = {} Nenue@29: self.WatchInfo = {} Nenue@29: print('|cFFFFFF00Bonus.GetNumWatched()|r', #tasks) Nenue@34: print(' |cFF00FFFFInternalGetTaskInfo|r:') 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@33: if (isOnMap or isInArea) and existingTask then Nenue@33: t.areaID = GetCurrentMapAreaID() Nenue@33: local _ Nenue@33: t.mapName, _, _, t.isMicroDungeon, t.microDungeonMapName = GetMapInfo() Nenue@33: print('|cFF00FF00scooping map info (questID '..questID..'):|r', t.areaID, t.mapName) Nenue@33: end Nenue@29: Nenue@29: local taskTitle Nenue@33: t.objectives = {} 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@34: o.index = objectiveIndex Nenue@29: o.text = text Nenue@34: o.type = objectiveType Nenue@29: o.finished = finished Nenue@29: o.displayAsObjective = displayAsObjective Nenue@29: end Nenue@29: Nenue@33: T.SetRewards(t, questID) Nenue@33: 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@34: t.numObjectives = numObjectives Nenue@33: t.isInArea = isInArea Nenue@33: t.isOnMap = isOnMap Nenue@33: t.existingTask = existingTask Nenue@33: t.questID = questID Nenue@33: t.id = questID Nenue@33: t.taskIndex = i Nenue@29: t.title = taskTitle Nenue@33: self.WatchInfo[i] = t 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@36: for i = 1, #self.usedBlocks do Nenue@36: self.usedBlocks[i]:Hide() Nenue@36: end Nenue@36: 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@33: Bonus.OnTurnIn = function(self, block, questID, xp, money) Nenue@33: local info = self.Info[questID] Nenue@33: if info.rewardInfo and #info.rewardInfo >= 1 then Nenue@33: for i, reward in ipairs(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@34: print('|cFFFF8800'..block:GetName()..':OnTurnIn call', questID, xp, money) Nenue@34: local savedTasks = B.Conf.TasksLog or {} Nenue@29: Nenue@33: info.completedTime = GetTime() Nenue@33: info.animate = true Nenue@34: T.SetAnimate(self.updateReasonModule) Nenue@34: savedTasks[questID] = { Nenue@34: id = questID, Nenue@34: title = info.title, Nenue@34: finished = true, Nenue@34: numObjectives = info.numObjectives, Nenue@34: objectives = info.objectives, Nenue@34: rewardInfo = info.rewardInfo, Nenue@34: } Nenue@34: B.Conf.TasksLog = savedTasks Nenue@34: Nenue@34: print(' ## CONF TASKLOG ##') Nenue@34: for i, t in pairs(savedTasks[questID]) do Nenue@34: print(' |cFFFFFF00'.. tostring(i)..'|r', t) Nenue@34: Nenue@34: end Nenue@34: for o, j in ipairs(savedTasks[questID].objectives) do Nenue@34: print(' |cFF00FFFF#'.. o ..'|r', j.type, j.finished) Nenue@34: end Nenue@33: Nenue@33: print('adding', info.title, 'to cache') 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@34: return 'default' Nenue@27: end Nenue@27: Nenue@33: Bonus.UpdateLine = function(handler, block, line, data) Nenue@27: local info = block.info Nenue@27: local print = lprint Nenue@31: local text, attachment = '', nil Nenue@27: line.displayColor = 'FFFFFF' Nenue@34: if data.type == 'progressbar' then Nenue@27: print(' |cFFFF44DDpercent='..tostring(GetQuestProgressBarPercent(info.questID))) Nenue@33: local percent = 100 Nenue@34: attachment = T.SetWidget(line, data, 'ProgressBar', info.questID..'-'..data.index) Nenue@33: if not data.finished then Nenue@33: percent = GetQuestProgressBarPercent(info.questID) Nenue@33: end Nenue@34: data.value = percent Nenue@34: data.maxValue = 100 Nenue@34: Nenue@34: print(attachment:GetNumPoints()) Nenue@34: for i = 1, attachment:GetNumPoints() do Nenue@34: print(' ',attachment:GetPoint(i)) Nenue@34: end Nenue@34: Nenue@34: Nenue@33: attachment.value = percent Nenue@33: attachment.maxValue = 100 Nenue@31: attachment:SetPoint('TOP', line, 'TOP', 0, 0) Nenue@34: attachment.status:SetFormattedText(PERCENTAGE_STRING, percent) Nenue@37: attachment:SetParent(handler.frame) Nenue@34: print(attachment.status:GetText()) Nenue@27: print(' |cFFFF0022** text:|r', data.text, '|cFFFF0022value:|r', data.value, '|cFFFF0022max:|r', data.maxValue) Nenue@27: end Nenue@34: text = data.text Nenue@31: return text, attachment Nenue@27: end Nenue@27: Nenue@33: Bonus.Select = function(handler, block) Nenue@33: print(handler, block) Nenue@33: handler:OnTurnIn(block, block.info.questID) Nenue@27: end Nenue@27: Bonus.Remove = function(self) Nenue@27: Nenue@27: end