annotate ObjectiveTracker/Quests.lua @ 40:03ed70f846de

- move block accessors into a new file - define a tMove function for reconciling the free/used tables as needed - when retrieving an old block frame, confirm ID still matches; resolves multiple watch items on one block - stop any animations when a block is freed; resolves stuck flare graphics
author Nenue
date Sun, 24 Apr 2016 14:15:25 -0400
parents 92534dc793f2
children
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@30 4 local GetQuestWatchInfo, GetQuestLogCompletionText = GetQuestWatchInfo, GetQuestLogCompletionText
Nenue@30 5 local GetQuestLogLeaderBoard, GetNumQuestLogEntries, GetQuestLogTitle = GetQuestLogLeaderBoard, GetNumQuestLogEntries, GetQuestLogTitle
Nenue@30 6 local GetQuestLogSpecialItemInfo, GetQuestLogSpecialItemCooldown = GetQuestLogSpecialItemInfo, GetQuestLogSpecialItemCooldown
Nenue@30 7 local GetSuperTrackedQuestID, GetMoney, C_Scenario, GetCVarBool, GetNumQuestWatches = GetSuperTrackedQuestID, GetMoney, C_Scenario, GetCVarBool, GetNumQuestWatches
Nenue@30 8 local GetQuestTagInfo, GetMoneyString, GetDistanceSqToQuest, GetQuestFactionGroup = GetQuestTagInfo, GetMoneyString, GetDistanceSqToQuest, GetQuestFactionGroup
Nenue@30 9 local QUEST_TAG_ACCOUNT, LE_QUEST_FACTION_HORDE, LE_QUEST_FREQUENCY_DAILY, LE_QUEST_FREQUENCY_WEEKLY = QUEST_TAG_ACCOUNT, LE_QUEST_FACTION_HORDE, LE_QUEST_FREQUENCY_DAILY, LE_QUEST_FREQUENCY_WEEKLY
Nenue@30 10 local QUEST_TAG_TCOORDS, IsQuestSequenced = QUEST_TAG_TCOORDS, IsQuestSequenced
Nenue@28 11 local Default, Quest = T.DefaultHandler, T.Quest
Nenue@37 12 local format, wipe, select = format, table.wipe, select
Nenue@37 13 local wipeall = B.wipeall
Nenue@37 14 local lprint, iprint, tprint = B.print('Line'), B.print('Info'), B.print('Tracker')
Nenue@37 15 local print = tprint
Nenue@40 16 local fprint = B.print('Frame')
Nenue@38 17
Nenue@38 18
Nenue@30 19 local superTrackQuestID, playerMoney, inScenario, showPOIs
Nenue@28 20 Quest.Update = function(self, reason, ...)
Nenue@38 21 local print = self.print
Nenue@28 22 print('QuestTracker:Update() received')
Nenue@28 23 T.UpdateActionButtons()
Nenue@28 24 Default.Update(self, reason, ...)
Nenue@28 25 end
Nenue@28 26
Nenue@28 27 T.Quest.numButtons = 0
Nenue@28 28 local usedButtons = T.Quest.itemButtons
Nenue@28 29 local freeButtons = T.Quest.freeButtons
Nenue@28 30
Nenue@38 31 Quest.UpdateObjectives = function(self, block)
Nenue@28 32 local print = lprint
Nenue@38 33 print('|cFF'..self.internalColor..'UpdateObjectives()')
Nenue@28 34 local info = block.info
Nenue@28 35
Nenue@28 36 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 37
Nenue@38 38 local displayObjectives = true
Nenue@34 39 local block_schema = 'default'
Nenue@28 40 if info.isAccount then
Nenue@28 41 if info.isFaction then
Nenue@28 42 print(' faction', info.tagID)
Nenue@34 43 block_schema = 'faction_'..info.tagID
Nenue@28 44 else
Nenue@28 45 print(' account', info.isAccount, info.isFaction)
Nenue@34 46 block_schema = 'account'
Nenue@28 47 end
Nenue@28 48 elseif info.isDaily then
Nenue@28 49 print(' daily', info.frequency)
Nenue@34 50 block_schema = 'daily'
Nenue@28 51 elseif info.isWeekly then
Nenue@28 52 print(' weekly', info.frequency)
Nenue@34 53 block_schema = 'weekly'
Nenue@28 54 end
Nenue@28 55 local completionText
Nenue@28 56 if info.isComplete then
Nenue@28 57 if info.isAutoComplete then
Nenue@34 58 local questID, popupType = GetAutoQuestPopUp(info.logIndex)
Nenue@28 59 if popupType == 'COMPLETE' then
Nenue@28 60 print(' :: auto-complete quest :: set the message')
Nenue@38 61 self:AddLine(block, T.strings.CLICK_TO_COMPLETE, nil, 'complete')
Nenue@28 62 end
Nenue@28 63 else
Nenue@28 64 if not completionText or info.completionText then
Nenue@34 65 info.completionText = GetQuestLogCompletionText(info.logIndex)
Nenue@28 66 end
Nenue@28 67 end
Nenue@38 68 self:AddLine(block, info.completionText, nil, 'complete')
Nenue@38 69 displayObjectives = false
Nenue@38 70 print('|cFF'..self.internalColor..' :: complete quest :: show instruction: "'.. tostring(info.completionText) .. '"')
Nenue@28 71 end
Nenue@28 72
Nenue@38 73 Default.UpdateObjectives(self, block, block_schema, displayObjectives)
Nenue@40 74 return 0, block_schema
Nenue@28 75 end
Nenue@28 76
Nenue@38 77 Quest.UpdateLine = function(handler, block, data)
Nenue@28 78 local objectiveType = data.type
Nenue@31 79 return data.text, nil, objectiveType
Nenue@28 80 end
Nenue@28 81
Nenue@28 82 -----------------------------
Nenue@28 83 --- QUEST
Nenue@37 84 local tremove, tinsert = tremove, tinsert
Nenue@37 85 local GetQuestLogIndexByID, IsQuestWatched = GetQuestLogIndexByID, IsQuestWatched
Nenue@28 86 Quest.QuestBlock = {}
Nenue@28 87 Quest.LogBlock = {}
Nenue@28 88 Quest.LogInfo = {}
Nenue@37 89
Nenue@39 90 Quest.OnRemoved = function(block)
Nenue@37 91
Nenue@37 92 end
Nenue@39 93
Nenue@39 94 Quest.GetBlock = function(self, index)
Nenue@39 95 local block = Default.GetBlock(self, index)
Nenue@39 96 block:SetScript('OnEvent', Quest.OnRemoved)
Nenue@39 97 block:RegisterEvent('QUEST_REMOVED')
Nenue@39 98 return block
Nenue@39 99 end
Nenue@39 100
Nenue@37 101 local watchesChecked = {}
Nenue@37 102 local infosChecked = {}
Nenue@37 103 local GetQuestWatchIndex = GetQuestWatchIndex
Nenue@37 104 --- Get a total of things to show, and straighten out the index while we're at it
Nenue@37 105 --- Return the number shown, total in log, and the info table to parse
Nenue@40 106 local blocksChecked = {}
Nenue@37 107 Quest.GetNumWatched = function (self, id, added)
Nenue@38 108 local print = self.print
Nenue@40 109 B.print('Block')('########')
Nenue@40 110 B.print('Block')('########')
Nenue@30 111 superTrackQuestID = GetSuperTrackedQuestID()
Nenue@30 112 playerMoney = GetMoney();
Nenue@30 113 inScenario = C_Scenario.IsInScenario();
Nenue@30 114 showPOIs = GetCVarBool("questPOI");
Nenue@37 115 local numAll = GetNumQuestLogEntries()
Nenue@37 116 local numWatched = GetNumQuestWatches()
Nenue@37 117 local bottomIndex = 1
Nenue@38 118 print('GetNumWatched', self.name, numWatched, 'of', numAll)
Nenue@37 119 local start, limit = 1, numAll
Nenue@37 120
Nenue@37 121 if id and not added then
Nenue@40 122 -- if a particular id is supplied, add to checklist
Nenue@37 123 if self.InfoBlock[id] then
Nenue@40 124 blocksChecked[self.InfoBlock[id]] = self.InfoBlock[id]
Nenue@37 125 end
Nenue@37 126 end
Nenue@37 127
Nenue@40 128 --- Start complicated frame-recycling bullshit
Nenue@37 129 for logIndex = start, limit do
Nenue@37 130 local reason1, reason2 = '', ''
Nenue@37 131 local title, level, suggestedGroup, isHeader, isCollapsed, isComplete, frequency, questID, startEvent, displayQuestID, isOnMap, hasLocalPOI, isTask, isStory = GetQuestLogTitle(logIndex)
Nenue@37 132 local watchIndex = GetQuestWatchIndex(logIndex)
Nenue@37 133
Nenue@40 134 -- check if: the watch data pointers don't match
Nenue@37 135 if watchIndex and watchIndex >= bottomIndex then
Nenue@37 136 local watchInfo = self.WatchInfo[watchIndex]
Nenue@37 137 local watchBlock = self.WatchBlock[watchIndex]
Nenue@37 138 if watchInfo and watchInfo.questID ~= questID then
Nenue@38 139 print('GetNumWatched', 'trimming WatchInfo ['..watchIndex..'] =/=', questID)
Nenue@37 140 self.WatchInfo[watchIndex] = nil
Nenue@37 141 end
Nenue@37 142 if watchBlock and watchBlock.info.questID ~= questID then
Nenue@38 143 print('GetNumWatched', 'trimming WatchBlock ['..watchIndex..'] =/=', watchBlock:GetName())
Nenue@37 144 self.WatchBlock[watchIndex] = nil
Nenue@40 145 blocksChecked[watchBlock] = watchBlock
Nenue@37 146 end
Nenue@37 147 end
Nenue@37 148
Nenue@40 149 -- check if: the logIndex pointer doesn't match
Nenue@37 150 local logBlock = self.LogBlock[logIndex]
Nenue@37 151 if logBlock and logBlock.info.questID ~= questID then
Nenue@40 152 print('GetQuests', 'replace info', logBlock.info.questID, '->', questID)
Nenue@37 153 self.LogBlock[logIndex] = nil
Nenue@40 154 blocksChecked[logBlock] = logBlock
Nenue@37 155 end
Nenue@37 156
Nenue@40 157 -- add to watch index if: the questID is non-zero
Nenue@37 158 if questID ~= 0 then
Nenue@37 159 self.Info[questID] = self:GetInfo(logIndex, watchIndex)
Nenue@40 160 print('GetQuests', format('request info |cFF00FF00%2d|r |cFFFFFF00%6d|r |cFFFF4400%3s|r', logIndex, questID, tostring(watchIndex or '')))
Nenue@37 161 end
Nenue@37 162 end
Nenue@37 163
Nenue@40 164 --- After GetInfo pass, look for any non-conformant blocks and deal with them
Nenue@40 165 for _, block in pairs(blocksChecked) do
Nenue@40 166 local logIndex = GetQuestLogIndexByID(block.info.questID, 'player')
Nenue@40 167 -- free if: logIndex doesn't resolve
Nenue@40 168 if not logIndex then
Nenue@40 169 B.print('Block')('GetNumWatched', '|cFFBBFF00block has no index '.. block:GetName()..'|r')
Nenue@40 170 self:ClearBlock(block)
Nenue@40 171 -- hide if: logIndex isn't being watched
Nenue@40 172 elseif not IsQuestWatched(block.info.logIndex) then
Nenue@40 173 B.print('Block')('GetNumWatched', '|cFFBBFF00fade from list '.. block:GetName()..'|r')
Nenue@40 174 -- todo: figure out why animation gets clobbered
Nenue@40 175 self:ClearBlock(block)
Nenue@37 176 end
Nenue@40 177 blocksChecked[block] = nil
Nenue@37 178 end
Nenue@37 179
Nenue@37 180 self.numWatched = numWatched
Nenue@37 181 self.numAll = numAll
Nenue@37 182
Nenue@37 183 return numWatched, numAll, self.WatchList
Nenue@28 184 end
Nenue@30 185
Nenue@37 186
Nenue@30 187 --- Returns an iterable table from which tracker blocks can be filled out. Data includes:
Nenue@30 188 -- All entry-layer GetXInfo return values
Nenue@30 189 -- Manifest of line data to be displayed in relation to the tracked object
Nenue@37 190 Quest.GetInfo = function (self, logIndex, watchIndex)
Nenue@28 191 local print = iprint
Nenue@37 192 local title, level, suggestedGroup, isHeader, isCollapsed, isComplete, frequency, questID, startEvent, displayQuestID, isOnMap, hasLocalPOI, isTask, isStory = GetQuestLogTitle(logIndex)
Nenue@30 193 if ( not questID ) then
Nenue@38 194 tprint('GetNumWatched', logIndex, watchIndex, '|cFFFF2299no data|r')
Nenue@28 195 return
Nenue@28 196 end
Nenue@28 197
Nenue@37 198 Quest.Info[questID] = Quest.Info[questID] or {}
Nenue@37 199 local q = Quest.Info[questID]
Nenue@37 200 q.questID = questID
Nenue@37 201 q.id = questID
Nenue@37 202 q.logIndex = logIndex
Nenue@37 203 q.watchIndex = watchIndex
Nenue@28 204
Nenue@37 205 local numObjectives, requiredMoney, isAutoComplete, failureTime, timeElapsed, questType
Nenue@37 206 = 0, 0, nil, false, false, 0
Nenue@37 207 if watchIndex then
Nenue@37 208 local _
Nenue@37 209 _,_,_, numObjectives, requiredMoney, _, _, isAutoComplete,
Nenue@37 210 failureTime, timeElapsed, questType = GetQuestWatchInfo(watchIndex)
Nenue@37 211 self.WatchList[watchIndex] = q
Nenue@37 212 --tprint(' |cFF88FF00GetInfo:|r set watch entry', watchIndex)
Nenue@38 213 print('GetInfo:', logIndex, watchIndex, '|cFFFF2299'..title..'|r')
Nenue@37 214 end
Nenue@37 215 self.LogInfo[logIndex] = q
Nenue@28 216
Nenue@37 217 q.numObjectives = numObjectives
Nenue@37 218 q.requiredMoney = requiredMoney
Nenue@37 219 q.failureTime = failureTime
Nenue@37 220 q.timeElapsed = timeElapsed
Nenue@30 221
Nenue@37 222
Nenue@37 223
Nenue@32 224 q.type = 'Quest'
Nenue@32 225 q.title = title
Nenue@32 226 q.level = level
Nenue@32 227 q.displayQuestID = displayQuestID
Nenue@32 228 q.suggestedGroup = suggestedGroup
Nenue@32 229
Nenue@30 230 -- re-use Blizzard logic for consistency
Nenue@32 231 local showQuest = true
Nenue@32 232 if isTask then showQuest = false end
Nenue@30 233 local watchMoney = false;
Nenue@30 234 local tagID, typeTag, frequencyTag, completionTag, completionText
Nenue@30 235 local isAccount, isFaction, isWeekly, isDaily = false, false, false, false
Nenue@30 236 local isBreadcrumb = false
Nenue@30 237 local questFailed = false
Nenue@30 238 local watchMoney = false
Nenue@30 239 local timerInfo, moneyInfo = false, false
Nenue@30 240 local objectives = q.objectives or {}
Nenue@30 241
Nenue@30 242
Nenue@30 243 -- Case 1: completed quest or "go to thing" breadcrumb
Nenue@30 244 -- * 1 line containing the completion text
Nenue@30 245 if ( isComplete and isComplete < 0 ) then
Nenue@30 246 isComplete = false
Nenue@30 247 questFailed = true
Nenue@30 248 elseif ( numObjectives == 0 and playerMoney >= requiredMoney and not startEvent ) then
Nenue@30 249 isComplete = true;
Nenue@30 250 questFailed = false
Nenue@30 251 if ( requiredMoney == 0 ) then
Nenue@30 252 isBreadcrumb = true;
Nenue@30 253 end
Nenue@30 254 end
Nenue@38 255 print('QuestFlags', (isComplete and 'isComplete' or ''), (questFailed and 'questFailed' or ''), (isBreadcrumb and 'isBreadcrumb' or ''))
Nenue@30 256
Nenue@30 257 -- completion message?
Nenue@30 258 local isSequenced = IsQuestSequenced(questID)
Nenue@30 259 local temp_status = ''
Nenue@30 260 if ( isComplete ) then
Nenue@30 261 temp_status = 'COMPLETED_OBJECTIVES'
Nenue@30 262 objectives = Quest.GetObjectives(questLogIndex, numObjectives, true, isSequenced, isStory)
Nenue@30 263 if ( isAutoComplete ) then
Nenue@30 264 temp_status = 'AUTOCOMPLETE_OBJECTIVES'
Nenue@30 265 completionText = _G.QUEST_WATCH_CLICK_TO_COMPLETE
Nenue@30 266 else
Nenue@30 267 if ( isBreadcrumb ) then
Nenue@30 268 temp_status = 'COMPLETE_BREADCRUMB'
Nenue@30 269 completionText = GetQuestLogCompletionText(questLogIndex)
Nenue@30 270 else
Nenue@30 271 temp_status = 'COMPLETE_READY_FOR_TURN_IN'
Nenue@30 272 completionText = _G.QUEST_WATCH_QUEST_READY
Nenue@30 273 end
Nenue@30 274 end
Nenue@30 275 elseif ( questFailed ) then
Nenue@30 276 temp_status = 'FAILED'
Nenue@30 277 -- Case 2: failed quest
Nenue@30 278 -- * 1 status line; hide other info
Nenue@30 279 completionText = _G.FAILED
Nenue@30 280 else
Nenue@30 281
Nenue@30 282 temp_status = 'PROGRESS_OBJECTIVES'
Nenue@30 283 -- Case 3: quest in progress
Nenue@30 284 -- * Multiple objective lines
Nenue@30 285 -- * Possible extra lines for money and timer data respectively
Nenue@39 286 self.print(' QuestInfo', title, questType, isAutoComplete)
Nenue@37 287 objectives = Quest.GetObjectives(logIndex, numObjectives, false, isSequenced, isStory)
Nenue@30 288 q.objectives = objectives
Nenue@30 289
Nenue@30 290 --- anything past here gets appended to existing objectives
Nenue@30 291
Nenue@30 292 -- money
Nenue@30 293 if ( requiredMoney > playerMoney ) then
Nenue@30 294
Nenue@30 295 temp_status = temp_status .. '_MONEY'
Nenue@30 296 local text = GetMoneyString(playerMoney).." / "..GetMoneyString(requiredMoney);
Nenue@30 297 moneyInfo = {
Nenue@30 298 type = 'money',
Nenue@30 299 text = text,
Nenue@30 300 finished = false,
Nenue@30 301 requiredMoney = requiredMoney,
Nenue@30 302 playerMoney = playerMoney,
Nenue@30 303 }
Nenue@31 304 tinsert(objectives, moneyInfo)
Nenue@30 305 end
Nenue@30 306
Nenue@30 307 -- time limit
Nenue@30 308 if ( failureTime ) then
Nenue@30 309 temp_status = temp_status .. '_TIMED'
Nenue@30 310 if ( timeElapsed and timeElapsed <= failureTime ) then
Nenue@30 311 timerInfo = {
Nenue@30 312 type = 'timer',
Nenue@30 313 finished = false,
Nenue@30 314 timeElapsed = timeElapsed,
Nenue@30 315 failureTime = failureTime,
Nenue@30 316 }
Nenue@31 317 tinsert(objectives, timerInfo)
Nenue@30 318 end
Nenue@30 319 end
Nenue@30 320 end
Nenue@30 321 q.objectives = objectives
Nenue@30 322 q.moneyInfo = moneyInfo
Nenue@30 323 q.timerInfo = timerInfo
Nenue@30 324 q.completionText = completionText
Nenue@30 325
Nenue@30 326 -- POI data
Nenue@30 327 local POI = false
Nenue@30 328 if ( showPOIs ) then
Nenue@30 329 POI = {
Nenue@30 330 questID = questID,
Nenue@37 331 logIndex = logIndex,
Nenue@37 332 watchIndex = watchIndex
Nenue@30 333 }
Nenue@30 334 local poiButton;
Nenue@30 335 if ( hasLocalPOI ) then
Nenue@30 336
Nenue@30 337 if ( isComplete ) then
Nenue@30 338 POI.type = 'normal'
Nenue@30 339 else
Nenue@30 340 POI.type = 'numeric'
Nenue@30 341 end
Nenue@30 342 elseif ( isComplete ) then
Nenue@30 343 POI.type = 'remote'
Nenue@30 344 end
Nenue@30 345
Nenue@37 346 local distance, onContinent = GetDistanceSqToQuest(logIndex)
Nenue@30 347 if distance ~= nil and distance > 0 then
Nenue@30 348 POI.distance = distance
Nenue@30 349 POI.onContinent = onContinent
Nenue@30 350 end
Nenue@30 351 end
Nenue@30 352 q.POI = POI
Nenue@30 353
Nenue@30 354 --- Block Tags
Nenue@30 355 -- completionTag - in progres, complete, failed, autocomplete
Nenue@30 356 -- typeTag - account, faction, pvp, dungeon, group
Nenue@30 357 -- frequencyTag - daily/weekly
Nenue@37 358 local schema = 'default'
Nenue@30 359 local questTagID, tagName = GetQuestTagInfo(questID)
Nenue@30 360 local tagInfo = {}
Nenue@30 361 local tagCoords = {}
Nenue@30 362 local factionGroup = GetQuestFactionGroup(questID);
Nenue@30 363 if( questTagID and questTagID == QUEST_TAG_ACCOUNT ) then
Nenue@30 364 if( factionGroup ) then
Nenue@30 365 tagID = "ALLIANCE"
Nenue@37 366 schema = 'alliance'
Nenue@30 367 if ( factionGroup == LE_QUEST_FACTION_HORDE ) then
Nenue@30 368 tagID = "HORDE"
Nenue@37 369 schema = 'horde'
Nenue@30 370 end
Nenue@30 371 isFaction = true
Nenue@30 372 else
Nenue@30 373 tagID = QUEST_TAG_ACCOUNT
Nenue@30 374 isAccount = true
Nenue@30 375 end
Nenue@30 376 tagInfo['typeTag'] = tagID
Nenue@30 377 tagCoords['typeTag'] = QUEST_TAG_TCOORDS[tagID]
Nenue@30 378 elseif ( factionGroup) then
Nenue@30 379 tagID = "ALLIANCE"
Nenue@30 380 if ( factionGroup == LE_QUEST_FACTION_HORDE ) then
Nenue@30 381 tagID = "HORDE"
Nenue@30 382 end
Nenue@30 383 isFaction = true
Nenue@30 384 tagInfo['typeTag'] = tagID
Nenue@30 385 tagCoords['typeTag'] = QUEST_TAG_TCOORDS[tagID]
Nenue@30 386 end
Nenue@30 387
Nenue@30 388 if( frequency == LE_QUEST_FREQUENCY_DAILY and (not isComplete or isComplete == 0) ) then
Nenue@30 389 tagID = 'DAILY'
Nenue@30 390 tagInfo['frequencyTag'] = tagID
Nenue@30 391 tagCoords['frequencyTag'] = QUEST_TAG_TCOORDS[tagID]
Nenue@30 392 isDaily = true
Nenue@37 393 schema = 'daily'
Nenue@30 394 elseif( frequency == LE_QUEST_FREQUENCY_WEEKLY and (not isComplete or isComplete == 0) )then
Nenue@30 395 tagID = 'WEEKLY'
Nenue@30 396 tagInfo['frequencyTag'] = tagID
Nenue@30 397 tagCoords['frequencyTag'] = QUEST_TAG_TCOORDS[tagID]
Nenue@30 398 isWeekly = true
Nenue@37 399 schema = 'weekly'
Nenue@30 400 elseif( questTagID ) then
Nenue@30 401 tagID = questTagID
Nenue@30 402 end
Nenue@30 403
Nenue@30 404 if( isComplete ) then
Nenue@30 405 tagInfo['completionTag'] = 'COMPLETED'
Nenue@30 406 elseif ( questFailed ) then
Nenue@30 407 tagInfo['completionTag'] = 'FAILED'
Nenue@30 408 end
Nenue@30 409 tagCoords['completionTag'] = QUEST_TAG_TCOORDS[tagInfo['completionTag']]
Nenue@30 410
Nenue@30 411 q.tagInfo = tagInfo
Nenue@30 412 q.tagCoords = tagCoords
Nenue@30 413 -- establishes the primary block tag for view compacting
Nenue@30 414 q.tagID = tagID
Nenue@30 415 q.tagName = tagName
Nenue@30 416
Nenue@30 417 -- action button information
Nenue@37 418 local link, icon, charges = GetQuestLogSpecialItemInfo(logIndex)
Nenue@37 419 local start, duration, enable = GetQuestLogSpecialItemCooldown(logIndex)
Nenue@30 420 if link or icon or charges then
Nenue@30 421 q.specialItem = {
Nenue@30 422 questID = questID,
Nenue@37 423 logIndex = questLogIndex,
Nenue@30 424 link = link,
Nenue@30 425 charges = charges,
Nenue@30 426 icon = icon,
Nenue@30 427 start = start,
Nenue@30 428 duration = duration,
Nenue@30 429 enable = enable,
Nenue@30 430 }
Nenue@30 431 end
Nenue@30 432
Nenue@32 433 if moneyInfo or timerInfo then
Nenue@32 434 numObjectives = #objectives
Nenue@32 435 end
Nenue@30 436
Nenue@30 437 -- raw data
Nenue@28 438 q.isComplete = isComplete
Nenue@28 439 q.startEvent = startEvent
Nenue@28 440 q.isAutoComplete = isAutoComplete
Nenue@28 441 q.questType = questType
Nenue@28 442 q.isTask = isTask
Nenue@28 443 q.isStory = isStory
Nenue@28 444 q.isOnMap = isOnMap
Nenue@28 445 q.hasLocalPOI = hasLocalPOI
Nenue@28 446 q.frequency = frequency
Nenue@28 447 q.isComplete = isComplete
Nenue@28 448 q.isStory = isStory
Nenue@28 449 q.isTask = isTask
Nenue@31 450 q.statusKey = temp_status
Nenue@32 451 q.selected = (questID == superTrackQuestID)
Nenue@28 452
Nenue@32 453 T.SetRewards(q, questID)
Nenue@32 454
Nenue@34 455 q.questID = questID
Nenue@37 456 q.logIndex = logIndex
Nenue@34 457 q.watchIndex = watchIndex
Nenue@34 458 q.id = questID
Nenue@37 459 q.schema = schema
Nenue@28 460
Nenue@30 461 if Devian and Devian.InWorkspace() then
Nenue@38 462 print('QuestStatus', temp_status, '|cFF00FF00questLogIndex|r:', logIndex, title)
Nenue@30 463 local temp ={}
Nenue@38 464 local data_txt = '|cFF'..self.internalColor..'values:|r'
Nenue@30 465 for k,v in pairs(q) do
Nenue@30 466 if type(v) =='number' then
Nenue@30 467 data_txt = data_txt .. ' |cFFFFFF00'..k..'|r: ' .. tostring(v)
Nenue@30 468 elseif type(v) == 'table' then
Nenue@30 469 tinsert(temp, k)
Nenue@28 470 end
Nenue@28 471 end
Nenue@38 472 print('DataStatus',data_txt)
Nenue@30 473 sort(temp, function(a,b) return a < b end)
Nenue@30 474 for i, k in ipairs(temp) do
Nenue@38 475 iprint('GetInfo', questID, ''..k..'|r')
Nenue@30 476 for kk,v in pairs(q[k]) do
Nenue@38 477 iprint('GetInfo', questID, kk, '=', v)
Nenue@30 478 end
Nenue@28 479 end
Nenue@28 480 end
Nenue@28 481
Nenue@30 482 return q
Nenue@30 483 end
Nenue@28 484
Nenue@37 485 Quest.GetObjectives = function(logIndex, numObjectives, isComplete, isSequenced, isStory)
Nenue@38 486 local print = Quest.print
Nenue@30 487 local objectives = {}
Nenue@39 488 if not logIndex then
Nenue@39 489 return
Nenue@39 490 end
Nenue@39 491
Nenue@30 492 for i = 1, numObjectives do
Nenue@37 493 local text, type, finished = GetQuestLogLeaderBoard(i, logIndex)
Nenue@39 494
Nenue@39 495 local progress = 0
Nenue@39 496 if finished then
Nenue@39 497 progress = 1
Nenue@39 498 elseif text then
Nenue@39 499 local quantity, maxQuantity = text:match('^(%d+)/(%d+)')
Nenue@39 500 if quantity and maxQuantity then
Nenue@39 501 progress = quantity / maxQuantity
Nenue@39 502 --print('GetObjectives', 'calculated objective progress:', quantity, '/', maxQuantity, '=', progress)
Nenue@39 503 end
Nenue@39 504 end
Nenue@39 505
Nenue@39 506 print('GetObjectives', format('|cFF88FF88#%d %s %s %s', i, tostring(type), tostring(text), tostring(finished)), '('.. tostring(progress)..')')
Nenue@39 507
Nenue@39 508
Nenue@30 509 objectives[i] = {
Nenue@28 510 index = i,
Nenue@28 511 type = type,
Nenue@28 512 text = text,
Nenue@39 513 finished = finished,
Nenue@39 514 progress = progress
Nenue@28 515 }
Nenue@28 516 end
Nenue@30 517 return objectives
Nenue@28 518 end
Nenue@28 519
Nenue@30 520 local huge, sqrt = math.huge, math.sqrt
Nenue@28 521 Quest.GetClosest = function()
Nenue@28 522 local minID, minTitle
Nenue@30 523 local minDist = huge
Nenue@28 524 local numQuests = GetNumQuestLogEntries()
Nenue@28 525 for questIndex = 1, numQuests do
Nenue@28 526 local distance, onContinent = GetDistanceSqToQuest(questIndex)
Nenue@28 527 local title, level, _, _, _, _, _, _, questID = GetQuestLogTitle(questIndex)
Nenue@28 528 if onContinent and distance < minDist then
Nenue@28 529 minDist = distance
Nenue@28 530 minTitle = title
Nenue@28 531 minID = questID
Nenue@28 532 end
Nenue@28 533 end
Nenue@28 534
Nenue@30 535 print('nearest quest is', minTitle, 'by', sqrt(minDist))
Nenue@28 536 return minID, minTitle, minDist
Nenue@28 537 end
Nenue@28 538
Nenue@28 539 Quest.OnTurnIn = function(self, questID, xp, money)
Nenue@28 540 end
Nenue@28 541
Nenue@29 542 Quest.Select = function (handler, block)
Nenue@29 543 if block.info.isAutoComplete and block.info.isComplete then
Nenue@34 544 ShowQuestComplete(block.info.logIndex)
Nenue@28 545 else
Nenue@29 546 SetSuperTrackedQuestID(block.info.questID)
Nenue@28 547 end
Nenue@28 548 end
Nenue@28 549
Nenue@29 550 Quest.Link = function(handler, block)
Nenue@34 551 local questLink = GetQuestLink(block.info.logIndex);
Nenue@28 552 if ( questLink ) then
Nenue@28 553 ChatEdit_InsertLink(questLink);
Nenue@28 554 end
Nenue@28 555 end
Nenue@28 556
Nenue@29 557 Quest.Open = function(handler, block)
Nenue@29 558 QuestMapFrame_OpenToQuestDetails(block.info.questID)
Nenue@28 559 end
Nenue@28 560
Nenue@29 561 Quest.Remove = function(handler, block)
Nenue@34 562 print('removing', block.info.logIndex, 'from watcher')
Nenue@34 563 RemoveQuestWatch(block.info.logIndex)
Nenue@29 564 end