annotate ObjectiveTracker/QuestTracker.lua @ 23:e837384ac363

Separating objective tracker module
author Nenue
date Sun, 10 Apr 2016 04:35:32 -0400
parents
children 66b927b46776
rev   line source
Nenue@23 1 local B = select(2,...).frame
Nenue@23 2 local T = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame')
Nenue@23 3 local _G, ipairs, max, min, unpack, floor, pairs, tostring, type, band = _G, ipairs, max, min, unpack, floor, pairs, tostring, type, bit.band
Nenue@23 4 local GetAutoQuestPopUp, GetQuestLogCompletionText = GetAutoQuestPopUp, GetQuestLogCompletionText
Nenue@23 5 local Default, Quest = T.DefaultHandler, T.Quest
Nenue@23 6 local format = format
Nenue@23 7 local print = B.print('Tracker')
Nenue@23 8 local lprint = B.print('Line')
Nenue@23 9
Nenue@23 10 local colors = T.colors
Nenue@23 11 Quest.UpdateObjectives = function(handler, block)
Nenue@23 12 local print = lprint
Nenue@23 13 print('|cFF00FFFFUpdateObjectives()')
Nenue@23 14 local info = block.info
Nenue@23 15
Nenue@23 16 local titlebg, textbg = colors.default.titlebg, colors.default.textbg
Nenue@23 17 print((info.isAccount and 'isAccount' or ''), (info.isFaction and 'isFaction' or ''), (info.isDaily and 'isDaily' or ''), (info.isWeekly and 'isWeekly' or ''), info.tagID, info.tagName)
Nenue@23 18
Nenue@23 19 if info.isAccount then
Nenue@23 20 if info.isFaction then
Nenue@23 21 print(' faction', info.tagID)
Nenue@23 22 titlebg, textbg = colors['faction_'..info.tagID].titlebg, colors.default.textbg
Nenue@23 23 else
Nenue@23 24 print(' account', info.isAccount, info.isFaction)
Nenue@23 25 titlebg, textbg = colors.account.titlebg, colors.account.textbg
Nenue@23 26 end
Nenue@23 27 elseif info.isDaily then
Nenue@23 28 print(' daily', info.frequency)
Nenue@23 29 titlebg, textbg = colors.daily.titlebg, colors.daily.textbg
Nenue@23 30 elseif info.isWeekly then
Nenue@23 31 print(' weekly', info.frequency)
Nenue@23 32 titlebg, textbg = colors.weekly.titlebg, colors.weekly.textbg
Nenue@23 33 end
Nenue@23 34
Nenue@23 35 block.titlebg:SetGradientAlpha(unpack(titlebg))
Nenue@23 36 block.statusbg:SetGradientAlpha(unpack(textbg))
Nenue@23 37
Nenue@23 38 local completionText
Nenue@23 39 if info.isAutoComplete then
Nenue@23 40 local questID, popupType = GetAutoQuestPopUp(info.questLogIndex)
Nenue@23 41 if popupType == 'COMPLETE' then
Nenue@23 42 print(' :: auto-complete quest :: set the message')
Nenue@23 43 info.completionText = CLICK_TO_COMPLETE
Nenue@23 44 end
Nenue@23 45 end
Nenue@23 46 if info.isComplete then
Nenue@23 47 if not completionText or info.completionText then
Nenue@23 48 info.completionText = GetQuestLogCompletionText(info.questLogIndex)
Nenue@23 49 end
Nenue@23 50 print(' :: complete quest :: show instruction: "'.. tostring(info.completionText) .. '"')
Nenue@23 51 end
Nenue@23 52
Nenue@23 53 Default.UpdateObjectives(handler, block)
Nenue@23 54 end
Nenue@23 55
Nenue@23 56 Quest.UpdateLine = function(handler, block, line, data)
Nenue@23 57 local print = lprint
Nenue@23 58 local objectiveType = data.type
Nenue@23 59 local r, g, b, a = 0, 1, 1, 1
Nenue@23 60
Nenue@23 61 line.progress = 0
Nenue@23 62 if data.finished then
Nenue@23 63 line.progress = 2
Nenue@23 64 r, g, b, a = 0, 1, 0, 1
Nenue@23 65 elseif objectiveType == 'monster' then
Nenue@23 66 r, g, b, a = 1, .55, .2, 1
Nenue@23 67 elseif objectiveType == 'item' then
Nenue@23 68 r, g, b, a = .8, .8, .8, 1
Nenue@23 69 elseif objectiveType == 'object' then
Nenue@23 70 r, g, b, a = 1, 1, 1, 1
Nenue@23 71 elseif objectiveType == 'player' then
Nenue@23 72 r, g, b, a = 0, 0.8, 1, 1
Nenue@23 73 end
Nenue@23 74 print(format(' |cFF%02X%02X%02X%0.1f, %0.1f, %0.1f|r', (r * 255), g * 255, b * 255, r, g, b))
Nenue@23 75
Nenue@23 76 line.displayColor = {r, g, b, a}
Nenue@23 77 line.status:SetTextColor(r, g, b, a)
Nenue@23 78 line.displayText = data.text
Nenue@23 79
Nenue@23 80 return line
Nenue@23 81 end
Nenue@23 82
Nenue@23 83 -----------------------------
Nenue@23 84 --- QUEST
Nenue@23 85 Quest.itemButtons = {}
Nenue@23 86 Quest.freeButtons = {}
Nenue@23 87 Quest.POI = {}
Nenue@23 88 Quest.QuestBlock = {}
Nenue@23 89 Quest.LogBlock = {}
Nenue@23 90 Quest.LogInfo = {}
Nenue@23 91
Nenue@23 92 function Quest:GetNumWatched ()
Nenue@23 93 print(self.name, self)
Nenue@23 94 self.numAll = GetNumQuestLogEntries()
Nenue@23 95 self.numWatched = GetNumQuestWatches()
Nenue@23 96 return self.numWatched, self.numAll
Nenue@23 97 end
Nenue@23 98 Quest.GetInfo = function (self, watchIndex)
Nenue@23 99 print('|cFF00DDFFQuest|r.|cFF0088FFGetInfo(|r'.. tostring(watchIndex)..'|r)')
Nenue@23 100 local questID, title, questIndex, numObjectives, requiredMoney, isComplete,
Nenue@23 101 startEvent, isAutoComplete, failureTime, timeElapsed, questType, isTask, isStory, isOnMap, hasLocalPOI = GetQuestWatchInfo(watchIndex)
Nenue@23 102
Nenue@23 103 if not questIndex then
Nenue@23 104 return
Nenue@23 105 end
Nenue@23 106
Nenue@23 107 local _, level, suggestedGroup, isHeader, isCollapsed, isComplete, frequency, _, startEvent, displayQuestID, isOnMap, hasLocalPOI, isTask, isStory = GetQuestLogTitle(questIndex)
Nenue@23 108
Nenue@23 109
Nenue@23 110 if not questID then
Nenue@23 111 return
Nenue@23 112 end
Nenue@23 113 Quest.Info[questID] = Quest.Info[questID] or {}
Nenue@23 114
Nenue@23 115 local q = Quest.Info[questID]
Nenue@23 116 q.watchIndex = watchIndex
Nenue@23 117 q.type = 'Quest'
Nenue@23 118 q.questID = questID
Nenue@23 119 q.title = title
Nenue@23 120 q.level = level
Nenue@23 121 q.displayQuestID = displayQuestID
Nenue@23 122 q.suggestedGroup = suggestedGroup
Nenue@23 123 q.questLogIndex = questIndex
Nenue@23 124 q.numObjectives = numObjectives
Nenue@23 125 q.requiredMoney = requiredMoney
Nenue@23 126 q.isComplete = isComplete
Nenue@23 127 q.startEvent = startEvent
Nenue@23 128 q.isAutoComplete = isAutoComplete
Nenue@23 129 q.failureTime = failureTime
Nenue@23 130 q.timeElapsed = timeElapsed
Nenue@23 131 q.questType = questType
Nenue@23 132 q.isTask = isTask
Nenue@23 133 q.isStory = isStory
Nenue@23 134 q.isOnMap = isOnMap
Nenue@23 135 q.hasLocalPOI = hasLocalPOI
Nenue@23 136 q.frequency = frequency
Nenue@23 137 q.isComplete = isComplete
Nenue@23 138 q.isStory = isStory
Nenue@23 139 q.isTask = isTask
Nenue@23 140
Nenue@23 141 --- resolve icon type and template
Nenue@23 142 local questTagID, tagName = GetQuestTagInfo(questID)
Nenue@23 143 local tagID
Nenue@23 144
Nenue@23 145 local factionGroup = GetQuestFactionGroup(questID);
Nenue@23 146 if( questTagID and questTagID == QUEST_TAG_ACCOUNT ) then
Nenue@23 147 if( factionGroup ) then
Nenue@23 148 tagID = "ALLIANCE";
Nenue@23 149 if ( factionGroup == LE_QUEST_FACTION_HORDE ) then
Nenue@23 150 tagID = "HORDE";
Nenue@23 151 end
Nenue@23 152 q.isFaction = true
Nenue@23 153 else
Nenue@23 154 tagID = QUEST_TAG_ACCOUNT;
Nenue@23 155 q.isAccount = true
Nenue@23 156 end
Nenue@23 157 q.typeTag = QUEST_TAG_TCOORDS[tagID]
Nenue@23 158 elseif ( factionGroup) then
Nenue@23 159 tagID = "ALLIANCE";
Nenue@23 160 if ( factionGroup == LE_QUEST_FACTION_HORDE ) then
Nenue@23 161 tagID = "HORDE";
Nenue@23 162 end
Nenue@23 163 q.isFaction = true
Nenue@23 164 end
Nenue@23 165
Nenue@23 166 if( frequency == LE_QUEST_FREQUENCY_DAILY and (not isComplete or isComplete == 0) ) then
Nenue@23 167 tagID = "DAILY";
Nenue@23 168 q.frequencyTag = QUEST_TAG_TCOORDS["DAILY"]
Nenue@23 169 q.isDaily = true
Nenue@23 170 elseif( frequency == LE_QUEST_FREQUENCY_WEEKLY and (not isComplete or isComplete == 0) )then
Nenue@23 171 tagID = "WEEKLY";
Nenue@23 172 q.frequencyTag = QUEST_TAG_TCOORDS["WEEKLY"]
Nenue@23 173 q.isWeekly = true
Nenue@23 174 elseif( questTagID ) then
Nenue@23 175 tagID = questTagID;
Nenue@23 176 end
Nenue@23 177
Nenue@23 178 if ( isComplete and isComplete < 0 ) then
Nenue@23 179 q.completionTag = QUEST_TAG_TCOORDS["FAILED"]
Nenue@23 180 q.isFailed = true
Nenue@23 181 elseif isComplete then
Nenue@23 182 q.completionTag = QUEST_TAG_TCOORDS["COMPLETED"]
Nenue@23 183 end
Nenue@23 184
Nenue@23 185
Nenue@23 186 q.tagID = questTagID
Nenue@23 187 q.tagName = tagName
Nenue@23 188
Nenue@23 189
Nenue@23 190
Nenue@23 191 --q.isBreadCrumb = isBreadCrumb
Nenue@23 192 q.completionText= GetQuestLogCompletionText(questIndex)
Nenue@23 193 q.numObjectives = GetNumQuestLeaderBoards(questIndex)
Nenue@23 194 q.objectives = {}
Nenue@23 195 for i = 1, q.numObjectives do
Nenue@23 196 local text, type, finished = GetQuestLogLeaderBoard(i, questIndex)
Nenue@23 197 print(format(' #%d %s %s %s', i, tostring(type), tostring(text), tostring(finished)))
Nenue@23 198 q.objectives[i] = {
Nenue@23 199 index = i,
Nenue@23 200 type = type,
Nenue@23 201 text = text,
Nenue@23 202 finished = finished
Nenue@23 203 }
Nenue@23 204 if type == 'event' then
Nenue@23 205 elseif type == 'monster' then
Nenue@23 206 elseif type == 'object' then
Nenue@23 207 elseif type == 'reputation' then
Nenue@23 208 elseif type == 'item' then
Nenue@23 209 end
Nenue@23 210 end
Nenue@23 211
Nenue@23 212 if requiredMoney >= 1 then
Nenue@23 213 local money = GetMoney()
Nenue@23 214 local moneyText = money
Nenue@23 215 local requiredSilver, requiredCopper
Nenue@23 216 local requiredGold = (requiredMoney > 10000) and (floor(requiredMoney/10000)) or nil
Nenue@23 217 if mod(requiredMoney, 10000) ~= 0 then
Nenue@23 218 requiredSilver = (requiredMoney > 100) and (mod(requiredMoney, 10000) / 100) or nil
Nenue@23 219 if mod(requiredMoney, 100) ~= 0 then
Nenue@23 220 requiredCopper = mod(requiredMoney, 100)
Nenue@23 221 end
Nenue@23 222 end
Nenue@23 223
Nenue@23 224 -- round the money value down
Nenue@23 225 if requiredMoney > 9999 and not (requiredSilver or requiredCopper) then
Nenue@23 226 moneyText = floor(money/10000)
Nenue@23 227 elseif requiredMoney < 10000 and mod(requiredMoney,100) == 0 then
Nenue@23 228 moneyText = floor(money/100)
Nenue@23 229 end
Nenue@23 230
Nenue@23 231 local text = moneyText
Nenue@23 232 local index = #q.objectives + 1
Nenue@23 233 local finished = (GetMoney() >= requiredMoney)
Nenue@23 234
Nenue@23 235 if not finished then
Nenue@23 236 text = text .. ' / ' .. GetCoinTextureString(requiredMoney, 12)
Nenue@23 237 else
Nenue@23 238 text = '' .. GetCoinTextureString(requiredMoney, 12)
Nenue@23 239 end
Nenue@23 240 q.objectives[index] = {
Nenue@23 241 index = index,
Nenue@23 242 type = 'progressbar',
Nenue@23 243 quantity = money,
Nenue@23 244 requiredQuantity = requiredMoney,
Nenue@23 245 text = text,
Nenue@23 246 finished = finished
Nenue@23 247 }
Nenue@23 248 print(format(' #%d %s %s %s', index, 'money', text, tostring(finished)))
Nenue@23 249 end
Nenue@23 250
Nenue@23 251
Nenue@23 252 local link, icon, charges = GetQuestLogSpecialItemInfo(questIndex)
Nenue@23 253 local start, duration, enable = GetQuestLogSpecialItemCooldown(questIndex)
Nenue@23 254 if link or icon or charges then
Nenue@23 255 q.specialItem = {
Nenue@23 256 questID = questID,
Nenue@23 257 questIndex = questIndex,
Nenue@23 258 link = link,
Nenue@23 259 charges = charges,
Nenue@23 260 icon = icon,
Nenue@23 261 start = start,
Nenue@23 262 duration = duration,
Nenue@23 263 enable = enable,
Nenue@23 264 }
Nenue@23 265 end
Nenue@23 266
Nenue@23 267 if QuestHasPOIInfo(questID) then
Nenue@23 268 local distance, onContinent = GetDistanceSqToQuest(questIndex)
Nenue@23 269 if distance ~= nil and distance > 0 then
Nenue@23 270 self.POI[questIndex] = {
Nenue@23 271 questIndex = questIndex,
Nenue@23 272 questID = questID,
Nenue@23 273 distance = distance,
Nenue@23 274 onContinent = onContinent
Nenue@23 275 }
Nenue@23 276 end
Nenue@23 277 end
Nenue@23 278
Nenue@23 279
Nenue@23 280 q.selected = (questID == GetSuperTrackedQuestID()) -- call directly so artifact data doesn't become an issue
Nenue@23 281 self.WatchInfo[watchIndex] = q
Nenue@23 282 self.LogInfo[questIndex] = q
Nenue@23 283 print('- logIndex =', questIndex, 'title =', title)
Nenue@23 284 return q
Nenue@23 285 end
Nenue@23 286
Nenue@23 287 Quest.GetClosest = function()
Nenue@23 288 local minID, minTitle
Nenue@23 289 local minDist = math.huge
Nenue@23 290 local numQuests = GetNumQuestLogEntries()
Nenue@23 291 for questIndex = 1, numQuests do
Nenue@23 292 local distance, onContinent = GetDistanceSqToQuest(questIndex)
Nenue@23 293 local title, level, _, _, _, _, _, _, questID = GetQuestLogTitle(questIndex)
Nenue@23 294 if onContinent and distance < minDist then
Nenue@23 295 minDist = distance
Nenue@23 296 minTitle = title
Nenue@23 297 minID = questID
Nenue@23 298 end
Nenue@23 299 end
Nenue@23 300
Nenue@23 301 print('nearest quest is', minTitle, 'by', math.sqrt(minDist))
Nenue@23 302 return minID, minTitle, minDist
Nenue@23 303 end
Nenue@23 304
Nenue@23 305 Quest.OnTurnIn = function(self, questID, xp, money)
Nenue@23 306
Nenue@23 307 end