3 local next, print = next, print;
4 local format = string.format;
5 local InCombatLockdown = InCombatLockdown;
6 local CTimerAfter = C_Timer.After;
7 local IsInGroup, IsInRaid = IsInGroup, IsInRaid;
8 local CheckInteractDistance = CheckInteractDistance;
9 local GetTime, UnitGUID, UnitName = GetTime, UnitGUID, UnitName;
10 local CanInspect, NotifyInspect, ClearInspectPlayer = CanInspect, NotifyInspect, ClearInspectPlayer;
11 local GetInventoryItemLink, GetInventoryItemID = GetInventoryItemLink, GetInventoryItemID;
12 local GetTalentInfo, GetInspectSpecialization = GetTalentInfo, GetInspectSpecialization;
13 local INVSLOT_MAINHAND, INVSLOT_WRIST = INVSLOT_MAINHAND, INVSLOT_WRIST;
17 local inspecting = nil;
18 local inspectui = nil;
19 local frame = CreateFrame("Frame", "OmaInspect");
25 if redoGuid and inspecting == redoGuid then
26 print("hit redo timeout, putting back on pending");
27 pending[redoGuid] = true;
30 if not inspectui then ClearInspectPlayer() end
34 local function inspect(id)
35 local guid = UnitGUID(id);
36 if not guid then return end
37 if InCombatLockdown() then
39 elseif not inspectui then
40 -- not necessary, but there's too many issues with inspect,
41 -- try to hope being nearby makes it more likely to work
42 -- no need to inspect people not in range before pull anyway
43 if CheckInteractDistance(id, 1) then
44 if not inspecting then
46 print("Sending inspect", UnitName(id));
49 CTimerAfter(20, redo);
61 hooksecurefunc("InspectUnit", function()
64 hooksecurefunc("NotifyInspect", function(id)
65 if inspecting ~= UnitGUID(id) then
69 hooksecurefunc("ClearInspectPlayer", function()
74 -- make sure pending inspects get done at some point
75 if not InCombatLockdown() then
76 local guid, _ = next(pending);
77 if guid and cache[guid] and cache[guid].id then
79 inspect(cache[guid].id);
85 function OmaInspect.Request(guid, id, callback, needItems, force)
86 if not id or not CanInspect(id) then return false end
87 if not guid or UnitGUID(id) ~= guid then return false end
89 if not cache[guid] then cache[guid] = {} end
90 local cached = cache[guid];
91 if not cached.time then cached.time = 0 end
94 cached.needItems = needItems;
95 local elapsed = GetTime() - cached.time;
96 if force or (not needItems and (not cached.talent ~= nil or elapsed > 60)) or
97 (needItems and (not cached.weapon or elapsed > 60)) then
98 if not pending[guid] or inspecting ~= guid then -- don't send multiple inspects
102 cached.cb(guid, cached.spec, cached.talent, cached.weapon, cached.wrist);
107 local function inspectReady(guid)
108 if not guid or inspectui then return end
109 local cached = cache[guid];
110 if cached and cached.id and UnitGUID(cached.id) == guid then
111 local time = GetTime();
112 local id = cached.id;
115 if InCombatLockdown() and not inspectui then
116 pending[guid] = true;
117 ClearInspectPlayer();
119 if CanInspect(id) then
120 if time - cached.time > 60 then -- refresh >1min
124 cached.weapon = GetInventoryItemLink(id, INVSLOT_MAINHAND);
125 cached.wrist = GetInventoryItemID(id, INVSLOT_WRIST);
127 cached.spec = GetInspectSpecialization(id);
128 local _, _, _, selected = GetTalentInfo(6, 2, 1, true, id);
129 cached.talent = selected;
132 ClearInspectPlayer();
133 if (cached.needItems and cached.weapon) or
134 (not cached.needItems and cached.talent ~= nil) then
135 print("Got inspect done", UnitName(id));
136 cached.cb(guid, cached.spec, cached.talent, cached.weapon, cached.wrist);
138 pending[guid] = true;
144 local function updateIds()
146 local prefix = "solo";
157 local id = format("%s%i", prefix, i);
158 local guid = UnitGUID(id);
159 if cache[guid] then cache[guid].id = id end
163 local function create()
164 frame:UnregisterAllEvents();
165 frame:SetScript("OnEvent", function(self, event, guid)
166 if event == "INSPECT_READY" then
168 elseif event == "GROUP_ROSTER_UPDATE" then
172 frame:RegisterEvent("INSPECT_READY");
173 frame:RegisterEvent("GROUP_ROSTER_UPDATE");
177 frame:RegisterEvent("PLAYER_LOGIN");
178 frame:SetScript("OnEvent", function(self, event)
179 if event == "PLAYER_LOGIN" then