Merge branch 'master' of zorba@192.168.100.11:questhelper
[QuestHelper.git] / collect_util.lua
blob7d745aa46cfbc7fd69dc10a1469a46076eb897be
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 return tonumber(guid:sub(9, 12), 16) -- here's our actual identifier
22 end
24 local function GetItemType(link, vague)
25 return tonumber(string.match(link,
26 (vague and "" or "^") .. "|cff%x%x%x%x%x%x|Hitem:(%d+):[%d:-]+|h%[[^%]]*%]|h|r".. (vague and "" or "$")
28 end
30 local function GetQuestType(link)
31 return tonumber(string.match(link,
32 "^|cff%x%x%x%x%x%x|Hquest:(%d+):[%d-]+|h%[[^%]]*%]|h|r$"
33 )), tonumber(string.match(link,
34 "^|cff%x%x%x%x%x%x|Hquest:%d+:([%d-]+)|h%[[^%]]*%]|h|r$"
36 end
38 function QH_Collect_Util_Init(_, API)
39 API.Utility_IsMonsterGUID = IsMonsterGUID
40 API.Utility_GetMonsterUID = GetMonsterUID
41 API.Utility_GetMonsterType = GetMonsterType
42 API.Utility_GetItemType = GetItemType
43 API.Utility_GetQuestType = GetQuestType
44 end