annotate ObjectiveTracker/Quests.lua @ 28:c33c17dd97e7

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