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