update changes
[QuestHelper.git] / collect_object.lua
blob15bc27e00502cbc62eeffa6825271c893d6d6468
1 QuestHelper_File["collect_object.lua"] = "Development Version"
2 QuestHelper_Loadtime["collect_object.lua"] = GetTime()
4 local debug_output = false
5 if QuestHelper_File["collect_object.lua"] == "Development Version" then debug_output = true end
7 local QHCO
9 local GetLoc
10 local Merger
11 local Patterns
13 local minetypes = {
14 mine = UNIT_SKINNABLE_ROCK,
15 herb = UNIT_SKINNABLE_HERB,
16 eng = UNIT_SKINNABLE_BOLTS,
17 skin = UNIT_SKINNABLE_LEATHER,
20 local function Tooltipy(self)
21 -- objects are a bitch since they have no unique ID or any standard way to detect them (that I know of).
22 -- So we kind of guess at it.
23 if self:GetAnchorType() == "ANCHOR_NONE" then
24 if self:GetItem() or self:GetUnit() or self:GetSpell() then return end
25 -- rglrglrglrglrglrgl
27 local skintype = nil
29 local lines = GameTooltip:NumLines()
30 if lines > 2 then -- not a normal world item
31 return
32 elseif lines == 2 then -- see if we're mine or herb
33 for k, v in pairs(minetypes) do
34 if _G["GameTooltipTextLeft2"]:GetText() == v then
35 skintype = k
36 end
37 end
38 if not skintype then return end -- we are neither!
39 elseif lines == 0 then -- this isn't much of anything, is it
40 return
41 end
43 local name = _G["GameTooltipTextLeft1"]:GetText()
45 if string.match(name, Patterns.CORPSE_TOOLTIP) then return end -- no corpses plzkthx
47 if not QHCO[name] then QHCO[name] = {} end
48 local qhci = QHCO[name]
50 for k, _ in pairs(minetypes) do
51 if k == skintype then
52 qhci[k .. "_yes"] = (qhci[k .. "_yes"] or 0) + 1
53 else
54 qhci[k .. "_no"] = (qhci[k .. "_no"] or 0) + 1
55 end
56 end
58 -- We have no unique identifier, so I'm just going to record every position we see. That said, I wonder if it's a good idea to add a cooldown.
59 -- Obviously, we also have no possible range data, so, welp.
60 Merger.Add(qhci, GetLoc(), true)
61 end
62 end
64 function QH_Collect_Object_Init(QHCData, API)
65 if not QHCData.object then QHCData.object = {} end
66 QHCO = QHCData.object
68 API.Registrar_TooltipHook(Tooltipy)
70 Patterns = API.Patterns
71 QuestHelper: Assert(Patterns)
73 API.Patterns_Register("CORPSE_TOOLTIP", "[^%s]+")
75 GetLoc = API.Callback_LocationBolusCurrent
76 QuestHelper: Assert(GetLoc)
78 Merger = API.Utility_Merger
79 QuestHelper: Assert(Merger)
80 end