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