annotate Modules/QuickAuctions.lua @ 49:9ff6a3b02332 ticket7

I have changed my mind, price distribution will always be based on the AH price, unless none is available, then all items have the same weight which is what was being done before.
author Asa Ayers <Asa.Ayers@Gmail.com>
date Wed, 21 Jul 2010 01:00:14 -0700
parents 5273038322d7
children 4ec321eb0dfe
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 -- add AH Cut
Asa@19 50 local keep = 1 - addon:GetAHCut()
Asa@19 51 return copper/keep
Asa@19 52 end
Asa@19 53
Asa@18 54 function addon:UpdateQAGroup(groupName)
Asa@18 55 if not addon.IsQAEnabled() then
Asa@18 56 return
Asa@18 57 end
Asa@18 58 if groupName then
Asa@18 59 local threshold = 0
Asa@18 60
Asa@18 61 for link in pairs(QAAPI:GetItemsInGroup(groupName)) do
Asa@18 62 local _, itemCost= ItemAuditor:GetItemCost(link, 0)
Asa@18 63
Asa@18 64 threshold = max(threshold, itemCost)
Asa@18 65 end
Asa@18 66
Asa@19 67 threshold = calculateQAThreshold(threshold)
Asa@18 68
Asa@18 69 QAAPI:SetGroupThreshold(groupName, ceil(threshold))
Asa@18 70 end
Asa@18 71 end
Asa@18 72
Asa@18 73 --[[
Asa@18 74 This is based on KTQ
Asa@18 75 ]]
Asa@18 76 function addon:Queue()
Asa@18 77 if LSW == nil then
Asa@18 78 self:Print("This feature requires LilSparky's Workshop.")
Asa@18 79 return
Asa@18 80 end
Asa@21 81 if Skillet == nil then
Asa@21 82 self:Print("This feature requires Skillet.")
Asa@21 83 return
Asa@21 84 end
Asa@21 85 if GetAuctionBuyout ~= nil then
Asa@21 86 elseif AucAdvanced and AucAdvanced.Version then
Asa@21 87 else
Asa@21 88 self:Print("This feature requires Auctionator, Auctioneer, AuctionLite, or AuctionMaster.")
Asa@21 89 return
Asa@21 90 end
Asa@21 91
Asa@21 92
Asa@21 93 if addon.IsQAEnabled() then
Asa@24 94 self:Debug("Auction Threshold: %d%%", self:GetAuctionThreshold()*100 )
Asa@21 95 end
Asa@20 96 self:Debug(format("Crafting Threshold: %s", self:FormatMoney(self:GetCraftingThreshold())))
Asa@21 97 local profitableItems = {}
Asa@21 98 local profitableIndex = 1
Asa@21 99 local numChecked = 0
Asa@18 100
Asa@18 101 for i = 1, GetNumTradeSkills() do
Asa@18 102 local itemLink = GetTradeSkillItemLink(i)
Asa@18 103 local itemId = Skillet:GetItemIDFromLink(itemLink)
Asa@18 104
Asa@18 105 --Figure out if its an enchant or not
Asa@18 106 _, _, _, _, altVerb = GetTradeSkillInfo(i)
Asa@18 107 if LSW.scrollData[itemId] ~= nil and altVerb == 'Enchant' then
Asa@18 108 -- Ask LSW for the correct scroll
Asa@18 109 itemId = LSW.scrollData[itemId]["scrollID"]
Asa@18 110 end
Asa@18 111
Asa@18 112 local skillName, skillType, numAvailable, isExpanded, altVerb = GetTradeSkillInfo(i)
Asa@18 113 local recipeLink = GetTradeSkillRecipeLink(i)
Asa@19 114 local stackSize = 1
Asa@18 115 if recipeLink ~= nil then
Asa@18 116 _, itemLink= GetItemInfo(itemId)
Asa@21 117
Asa@21 118
Asa@21 119 -- if QA isn't enabled, this will just return nil
Asa@21 120 local QAGroup = nil
Asa@21 121 if addon.IsQAEnabled() then
Asa@21 122 QAGroup = QAAPI:GetItemGroup(itemLink)
Asa@21 123 if QAGroup ~= nil then
Asa@21 124 stackSize = QAAPI:GetGroupPostCap(QAGroup) * QAAPI:GetGroupPerAuction(QAGroup)
Asa@21 125 stackSize = stackSize / GetTradeSkillNumMade(i)
Asa@21 126
Asa@21 127 -- bonus
Asa@21 128 stackSize = ceil(stackSize *1.25)
Asa@21 129 end
Asa@18 130 end
Asa@21 131
Asa@18 132 local count = Altoholic:GetItemCount(itemId)
Asa@18 133
Asa@19 134 if count < stackSize and itemLink ~= nil then
Asa@18 135 local found, _, skillString = string.find(recipeLink, "^|%x+|H(.+)|h%[.+%]")
Asa@18 136 local _, skillId = strsplit(":", skillString )
Asa@18 137
Asa@19 138 local toQueue = stackSize - count
Asa@19 139 local newCost = 0
Asa@18 140 for reagentId = 1, GetTradeSkillNumReagents(i) do
Asa@18 141 _, _, reagentCount = GetTradeSkillReagentInfo(i, reagentId);
Asa@18 142 reagentLink = GetTradeSkillReagentItemLink(i, reagentId)
Asa@19 143 newCost = newCost + addon:GetReagentCost(reagentLink, reagentCount)
Asa@18 144 end
Asa@18 145
Asa@19 146 local currentInvested, _, currentCount = addon:GetItemCost(itemLink)
Asa@19 147 local newThreshold = (newCost + currentInvested) / (currentCount + toQueue)
Asa@19 148
Asa@21 149 if addon.IsQAEnabled() then
Asa@21 150 newThreshold = calculateQAThreshold(newThreshold)
Asa@21 151 else
Asa@21 152 -- if quick auctions isn't enabled, this will cause the decision to rely
Asa@21 153 -- completly on the crafting threshold
Asa@21 154 newThreshold = 0
Asa@21 155 end
Asa@21 156 local currentPrice = addon:GetAuctionPrice(itemLink) or 0
Asa@21 157 numChecked = numChecked + 1
Asa@18 158
Asa@20 159 if newThreshold < currentPrice and (currentPrice - newCost) > self:GetCraftingThreshold() then
Asa@21 160
Asa@21 161 profitableItems[profitableIndex] = {
Asa@21 162 itemLink = itemLink,
Asa@21 163 SkillID = skillId,
Asa@21 164 Index = i,
Asa@21 165 toQueue = toQueue,
Asa@21 166 profit = (currentPrice - newCost) * toQueue
Asa@21 167 }
Asa@21 168 profitableIndex = profitableIndex + 1
Asa@23 169 else
Asa@23 170 local skipMessage = format("Skipping %s x%s. Profit: %s ", itemLink, toQueue, addon:FormatMoney(currentPrice - newCost))
Asa@23 171 if ItemAuditor.db.profile.messages.queue_skip then
Asa@23 172 self:Print(skipMessage)
Asa@23 173 else
Asa@23 174 self:Debug(format("Skipping %s x%s. Profit: %s ", itemLink, toQueue, addon:FormatMoney(currentPrice - newCost)))
Asa@23 175 end
Asa@18 176 end
Asa@18 177 end
Asa@21 178 end
Asa@18 179 end
Asa@21 180 local numAdded = 0
Asa@21 181 table.sort(profitableItems, function(a, b) return a.profit > b.profit end)
Asa@21 182 for key, data in pairs(profitableItems) do
Asa@21 183 self:Print(format("Adding %s x%s to skillet queue. Profit: %s",
Asa@21 184 data.itemLink,
Asa@21 185 data.toQueue,
Asa@21 186 self:FormatMoney(data.profit)
Asa@21 187 ))
Asa@21 188 self:AddToQueue(data.SkillID, data.Index, data.toQueue)
Asa@21 189 numAdded = numAdded +1
Asa@21 190 end
Asa@21 191 self:Print(format("%d items checked", numChecked))
Asa@21 192 self:Print(format("%d queued", numAdded))
Asa@18 193 end
Asa@18 194
Asa@18 195 function addon:GetReagentCost(link, total)
Asa@18 196 local totalCost = 0
Asa@19 197
Asa@19 198 if Skillet:VendorSellsReagent(link) then
Asa@19 199 local _, _, _, _, _, _, _, _, _, _, itemVendorPrice = GetItemInfo (link);
Asa@19 200 totalCost = itemVendorPrice * total
Asa@19 201 total = 0
Asa@19 202 end
Asa@19 203
Asa@19 204
Asa@18 205 local investedTotal, investedPerItem, count = addon:GetItemCost(link)
Asa@18 206
Asa@18 207 if count > 0 then
Asa@18 208 if total <= count then
Asa@18 209 totalCost = investedPerItem * total
Asa@18 210 total = 0
Asa@18 211 else
Asa@18 212 totalCost = investedTotal
Asa@18 213 total = total - count
Asa@18 214 end
Asa@18 215 end
Asa@18 216
Asa@18 217 -- If there is none on the auction house, this uses a large enough number
Asa@18 218 -- to prevent us from trying to make the item.
Asa@21 219 local ahPrice = (self:GetAuctionPrice(link) or 99990000)
Asa@21 220 -- local itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType, _, _, _, _, itemVendorPrice = GetItemInfo (link);
Asa@18 221
Asa@18 222 return totalCost + (ahPrice * total)
Asa@18 223 end
Asa@18 224
Asa@21 225 function addon:GetAuctionPrice(itemLink)
Asa@21 226 if GetAuctionBuyout ~= nil then
Asa@21 227 return GetAuctionBuyout(itemLink)
Asa@21 228 elseif AucAdvanced and AucAdvanced.Version then
Asa@21 229 local _, _, _, _, _, lowBuy= AucAdvanced.Modules.Util.SimpleAuction.Private.GetItems(itemLink)
Asa@21 230 return lowBuy
Asa@21 231 end
Asa@21 232 return nil
Asa@21 233 end
Asa@21 234
Asa@18 235 function addon:AddToQueue(skillId,skillIndex, toQueue)
Asa@18 236 if Skillet == nil then
Asa@18 237 self:Print("Skillet not loaded")
Asa@21 238 return
Asa@18 239 end
Asa@18 240 if Skillet.QueueCommandIterate ~= nil then
Asa@18 241 local queueCommand = Skillet:QueueCommandIterate(tonumber(skillId), toQueue)
Asa@18 242 Skillet:AddToQueue(queueCommand)
Asa@18 243 else
Asa@18 244 Skillet.stitch:AddToQueue(skillIndex, toQueue)
Asa@18 245 end
Asa@18 246 end