Asa@63
|
1 local ItemAuditor = select(2, ...)
|
Asa@63
|
2 local QuickAuctions= ItemAuditor:NewModule("QuickAuctions")
|
Asa@64
|
3 local Crafting = ItemAuditor:GetModule("Crafting")
|
Asa@68
|
4 local Utils = ItemAuditor:GetModule("Utils")
|
Asa@89
|
5 local AuctionHouse = ItemAuditor:GetModule("AuctionHouse")
|
Asa@18
|
6
|
Asa@86
|
7 local PT = LibStub("LibPeriodicTable-3.1")
|
Asa@86
|
8
|
Asa@62
|
9 --[[
|
Asa@62
|
10 This is simply for compatibility while I change the QA API. Once
|
Asa@62
|
11 my changes get merged into the main project, this can go away.
|
Asa@62
|
12 ]]
|
Asa@62
|
13 if QAAPI ~= nil and QAAPI.GetGroupThreshold ~= nil and QAAPI.GetGroupConfig == nil then
|
Asa@62
|
14 function QAAPI:GetGroupConfig(groupName)
|
Asa@62
|
15 return QAAPI:GetGroupThreshold(groupName),
|
Asa@62
|
16 QAAPI:GetGroupPostCap(groupName),
|
Asa@62
|
17 QAAPI:GetGroupPerAuction(groupName)
|
Asa@62
|
18 end
|
Asa@62
|
19
|
Asa@62
|
20 function QAAPI:SetGroupConfig(groupName, key, value)
|
Asa@62
|
21 if key == 'threshold' then
|
Asa@62
|
22 return QAAPI:SetGroupThreshold(groupName, value)
|
Asa@62
|
23 end
|
Asa@62
|
24 end
|
Asa@62
|
25 end
|
Asa@62
|
26
|
Asa@62
|
27
|
Asa@62
|
28
|
Asa@63
|
29 function ItemAuditor:IsQACompatible()
|
Asa@62
|
30 return (QAAPI ~= nil and QAAPI.GetGroupConfig ~= nil)
|
Asa@18
|
31 end
|
Asa@18
|
32
|
Asa@63
|
33 function ItemAuditor:IsQAEnabled()
|
Asa@119
|
34 if ItemAuditor:IsQACompatible() then
|
Asa@119
|
35 local qam = GetAddOnInfo('QAManager')
|
Asa@119
|
36 if qam then
|
Asa@119
|
37 ItemAuditor.Options.args.qa_options.disabled = true
|
Asa@119
|
38 if ItemAuditor.db.char.use_quick_auctions then
|
Asa@119
|
39 ItemAuditor.db.char.use_quick_auctions = false
|
Asa@119
|
40 StaticPopupDialogs["ItemAuditor_QAOptionsReplaced"] = {
|
Asa@119
|
41 text = "The ability to have ItemAuditor adjust your QA thresholds is being moved to QAManager. If you have to use the options within ItemAuditor you can disable QAManager to restore them for now, but this option will change in the future.",
|
Asa@119
|
42 button1 = "OK",
|
Asa@119
|
43 timeout = 0,
|
Asa@119
|
44 whileDead = true,
|
Asa@119
|
45 hideOnEscape = true,
|
Asa@119
|
46 OnAccept = function()
|
Asa@119
|
47 -- StaticPopupDialogs["ItemAuditor_QAOptionsReplaced"] = nil
|
Asa@119
|
48 end,
|
Asa@119
|
49 }
|
Asa@119
|
50 StaticPopup_Show('ItemAuditor_QAOptionsReplaced')
|
Asa@119
|
51 end
|
Asa@119
|
52 return false
|
Asa@119
|
53 end
|
Asa@119
|
54 return ItemAuditor.db.char.use_quick_auctions
|
Asa@119
|
55 end
|
Asa@119
|
56 return false
|
Asa@18
|
57 end
|
Asa@18
|
58
|
Asa@63
|
59 function ItemAuditor:IsQADisabled()
|
Asa@18
|
60 return not self:IsQAEnabled()
|
Asa@18
|
61 end
|
Asa@18
|
62
|
Asa@63
|
63 function ItemAuditor:SetQAEnabled(info, value)
|
Asa@18
|
64 ItemAuditor.db.char.use_quick_auctions = value
|
Asa@18
|
65 end
|
Asa@18
|
66
|
Asa@63
|
67 function ItemAuditor:RefreshQAGroups()
|
Asa@63
|
68 if not ItemAuditor.IsQAEnabled() then
|
Asa@18
|
69 return
|
Asa@18
|
70 end
|
Asa@18
|
71 for groupName in pairs(QAAPI:GetGroups()) do
|
Asa@18
|
72 self:UpdateQAGroup(groupName)
|
Asa@18
|
73 end
|
Asa@18
|
74 end
|
Asa@18
|
75
|
Asa@63
|
76 function ItemAuditor:UpdateQAThreshold(link)
|
Asa@63
|
77 if not ItemAuditor.IsQAEnabled() then
|
Asa@18
|
78 return
|
Asa@18
|
79 end
|
Asa@18
|
80 _, link= GetItemInfo(link)
|
Asa@18
|
81
|
Asa@18
|
82 self:UpdateQAGroup(QAAPI:GetItemGroup(link))
|
Asa@18
|
83 end
|
Asa@18
|
84
|
Asa@19
|
85 local function calculateQAThreshold(copper)
|
Asa@19
|
86 if copper == 0 then
|
Asa@19
|
87 copper = 1
|
Asa@19
|
88 end
|
Asa@19
|
89
|
Asa@19
|
90 -- add my minimum profit margin
|
Asa@20
|
91 -- GetAuctionThreshold returns a percent as a whole number. This will convert 25 to 1.25
|
Asa@111
|
92 local min_by_percent = copper * (1+ItemAuditor:GetAuctionThreshold())
|
Asa@111
|
93 local min_by_value = copper + ItemAuditor.db.char.auction_threshold_value
|
Asa@111
|
94 copper = max(min_by_percent, min_by_value)
|
Asa@19
|
95
|
Asa@19
|
96 -- add AH Cut
|
Asa@63
|
97 local keep = 1 - ItemAuditor:GetAHCut()
|
Asa@19
|
98 return copper/keep
|
Asa@19
|
99 end
|
Asa@19
|
100
|
Asa@63
|
101 function ItemAuditor:UpdateQAGroup(groupName)
|
Asa@63
|
102 if not ItemAuditor.IsQAEnabled() then
|
Asa@18
|
103 return
|
Asa@18
|
104 end
|
Asa@18
|
105 if groupName then
|
Asa@18
|
106 local threshold = 0
|
Asa@18
|
107
|
Asa@18
|
108 for link in pairs(QAAPI:GetItemsInGroup(groupName)) do
|
Asa@18
|
109 local _, itemCost= ItemAuditor:GetItemCost(link, 0)
|
Asa@18
|
110
|
Asa@18
|
111 threshold = max(threshold, itemCost)
|
Asa@18
|
112 end
|
Asa@18
|
113
|
Asa@19
|
114 threshold = calculateQAThreshold(threshold)
|
Asa@18
|
115
|
Asa@62
|
116 QAAPI:SetGroupConfig(groupName, 'threshold', ceil(threshold))
|
Asa@18
|
117 end
|
Asa@18
|
118 end
|
Asa@18
|
119
|
Asa@59
|
120 local function isProfitable(data)
|
Asa@129
|
121 if ItemAuditor:IsQACompatible() then
|
Asa@59
|
122 local QAGroup = QAAPI:GetItemGroup(data.link)
|
Asa@59
|
123 if QAGroup ~= nil then
|
Asa@63
|
124 local currentInvested, _, currentCount = ItemAuditor:GetItemCost(data.link)
|
Asa@62
|
125 local threshold, postCap, perAuction = QAAPI:GetGroupConfig(QAGroup)
|
Asa@62
|
126 local stackSize = postCap * perAuction
|
Asa@59
|
127
|
Asa@59
|
128 -- bonus
|
Asa@71
|
129 stackSize = ceil(stackSize * (1+ItemAuditor.db.char.qa_extra))
|
Asa@77
|
130 local target = stackSize
|
Asa@77
|
131 stackSize = stackSize - currentCount
|
Asa@59
|
132
|
Asa@59
|
133 local newThreshold = ((data.cost*stackSize) + currentInvested) / (currentCount + stackSize)
|
Asa@59
|
134 newThreshold = calculateQAThreshold(newThreshold)
|
Asa@59
|
135
|
Asa@59
|
136 if newThreshold < data.price then
|
Asa@77
|
137 return target
|
Asa@59
|
138 end
|
Asa@59
|
139
|
Asa@59
|
140 return -1
|
Asa@59
|
141 end
|
Asa@59
|
142 end
|
Asa@59
|
143 return 0
|
Asa@59
|
144 end
|
Asa@112
|
145
|
Asa@112
|
146 local QADeciderOptions = {
|
Asa@112
|
147 extra = {
|
Asa@112
|
148 type = "range",
|
Asa@112
|
149 name = "Create Extra",
|
Asa@112
|
150 desc = "This is the amount of an item that should be created above what you sell in one post in QuickAuctions."..
|
Asa@112
|
151 "If you sell 4 stacks of 5 of an item and your extra is 25%, it will queue enough for you to have 25 of that item.",
|
Asa@112
|
152 min = 0.0,
|
Asa@112
|
153 max = 1.0,
|
Asa@112
|
154 step = 0.01,
|
Asa@112
|
155 isPercent = true,
|
Asa@112
|
156 get = function() return ItemAuditor.db.char.qa_extra end,
|
Asa@112
|
157 set = function(info, value)
|
Asa@112
|
158 ItemAuditor.db.char.qa_extra = value
|
Asa@112
|
159 end,
|
Asa@129
|
160 disabled = function() return not ItemAuditor:IsQACompatible() end,
|
Asa@112
|
161 order = 10,
|
Asa@112
|
162 },
|
Asa@112
|
163 }
|
Asa@112
|
164 Crafting.RegisterCraftingDecider('IA QuickAuctions', isProfitable, QADeciderOptions)
|
Asa@59
|
165
|
Asa@68
|
166
|
Asa@63
|
167 function ItemAuditor:Queue()
|
Asa@70
|
168 local dest, name = Crafting.GetQueueDestination()
|
Asa@68
|
169 local function Export(data)
|
Asa@70
|
170 ItemAuditor:Print(format("Adding %s x%s to %s queue. Profit: %s",
|
Asa@68
|
171 data.link,
|
Asa@68
|
172 data.queue,
|
Asa@70
|
173 name,
|
Asa@68
|
174 Utils.FormatMoney(data.profit)
|
Asa@68
|
175 ))
|
Asa@70
|
176 dest(data)
|
Asa@18
|
177 end
|
Asa@68
|
178 ItemAuditor:UpdateCraftingTable()
|
Asa@68
|
179 Crafting.Export(Export)
|
Asa@18
|
180 end
|
Asa@18
|
181
|
Asa@63
|
182 function ItemAuditor:GetReagentCost(link, total)
|
Asa@18
|
183 local totalCost = 0
|
Asa@19
|
184
|
Asa@86
|
185 if PT:ItemInSet(link,"Tradeskill.Mat.BySource.Vendor") then
|
Asa@19
|
186 local _, _, _, _, _, _, _, _, _, _, itemVendorPrice = GetItemInfo (link);
|
Asa@19
|
187 totalCost = itemVendorPrice * total
|
Asa@19
|
188 total = 0
|
Asa@19
|
189 end
|
Asa@19
|
190
|
Asa@19
|
191
|
Asa@63
|
192 local investedTotal, investedPerItem, count = ItemAuditor:GetItemCost(link)
|
Asa@18
|
193
|
Asa@18
|
194 if count > 0 then
|
Asa@18
|
195 if total <= count then
|
Asa@18
|
196 totalCost = investedPerItem * total
|
Asa@18
|
197 total = 0
|
Asa@18
|
198 else
|
Asa@18
|
199 totalCost = investedTotal
|
Asa@18
|
200 total = total - count
|
Asa@18
|
201 end
|
Asa@18
|
202 end
|
Asa@18
|
203
|
Asa@18
|
204 -- If there is none on the auction house, this uses a large enough number
|
Asa@18
|
205 -- to prevent us from trying to make the item.
|
Asa@21
|
206 local ahPrice = (self:GetAuctionPrice(link) or 99990000)
|
Asa@21
|
207 -- local itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType, _, _, _, _, itemVendorPrice = GetItemInfo (link);
|
Asa@18
|
208
|
Asa@18
|
209 return totalCost + (ahPrice * total)
|
Asa@18
|
210 end
|
Asa@18
|
211
|
Asa@63
|
212 function ItemAuditor:GetAuctionPrice(itemLink)
|
Asa@89
|
213 return AuctionHouse:GetAuctionPrice(itemLink)
|
Asa@21
|
214 end
|
Asa@21
|
215
|
Asa@63
|
216 function ItemAuditor:AddToQueue(skillId,skillIndex, toQueue)
|
Asa@18
|
217 if Skillet == nil then
|
Asa@18
|
218 self:Print("Skillet not loaded")
|
Asa@21
|
219 return
|
Asa@18
|
220 end
|
Asa@18
|
221 if Skillet.QueueCommandIterate ~= nil then
|
Asa@18
|
222 local queueCommand = Skillet:QueueCommandIterate(tonumber(skillId), toQueue)
|
Asa@18
|
223 Skillet:AddToQueue(queueCommand)
|
Asa@18
|
224 else
|
Asa@18
|
225 Skillet.stitch:AddToQueue(skillIndex, toQueue)
|
Asa@18
|
226 end
|
Asa@18
|
227 end
|
Asa@67
|
228
|
Asa@67
|
229 ItemAuditor.Options.args.qa_options = {
|
Asa@67
|
230 name = "QA Options",
|
Asa@67
|
231 desc = "Control how ItemAuditor integrates with QuickAuctions",
|
Asa@67
|
232 type = 'group',
|
Asa@67
|
233 disabled = function() return not ItemAuditor:IsQACompatible() end,
|
Asa@67
|
234 args = {
|
Asa@67
|
235 toggle_qa = {
|
Asa@67
|
236 type = "toggle",
|
Asa@67
|
237 name = "Enable Quick Auctions",
|
Asa@67
|
238 desc = "This will enable or disable Quick Auctions integration",
|
Asa@67
|
239 get = "IsQAEnabled",
|
Asa@67
|
240 set = "SetQAEnabled",
|
Asa@67
|
241 order = 0,
|
Asa@67
|
242 },
|
Asa@111
|
243 enable_percent = {
|
Asa@111
|
244 type = "toggle",
|
Asa@111
|
245 name = "Use percent to calculate threshold.",
|
Asa@111
|
246 get = function() return ItemAuditor.db.char.auction_threshold > 0 end,
|
Asa@111
|
247 set = function(info, value)
|
Asa@111
|
248 value = value and 0.15 or 0
|
Asa@111
|
249 ItemAuditor.db.char.auction_threshold = value
|
Asa@111
|
250 end,
|
Asa@111
|
251 order = 1,
|
Asa@111
|
252 },
|
Asa@67
|
253 auction_threshold = {
|
Asa@67
|
254 type = "range",
|
Asa@67
|
255 name = "Auction Threshold",
|
Asa@111
|
256 desc = "Don't sell items for less than this amount of profit.",
|
Asa@67
|
257 min = 0.0,
|
Asa@67
|
258 max = 1.0,
|
Asa@67
|
259 isPercent = true,
|
Asa@111
|
260 hidden = function() return ItemAuditor.db.char.auction_threshold == 0 end,
|
Asa@67
|
261 get = function() return ItemAuditor.db.char.auction_threshold end,
|
Asa@67
|
262 set = function(info, value)
|
Asa@67
|
263 ItemAuditor.db.char.auction_threshold = value
|
Asa@71
|
264 -- ItemAuditor:RefreshQAGroups()
|
Asa@71
|
265 end,
|
Asa@71
|
266 disabled = 'IsQADisabled',
|
Asa@111
|
267 order = 2,
|
Asa@111
|
268 },
|
Asa@111
|
269 enable_absolute = {
|
Asa@111
|
270 type = "toggle",
|
Asa@111
|
271 name = "Use value to calculate threshold.",
|
Asa@111
|
272 get = function() return ItemAuditor.db.char.auction_threshold_value > 0 end,
|
Asa@111
|
273 set = function(info, value)
|
Asa@111
|
274 value = value and 100000 or 0
|
Asa@111
|
275 ItemAuditor.db.char.auction_threshold_value = value
|
Asa@111
|
276 end,
|
Asa@111
|
277 order = 3,
|
Asa@111
|
278 },
|
Asa@111
|
279 auction_threshold_absolute = {
|
Asa@111
|
280 type = "input",
|
Asa@111
|
281 name = "Auction Threshold",
|
Asa@111
|
282 desc = "Don't sell items for less than this amount of profit.",
|
Asa@111
|
283 hidden = function() return ItemAuditor.db.char.auction_threshold_value == 0 end,
|
Asa@111
|
284 get = function() return
|
Asa@111
|
285 Utils.FormatMoney(ItemAuditor.db.char.auction_threshold_value , '', true)
|
Asa@111
|
286 end,
|
Asa@111
|
287 validate = function(info, value)
|
Asa@111
|
288 if not Utils.validateMoney(value) then
|
Asa@111
|
289 return "Invalid money format"
|
Asa@111
|
290 end
|
Asa@111
|
291 return true
|
Asa@111
|
292 end,
|
Asa@111
|
293 set = function(info, value)
|
Asa@111
|
294 ItemAuditor.db.char.auction_threshold_value = Utils.parseMoney(value)
|
Asa@111
|
295 end,
|
Asa@111
|
296 usage = "###g ##s ##c",
|
Asa@111
|
297 disabled = 'IsQADisabled',
|
Asa@111
|
298 order = 4,
|
Asa@111
|
299 },
|
Asa@67
|
300 refresh_qa = {
|
Asa@67
|
301 type = "execute",
|
Asa@67
|
302 name = "Refresh QA Thresholds",
|
Asa@67
|
303 desc = "Resets all Quick Auctions thresholds",
|
Asa@67
|
304 func = "RefreshQAGroups",
|
Asa@67
|
305 disabled = 'IsQADisabled',
|
Asa@111
|
306 order = 15,
|
Asa@67
|
307 },
|
Asa@67
|
308 }
|
Asa@67
|
309 }
|
Asa@67
|
310
|
Asa@67
|
311 ItemAuditor.Options.args.queue = {
|
Asa@67
|
312 type = "execute",
|
Asa@67
|
313 name = "queue",
|
Asa@67
|
314 desc = "Queue",
|
Asa@67
|
315 func = "Queue",
|
Asa@67
|
316 guiHidden = true,
|
Asa@67
|
317 } |