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