will this help? maybe
[QuestHelper.git] / collect_object.lua
blob65c4527ca4bf00539cb7cd19c3809e89b9b612ec
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 --[[
31 if lines == 2 then -- see if we're mine or herb
32 for k, v in pairs(minetypes) do
33 if _G["GameTooltipTextLeft2"]:GetText() == v then
34 skintype = k
35 end
36 end
37 if not skintype then return end -- we are neither!
38 elseif lines == 0 then -- this isn't much of anything, is it
39 return
40 end]]
42 if not skintype then
43 local cline = 2
45 -- the painful process of checking to see if it might be a game object
46 -- first, look for a "requires" line
48 if not (_G["GameTooltipTextLeft" .. cline] and _G["GameTooltipTextLeft" .. cline]:IsShown()) then return end
51 local gt = _G["GameTooltipTextLeft" .. cline]:GetText()
52 if string.match(gt, Patterns.LOCKED_WITH_ITEM) or string.match(gt, Patterns.LOCKED_WITH_SPELL) or string.match(gt, Patterns.LOCKED_WITH_SPELL_KNOWN) then cline = cline + 1 end
53 end
55 if not (_G["GameTooltipTextLeft" .. cline] and _G["GameTooltipTextLeft" .. cline]:IsShown()) then return end
57 local r, g, b, a = _G["GameTooltipTextLeft" .. cline]:GetTextColor()
58 r, g, b, a = math.floor(r * 255 + 0.5), math.floor(g * 255 + 0.5), math.floor(b * 255 + 0.5), math.floor(a * 255 + 0.5)
59 if not (r == 255 and g == 210 and b == 0 and a == 255) then return end -- not a quest item, which I guess we care about
60 cline = cline + 1
62 if not (_G["GameTooltipTextLeft" .. cline] and _G["GameTooltipTextLeft" .. cline]:IsShown()) then return end
64 local r, g, b, a = _G["GameTooltipTextLeft" .. cline]:GetTextColor()
65 r, g, b, a = math.floor(r * 255 + 0.5), math.floor(g * 255 + 0.5), math.floor(b * 255 + 0.5), math.floor(a * 255 + 0.5)
66 if not (r == 255 and g == 255 and b == 255 and a == 255) or not _G["GameTooltipTextLeft" .. cline]:GetText():match("^ - ") then return end -- not a quest item, which I guess we care about
68 -- alright good enough
69 end
71 local name = _G["GameTooltipTextLeft1"]:GetText()
73 if string.match(name, Patterns.CORPSE_TOOLTIP) then return end -- no corpses plzkthx
75 if debug_output then QuestHelper:TextOut("Parsing " .. name) end
77 if not QHCO[name] then QHCO[name] = {} end
78 local qhci = QHCO[name]
80 --[[
81 for k, _ in pairs(minetypes) do
82 if k == skintype then
83 qhci[k .. "_yes"] = (qhci[k .. "_yes"] or 0) + 1
84 else
85 qhci[k .. "_no"] = (qhci[k .. "_no"] or 0) + 1
86 end
87 end]]
89 -- 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.
90 -- Obviously, we also have no possible range data, so, welp.
91 Merger.Add(qhci, GetLoc(), true)
92 end
93 end
95 function QH_Collect_Object_Init(QHCData, API)
96 if not QHCData.object then QHCData.object = {} end
97 QHCO = QHCData.object
99 API.Registrar_TooltipHook(Tooltipy)
101 Patterns = API.Patterns
102 QuestHelper: Assert(Patterns)
104 API.Patterns_Register("CORPSE_TOOLTIP", "[^%s]+")
105 API.Patterns_Register("LOCKED_WITH_ITEM", "[^%s]+")
106 API.Patterns_Register("LOCKED_WITH_SPELL", "[^%s]+")
107 API.Patterns_Register("LOCKED_WITH_SPELL_KNOWN", "[^%s]+")
109 GetLoc = API.Callback_LocationBolusCurrent
110 QuestHelper: Assert(GetLoc)
112 Merger = API.Utility_Merger
113 QuestHelper: Assert(Merger)