2012-01-01 04:01:18 +01:00
local GetTime = QuestHelper_GetTime
2010-11-08 14:28:59 +01:00
QuestHelper_File [ " collect_monster.lua " ] = " 4.0.1.$svnversion$ "
2010-10-24 23:17:33 +02:00
QuestHelper_Loadtime [ " collect_monster.lua " ] = GetTime ( )
local debug_output = false
if QuestHelper_File [ " collect_monster.lua " ] == " Development Version " then debug_output = true end
local QHCM
local GetLoc
local Merger
local Patterns
local IsMonsterGUID
local GetMonsterUID
local GetMonsterType
2012-01-01 03:22:56 +01:00
local logon = GetTime ( ) -- Because I'm incredibly paranoid, I'm waiting fifteen minutes after logon to assume they're not drunk.
2010-10-24 23:17:33 +02:00
local drunk_logon = true
local drunk_message = false
local function SystemMessage ( arg , arg2 , arg3 )
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
drunk_message = true
elseif strfind ( arg , Patterns [ " DRUNK_MESSAGE_SELF1 " ] ) or strfind ( arg , Patterns [ " DRUNK_MESSAGE_ITEM_SELF1 " ] ) then
drunk_message = false
end
end
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.
local recentlySeenCritters = { } -- We try not to repeatedly record critters frequently.
-- 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.
local recentlySeenCritters_NextTrash = { }
local recentlySeenCritters_Recent = { }
local function AccumulateFrequency ( target , name , data )
2011-01-22 03:44:34 +01:00
if not target [ name ] then target [ name ] = { } end
2011-01-21 12:17:58 +01:00
target [ name ] [ data ] = ( target [ name ] [ data ] or 0 ) + 1
--local key = name .. "_" .. tostring(data)
--target[key] = (target[key] or 0) + 1
2010-10-24 23:17:33 +02:00
end
local function MouseoverUnit ( )
2012-01-01 03:22:56 +01:00
if logon and logon + 60 * 15 < GetTime ( ) then
2010-10-24 23:17:33 +02:00
logon = nil
drunk_logon = false
end
2013-01-31 04:19:54 +01:00
2010-10-24 23:17:33 +02:00
-- First off, we see if it's "interesting".
-- The original code for this filtered out critters. I don't, because critters are cute, and rare.
if UnitExists ( " mouseover " ) and UnitIsVisible ( " mouseover " ) and not UnitIsPlayer ( " mouseover " ) and not UnitPlayerControlled ( " mouseover " ) then
local guid = UnitGUID ( " mouseover " )
2013-01-31 04:19:54 +01:00
2010-10-24 23:17:33 +02:00
if not IsMonsterGUID ( guid ) then return end -- pet that isn't controlled by a player? NPC pet? It's kind of unclear, but I'm getting some, so, FIXED
local creatureid = GetMonsterUID ( guid )
2013-01-31 04:19:54 +01:00
2010-10-24 23:17:33 +02:00
if not recentlySeenCritters [ creatureid ] then
recentlySeenCritters_Recent [ creatureid ] = true
recentlySeenCritters [ creatureid ] = true
2013-01-31 04:19:54 +01:00
2010-10-24 23:17:33 +02:00
-- register the critter here
local cid = GetMonsterType ( guid )
2013-01-31 04:19:54 +01:00
--if not QHCM[cid] then QHCM[cid] = {} end
--local critter = QHCM[cid]
local critter = { }
critter.id = cid
if cid < 30621 or cid > 30625 then
--AccumulateFrequency(critter, "name", UnitName("mouseover")) -- The exceptions are for Herald Volasj's minions, which are named after your partymembers.
critter.name = UnitName ( " mouseover " )
end
--AccumulateFrequency(critter, "reaction", UnitReaction("mouseover", "player"))
critter.reaction = UnitReaction ( " mouseover " , " player " )
2010-10-24 23:17:33 +02:00
if not drunk_logon and not drunk_message then
2013-01-31 04:19:54 +01:00
--AccumulateFrequency(critter, "level", UnitLevel("mouseover"))
critter.level = UnitLevel ( " mouseover " )
2010-10-24 23:17:33 +02:00
end
2013-01-31 04:19:54 +01:00
2010-10-24 23:17:33 +02:00
local minrange = InteractDistances [ 1 ]
local maxrange = 255
-- Now we try to derive a bound for how far away it is
for i = # InteractDistances - 1 , 1 , - 1 do
if CheckInteractDistance ( " mouseover " , i ) then
minrange = InteractDistances [ i + 1 ]
maxrange = InteractDistances [ i ]
break
end
end
QuestHelper : Assert ( minrange >= 0 and minrange < 256 and maxrange >= 0 and maxrange < 256 )
2013-01-31 04:19:54 +01:00
critter.loc = GetLoc ( )
critter.minrange = minrange
critter.maxrange = maxrange
table.insert ( QHCM , critter )
--[[
2011-01-21 02:06:11 +01:00
local data = { }
data.loc = GetLoc ( )
data.minrange = minrange
data.maxrange = maxrange
2011-06-19 06:05:19 +02:00
if not critter.encounters then critter.encounters = { } end
table.insert ( critter.encounters , data )
2013-01-31 04:19:54 +01:00
] ]
2011-01-21 02:06:11 +01:00
--Merger.Add(critter, string.format("(%s %s %s),", GetLoc(), tostring(minrange), tostring(maxrange))) --strchar(minrange, maxrange))
2013-01-31 04:19:54 +01:00
2010-10-24 23:17:33 +02:00
if # recentlySeenCritters_Recent >= 100 then
for k , v in recentlySeenCritters_NextTrash do
recentlySeenCritters [ v ] = nil
end
2013-01-31 04:19:54 +01:00
2010-10-24 23:17:33 +02:00
recentlySeenCritters_NextTrash = recentlySeenCritters_Recent
recentlySeenCritters_Recent = { } -- BAM, garbage collection!
end
end
end
end
2012-09-26 01:52:08 +02:00
function QH_Collect_Monster_FactionChange ( QHCData )
2010-10-24 23:17:33 +02:00
if not QHCData.monster then QHCData.monster = { } end
QHCM = QHCData.monster
2012-09-26 01:52:08 +02:00
end
function QH_Collect_Monster_Init ( QHCData , API )
QH_Collect_Monster_FactionChange ( QHCData )
2010-10-24 23:17:33 +02:00
QH_Event ( " UPDATE_MOUSEOVER_UNIT " , MouseoverUnit )
QH_Event ( " CHAT_MSG_SYSTEM " , SystemMessage )
2013-01-31 04:19:54 +01:00
2010-10-24 23:17:33 +02:00
Patterns = API.Patterns
QuestHelper : Assert ( Patterns )
2013-01-31 04:19:54 +01:00
2010-10-24 23:17:33 +02:00
API.Patterns_Register ( " DRUNK_MESSAGE_SELF1 " , " |c.*|r " )
API.Patterns_Register ( " DRUNK_MESSAGE_SELF2 " , " |c.*|r " )
API.Patterns_Register ( " DRUNK_MESSAGE_SELF3 " , " |c.*|r " )
API.Patterns_Register ( " DRUNK_MESSAGE_SELF4 " , " |c.*|r " )
API.Patterns_Register ( " DRUNK_MESSAGE_ITEM_SELF1 " , " |c.*|r " )
API.Patterns_Register ( " DRUNK_MESSAGE_ITEM_SELF2 " , " |c.*|r " )
API.Patterns_Register ( " DRUNK_MESSAGE_ITEM_SELF3 " , " |c.*|r " )
API.Patterns_Register ( " DRUNK_MESSAGE_ITEM_SELF4 " , " |c.*|r " )
GetLoc = API.Callback_LocationBolusCurrent
QuestHelper : Assert ( GetLoc )
2013-01-31 04:19:54 +01:00
2010-10-24 23:17:33 +02:00
Merger = API.Utility_Merger
QuestHelper : Assert ( Merger )
2013-01-31 04:19:54 +01:00
2010-10-24 23:17:33 +02:00
IsMonsterGUID = API.Utility_IsMonsterGUID
GetMonsterUID = API.Utility_GetMonsterUID
GetMonsterType = API.Utility_GetMonsterType
QuestHelper : Assert ( IsMonsterGUID )
QuestHelper : Assert ( GetMonsterUID )
QuestHelper : Assert ( GetMonsterType )
end