3 local next, print = next, print;
4 local format = string.format;
5 local InCombatLockdown = InCombatLockdown;
6 local CTimerAfter = C_Timer.After;
7 local UnitIsDeadOrGhost = UnitIsDeadOrGhost;
8 local IsInGroup, IsInRaid = IsInGroup, IsInRaid;
9 local CheckInteractDistance = CheckInteractDistance;
10 local GetTime, UnitGUID, UnitName = GetTime, UnitGUID, UnitName;
11 local CanInspect, NotifyInspect, ClearInspectPlayer = CanInspect, NotifyInspect, ClearInspectPlayer;
12 local GetInventoryItemLink, GetInventoryItemID = GetInventoryItemLink, GetInventoryItemID;
13 local GetTalentInfo, GetInspectSpecialization = GetTalentInfo, GetInspectSpecialization;
14 local INVSLOT_MAINHAND, INVSLOT_WRIST = INVSLOT_MAINHAND, INVSLOT_WRIST;
18 local inspecting = nil;
19 local inspectui = nil;
20 local frame = CreateFrame("Frame", "OmaInspect");
26 if redoGuid and inspecting == redoGuid then
27 print("hit redo timeout, putting back on pending");
28 pending[redoGuid] = true;
31 if not inspectui then ClearInspectPlayer() end
35 local function inspect(id)
36 local guid = UnitGUID(id);
37 if not guid then return end
38 if InCombatLockdown() then
40 elseif not inspectui then
41 -- not necessary, but there's too many issues with inspect,
42 -- try to hope being nearby makes it more likely to work
43 -- no need to inspect people not in range before pull anyway
44 if not UnitIsDeadOrGhost("player") and
45 CheckInteractDistance(id, 1) and CanInspect(id) then
46 if not inspecting then
48 print("Sending inspect", UnitName(id));
51 CTimerAfter(20, redo);
63 hooksecurefunc("InspectUnit", function()
66 hooksecurefunc("NotifyInspect", function(id)
67 if inspecting ~= UnitGUID(id) then
71 hooksecurefunc("ClearInspectPlayer", function()
76 -- make sure pending inspects get done at some point
77 if not InCombatLockdown() then
78 local guid, _ = next(pending);
79 if guid and cache[guid] and cache[guid].id then
81 inspect(cache[guid].id);
87 function OmaInspect.Request(guid, id, callback, needItems, force)
88 if not id or not CanInspect(id) then return false end
89 if not guid or UnitGUID(id) ~= guid then return false end
91 if not cache[guid] then cache[guid] = {} end
92 local cached = cache[guid];
93 if not cached.time then cached.time = 0 end
96 cached.needItems = needItems;
97 local elapsed = GetTime() - cached.time;
98 if force or (not needItems and (not cached.talent or elapsed > 60)) or
99 (needItems and (not cached.weapon or elapsed > 60)) then
100 if not pending[guid] or inspecting ~= guid then -- don't send multiple inspects
104 cached.cb(guid, cached.spec, cached.talent, cached.weapon, cached.wrist);
109 local function inspectReady(guid)
110 if not guid or inspecting ~= guid then print("Got inspect from elsewhere"); return end
111 local cached = cache[guid];
112 if cached and cached.id and UnitGUID(cached.id) == guid then
113 local time = GetTime();
114 local id = cached.id;
117 if InCombatLockdown() and not inspectui then
118 pending[guid] = true;
119 if not inspectui then ClearInspectPlayer() end
121 if CanInspect(id) then
122 if time - cached.time > 60 then -- refresh >1min
125 if cached.needItems then
126 cached.weapon = GetInventoryItemLink(id, INVSLOT_MAINHAND);
127 cached.wrist = GetInventoryItemID(id, INVSLOT_WRIST);
129 cached.spec = GetInspectSpecialization(id);
130 local _, _, _, selected = GetTalentInfo(6, 2, 1, true, id);
131 cached.talent = selected;
134 if not inspectui then ClearInspectPlayer() end
135 if (cached.needItems and cached.weapon) or
136 (not cached.needItems and cached.talent ~= nil) then
137 print("Got inspect done", UnitName(id));
138 cached.cb(guid, cached.spec, cached.talent, cached.weapon, cached.wrist);
140 pending[guid] = true;
146 local function updateIds()
148 local prefix = "solo";
159 local id = format("%s%i", prefix, i);
160 local guid = UnitGUID(id);
161 if cache[guid] then cache[guid].id = id end
165 local function create()
166 frame:UnregisterAllEvents();
167 frame:SetScript("OnEvent", function(self, event, guid)
168 if event == "INSPECT_READY" then
170 elseif event == "GROUP_ROSTER_UPDATE" then
174 frame:RegisterEvent("INSPECT_READY");
175 frame:RegisterEvent("GROUP_ROSTER_UPDATE");
179 frame:RegisterEvent("PLAYER_LOGIN");
180 frame:SetScript("OnEvent", function(self, event)
181 if event == "PLAYER_LOGIN" then