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