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