annotate Modules/QuickAuctions.lua @ 82:e9f7bc9199ca release 2010-08-05

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