Skip to content

Commit

Permalink
Update ItemLevel.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
leg883 committed Jul 8, 2015
1 parent 80d9447 commit e2ce2f2
Showing 1 changed file with 39 additions and 58 deletions.
97 changes: 39 additions & 58 deletions ShestakUI/Modules/Tooltip/ItemLevel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ if C.tooltip.enable ~= true or C.tooltip.average_lvl ~= true then return end
----------------------------------------------------------------------------------------
-- Equipped average item level(Cloudy Unit Info by Cloudyfa)
----------------------------------------------------------------------------------------

--- Variables ---
local currentID, currentGUID
local currentUNIT, currentGUID
local GearDB, SpecDB = {}, {}

local nextInspectRequest = 0
Expand All @@ -15,11 +14,12 @@ local lastInspectRequest = 0
local prefixColor = "|cffF9D700"
local detailColor = "|cffffffff"

local gearPrefix = STAT_FORMAT:format(STAT_AVERAGE_ITEM_LEVEL).."|Heqppditmlvl|h |h"..HIGHLIGHT_FONT_COLOR_CODE
local gearPrefix = STAT_AVERAGE_ITEM_LEVEL .. ": "
local specPrefix = SPECIALIZATION .. ": "
local _

--- Create Frame ---
local f = CreateFrame("Frame")
local f = CreateFrame("Frame", "CloudyUnitInfo")
f:RegisterEvent("UNIT_INVENTORY_CHANGED")
f:RegisterEvent("INSPECT_READY")

Expand Down Expand Up @@ -65,33 +65,9 @@ local function SetUnitInfo(gear, spec)
GameTooltip:Show()
end

--- BOA Item Level ---
local function BOALevel(level, slot)
if (level > 80) and (slot ~= "INVTYPE_CLOAK") and (slot ~= "INVTYPE_HEAD") and (slot ~= "INVTYPE_LEGS") then
level = 80
elseif (level > 85) then
level = 85
end

if (level > 83) then
level = 333 - (85 - level) * 8
elseif (level > 80) then
level = 317 - (83 - level) * 17
elseif (level >= 68) then
level = 187 - (80 - level) * 4
elseif (level >= 58) then
level = 109 - (68 - level) * 3
else
level = level + 5
end

return level
end

--- PVP Item Detect ---
local function IsPVPItem(link)
local itemStats = GetItemStats(link)

for stat in pairs(itemStats) do
if (stat == "ITEM_MOD_RESILIENCE_RATING_SHORT") or (stat == "ITEM_MOD_PVP_POWER_SHORT") then
return true
Expand Down Expand Up @@ -122,39 +98,44 @@ local function GetItemLevel(itemLink)
end

--- Unit Gear Info ---
local function UnitGear(id)
if (not id) or (UnitGUID(id) ~= currentGUID) then return end
local function UnitGear(unit)
if (not unit) or (UnitGUID(unit) ~= currentGUID) then return end

local ulvl = UnitLevel(id)
local class = select(2, UnitClass(id))
local ulvl = UnitLevel(unit)
local class = select(2, UnitClass(unit))

local ilvl, boa, pvp = 0, 0, 0
local total, count, delay = 0, 16, nil
local mainhand, offhand, twohand = 1, 1, 0

for i = 1, 17 do
if (i ~= 4) then
local itemTexture = GetInventoryItemTexture(id, i)
local itemTexture = GetInventoryItemTexture(unit, i)

if itemTexture then
local itemLink = GetInventoryItemLink(id, i)
local itemLink = GetInventoryItemLink(unit, i)

if (not itemLink) then
delay = true
else
local _, _, quality, level, _, _, _, _, slot = GetItemInfo(itemLink)
local currentLevel = GetItemLevel(itemLink)

if (not quality) or (not level) then
delay = true
else
local currentLevel = GetItemLevel(itemLink)
if currentLevel then
total = total + currentLevel
else
total = total + level
end
if IsPVPItem(itemLink) then
pvp = pvp + 1

if quality == 7 then
boa = boa + 1
else
if IsPVPItem(itemLink) then
pvp = pvp + 1
end
end

if (i >= 16) then
Expand All @@ -179,15 +160,15 @@ local function UnitGear(id)
end

if (not delay) then
if (id == "player") and (GetAverageItemLevel() > 0) then
if (unit == "player") and (GetAverageItemLevel() > 0) then
_, ilvl = GetAverageItemLevel()
else
ilvl = total / count
end

if (ilvl > 0) then ilvl = string.format("%.1f", ilvl) end
if (boa > 0) then ilvl = ilvl .. " |cffe6cc80" .. boa .. " BOA" end
if (pvp > 0) then ilvl = ilvl .. " |cffa335ee" .. pvp .. " PvP" end
if (boa > 0) then ilvl = ilvl .. " |cffe6cc80" .. boa .. " " .. HEIRLOOMS end
if (pvp > 0) then ilvl = ilvl .. " |cffa335ee" .. pvp .. " " .. PVP end
else
ilvl = nil
end
Expand All @@ -196,12 +177,12 @@ local function UnitGear(id)
end

--- Unit Specialization ---
local function UnitSpec(id)
if (not id) or (UnitGUID(id) ~= currentGUID) then return end
local function UnitSpec(unit)
if (not unit) or (UnitGUID(unit) ~= currentGUID) then return end

local specName

if (id == "player") then
if (unit == "player") then
local specIndex = GetSpecialization()

if specIndex then
Expand All @@ -210,7 +191,7 @@ local function UnitSpec(id)
specName = NONE
end
else
local specID = GetInspectSpecialization(id)
local specID = GetInspectSpecialization(unit)

if specID and (specID > 0) then
_, specName = GetSpecializationInfoByID(specID)
Expand All @@ -223,16 +204,16 @@ local function UnitSpec(id)
end

--- Scan Current Unit ---
local function ScanUnit(id, forced)
local function ScanUnit(unit, forced)
local cachedGear, cachedSpec

if UnitIsUnit(id, "player") then
if UnitIsUnit(unit, "player") then
cachedGear = UnitGear("player")
cachedSpec = UnitSpec("player")

SetUnitInfo(cachedGear or CONTINUED, cachedSpec or CONTINUED)
else
if (not id) or (UnitGUID(id) ~= currentGUID) then return end
if (not unit) or (UnitGUID(unit) ~= currentGUID) then return end

cachedGear = GearDB[currentGUID]
--cachedSpec = SpecDB[currentGUID]
Expand All @@ -248,7 +229,7 @@ local function ScanUnit(id, forced)
if UnitAffectingCombat("player") then return end
end

if (not UnitIsVisible(id)) then return end
if (not UnitIsVisible(unit)) then return end
if UnitIsDeadOrGhost("player") or UnitOnTaxi("player") then return end
if InspectFrame and InspectFrame:IsShown() then return end

Expand Down Expand Up @@ -278,7 +259,7 @@ hooksecurefunc("PaperDollFrame_SetItemLevel", function(self, unit)
if (equip > 0) then equip = string.format("%.1f", equip) end

local ilvl = equip
if (equip < total) then
if (equip ~= total) then
ilvl = equip .. " / " .. total
end

Expand All @@ -291,22 +272,22 @@ end)
--- Handle Events ---
f:SetScript("OnEvent", function(self, event, ...)
if (event == "UNIT_INVENTORY_CHANGED") then
local id = ...
if (UnitGUID(id) == currentGUID) then
ScanUnit(id, true)
local unit = ...
if (UnitGUID(unit) == currentGUID) then
ScanUnit(unit, true)
end
elseif (event == "INSPECT_READY") then
local guid = ...
if (guid ~= currentGUID) then return end

local gear = UnitGear(currentID)
local gear = UnitGear(currentUNIT)
GearDB[currentGUID] = gear

local spec = UnitSpec(currentID)
local spec = UnitSpec(currentUNIT)
SpecDB[currentGUID] = spec

if (not gear) or (not spec) then
ScanUnit(currentID, true)
ScanUnit(currentUNIT, true)
else
SetUnitInfo(gear, spec)
end
Expand All @@ -319,9 +300,9 @@ f:SetScript("OnUpdate", function(self, elapsed)

self:Hide()

if currentID and (UnitGUID(currentID) == currentGUID) then
if currentUNIT and (UnitGUID(currentUNIT) == currentGUID) then
lastInspectRequest = GetTime()
NotifyInspect(currentID)
NotifyInspect(currentUNIT)
end
end)

Expand All @@ -331,6 +312,6 @@ GameTooltip:HookScript("OnTooltipSetUnit", function(self)
if (not unit) or (not CanInspect(unit)) then return end
if (UnitLevel(unit) > 0) and (UnitLevel(unit) < 10) then return end

currentID, currentGUID = unit, UnitGUID(unit)
currentUNIT, currentGUID = unit, UnitGUID(unit)
ScanUnit(unit)
end)

0 comments on commit e2ce2f2

Please sign in to comment.