disable the flight stuff for now, we'll fix it after thanksgiving
[QuestHelper.git] / collect_monster.lua
bloba4ee93b5a53b97dce610985ca33b9f6206da0014
1 QuestHelper_File["collect_monster.lua"] = "Development Version"
3 local debug_output = false
4 if QuestHelper_File["collect_monster.lua"] == "Development Version" then debug_output = true end
6 local QHCM
8 local GetLoc
9 local Merger
10 local Patterns
12 local logon = GetTime() -- Because I'm incredibly paranoid, I'm waiting fifteen minutes after logon to assume they're not drunk.
13 local drunk_logon = true
14 local drunk_message = false
16 local function SystemMessage(arg, arg2, arg3)
17 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
18 drunk_message = true
19 elseif strfind(arg, Patterns["DRUNK_MESSAGE_SELF1"]) or strfind(arg, Patterns["DRUNK_MESSAGE_ITEM_SELF1"]) then
20 drunk_message = false
21 end
22 end
24 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.
26 local recentlySeenCritters = {} -- We try not to repeatedly record critters frequently.
28 -- 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.
29 local recentlySeenCritters_NextTrash = {}
30 local recentlySeenCritters_Recent = {}
32 local function AccumulateFrequency(target, name, data)
33 local key = name .. "_" .. tostring(data)
34 target[key] = (target[key] or 0) + 1
35 end
37 local function MouseoverUnit()
38 if logon and logon + 60 * 15 < GetTime() then
39 logon = nil
40 drunk_logon = false
41 end
43 -- First off, we see if it's "interesting".
44 -- The original code for this filtered out critters. I don't, because critters are cute, and rare.
45 if UnitExists("mouseover") and UnitIsVisible("mouseover") and not UnitIsPlayer("mouseover") and not UnitPlayerControlled("mouseover") then
46 local guid = UnitGUID("mouseover")
48 QuestHelper: Assert(#guid == 18, "guid len " .. guid) -- 64 bits, plus the 0x prefix
49 QuestHelper: Assert(guid:sub(1, 2) == "0x", "guid 0x-prefix " .. guid)
50 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.
51 local creatureid = guid:sub(9, 18) -- here's our actual identifier
53 if not recentlySeenCritters[creatureid] then
54 recentlySeenCritters_Recent[creatureid] = true
55 recentlySeenCritters[creatureid] = true
57 -- register the critter here
58 local cid = tonumber(creatureid:sub(1, 4), 16)
60 if not QHCM[cid] then QHCM[cid] = {} end
61 local critter = QHCM[cid]
63 AccumulateFrequency(critter, "name", UnitName("mouseover"))
64 AccumulateFrequency(critter, "reaction", UnitReaction("mouseover", "player"))
65 if not drunk_logon and not drunk_message then
66 AccumulateFrequency(critter, "level", UnitLevel("mouseover"))
67 end
69 local minrange = InteractDistances[1]
70 local maxrange = 255
71 -- Now we try to derive a bound for how far away it is
72 for i = #InteractDistances - 1, 1, -1 do
73 if CheckInteractDistance("mouseover", i) then
74 minrange = InteractDistances[i + 1]
75 maxrange = InteractDistances[i]
76 break
77 end
78 end
79 QuestHelper: Assert(minrange >= 0 and minrange < 256 and maxrange >= 0 and maxrange < 256)
80 Merger.Add(critter, GetLoc() .. strchar(minrange, maxrange))
82 if #recentlySeenCritters_Recent >= 100 then
83 for k, v in recentlySeenCritters_NextTrash do
84 recentlySeenCritters[v] = nil
85 end
87 recentlySeenCritters_NextTrash = recentlySeenCritters_Recent
88 recentlySeenCritters_Recent = {} -- BAM, garbage collection!
89 end
90 end
91 end
92 end
94 function QH_Collect_Monster_Init(QHCData, API)
95 if not QHCData.monster then QHCData.monster = {} end
96 QHCM = QHCData.monster
98 API.Registrar_EventHook("UPDATE_MOUSEOVER_UNIT", MouseoverUnit)
99 API.Registrar_EventHook("CHAT_MSG_SYSTEM", SystemMessage)
101 Patterns = API.Patterns
102 QuestHelper: Assert(Patterns)
104 API.Patterns_Register("DRUNK_MESSAGE_SELF1", "|c.*|r")
105 API.Patterns_Register("DRUNK_MESSAGE_SELF2", "|c.*|r")
106 API.Patterns_Register("DRUNK_MESSAGE_SELF3", "|c.*|r")
107 API.Patterns_Register("DRUNK_MESSAGE_SELF4", "|c.*|r")
108 API.Patterns_Register("DRUNK_MESSAGE_ITEM_SELF1", "|c.*|r")
109 API.Patterns_Register("DRUNK_MESSAGE_ITEM_SELF2", "|c.*|r")
110 API.Patterns_Register("DRUNK_MESSAGE_ITEM_SELF3", "|c.*|r")
111 API.Patterns_Register("DRUNK_MESSAGE_ITEM_SELF4", "|c.*|r")
113 GetLoc = API.Callback_LocationBolusCurrent
114 QuestHelper: Assert(GetLoc)
116 Merger = API.Utility_Merger
117 QuestHelper: Assert(Merger)