comparison Modules/QuickAuctions.lua @ 68:2d65db19d3ce

Fixed a bug with the crafting threshold options. Updated /ia queue so that it is a shortcut to using /ia crafting and then clicking export.
author Asa Ayers <Asa.Ayers@Gmail.com>
date Wed, 28 Jul 2010 11:37:43 -0700
parents b6c30a5156f9
children 3930518cb8d9
comparison
equal deleted inserted replaced
67:b6c30a5156f9 68:2d65db19d3ce
1 local ItemAuditor = select(2, ...) 1 local ItemAuditor = select(2, ...)
2 local QuickAuctions= ItemAuditor:NewModule("QuickAuctions") 2 local QuickAuctions= ItemAuditor:NewModule("QuickAuctions")
3 local Crafting = ItemAuditor:GetModule("Crafting") 3 local Crafting = ItemAuditor:GetModule("Crafting")
4 local Utils = ItemAuditor:GetModule("Utils")
4 5
5 --[[ 6 --[[
6 This is simply for compatibility while I change the QA API. Once 7 This is simply for compatibility while I change the QA API. Once
7 my changes get merged into the main project, this can go away. 8 my changes get merged into the main project, this can go away.
8 ]] 9 ]]
114 end 115 end
115 return 0 116 return 0
116 end 117 end
117 Crafting.RegisterCraftingDecider('IA QuickAuctions', isProfitable) 118 Crafting.RegisterCraftingDecider('IA QuickAuctions', isProfitable)
118 119
119 --[[ 120
120 This is based on KTQ
121 ]]
122 function ItemAuditor:Queue() 121 function ItemAuditor:Queue()
123 if LSW == nil then 122 local function Export(data)
124 self:Print("This feature requires LilSparky's Workshop.") 123 ItemAuditor:Print(format("Adding %s x%s to skillet queue. Profit: %s",
125 return 124 data.link,
126 end 125 data.queue,
127 if Skillet == nil then 126 Utils.FormatMoney(data.profit)
128 self:Print("This feature requires Skillet.")
129 return
130 end
131 if GetAuctionBuyout ~= nil then
132 elseif AucAdvanced and AucAdvanced.Version then
133 else
134 self:Print("This feature requires Auctionator, Auctioneer, AuctionLite, or AuctionMaster.")
135 return
136 end
137
138
139 if ItemAuditor.IsQAEnabled() then
140 self:Debug("Auction Threshold: %d%%", self:GetAuctionThreshold()*100 )
141 end
142 self:Debug(format("Crafting Threshold: %s", self:FormatMoney(self:GetCraftingThreshold())))
143 local profitableItems = {}
144 local profitableIndex = 1
145 local numChecked = 0
146
147 for i = 1, GetNumTradeSkills() do
148 local itemLink = GetTradeSkillItemLink(i)
149 local itemId = Skillet:GetItemIDFromLink(itemLink)
150
151 --Figure out if its an enchant or not
152 _, _, _, _, altVerb = GetTradeSkillInfo(i)
153 if LSW.scrollData[itemId] ~= nil and altVerb == 'Enchant' then
154 -- Ask LSW for the correct scroll
155 itemId = LSW.scrollData[itemId]["scrollID"]
156 end
157
158 local skillName, skillType, numAvailable, isExpanded, altVerb = GetTradeSkillInfo(i)
159 local recipeLink = GetTradeSkillRecipeLink(i)
160 local stackSize = 1
161 if recipeLink ~= nil then
162 _, itemLink= GetItemInfo(itemId)
163
164
165 -- if QA isn't enabled, this will just return nil
166 local QAGroup = nil
167 if ItemAuditor.IsQAEnabled() then
168 QAGroup = QAAPI:GetItemGroup(itemLink)
169 if QAGroup ~= nil then
170 local threshold, postCap, perAuction = QAAPI:GetGroupConfig(QAGroup)
171 stackSize = postCap * perAuction
172 stackSize = stackSize / GetTradeSkillNumMade(i)
173
174 -- bonus
175 stackSize = ceil(stackSize *1.25)
176 end
177 end
178
179 local count = Altoholic:GetItemCount(itemId)
180
181 if count < stackSize and itemLink ~= nil then
182 local found, _, skillString = string.find(recipeLink, "^|%x+|H(.+)|h%[.+%]")
183 local _, skillId = strsplit(":", skillString )
184
185 local toQueue = stackSize - count
186 local newCost = 0
187 for reagentId = 1, GetTradeSkillNumReagents(i) do
188 _, _, reagentCount = GetTradeSkillReagentInfo(i, reagentId);
189 reagentLink = GetTradeSkillReagentItemLink(i, reagentId)
190 newCost = newCost + ItemAuditor:GetReagentCost(reagentLink, reagentCount)
191 end
192
193 local currentInvested, _, currentCount = ItemAuditor:GetItemCost(itemLink)
194 local newThreshold = (newCost + currentInvested) / (currentCount + toQueue)
195
196 if ItemAuditor.IsQAEnabled() then
197 newThreshold = calculateQAThreshold(newThreshold)
198 else
199 -- if quick auctions isn't enabled, this will cause the decision to rely
200 -- completly on the crafting threshold
201 newThreshold = 0
202 end
203 local currentPrice = ItemAuditor:GetAuctionPrice(itemLink) or 0
204 numChecked = numChecked + 1
205
206 if newThreshold < currentPrice and (currentPrice - newCost) > self:GetCraftingThreshold() then
207
208 profitableItems[profitableIndex] = {
209 itemLink = itemLink,
210 SkillID = skillId,
211 Index = i,
212 toQueue = toQueue,
213 profit = (currentPrice - newCost) * toQueue
214 }
215 profitableIndex = profitableIndex + 1
216 else
217 local skipMessage = format("Skipping %s x%s. Profit: %s ", itemLink, toQueue, ItemAuditor:FormatMoney(currentPrice - newCost))
218 if ItemAuditor.db.profile.messages.queue_skip then
219 self:Print(skipMessage)
220 else
221 self:Debug(format("Skipping %s x%s. Profit: %s ", itemLink, toQueue, ItemAuditor:FormatMoney(currentPrice - newCost)))
222 end
223 end
224 end
225 end
226 end
227 local numAdded = 0
228 table.sort(profitableItems, function(a, b) return a.profit > b.profit end)
229 for key, data in pairs(profitableItems) do
230 self:Print(format("Adding %s x%s to skillet queue. Profit: %s",
231 data.itemLink,
232 data.toQueue,
233 self:FormatMoney(data.profit)
234 )) 127 ))
235 self:AddToQueue(data.SkillID, data.Index, data.toQueue) 128 Crafting.ExportToSkillet(data)
236 numAdded = numAdded +1 129 end
237 end 130 ItemAuditor:UpdateCraftingTable()
238 self:Print(format("%d items checked", numChecked)) 131 Crafting.Export(Export)
239 self:Print(format("%d queued", numAdded))
240 end 132 end
241 133
242 function ItemAuditor:GetReagentCost(link, total) 134 function ItemAuditor:GetReagentCost(link, total)
243 local totalCost = 0 135 local totalCost = 0
244 136