PageRenderTime 62ms CodeModel.GetById 40ms app.highlight 3ms RepoModel.GetById 17ms app.codeStats 0ms

/Tukui/modules/tooltip/tooltipilvl.lua

http://github.com/Asphyxia/Tukui
Lua | 42 lines | 34 code | 4 blank | 4 comment | 7 complexity | 63050d2fe9397ce992f516ae9132854b MD5 | raw file
 1-- Credits to Gsuz
 2
 3local T, C, L = unpack(Tukui)
 4if C.tooltip.enable ~= true then return end
 5
 6-- Setup slotnames
 7local SlotName = {
 8        "Head","Neck","Shoulder","Back","Chest","Wrist",
 9        "Hands","Waist","Legs","Feet","Finger0","Finger1",
10        "Trinket0","Trinket1","MainHand","SecondaryHand","Ranged","Ammo"
11    }
12	
13-- Scan target's items
14local function GetItemLVL(unit)
15local total, item = 0, 0;
16    for i in pairs(SlotName) do
17        local slot = GetInventoryItemLink(unit, GetInventorySlotInfo(SlotName[i] .. "Slot"));
18        if (slot ~= nil) then
19            item = item + 1;
20            total = total + select(4, GetItemInfo(slot))
21        end
22    end
23    if (item > 0) then
24        return floor(total / item);
25    end
26    return 0;
27end
28
29-- Insert into tooltip
30GameTooltip:HookScript("OnTooltipSetUnit", function(self, ...)
31    if (IsShiftKeyDown()) then
32        local _, unit = GameTooltip:GetUnit();
33        if (unit and CanInspect(unit)) then
34            if (not ((InspectFrame and InspectFrame:IsShown()) or (Examiner and Examiner:IsShown()))) then
35                NotifyInspect(unit);
36                GameTooltip:AddLine("Item Level: " .. GetItemLVL(unit));
37                ClearInspectPlayer(unit);
38                GameTooltip:Show();
39            end
40        end
41    end
42end)