annotate ObjectiveTracker/Quests.lua @ 29:adcd7c328d07

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