annotate Modules/QuickAuctions.lua @ 86:8d5ad3b71f6f

Removed references to Skillet in core functionality. Skillet really should be optional.
author Asa Ayers <Asa.Ayers@Gmail.com>
date Sat, 07 Aug 2010 11:16:21 -0700
parents 88a42e00b866
children 54b917340283
rev   line source
Asa@63 1 local ItemAuditor = select(2, ...)
Asa@63 2 local QuickAuctions= ItemAuditor:NewModule("QuickAuctions")
Asa@64 3 local Crafting = ItemAuditor:GetModule("Crafting")
Asa@68 4 local Utils = ItemAuditor:GetModule("Utils")
Asa@18 5
Asa@86 6 local PT = LibStub("LibPeriodicTable-3.1")
Asa@86 7
Asa@62 8 --[[
Asa@62 9 This is simply for compatibility while I change the QA API. Once
Asa@62 10 my changes get merged into the main project, this can go away.
Asa@62 11 ]]
Asa@62 12 if QAAPI ~= nil and QAAPI.GetGroupThreshold ~= nil and QAAPI.GetGroupConfig == nil then
Asa@62 13 function QAAPI:GetGroupConfig(groupName)
Asa@62 14 return QAAPI:GetGroupThreshold(groupName),
Asa@62 15 QAAPI:GetGroupPostCap(groupName),
Asa@62 16 QAAPI:GetGroupPerAuction(groupName)
Asa@62 17 end
Asa@62 18
Asa@62 19 function QAAPI:SetGroupConfig(groupName, key, value)
Asa@62 20 if key == 'threshold' then
Asa@62 21 return QAAPI:SetGroupThreshold(groupName, value)
Asa@62 22 end
Asa@62 23 end
Asa@62 24 end
Asa@62 25
Asa@62 26
Asa@62 27
Asa@63 28 function ItemAuditor:IsQACompatible()
Asa@62 29 return (QAAPI ~= nil and QAAPI.GetGroupConfig ~= nil)
Asa@18 30 end
Asa@18 31
Asa@63 32 function ItemAuditor:IsQAEnabled()
Asa@63 33 return ItemAuditor:IsQACompatible() and ItemAuditor.db.char.use_quick_auctions
Asa@18 34 end
Asa@18 35
Asa@63 36 function ItemAuditor:IsQADisabled()
Asa@18 37 return not self:IsQAEnabled()
Asa@18 38 end
Asa@18 39
Asa@63 40 function ItemAuditor:SetQAEnabled(info, value)
Asa@18 41 ItemAuditor.db.char.use_quick_auctions = value
Asa@18 42 end
Asa@18 43
Asa@63 44 function ItemAuditor:RefreshQAGroups()
Asa@63 45 if not ItemAuditor.IsQAEnabled() then
Asa@18 46 return
Asa@18 47 end
Asa@18 48 for groupName in pairs(QAAPI:GetGroups()) do
Asa@18 49 self:UpdateQAGroup(groupName)
Asa@18 50 end
Asa@18 51 end
Asa@18 52
Asa@63 53 function ItemAuditor:UpdateQAThreshold(link)
Asa@63 54 if not ItemAuditor.IsQAEnabled() then
Asa@18 55 return
Asa@18 56 end
Asa@18 57 _, link= GetItemInfo(link)
Asa@18 58
Asa@18 59 self:UpdateQAGroup(QAAPI:GetItemGroup(link))
Asa@18 60 end
Asa@18 61
Asa@19 62 local function calculateQAThreshold(copper)
Asa@19 63 if copper == 0 then
Asa@19 64 copper = 1
Asa@19 65 end
Asa@19 66
Asa@19 67 -- add my minimum profit margin
Asa@20 68 -- GetAuctionThreshold returns a percent as a whole number. This will convert 25 to 1.25
Asa@63 69 copper = copper * (1+ItemAuditor:GetAuctionThreshold())
Asa@19 70
Asa@19 71 -- add AH Cut
Asa@63 72 local keep = 1 - ItemAuditor:GetAHCut()
Asa@19 73 return copper/keep
Asa@19 74 end
Asa@19 75
Asa@63 76 function ItemAuditor:UpdateQAGroup(groupName)
Asa@63 77 if not ItemAuditor.IsQAEnabled() then
Asa@18 78 return
Asa@18 79 end
Asa@18 80 if groupName then
Asa@18 81 local threshold = 0
Asa@18 82
Asa@18 83 for link in pairs(QAAPI:GetItemsInGroup(groupName)) do
Asa@18 84 local _, itemCost= ItemAuditor:GetItemCost(link, 0)
Asa@18 85
Asa@18 86 threshold = max(threshold, itemCost)
Asa@18 87 end
Asa@18 88
Asa@19 89 threshold = calculateQAThreshold(threshold)
Asa@18 90
Asa@62 91 QAAPI:SetGroupConfig(groupName, 'threshold', ceil(threshold))
Asa@18 92 end
Asa@18 93 end
Asa@18 94
Asa@59 95 local function isProfitable(data)
Asa@63 96 if ItemAuditor.IsQAEnabled() then
Asa@59 97 local QAGroup = QAAPI:GetItemGroup(data.link)
Asa@59 98 if QAGroup ~= nil then
Asa@63 99 local currentInvested, _, currentCount = ItemAuditor:GetItemCost(data.link)
Asa@62 100 local threshold, postCap, perAuction = QAAPI:GetGroupConfig(QAGroup)
Asa@62 101 local stackSize = postCap * perAuction
Asa@59 102
Asa@59 103 -- bonus
Asa@71 104 stackSize = ceil(stackSize * (1+ItemAuditor.db.char.qa_extra))
Asa@77 105 local target = stackSize
Asa@77 106 stackSize = stackSize - currentCount
Asa@59 107
Asa@59 108 local newThreshold = ((data.cost*stackSize) + currentInvested) / (currentCount + stackSize)
Asa@59 109 newThreshold = calculateQAThreshold(newThreshold)
Asa@59 110
Asa@59 111 if newThreshold < data.price then
Asa@77 112 return target
Asa@59 113 end
Asa@59 114
Asa@59 115 return -1
Asa@59 116 end
Asa@59 117 end
Asa@59 118 return 0
Asa@59 119 end
Asa@64 120 Crafting.RegisterCraftingDecider('IA QuickAuctions', isProfitable)
Asa@59 121
Asa@68 122
Asa@63 123 function ItemAuditor:Queue()
Asa@70 124 local dest, name = Crafting.GetQueueDestination()
Asa@68 125 local function Export(data)
Asa@70 126 ItemAuditor:Print(format("Adding %s x%s to %s queue. Profit: %s",
Asa@68 127 data.link,
Asa@68 128 data.queue,
Asa@70 129 name,
Asa@68 130 Utils.FormatMoney(data.profit)
Asa@68 131 ))
Asa@70 132 dest(data)
Asa@18 133 end
Asa@68 134 ItemAuditor:UpdateCraftingTable()
Asa@68 135 Crafting.Export(Export)
Asa@18 136 end
Asa@18 137
Asa@63 138 function ItemAuditor:GetReagentCost(link, total)
Asa@18 139 local totalCost = 0
Asa@19 140
Asa@86 141 if PT:ItemInSet(link,"Tradeskill.Mat.BySource.Vendor") then
Asa@19 142 local _, _, _, _, _, _, _, _, _, _, itemVendorPrice = GetItemInfo (link);
Asa@19 143 totalCost = itemVendorPrice * total
Asa@19 144 total = 0
Asa@19 145 end
Asa@19 146
Asa@19 147
Asa@63 148 local investedTotal, investedPerItem, count = ItemAuditor:GetItemCost(link)
Asa@18 149
Asa@18 150 if count > 0 then
Asa@18 151 if total <= count then
Asa@18 152 totalCost = investedPerItem * total
Asa@18 153 total = 0
Asa@18 154 else
Asa@18 155 totalCost = investedTotal
Asa@18 156 total = total - count
Asa@18 157 end
Asa@18 158 end
Asa@18 159
Asa@18 160 -- If there is none on the auction house, this uses a large enough number
Asa@18 161 -- to prevent us from trying to make the item.
Asa@21 162 local ahPrice = (self:GetAuctionPrice(link) or 99990000)
Asa@21 163 -- local itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType, _, _, _, _, itemVendorPrice = GetItemInfo (link);
Asa@18 164
Asa@18 165 return totalCost + (ahPrice * total)
Asa@18 166 end
Asa@18 167
Asa@63 168 function ItemAuditor:GetAuctionPrice(itemLink)
Asa@78 169 local link = select(2, GetItemInfo(itemLink))
Asa@78 170 assert(link, 'Invalid item link: '..itemLink)
Asa@21 171 if GetAuctionBuyout ~= nil then
Asa@78 172 return GetAuctionBuyout(link)
Asa@21 173 elseif AucAdvanced and AucAdvanced.Version then
Asa@78 174 local _, _, _, _, _, lowBuy= AucAdvanced.Modules.Util.SimpleAuction.Private.GetItems(link)
Asa@21 175 return lowBuy
Asa@21 176 end
Asa@21 177 return nil
Asa@21 178 end
Asa@21 179
Asa@63 180 function ItemAuditor:AddToQueue(skillId,skillIndex, toQueue)
Asa@18 181 if Skillet == nil then
Asa@18 182 self:Print("Skillet not loaded")
Asa@21 183 return
Asa@18 184 end
Asa@18 185 if Skillet.QueueCommandIterate ~= nil then
Asa@18 186 local queueCommand = Skillet:QueueCommandIterate(tonumber(skillId), toQueue)
Asa@18 187 Skillet:AddToQueue(queueCommand)
Asa@18 188 else
Asa@18 189 Skillet.stitch:AddToQueue(skillIndex, toQueue)
Asa@18 190 end
Asa@18 191 end
Asa@67 192
Asa@67 193 ItemAuditor.Options.args.qa_options = {
Asa@67 194 name = "QA Options",
Asa@67 195 desc = "Control how ItemAuditor integrates with QuickAuctions",
Asa@67 196 type = 'group',
Asa@67 197 disabled = function() return not ItemAuditor:IsQACompatible() end,
Asa@67 198 args = {
Asa@67 199 toggle_qa = {
Asa@67 200 type = "toggle",
Asa@67 201 name = "Enable Quick Auctions",
Asa@67 202 desc = "This will enable or disable Quick Auctions integration",
Asa@67 203 get = "IsQAEnabled",
Asa@67 204 set = "SetQAEnabled",
Asa@67 205 order = 0,
Asa@67 206 },
Asa@67 207 auction_threshold = {
Asa@67 208 type = "range",
Asa@67 209 name = "Auction Threshold",
Asa@67 210 desc = "Don't create items that will make less than this amount of profit",
Asa@67 211 min = 0.0,
Asa@67 212 max = 1.0,
Asa@67 213 isPercent = true,
Asa@67 214 get = function() return ItemAuditor.db.char.auction_threshold end,
Asa@67 215 set = function(info, value)
Asa@67 216 ItemAuditor.db.char.auction_threshold = value
Asa@71 217 -- ItemAuditor:RefreshQAGroups()
Asa@71 218 end,
Asa@71 219 disabled = 'IsQADisabled',
Asa@71 220 order = 1,
Asa@71 221 },
Asa@71 222 extra = {
Asa@71 223 type = "range",
Asa@71 224 name = "Create Extra",
Asa@71 225 desc = "This is the amount of an item that should be created above what you sell in one post in QuickAuctions."..
Asa@71 226 "If you sell 4 stacks of 5 of an item and your extra is 25%, it will queue enough for you to have 25 of that item.",
Asa@71 227 min = 0.0,
Asa@71 228 max = 1.0,
Asa@71 229 isPercent = true,
Asa@71 230 get = function() return ItemAuditor.db.char.qa_extra end,
Asa@71 231 set = function(info, value)
Asa@71 232 ItemAuditor.db.char.qa_extra = value
Asa@67 233 end,
Asa@67 234 disabled = 'IsQADisabled',
Asa@67 235 order = 1,
Asa@67 236 },
Asa@67 237 refresh_qa = {
Asa@67 238 type = "execute",
Asa@67 239 name = "Refresh QA Thresholds",
Asa@67 240 desc = "Resets all Quick Auctions thresholds",
Asa@67 241 func = "RefreshQAGroups",
Asa@67 242 disabled = 'IsQADisabled',
Asa@67 243 order = 9,
Asa@67 244 },
Asa@67 245 }
Asa@67 246 }
Asa@67 247
Asa@67 248 ItemAuditor.Options.args.queue = {
Asa@67 249 type = "execute",
Asa@67 250 name = "queue",
Asa@67 251 desc = "Queue",
Asa@67 252 func = "Queue",
Asa@67 253 guiHidden = true,
Asa@67 254 }