annotate Modules/AuctionHouse.lua @ 149:c949a0f26d9e

Added tag 2010-10-16 for changeset 106c1523777e
author Asa Ayers <Asa.Ayers@Gmail.com>
date Sat, 16 Oct 2010 07:36:11 -0700
parents 4f26dc55455d
children
rev   line source
Asa@89 1 local ItemAuditor = select(2, ...)
Asa@89 2 local AuctionHouse = ItemAuditor:NewModule("AuctionHouse")
Asa@89 3
Asa@93 4 local Utils = ItemAuditor:GetModule("Utils")
Asa@93 5
Asa@89 6 local addon_options
Asa@89 7 local function getAddons()
Asa@89 8 -- this will ensure that the addons are only scanned once per session.
Asa@89 9 if not addon_options then
Asa@89 10 addon_options = {}
Asa@89 11 local total = 0
Asa@89 12 local lastKey
Asa@89 13 if AucAdvanced and AucAdvanced.Version then
Asa@89 14 addon_options['auctioneer'] = 'Auctioneer'
Asa@89 15 total = total + 1
Asa@89 16 lastKey = 'auctioneer'
Asa@89 17 end
Asa@89 18 if GetAuctionBuyout ~= nil then
Asa@89 19 addon_options['other'] = 'Other (GetAuctionBuyout compatibile)'
Asa@89 20 total = total + 1
Asa@89 21 lastKey = 'other'
Asa@89 22 end
Asa@89 23
Asa@89 24 if total == 1 or not ItemAuditor.db.profile.auction_addon then
Asa@89 25 ItemAuditor.db.profile.auction_addon = lastKey
Asa@89 26 end
Asa@89 27 end
Asa@89 28
Asa@89 29 return addon_options
Asa@89 30 end
Asa@89 31
Asa@89 32 local function getSelected()
Asa@89 33 -- just making sure ItemAuditor.db.profile.auction_addon is set if there is only one addon
Asa@89 34 if not addon_options then
Asa@89 35 getAddons()
Asa@89 36 end
Asa@89 37
Asa@89 38 return ItemAuditor.db.profile.auction_addon
Asa@89 39 end
Asa@89 40
Asa@90 41 local function setAddon(info, value)
Asa@90 42 ItemAuditor.db.profile.auction_addon = value
Asa@90 43 end
Asa@90 44
Asa@90 45 local function getPricingMethods()
Asa@90 46 if ItemAuditor.db.profile.auction_addon == 'other' then
Asa@90 47 return {
Asa@90 48 low = 'Lowest Price',
Asa@90 49 }
Asa@90 50 else
Asa@90 51 return {
Asa@90 52 low = 'Lowest Price',
Asa@90 53 market = 'Market Price',
Asa@90 54 }
Asa@90 55 end
Asa@90 56 end
Asa@90 57
Asa@89 58 ItemAuditor.Options.args.auction_house = {
Asa@89 59 name = "Auction House",
Asa@89 60 type = 'group',
Asa@89 61 args = {
Asa@89 62 ah_addon = {
Asa@89 63 type = "select",
Asa@89 64 name = "Addon",
Asa@89 65 desc = "",
Asa@89 66 values = getAddons,
Asa@89 67 get = getSelected,
Asa@90 68 set = setAddon,
Asa@89 69 order = 0,
Asa@89 70 },
Asa@90 71 pricingMethod = {
Asa@90 72 type = "select",
Asa@90 73 name = "Pricing Method",
Asa@90 74 desc = "",
Asa@90 75 values = getPricingMethods,
Asa@90 76 get = function() return ItemAuditor.db.profile.pricing_method end,
Asa@90 77 set = function(info, value) ItemAuditor.db.profile.pricing_method = value end,
Asa@90 78 order = 1,
Asa@90 79 }
Asa@93 80
Asa@89 81 },
Asa@89 82 }
Asa@89 83
Asa@93 84 local function clearSnatch()
Asa@93 85 ItemAuditor:Print('clearing snatch')
Asa@93 86 local Snatch = AucAdvanced.Modules.Util.SearchUI.Searchers.Snatch
Asa@93 87 local snatchList = Snatch.Private.snatchList
Asa@93 88
Asa@93 89 for itemLink in pairs(snatchList) do
Asa@93 90 local link = select(2, GetItemInfo('item:'..itemLink))
Asa@93 91 Snatch.RemoveSnatch(link)
Asa@93 92 end
Asa@93 93 end
Asa@93 94
Asa@93 95 function AuctionHouse.Snatch()
Asa@93 96 if not AucAdvanced or not AucAdvanced.Version then
Asa@93 97 ItemAuditor:Print("The snatch command requires Auctioneer.")
Asa@93 98 return
Asa@93 99 end
Asa@93 100
Asa@93 101 local Snatch = AucAdvanced.Modules.Util.SearchUI.Searchers.Snatch
Asa@93 102 if not Snatch.Private.frame then
Asa@93 103 ItemAuditor:Print("You must visit the Auction House before you can update Auctioneer's snatch list.")
Asa@93 104 return
Asa@93 105 end
Asa@93 106 clearSnatch()
Asa@93 107
Asa@94 108 local snatchList = {}
Asa@93 109 local function Export(data)
Asa@127 110 if data.haveMaterials < data.queue then
Asa@94 111 for id, reagent in pairs(data.reagents) do
Asa@94 112 if reagent.need > 0 and not snatchList[reagent.link] then
Asa@94 113 snatchList[reagent.link] = true
Asa@94 114 ItemAuditor:Print("Adding %s for %s", reagent.link, Utils.FormatMoney(reagent.price))
Asa@94 115 Snatch.AddSnatch(reagent.link, reagent.price)
Asa@94 116 end
Asa@94 117 end
Asa@93 118 end
Asa@93 119 end
Asa@93 120 ItemAuditor:UpdateCraftingTable()
Asa@93 121 ItemAuditor:GetModule("Crafting").Export(Export)
Asa@93 122 end
Asa@93 123
Asa@93 124 ItemAuditor.Options.args.snatch = {
Asa@93 125 type = "execute",
Asa@93 126 handler = AuctionHouse,
Asa@93 127 name = "snatch",
Asa@93 128 desc = "Replace Auctioner's snatch list with all the reagents you need for crafting.",
Asa@93 129 func = "Snatch",
Asa@93 130 guiHidden = true,
Asa@93 131 }
Asa@93 132
Asa@89 133 function AuctionHouse:GetAuctionPrice(itemLink)
Asa@89 134 local link = select(2, GetItemInfo(itemLink))
Asa@89 135 assert(link, 'Invalid item link: '..itemLink)
Asa@89 136 local addon = getSelected()
Asa@90 137 local prices = ItemAuditor.db.profile.pricing_method or 'low'
Asa@89 138 if GetAuctionBuyout ~= nil and addon == 'other' then
Asa@89 139 return GetAuctionBuyout(link)
Asa@89 140 elseif AucAdvanced and AucAdvanced.Version and addon == 'auctioneer' then
Asa@90 141 if prices == 'low' then
Asa@90 142 local _, _, _, _, _, lowBuy= AucAdvanced.Modules.Util.SimpleAuction.Private.GetItems(link)
Asa@90 143 return lowBuy
Asa@90 144 else
Asa@90 145 return AucAdvanced.API.GetMarketValue(link)
Asa@90 146 end
Asa@89 147 end
Asa@89 148 return nil
Asa@89 149 end