Report on hidden quests
[QuestHelper.git] / collect_monster.lua
blob007f4e8d8c1aeb2d70474bbbe2877492a98c01e7
1 QuestHelper_File["collect_monster.lua"] = "Development Version"
2 QuestHelper_Loadtime["collect_monster.lua"] = GetTime()
4 local debug_output = false
5 if QuestHelper_File["collect_monster.lua"] == "Development Version" then debug_output = true end
7 local QHCM
9 local GetLoc
10 local Merger
11 local Patterns
13 local GetMonsterUID
14 local GetMonsterType
16 local logon = GetTime() -- Because I'm incredibly paranoid, I'm waiting fifteen minutes after logon to assume they're not drunk.
17 local drunk_logon = true
18 local drunk_message = false
20 local function SystemMessage(arg, arg2, arg3)
21 if strfind(arg, Patterns["DRUNK_MESSAGE_SELF2"]) or strfind(arg, Patterns["DRUNK_MESSAGE_SELF3"]) or strfind(arg, Patterns["DRUNK_MESSAGE_SELF4"]) or strfind(arg, Patterns["DRUNK_MESSAGE_ITEM_SELF2"]) or strfind(arg, Patterns["DRUNK_MESSAGE_ITEM_SELF3"]) or strfind(arg, Patterns["DRUNK_MESSAGE_ITEM_SELF4"]) then
22 drunk_message = true
23 elseif strfind(arg, Patterns["DRUNK_MESSAGE_SELF1"]) or strfind(arg, Patterns["DRUNK_MESSAGE_ITEM_SELF1"]) then
24 drunk_message = false
25 end
26 end
28 local InteractDistances = {28, 11, 10, 0} -- There's actually a 4, but it's also 28 and it's kind of handy to be able to do it this way.
30 local recentlySeenCritters = {} -- We try not to repeatedly record critters frequently.
32 -- Kind of a nasty system here, built for efficiency and simplicity. All newly-seen critters go into Recent. When Recent reaches a certain size (100?) everything in NextTrash is deleted and NextTrash is replaced with Recent. Badabing, badaboom.
33 local recentlySeenCritters_NextTrash = {}
34 local recentlySeenCritters_Recent = {}
36 local function AccumulateFrequency(target, name, data)
37 local key = name .. "_" .. tostring(data)
38 target[key] = (target[key] or 0) + 1
39 end
41 local function MouseoverUnit()
42 if logon and logon + 60 * 15 < GetTime() then
43 logon = nil
44 drunk_logon = false
45 end
47 -- First off, we see if it's "interesting".
48 -- The original code for this filtered out critters. I don't, because critters are cute, and rare.
49 if UnitExists("mouseover") and UnitIsVisible("mouseover") and not UnitIsPlayer("mouseover") and not UnitPlayerControlled("mouseover") then
50 local guid = UnitGUID("mouseover")
52 local creatureid = GetMonsterUID(guid)
54 if not recentlySeenCritters[creatureid] then
55 recentlySeenCritters_Recent[creatureid] = true
56 recentlySeenCritters[creatureid] = true
58 -- register the critter here
59 local cid = GetMonsterType(guid)
61 if not QHCM[cid] then QHCM[cid] = {} end
62 local critter = QHCM[cid]
64 AccumulateFrequency(critter, "name", UnitName("mouseover"))
65 AccumulateFrequency(critter, "reaction", UnitReaction("mouseover", "player"))
66 if not drunk_logon and not drunk_message then
67 AccumulateFrequency(critter, "level", UnitLevel("mouseover"))
68 end
70 local minrange = InteractDistances[1]
71 local maxrange = 255
72 -- Now we try to derive a bound for how far away it is
73 for i = #InteractDistances - 1, 1, -1 do
74 if CheckInteractDistance("mouseover", i) then
75 minrange = InteractDistances[i + 1]
76 maxrange = InteractDistances[i]
77 break
78 end
79 end
80 QuestHelper: Assert(minrange >= 0 and minrange < 256 and maxrange >= 0 and maxrange < 256)
81 Merger.Add(critter, GetLoc() .. strchar(minrange, maxrange))
83 if #recentlySeenCritters_Recent >= 100 then
84 for k, v in recentlySeenCritters_NextTrash do
85 recentlySeenCritters[v] = nil
86 end
88 recentlySeenCritters_NextTrash = recentlySeenCritters_Recent
89 recentlySeenCritters_Recent = {} -- BAM, garbage collection!
90 end
91 end
92 end
93 end
95 function QH_Collect_Monster_Init(QHCData, API)
96 if not QHCData.monster then QHCData.monster = {} end
97 QHCM = QHCData.monster
99 API.Registrar_EventHook("UPDATE_MOUSEOVER_UNIT", MouseoverUnit)
100 API.Registrar_EventHook("CHAT_MSG_SYSTEM", SystemMessage)
102 Patterns = API.Patterns
103 QuestHelper: Assert(Patterns)
105 API.Patterns_Register("DRUNK_MESSAGE_SELF1", "|c.*|r")
106 API.Patterns_Register("DRUNK_MESSAGE_SELF2", "|c.*|r")
107 API.Patterns_Register("DRUNK_MESSAGE_SELF3", "|c.*|r")
108 API.Patterns_Register("DRUNK_MESSAGE_SELF4", "|c.*|r")
109 API.Patterns_Register("DRUNK_MESSAGE_ITEM_SELF1", "|c.*|r")
110 API.Patterns_Register("DRUNK_MESSAGE_ITEM_SELF2", "|c.*|r")
111 API.Patterns_Register("DRUNK_MESSAGE_ITEM_SELF3", "|c.*|r")
112 API.Patterns_Register("DRUNK_MESSAGE_ITEM_SELF4", "|c.*|r")
114 GetLoc = API.Callback_LocationBolusCurrent
115 QuestHelper: Assert(GetLoc)
117 Merger = API.Utility_Merger
118 QuestHelper: Assert(Merger)
120 GetMonsterUID = API.Utility_GetMonsterUID
121 GetMonsterType = API.Utility_GetMonsterType
122 QuestHelper: Assert(GetMonsterUID)
123 QuestHelper: Assert(GetMonsterType)