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
50 CTimerAfter(20, redo);
62 hooksecurefunc("InspectUnit", function()
65 hooksecurefunc("NotifyInspect", function(id)
66 if inspecting ~= UnitGUID(id) then
70 hooksecurefunc("ClearInspectPlayer", function()
75 -- make sure pending inspects get done at some point
76 if not InCombatLockdown() then
77 local guid, _ = next(pending);
78 if guid and cache[guid] and cache[guid].id then
80 inspect(cache[guid].id);
86 function OmaInspect.Request(guid, id, callback, needItems, force)
87 if not id or not CanInspect(id) then return false end
88 if not guid or UnitGUID(id) ~= guid then return false end
90 if not cache[guid] then cache[guid] = {} end
91 local cached = cache[guid];
92 if not cached.time then cached.time = 0 end
95 cached.needItems = needItems;
96 local elapsed = GetTime() - cached.time;
97 if force or (not needItems and (cached.talent == nil or elapsed > 60)) or
98 (needItems and (cached.weapon == nil or elapsed > 60)) then
99 if not pending[guid] or inspecting ~= guid then -- don't send multiple inspects
103 cached.cb(guid, cached.spec, cached.talent, cached.weapon, cached.wrist);
108 local function inspectReady(guid)
109 if not guid or inspecting ~= guid then return end
110 local cached = cache[guid];
111 if cached and cached.id and UnitGUID(cached.id) == guid then
112 local time = GetTime();
113 local id = cached.id;
116 if InCombatLockdown() and not inspectui then
117 pending[guid] = true;
118 if not inspectui then ClearInspectPlayer() end
120 if CanInspect(id) then
123 if cached.needItems then
124 cached.weapon = GetInventoryItemLink(id, INVSLOT_MAINHAND);
125 cached.wrist = GetInventoryItemID(id, INVSLOT_WRIST);
127 cached.spec = GetInspectSpecialization(id);
128 local _, _, _, selected = GetTalentInfo(6, 1, 1, true, id);
129 cached.talent = selected;
131 if not inspectui then ClearInspectPlayer() end
132 if (cached.needItems and cached.weapon) or
133 (not cached.needItems and cached.talent ~= nil) then
134 cached.cb(guid, cached.spec, cached.talent, cached.weapon, cached.wrist);
136 pending[guid] = true;
142 local function updateIds()
144 local prefix = "solo";
155 local id = format("%s%i", prefix, i);
156 local guid = UnitGUID(id);
157 if cache[guid] then cache[guid].id = id end
161 local function create()
162 frame:UnregisterAllEvents();
163 frame:SetScript("OnEvent", function(self, event, guid)
164 if event == "INSPECT_READY" then
166 elseif event == "GROUP_ROSTER_UPDATE" then
170 frame:RegisterEvent("INSPECT_READY");
171 frame:RegisterEvent("GROUP_ROSTER_UPDATE");
175 frame:SetScript("OnEvent", function(self, event)
178 frame:RegisterEvent("PLAYER_LOGIN");