annotate Modules/QuickAuctions.lua @ 21:d7f02c84994c

Changed QA to be an option part of /ia queue. If QA is there, IA will queue enough of an item to be created to have 1.25x QA auctino count x QA stack size (rounded up) items. If it is not there, it will create 1 on every profitable item. This commit also adds support for Auctioneer.
author Asa Ayers <Asa.Ayers@Gmail.com>
date Tue, 06 Jul 2010 23:48:54 -0700
parents ff9a698caebc
children 819bfdc5d73c
rev   line source
Asa@18 1 local addonName, addonTable = ...;
Asa@18 2 local addon = _G[addonName]
Asa@18 3
Asa@18 4 function addon:IsQACompatible()
Asa@18 5 return (QAAPI ~= nil and QAAPI.GetGroups ~= nil)
Asa@18 6 end
Asa@18 7
Asa@18 8 function addon:IsQAEnabled()
Asa@18 9 return addon:IsQACompatible() and ItemAuditor.db.char.use_quick_auctions
Asa@18 10 end
Asa@18 11
Asa@18 12 function addon:IsQADisabled()
Asa@18 13 return not self:IsQAEnabled()
Asa@18 14 end
Asa@18 15
Asa@18 16 function addon:SetQAEnabled(info, value)
Asa@18 17 ItemAuditor.db.char.use_quick_auctions = value
Asa@18 18 end
Asa@18 19
Asa@18 20 function addon:RefreshQAGroups()
Asa@18 21 if not addon.IsQAEnabled() then
Asa@18 22 return
Asa@18 23 end
Asa@18 24 for groupName in pairs(QAAPI:GetGroups()) do
Asa@18 25 self:UpdateQAGroup(groupName)
Asa@18 26 end
Asa@18 27 end
Asa@18 28
Asa@18 29 function addon:UpdateQAThreshold(link)
Asa@18 30 if not addon.IsQAEnabled() then
Asa@18 31 return
Asa@18 32 end
Asa@18 33 _, link= GetItemInfo(link)
Asa@18 34
Asa@18 35 self:UpdateQAGroup(QAAPI:GetItemGroup(link))
Asa@18 36 end
Asa@18 37
Asa@19 38 addon.profit_margin = 1.15
Asa@19 39
Asa@19 40 local function calculateQAThreshold(copper)
Asa@19 41 if copper == 0 then
Asa@19 42 copper = 1
Asa@19 43 end
Asa@19 44
Asa@19 45 -- add my minimum profit margin
Asa@20 46 -- GetAuctionThreshold returns a percent as a whole number. This will convert 25 to 1.25
Asa@20 47 copper = copper * (1+addon:GetAuctionThreshold())
Asa@19 48
Asa@19 49 -- Adding the cost of mailing every item once.
Asa@19 50 copper = copper + 30
Asa@19 51
Asa@19 52 -- add AH Cut
Asa@19 53 local keep = 1 - addon:GetAHCut()
Asa@19 54 return copper/keep
Asa@19 55 end
Asa@19 56
Asa@18 57 function addon:UpdateQAGroup(groupName)
Asa@18 58 if not addon.IsQAEnabled() then
Asa@18 59 return
Asa@18 60 end
Asa@18 61 if groupName then
Asa@18 62 local threshold = 0
Asa@18 63
Asa@18 64 for link in pairs(QAAPI:GetItemsInGroup(groupName)) do
Asa@18 65 local _, itemCost= ItemAuditor:GetItemCost(link, 0)
Asa@18 66
Asa@18 67 threshold = max(threshold, itemCost)
Asa@18 68 end
Asa@18 69
Asa@19 70 threshold = calculateQAThreshold(threshold)
Asa@18 71
Asa@18 72 QAAPI:SetGroupThreshold(groupName, ceil(threshold))
Asa@18 73 end
Asa@18 74 end
Asa@18 75
Asa@18 76 --[[
Asa@18 77 This is based on KTQ
Asa@18 78 ]]
Asa@18 79 function addon:Queue()
Asa@18 80 if LSW == nil then
Asa@18 81 self:Print("This feature requires LilSparky's Workshop.")
Asa@18 82 return
Asa@18 83 end
Asa@21 84 if Skillet == nil then
Asa@21 85 self:Print("This feature requires Skillet.")
Asa@21 86 return
Asa@21 87 end
Asa@21 88 if GetAuctionBuyout ~= nil then
Asa@21 89 elseif AucAdvanced and AucAdvanced.Version then
Asa@21 90 else
Asa@21 91 self:Print("This feature requires Auctionator, Auctioneer, AuctionLite, or AuctionMaster.")
Asa@21 92 return
Asa@21 93 end
Asa@21 94
Asa@21 95
Asa@21 96 if addon.IsQAEnabled() then
Asa@21 97 self:Debug(format("Auction Threshold: %d%%", self:GetAuctionThreshold()*100 ))
Asa@21 98 end
Asa@20 99 self:Debug(format("Crafting Threshold: %s", self:FormatMoney(self:GetCraftingThreshold())))
Asa@21 100 local profitableItems = {}
Asa@21 101 local profitableIndex = 1
Asa@21 102 local numChecked = 0
Asa@18 103
Asa@18 104 for i = 1, GetNumTradeSkills() do
Asa@18 105 local itemLink = GetTradeSkillItemLink(i)
Asa@18 106 local itemId = Skillet:GetItemIDFromLink(itemLink)
Asa@18 107
Asa@18 108 --Figure out if its an enchant or not
Asa@18 109 _, _, _, _, altVerb = GetTradeSkillInfo(i)
Asa@18 110 if LSW.scrollData[itemId] ~= nil and altVerb == 'Enchant' then
Asa@18 111 -- Ask LSW for the correct scroll
Asa@18 112 itemId = LSW.scrollData[itemId]["scrollID"]
Asa@18 113 end
Asa@18 114
Asa@18 115 local skillName, skillType, numAvailable, isExpanded, altVerb = GetTradeSkillInfo(i)
Asa@18 116 local recipeLink = GetTradeSkillRecipeLink(i)
Asa@19 117 local stackSize = 1
Asa@18 118 if recipeLink ~= nil then
Asa@18 119 _, itemLink= GetItemInfo(itemId)
Asa@21 120
Asa@21 121
Asa@21 122 -- if QA isn't enabled, this will just return nil
Asa@21 123 local QAGroup = nil
Asa@21 124 if addon.IsQAEnabled() then
Asa@21 125 QAGroup = QAAPI:GetItemGroup(itemLink)
Asa@21 126 if QAGroup ~= nil then
Asa@21 127 stackSize = QAAPI:GetGroupPostCap(QAGroup) * QAAPI:GetGroupPerAuction(QAGroup)
Asa@21 128 stackSize = stackSize / GetTradeSkillNumMade(i)
Asa@21 129
Asa@21 130 -- bonus
Asa@21 131 stackSize = ceil(stackSize *1.25)
Asa@21 132 end
Asa@18 133 end
Asa@21 134
Asa@18 135 local count = Altoholic:GetItemCount(itemId)
Asa@18 136
Asa@19 137 if count < stackSize and itemLink ~= nil then
Asa@18 138 local found, _, skillString = string.find(recipeLink, "^|%x+|H(.+)|h%[.+%]")
Asa@18 139 local _, skillId = strsplit(":", skillString )
Asa@18 140
Asa@19 141 local toQueue = stackSize - count
Asa@19 142 local newCost = 0
Asa@18 143 for reagentId = 1, GetTradeSkillNumReagents(i) do
Asa@18 144 _, _, reagentCount = GetTradeSkillReagentInfo(i, reagentId);
Asa@18 145 reagentLink = GetTradeSkillReagentItemLink(i, reagentId)
Asa@19 146 newCost = newCost + addon:GetReagentCost(reagentLink, reagentCount)
Asa@18 147 end
Asa@18 148
Asa@19 149 local currentInvested, _, currentCount = addon:GetItemCost(itemLink)
Asa@19 150 local newThreshold = (newCost + currentInvested) / (currentCount + toQueue)
Asa@19 151
Asa@21 152 if addon.IsQAEnabled() then
Asa@21 153 newThreshold = calculateQAThreshold(newThreshold)
Asa@21 154 else
Asa@21 155 -- if quick auctions isn't enabled, this will cause the decision to rely
Asa@21 156 -- completly on the crafting threshold
Asa@21 157 newThreshold = 0
Asa@21 158 end
Asa@21 159 local currentPrice = addon:GetAuctionPrice(itemLink) or 0
Asa@21 160 numChecked = numChecked + 1
Asa@18 161
Asa@20 162 if newThreshold < currentPrice and (currentPrice - newCost) > self:GetCraftingThreshold() then
Asa@21 163
Asa@21 164 profitableItems[profitableIndex] = {
Asa@21 165 itemLink = itemLink,
Asa@21 166 SkillID = skillId,
Asa@21 167 Index = i,
Asa@21 168 toQueue = toQueue,
Asa@21 169 profit = (currentPrice - newCost) * toQueue
Asa@21 170 }
Asa@21 171 profitableIndex = profitableIndex + 1
Asa@20 172 elseif ItemAuditor.db.profile.messages.queue_skip then
Asa@21 173 self:Print(format("Skipping %s x%s. Profit: %s ", itemLink, toQueue, addon:FormatMoney(currentPrice - newCost)))
Asa@18 174 end
Asa@18 175 end
Asa@21 176 end
Asa@18 177 end
Asa@21 178 local numAdded = 0
Asa@21 179 table.sort(profitableItems, function(a, b) return a.profit > b.profit end)
Asa@21 180 for key, data in pairs(profitableItems) do
Asa@21 181 self:Print(format("Adding %s x%s to skillet queue. Profit: %s",
Asa@21 182 data.itemLink,
Asa@21 183 data.toQueue,
Asa@21 184 self:FormatMoney(data.profit)
Asa@21 185 ))
Asa@21 186 self:AddToQueue(data.SkillID, data.Index, data.toQueue)
Asa@21 187 numAdded = numAdded +1
Asa@21 188 end
Asa@21 189 self:Print(format("%d items checked", numChecked))
Asa@21 190 self:Print(format("%d queued", numAdded))
Asa@18 191 end
Asa@18 192
Asa@18 193 function addon:GetReagentCost(link, total)
Asa@18 194 local totalCost = 0
Asa@19 195
Asa@19 196 if Skillet:VendorSellsReagent(link) then
Asa@19 197 local _, _, _, _, _, _, _, _, _, _, itemVendorPrice = GetItemInfo (link);
Asa@19 198 totalCost = itemVendorPrice * total
Asa@19 199 total = 0
Asa@19 200 end
Asa@19 201
Asa@19 202
Asa@18 203 local investedTotal, investedPerItem, count = addon:GetItemCost(link)
Asa@18 204
Asa@18 205 if count > 0 then
Asa@18 206 if total <= count then
Asa@18 207 totalCost = investedPerItem * total
Asa@18 208 total = 0
Asa@18 209 else
Asa@18 210 totalCost = investedTotal
Asa@18 211 total = total - count
Asa@18 212 end
Asa@18 213 end
Asa@18 214
Asa@18 215 -- If there is none on the auction house, this uses a large enough number
Asa@18 216 -- to prevent us from trying to make the item.
Asa@21 217 local ahPrice = (self:GetAuctionPrice(link) or 99990000)
Asa@21 218 -- local itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType, _, _, _, _, itemVendorPrice = GetItemInfo (link);
Asa@18 219
Asa@18 220 return totalCost + (ahPrice * total)
Asa@18 221 end
Asa@18 222
Asa@21 223 function addon:GetAuctionPrice(itemLink)
Asa@21 224 if GetAuctionBuyout ~= nil then
Asa@21 225 return GetAuctionBuyout(itemLink)
Asa@21 226 elseif AucAdvanced and AucAdvanced.Version then
Asa@21 227 local _, _, _, _, _, lowBuy= AucAdvanced.Modules.Util.SimpleAuction.Private.GetItems(itemLink)
Asa@21 228 return lowBuy
Asa@21 229 end
Asa@21 230 return nil
Asa@21 231 end
Asa@21 232
Asa@18 233 function addon:AddToQueue(skillId,skillIndex, toQueue)
Asa@18 234 if Skillet == nil then
Asa@18 235 self:Print("Skillet not loaded")
Asa@21 236 return
Asa@18 237 end
Asa@18 238 if Skillet.QueueCommandIterate ~= nil then
Asa@18 239 local queueCommand = Skillet:QueueCommandIterate(tonumber(skillId), toQueue)
Asa@18 240 Skillet:AddToQueue(queueCommand)
Asa@18 241 else
Asa@18 242 Skillet.stitch:AddToQueue(skillIndex, toQueue)
Asa@18 243 end
Asa@18 244 end