-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLibObjectiveProgress-1.0.lua
More file actions
69 lines (53 loc) · 2.59 KB
/
LibObjectiveProgress-1.0.lua
File metadata and controls
69 lines (53 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
--[[
LibObjectiveProgress: Core API
Developed by: Simca@Malfurion (MMOSimca)
]]--
-- Set major/minor version
local MAJOR, MINOR = "LibObjectiveProgress-1.0", @project-revision@
assert(LibStub, MAJOR .. " requires LibStub")
-- Initialize library
local LOP, oldversion = LibStub:NewLibrary(MAJOR, MINOR)
if not LOP then return end
-- Localized function references
local CQL_GetNumQuestLogEntries = _G.C_QuestLog.GetNumQuestLogEntries
local CQL_GetInfo = _G.C_QuestLog.GetInfo
function LOP:GetNPCWeightByMap(mapID, npcID, isTeeming, isAlternate)
-- Load map-based weight data if needed
if not LOP.MapBasedWeights then LOP:LoadWeightDataByMap() end
-- Ensure that specified map/NPC is valid
local tableIndex = 1
if isTeeming then tableIndex = 2 end
if isAlternate then tableIndex = tableIndex + 2 end -- Allows alternate maps for weird scenarios
-- For Karazhan, isAlternate=false means Lower Karazhan and isAlternate=true means Upper Karazhan
-- For Siege of Boralus, isAlternate=false means Alliance and isAlternate=true means Horde
if not LOP.MapBasedWeights[mapID] or not LOP.MapBasedWeights[mapID][tableIndex] or not LOP.MapBasedWeights[mapID][tableIndex][npcID] then return nil end
-- Get map-based weight data for specified NPC
return LOP.MapBasedWeights[mapID][tableIndex][npcID]
end
function LOP:GetNPCWeightByQuest(questID, npcID)
-- Load map-based weight data if needed
if not LOP.QuestBasedWeights then LOP:LoadWeightDataByQuest() end
-- Ensure that specified map / NPC is valid
if not LOP.QuestBasedWeights[questID] or not LOP.QuestBasedWeights[questID][npcID] then return nil end
-- Get map-based weight data for specified NPC
return LOP.QuestBasedWeights[questID][npcID]
end
function LOP:GetNPCWeightByCurrentQuests(npcID)
-- Table variable declared here
local questTable = nil
-- Get NPC weight for all quests in log
local numEntries = CQL_GetNumQuestLogEntries()
for questLogIndex = 1, numEntries do
local questInfo = CQL_GetInfo(questLogIndex)
-- If this row isn't a header, has a valid questID, and has a valid weight, then initialize the table and record the questID/weight pair
if questInfo and not questInfo.isHeader and questInfo.questID ~= 0 then
local weight = LOP:GetNPCWeightByQuest(questInfo.questID, npcID)
if weight then
questTable = questTable or {}
questTable[questInfo.questID] = weight
end
end
end
-- Return completed table (or nil if no quests reference the NPC in question)
return questTable
end