Language:
Lua     Change language:
Pastebin: 74187
Author: bunnyfufu
Subject: EvalWoWEcon
Created: 2007-09-21 18:28:04
Download and save
Toggle line numbers
1--[[ 
2    This is a module for BtmScan to evaluate an item for purchase. 
3 
4    License: 
5        This program is free software; you can redistribute it and/or 
6        modify it under the terms of the GNU General Public License 
7        as published by the Free Software Foundation; either version 2 
8        of the License, or (at your option) any later version. 
9 
10        This program is distributed in the hope that it will be useful, 
11        but WITHOUT ANY WARRANTY; without even the implied warranty of 
12        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
13        GNU General Public License for more details. 
14 
15        You should have received a copy of the GNU General Public License 
16        along with this program(see GPL.txt); if not, write to the Free Software 
17        Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. 
18 
19    Note: 
20        This AddOn's source code is specifically designed to work with 
21        World of Warcraft's interpreted AddOn system. 
22        You have an implicit licence to use this AddOn with these facilities 
23        since that is its designated purpose as per: 
24        http://www.fsf org/licensing/licenses/gpl-faq.html#InterpreterIncompat 
25]] 
26 
27-- If auctioneer is not loaded, then we cannot run. 
28if not (AucAdvanced or (Auctioneer and Auctioneer.Statistic)) then return end 
29 
30local libName = "WOWEcon" 
31local lcName = libName:lower() 
32local lib = { name = lcName, propername = libName } 
33table.insert(BtmScan.evaluators, lcName) 
34local define = BtmScan.Settings.SetDefault 
35local get = BtmScan.Settings.GetSetting 
36local set = BtmScan.Settings.SetSetting 
37 
38BtmScan.evaluators[lcName] = lib 
39 
40function lib:valuate(item, tooltip) 
41    local price = 0 
42 
43    -- If we're not enabled, scadaddle! 
44    if (not get(lcName..".enable")) then return end 
45 
46  -- All items, even grey/vendor items, are considered 
47 
48  --[[ Which scope for pricing are we to use? 
49    local scope = get(lcName..'.adjust.scope') 
50  if (scope == "server") then 
51    scope = Wowecon.API.SERVER_PRICE 
52  elseif (scope == "auto") then 
53    scope = Wowecon.API.AUTO_PRICE 
54  else scope = Wowecon.API.GLOBAL_PRICE 
55  end 
56--]] 
57  local scope = Wowecon.API.GLOBAL_PRICE --temp hard-coding scope to global 
58  local wowecon = Wowecon.API.GetAuctionPrice_ByLink(item.link, scope) 
59 
60    -- Adjust for brokerage / deposit costs 
61    local adjusted = wowecon 
62    local deposit = get(lcName..'.adjust.deposit'
63    local brokerage = get(lcName..'.adjust.brokerage'
64 
65    if (deposit or brokerage) then 
66        local basis = get(lcName..'.adjust.basis'
67        local brokerRate, depositRate = 0.05, 0.05 
68        if (basis == "neutral") then 
69            brokerRate, depositRate = 0.15, 0.25 
70        end 
71        if (deposit) then 
72            local relistings = get(lcName..'.adjust.listings'
73            local amount = (BtmScan.GetDepositCost(item.id, item.count, depositRate) * relistings) 
74            adjusted = adjusted - amount 
75            item:info(" - "..relistings.." x deposit", amount) 
76        end 
77        if (brokerage) then 
78            local amount = (wowecon * brokerRate) 
79            adjusted = adjusted - amount 
80            item:info(" - Brokerage", amount) 
81        end 
82        item:info(" = Adjusted amount", adjusted) 
83    end 
84 
85    -- Valuate this item 
86    local pct = get(lcName..".profit.pct"
87    local min = get(lcName..".profit.min"
88    local value, mkdown = BtmScan.Markdown(adjusted, pct, min
89    item:info((" - %d%% / %s markdown"):format(pct,BtmScan.GSC(min, true)), mkdown) 
90 
91    -- Check for tooltip evaluation 
92    if (tooltip) then 
93        item.what = self.name 
94        item.valuation = value 
95        if (item.bid == 0) then 
96            return 
97        end 
98    end 
99 
100    -- If the current purchase price is more than our valuation, 
101    -- another module "wins" this purchase. 
102    if (value < item.purchase) then return end 
103 
104    -- Check to see what the most we can pay for this item is. 
105    if (item.canbuy and not get(lcName..".never.buy") and item.buy < value) then 
106        price = item.buy 
107    elseif (item.canbid and not get(lcName..".never.bid") and item.bid < value) then 
108        price = item.bid 
109    end 
110 
111    -- Check our projected profit level 
112    local profit = 0 
113    if price > 0 then profit = value - price end 
114 
115    -- If what we are willing to pay for this item beats what 
116    -- other modules are willing to pay, and we can make more 
117    -- profit, then we "win". 
118    if (price >= item.purchase and profit > item.profit) then 
119        item.purchase = price 
120        item.reason = self.name 
121        item.what = self.name 
122        item.profit = profit 
123        item.valuation = wowecon 
124    end 
125end 
126 
127local qualityTable = { 
128    {0, ITEM_QUALITY0_DESC}
129    {1, ITEM_QUALITY1_DESC}
130    {2, ITEM_QUALITY2_DESC}
131    {3, ITEM_QUALITY3_DESC}
132    {4, ITEM_QUALITY4_DESC}
133    {5, ITEM_QUALITY5_DESC}
134    {6, ITEM_QUALITY6_DESC}
135} 
136local ahList = { 
137    {'faction', "Faction AH Fees"}
138    {'neutral', "Neutral AH Fees"}
139} 
140 
141define(lcName..'.enable', true
142define(lcName..'.profit.min', 3000
143define(lcName..'.profit.pct', 30
144define(lcName..'.quality.check', true
145define(lcName..'.quality.min', 1
146define(lcName..'.adjust.basis', "faction"
147define(lcName..'.adjust.brokerage', true
148define(lcName..'.adjust.listings', 1
149define(lcName..'.never.bid', false
150define(lcName..'.never.buyout', false
151function lib:setup(gui) 
152    id = gui:AddTab(libName) 
153    gui:AddControl(id, "Subhead",          0,    libName.." Settings"
154    gui:AddControl(id, "Checkbox",         0, 1, lcName..".enable", "Enable purchasing for "..lcName) 
155    gui:AddControl(id, "Checkbox",         0, 1, lcName..".never.buy", "Never buyout items"
156    gui:AddControl(id, "Checkbox",         0, 1, lcName..".never.bid", "Never bid on items"
157    gui:AddControl(id, "MoneyFramePinned", 0, 1, lcName..".profit.min", 1, 99999999, "Minimum Profit"
158    gui:AddControl(id, "WideSlider",       0, 1, lcName..".profit.pct", 1, 100, 0.5, "Minimum Discount: %0.01f%%"
159    gui:AddControl(id, "Checkbox",         0, 1, lcName..".quality.check", "Enable quality checking:"
160    gui:AddControl(id, "Selectbox",        0, 2, qualityTable, lcName..".quality.min", "Minimum item quality"
161    gui:AddControl(id, "Subhead",          0,    "Fees adjustment"
162    gui:AddControl(id, "Selectbox",        0, 1, ahList, lcName..".adjust.basis", "Deposit/fees basis"
163    gui:AddControl(id, "Checkbox",         0, 1, lcName..".adjust.brokerage", "Subtract auction fees from projected profit"
164    gui:AddControl(id, "Checkbox",         0, 1, lcName..".adjust.deposit", "Subtract deposit cost from projected profit"
165    gui:AddControl(id, "WideSlider",       0, 2, lcName..".adjust.listings", 1, 10, 0.1, "Average relistings: %0.1fx"
166end 
167 
168 
Download and save
Toggle line numbers
Thread:
[74187] EvalWoWEcon by bunnyfufu at 2007-09-21 18:28:04
Tip: Click the line numbers to toggle highliting on that line.

Paste followup:

Language:
Author:
Subject:


    Tabstop:     bigger biggest
Note: You can prefix a line with "@@@" to highlight it.