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