-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCapture.lua
More file actions
142 lines (128 loc) · 4.19 KB
/
Copy pathCapture.lua
File metadata and controls
142 lines (128 loc) · 4.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
local ADDON_NAME, ns = ...
local Capture = {}
ns.Capture = Capture
-- Hidden tooltip used only to scan inventory items for empty gem sockets.
local scanner = CreateFrame("GameTooltip", "ScryScanTooltip", UIParent, "GameTooltipTemplate")
scanner:SetOwner(UIParent, "ANCHOR_NONE")
-- Localized "Empty Socket" strings; whatever the client exposes.
local EMPTY_SOCKET_STRINGS = {}
for _, g in ipairs({ "EMPTY_SOCKET_RED", "EMPTY_SOCKET_YELLOW", "EMPTY_SOCKET_BLUE", "EMPTY_SOCKET_META", "EMPTY_SOCKET_PRISMATIC" }) do
local s = _G[g]
if s then
EMPTY_SOCKET_STRINGS[s] = true
end
end
-- Find the unit token whose GUID matches, without ever initiating an inspect.
local function unitForGUID(guid)
local candidates = { "target", "mouseover", "focus" }
if IsInRaid() then
for i = 1, GetNumGroupMembers() do
candidates[#candidates + 1] = "raid" .. i
end
elseif IsInGroup() then
for i = 1, GetNumGroupMembers() - 1 do
candidates[#candidates + 1] = "party" .. i
end
end
for _, unit in ipairs(candidates) do
if UnitExists(unit) and UnitGUID(unit) == guid then
return unit
end
end
return nil
end
-- Parse enchant id (and gem ids) out of an item link's itemString.
local function parseItemString(link)
-- item:itemID:enchantId:gem1:gem2:gem3:gem4:...
local itemString = link:match("item[%-?%d:]+")
if not itemString then
return nil
end
local fields = {}
for v in (itemString .. ":"):gmatch("(.-):") do
fields[#fields + 1] = v
end
local enchantId = tonumber(fields[3]) or 0 -- fields[1]="item", fields[2]=itemID, fields[3]=enchant
return enchantId
end
-- Count empty gem sockets on the item currently in `slotId` of `unit`.
local function countEmptySockets(unit, slotId)
scanner:ClearLines()
scanner:SetOwner(UIParent, "ANCHOR_NONE")
scanner:SetInventoryItem(unit, slotId)
local empty = 0
for i = 1, scanner:NumLines() do
local fs = _G["ScryScanTooltipTextLeft" .. i]
local text = fs and fs:GetText()
if text and EMPTY_SOCKET_STRINGS[text] then
empty = empty + 1
end
end
return empty
end
-- Read the inspected unit's talent spread. Taint-free: only reads after INSPECT_READY.
-- Prefers C_SpecializationInfo (used by the Classic InspectTalentFrame); falls back to
-- the classic global GetTalentTabInfo. Returns { tabs = { {name, points} }, total, spec } or nil.
local function captureTalents()
local csi = C_SpecializationInfo
local numTabs = (GetNumTalentTabs and GetNumTalentTabs(true)) or 3
local group = (csi and csi.GetActiveSpecGroup and csi.GetActiveSpecGroup(true)) or nil
local tabs, total, best, bestPts, parts = {}, 0, nil, -1, {}
for i = 1, numTabs do
local name, points
if csi and csi.GetSpecializationInfo then
local _, n, _, _, _, _, p = csi.GetSpecializationInfo(i, true, false, nil, nil, group)
name, points = n, p
elseif GetTalentTabInfo then
name, _, points = GetTalentTabInfo(i, true)
end
if not name then
break
end
points = points or 0
tabs[i] = { name = name, points = points }
total = total + points
parts[#parts + 1] = tostring(points)
if points > bestPts then
bestPts, best = points, name
end
end
if #tabs == 0 then
return nil
end
local spec = (best and (best .. " ") or "") .. table.concat(parts, "/")
return { tabs = tabs, total = total, spec = spec }
end
function Capture:OnInspectReady(guid)
if not guid then
return
end
local unit = unitForGUID(guid)
if not unit or not UnitIsPlayer(unit) then
return
end
local _, classFile = UnitClass(unit)
local name, realm = UnitName(unit)
local record = {
name = name,
realm = realm,
class = classFile,
time = time(), -- epoch seconds, so TTL survives reloads (GetTime() would not)
slots = {},
}
for _, slot in ipairs(ns.Checks.SLOTS) do
local link = GetInventoryItemLink(unit, slot.id)
if link then
record.slots[slot.id] = {
link = link,
enchantId = parseItemString(link),
emptySockets = countEmptySockets(unit, slot.id),
}
end
end
if ns.db.profile.checkTalents then
record.talents = captureTalents()
end
record.problems = ns.Checks:Analyze(record)
ns.db.global.cache[guid] = record
end