public
Description: WoW Addon - Prospecting and Disenchanting Aide
Homepage: http://www.tekkub.net
Clone URL: git://github.com/tekkub/panda.git
Click here to lend your support to: panda and make a donation at www.pledgie.com !
commit  c77c341aaebf1221d1f386d58d8691fbeea190fc
tree    f8a19e655d4cf7b839d56a7f30be63a387484fbe
parent  01305ef6c21271188150166254b705312835e11f
panda / DETooltip.lua
100644 57 lines (43 sloc) 1.794 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

local Panda = Panda
local GS = Panda.GS
local GetItemInfo = GetItemInfo
 
 
local results, probs = {}, {}
local values = setmetatable({}, {
  __index = function(t, link)
    if not link then return end
 
    local name, _, qual, itemLevel, _, itemType, itemSubType, _, _, texture = GetItemInfo(link)
 
    if not name or not Panda:DEable(link) then
      t[link] = false
      return
    end
 
    local id1, qtytxt1, perctxt1, qty1, weight1, id2, qtytxt2, perctxt2, qty2, weight2, id3, _, _, qty3, weight3 = Panda:GetPossibleDisenchants(link)
    local bo1, bo2, bo3 = Panda:GetAHBuyout(id1), Panda:GetAHBuyout(id2), Panda:GetAHBuyout(id3)
    local mean = GS((id1 and qty1*weight1*bo1 or 0)+ (id2 and qty2*weight2*bo2 or 0) + (id3 and qty3*weight3*bo3 or 0))
    local mode = GS(qty1*bo1)
 
    if qual == 2 and itemType == "Weapon" then id1, qtytxt1, perctxt1 = id2, qtytxt2, perctxt2 end
    results[link] = qtytxt1.." "..select(2, GetItemInfo(id1))
    probs[link] = perctxt1
 
    val = string.format("%s (%s \206\188)", mode, mean)
    t[link] = val
    return val
  end,
})
 
 
local f = CreateFrame("Frame")
f:RegisterEvent("AUCTION_ITEM_LIST_UPDATE")
f:SetScript("OnEvent", function() for i in pairs(values) do values[i] = nil end end)
 
local origs = {}
local OnTooltipSetItem = function(frame, ...)
  assert(frame, "arg 1 is nil, someone isn't hooking correctly")
 
  local _, link = frame:GetItem()
  local val = values[link]
  if val and val ~= 0 then
    frame:AddDoubleLine("Disenchant ("..(probs[link] or "???").."):", results[link] or "???")
    frame:AddDoubleLine("Estimated DE Value:", val)
  end
  if origs[frame] then return origs[frame](frame, ...) end
end
 
for i,frame in pairs{GameTooltip, ItemRefTooltip} do
  origs[frame] = frame:GetScript("OnTooltipSetItem")
  frame:SetScript("OnTooltipSetItem", OnTooltipSetItem)
end