fffff
[QuestHelper.git] / collect_util.lua
blob5ce7765c4bba0e9d10c5ae3121ebb4e3d04dfcdd
1 QuestHelper_File["collect_util.lua"] = "Development Version"
2 QuestHelper_Loadtime["collect_util.lua"] = GetTime()
4 local function IsMonsterGUID(guid)
5 QuestHelper: Assert(#guid == 18, "guid len " .. guid) -- 64 bits, plus the 0x prefix
6 QuestHelper: Assert(guid:sub(1, 2) == "0x", "guid 0x-prefix " .. guid)
7 return guid:sub(5, 5) == "3" or guid:sub(5, 5) == "5"
8 end
10 local function GetMonsterUID(guid)
11 QuestHelper: Assert(#guid == 18, "guid len " .. guid) -- 64 bits, plus the 0x prefix
12 QuestHelper: Assert(guid:sub(1, 2) == "0x", "guid 0x-prefix " .. guid)
13 QuestHelper: Assert(guid:sub(5, 5) == "3" or guid:sub(5, 5) == "5", "guid 3-prefix " .. guid) -- It *shouldn't* be a player or a pet by the time we've gotten here. If so, something's gone wrong.
14 return guid:sub(9, 18) -- here's our actual identifier
15 end
17 local function GetMonsterType(guid)
18 QuestHelper: Assert(#guid == 18, "guid len " .. guid) -- 64 bits, plus the 0x prefix
19 QuestHelper: Assert(guid:sub(1, 2) == "0x", "guid 0x-prefix " .. guid)
20 QuestHelper: Assert(guid:sub(5, 5) == "3" or guid:sub(5, 5) == "5", "guid 3-prefix " .. guid) -- It *shouldn't* be a player or a pet by the time we've gotten here. If so, something's gone wrong.
21 if GetBuildInfo():sub(1, 3) == "3.2" then
22 return tonumber(guid:sub(9, 12), 16) -- here's our actual identifier
23 else
24 return tonumber(guid:sub(7, 10), 16) -- 3.3 and in the future, including 0.3.0
25 end
26 end
28 local function GetItemType(link, vague)
29 return tonumber(string.match(link,
30 (vague and "" or "^") .. "|cff%x%x%x%x%x%x|Hitem:(%d+):[%d:-]+|h%[[^%]]*%]|h|r".. (vague and "" or "$")
32 end
34 local function GetQuestType(link)
35 return tonumber(string.match(link,
36 "^|cff%x%x%x%x%x%x|Hquest:(%d+):[%d-]+|h%[[^%]]*%]|h|r$"
37 )), tonumber(string.match(link,
38 "^|cff%x%x%x%x%x%x|Hquest:%d+:([%d-]+)|h%[[^%]]*%]|h|r$"
40 end
42 function QH_Collect_Util_Init(_, API)
43 API.Utility_IsMonsterGUID = IsMonsterGUID
44 API.Utility_GetMonsterUID = GetMonsterUID
45 API.Utility_GetMonsterType = GetMonsterType
46 API.Utility_GetItemType = GetItemType
47 API.Utility_GetQuestType = GetQuestType
48 end