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 !
tekkub (author)
Fri Jun 27 20:44:44 -0700 2008
commit  0549be7ae2f3eb24cbe1079fdd19372e4586c7df
tree    4e2431039d3768d1744f442524013ae08fa1a1b2
parent  21e00a5520c69bc10efc9f3f93e7802b4b6043a5
panda / BtmScanner.lua
100644 129 lines (103 sloc) 3.948 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
function Panda:ADDON_LOADED(event, addon)
  if addon ~= "BtmScan" then return end
 
  local libName = "Panda DE"
  local lcName = libName:lower()
  local lib = { name = lcName, propername = libName }
  table.insert(BtmScan.evaluators, lcName)
  local define = BtmScan.Settings.SetDefault
  local get = BtmScan.Settings.GetSetting
  local set = BtmScan.Settings.SetSetting
 
  BtmScan.evaluators[lcName] = lib
 
 
  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, _, _, qty1 = Panda:GetPossibleDisenchants(link)
      local bo1 = Panda:GetAHBuyout(id1)
 
      val = qty1*bo1
      t[link] = val
      return val
    end,
  })
 
 
  function lib:valuate(item, tooltip)
    local price = 0
 
    if not get(lcName..".enable") or item.qual <= 1 then return end
 
    -- Valuate this item
    local market = values[item.id]
    if not market then
      item:info("Unable to get DE value")
      return
    end
    item:info("Disenchant value", market)
 
    -- Adjust for brokerage / deposit costs
    local adjusted = market
    local brokerage = get(lcName..'.adjust.brokerage')
 
    if brokerage then
      local basis = get(lcName..'.adjust.basis')
      local brokerRate, depositRate = 0.05, 0.05
      if (basis == "neutral") then
        brokerRate, depositRate = 0.15, 0.25
      end
      if (brokerage) then
        local amount = (market * brokerRate)
        adjusted = adjusted - amount
        item:info(" - Brokerage", amount)
      end
      item:info(" = Adjusted amount", adjusted)
    end
 
    -- Calculate the real value of this item once our profit is taken out
    local pct = get(lcName..".profit.pct")
    local min = get(lcName..".profit.min")
    local value, mkdown = BtmScan.Markdown(adjusted, pct, min)
    item:info((" - %d%% / %s markdown"):format(pct,BtmScan.GSC(min, true)), mkdown)
 
    -- Check for tooltip evaluation
    if tooltip then
      item.what = self.name
      item.valuation = value
      if item.bid == 0 then return end
    end
 
    -- If the current purchase price is more than our valuation,
    -- another module "wins" this purchase.
    if value < item.purchase then return end
 
    -- Check to see what the most we can pay for this item is.
    if item.canbuy and item.buy < value then price = item.buy
    elseif item.canbid and item.bid < value then price = item.bid end
 
    -- Check our projected profit level
    local profit = price > 0 and (value - price) or 0
 
    -- If what we are willing to pay for this item beats what
    -- other modules are willing to pay, and we can make more
    -- profit, then we "win".
    if price >= item.purchase and profit > item.profit then
      item.purchase = price
      item.reason = self.name
      item.what = self.name
      item.profit = profit
      item.valuation = market
    end
  end
 
  local ahList = {
    {'faction', "Faction AH Fees"},
    {'neutral', "Neutral AH Fees"},
  }
 
  define(lcName..'.enable', true)
  define(lcName..'.profit.min', 4500)
  define(lcName..'.profit.pct', 45)
  define(lcName..'.adjust.brokerage', true)
  define(lcName..'.adjust.basis', "faction")
 
  function lib:setup(gui)
    id = gui:AddTab(libName)
    gui:AddControl(id, "Subhead", 0, libName.." Settings")
    gui:AddControl(id, "Checkbox", 0, 1, lcName..".enable", "Enable purchasing for "..lcName)
    gui:AddControl(id, "MoneyFramePinned", 0, 1, lcName..".profit.min", 1, 99999999, "Minimum Profit")
    gui:AddControl(id, "WideSlider", 0, 1, lcName..".profit.pct", 1, 100, 0.5, "Minimum Discount: %0.01f%%")
    gui:AddControl(id, "Subhead", 0, "Fees adjustment")
    gui:AddControl(id, "Selectbox", 0, 1, ahList, lcName..".adjust.basis", "Auction fees basis")
    gui:AddControl(id, "Checkbox", 0, 1, lcName..".adjust.brokerage", "Subtract auction fees from projected profit")
  end
 
  self:UnregisterEvent("ADDON_LOADED")
  self.ADDON_LOADED = nil
end