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@18
|
5
|
Asa@62
|
6 --[[
|
Asa@62
|
7 This is simply for compatibility while I change the QA API. Once
|
Asa@62
|
8 my changes get merged into the main project, this can go away.
|
Asa@62
|
9 ]]
|
Asa@62
|
10 if QAAPI ~= nil and QAAPI.GetGroupThreshold ~= nil and QAAPI.GetGroupConfig == nil then
|
Asa@62
|
11 function QAAPI:GetGroupConfig(groupName)
|
Asa@62
|
12 return QAAPI:GetGroupThreshold(groupName),
|
Asa@62
|
13 QAAPI:GetGroupPostCap(groupName),
|
Asa@62
|
14 QAAPI:GetGroupPerAuction(groupName)
|
Asa@62
|
15 end
|
Asa@62
|
16
|
Asa@62
|
17 function QAAPI:SetGroupConfig(groupName, key, value)
|
Asa@62
|
18 if key == 'threshold' then
|
Asa@62
|
19 return QAAPI:SetGroupThreshold(groupName, value)
|
Asa@62
|
20 end
|
Asa@62
|
21 end
|
Asa@62
|
22 end
|
Asa@62
|
23
|
Asa@62
|
24
|
Asa@62
|
25
|
Asa@63
|
26 function ItemAuditor:IsQACompatible()
|
Asa@62
|
27 return (QAAPI ~= nil and QAAPI.GetGroupConfig ~= nil)
|
Asa@18
|
28 end
|
Asa@18
|
29
|
Asa@63
|
30 function ItemAuditor:IsQAEnabled()
|
Asa@63
|
31 return ItemAuditor:IsQACompatible() and ItemAuditor.db.char.use_quick_auctions
|
Asa@18
|
32 end
|
Asa@18
|
33
|
Asa@63
|
34 function ItemAuditor:IsQADisabled()
|
Asa@18
|
35 return not self:IsQAEnabled()
|
Asa@18
|
36 end
|
Asa@18
|
37
|
Asa@63
|
38 function ItemAuditor:SetQAEnabled(info, value)
|
Asa@18
|
39 ItemAuditor.db.char.use_quick_auctions = value
|
Asa@18
|
40 end
|
Asa@18
|
41
|
Asa@63
|
42 function ItemAuditor:RefreshQAGroups()
|
Asa@63
|
43 if not ItemAuditor.IsQAEnabled() then
|
Asa@18
|
44 return
|
Asa@18
|
45 end
|
Asa@18
|
46 for groupName in pairs(QAAPI:GetGroups()) do
|
Asa@18
|
47 self:UpdateQAGroup(groupName)
|
Asa@18
|
48 end
|
Asa@18
|
49 end
|
Asa@18
|
50
|
Asa@63
|
51 function ItemAuditor:UpdateQAThreshold(link)
|
Asa@63
|
52 if not ItemAuditor.IsQAEnabled() then
|
Asa@18
|
53 return
|
Asa@18
|
54 end
|
Asa@18
|
55 _, link= GetItemInfo(link)
|
Asa@18
|
56
|
Asa@18
|
57 self:UpdateQAGroup(QAAPI:GetItemGroup(link))
|
Asa@18
|
58 end
|
Asa@18
|
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@63
|
67 copper = copper * (1+ItemAuditor:GetAuctionThreshold())
|
Asa@19
|
68
|
Asa@19
|
69 -- add AH Cut
|
Asa@63
|
70 local keep = 1 - ItemAuditor:GetAHCut()
|
Asa@19
|
71 return copper/keep
|
Asa@19
|
72 end
|
Asa@19
|
73
|
Asa@63
|
74 function ItemAuditor:UpdateQAGroup(groupName)
|
Asa@63
|
75 if not ItemAuditor.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@63
|
94 if ItemAuditor.IsQAEnabled() then
|
Asa@59
|
95 local QAGroup = QAAPI:GetItemGroup(data.link)
|
Asa@59
|
96 if QAGroup ~= nil then
|
Asa@63
|
97 local currentInvested, _, currentCount = ItemAuditor: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@71
|
104 stackSize = ceil(stackSize * (1+ItemAuditor.db.char.qa_extra))
|
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@64
|
118 Crafting.RegisterCraftingDecider('IA QuickAuctions', isProfitable)
|
Asa@59
|
119
|
Asa@68
|
120
|
Asa@63
|
121 function ItemAuditor:Queue()
|
Asa@70
|
122 local dest, name = Crafting.GetQueueDestination()
|
Asa@68
|
123 local function Export(data)
|
Asa@70
|
124 ItemAuditor:Print(format("Adding %s x%s to %s queue. Profit: %s",
|
Asa@68
|
125 data.link,
|
Asa@68
|
126 data.queue,
|
Asa@70
|
127 name,
|
Asa@68
|
128 Utils.FormatMoney(data.profit)
|
Asa@68
|
129 ))
|
Asa@70
|
130 dest(data)
|
Asa@18
|
131 end
|
Asa@68
|
132 ItemAuditor:UpdateCraftingTable()
|
Asa@68
|
133 Crafting.Export(Export)
|
Asa@18
|
134 end
|
Asa@18
|
135
|
Asa@63
|
136 function ItemAuditor:GetReagentCost(link, total)
|
Asa@18
|
137 local totalCost = 0
|
Asa@19
|
138
|
Asa@19
|
139 if Skillet:VendorSellsReagent(link) then
|
Asa@19
|
140 local _, _, _, _, _, _, _, _, _, _, itemVendorPrice = GetItemInfo (link);
|
Asa@19
|
141 totalCost = itemVendorPrice * total
|
Asa@19
|
142 total = 0
|
Asa@19
|
143 end
|
Asa@19
|
144
|
Asa@19
|
145
|
Asa@63
|
146 local investedTotal, investedPerItem, count = ItemAuditor:GetItemCost(link)
|
Asa@18
|
147
|
Asa@18
|
148 if count > 0 then
|
Asa@18
|
149 if total <= count then
|
Asa@18
|
150 totalCost = investedPerItem * total
|
Asa@18
|
151 total = 0
|
Asa@18
|
152 else
|
Asa@18
|
153 totalCost = investedTotal
|
Asa@18
|
154 total = total - count
|
Asa@18
|
155 end
|
Asa@18
|
156 end
|
Asa@18
|
157
|
Asa@18
|
158 -- If there is none on the auction house, this uses a large enough number
|
Asa@18
|
159 -- to prevent us from trying to make the item.
|
Asa@21
|
160 local ahPrice = (self:GetAuctionPrice(link) or 99990000)
|
Asa@21
|
161 -- local itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType, _, _, _, _, itemVendorPrice = GetItemInfo (link);
|
Asa@18
|
162
|
Asa@18
|
163 return totalCost + (ahPrice * total)
|
Asa@18
|
164 end
|
Asa@18
|
165
|
Asa@63
|
166 function ItemAuditor:GetAuctionPrice(itemLink)
|
Asa@21
|
167 if GetAuctionBuyout ~= nil then
|
Asa@21
|
168 return GetAuctionBuyout(itemLink)
|
Asa@21
|
169 elseif AucAdvanced and AucAdvanced.Version then
|
Asa@21
|
170 local _, _, _, _, _, lowBuy= AucAdvanced.Modules.Util.SimpleAuction.Private.GetItems(itemLink)
|
Asa@21
|
171 return lowBuy
|
Asa@21
|
172 end
|
Asa@21
|
173 return nil
|
Asa@21
|
174 end
|
Asa@21
|
175
|
Asa@63
|
176 function ItemAuditor:AddToQueue(skillId,skillIndex, toQueue)
|
Asa@18
|
177 if Skillet == nil then
|
Asa@18
|
178 self:Print("Skillet not loaded")
|
Asa@21
|
179 return
|
Asa@18
|
180 end
|
Asa@18
|
181 if Skillet.QueueCommandIterate ~= nil then
|
Asa@18
|
182 local queueCommand = Skillet:QueueCommandIterate(tonumber(skillId), toQueue)
|
Asa@18
|
183 Skillet:AddToQueue(queueCommand)
|
Asa@18
|
184 else
|
Asa@18
|
185 Skillet.stitch:AddToQueue(skillIndex, toQueue)
|
Asa@18
|
186 end
|
Asa@18
|
187 end
|
Asa@67
|
188
|
Asa@67
|
189 ItemAuditor.Options.args.qa_options = {
|
Asa@67
|
190 name = "QA Options",
|
Asa@67
|
191 desc = "Control how ItemAuditor integrates with QuickAuctions",
|
Asa@67
|
192 type = 'group',
|
Asa@67
|
193 disabled = function() return not ItemAuditor:IsQACompatible() end,
|
Asa@67
|
194 args = {
|
Asa@67
|
195 toggle_qa = {
|
Asa@67
|
196 type = "toggle",
|
Asa@67
|
197 name = "Enable Quick Auctions",
|
Asa@67
|
198 desc = "This will enable or disable Quick Auctions integration",
|
Asa@67
|
199 get = "IsQAEnabled",
|
Asa@67
|
200 set = "SetQAEnabled",
|
Asa@67
|
201 order = 0,
|
Asa@67
|
202 },
|
Asa@67
|
203 auction_threshold = {
|
Asa@67
|
204 type = "range",
|
Asa@67
|
205 name = "Auction Threshold",
|
Asa@67
|
206 desc = "Don't create items that will make less than this amount of profit",
|
Asa@67
|
207 min = 0.0,
|
Asa@67
|
208 max = 1.0,
|
Asa@67
|
209 isPercent = true,
|
Asa@67
|
210 get = function() return ItemAuditor.db.char.auction_threshold end,
|
Asa@67
|
211 set = function(info, value)
|
Asa@67
|
212 ItemAuditor.db.char.auction_threshold = value
|
Asa@71
|
213 -- ItemAuditor:RefreshQAGroups()
|
Asa@71
|
214 end,
|
Asa@71
|
215 disabled = 'IsQADisabled',
|
Asa@71
|
216 order = 1,
|
Asa@71
|
217 },
|
Asa@71
|
218 extra = {
|
Asa@71
|
219 type = "range",
|
Asa@71
|
220 name = "Create Extra",
|
Asa@71
|
221 desc = "This is the amount of an item that should be created above what you sell in one post in QuickAuctions."..
|
Asa@71
|
222 "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
|
223 min = 0.0,
|
Asa@71
|
224 max = 1.0,
|
Asa@71
|
225 isPercent = true,
|
Asa@71
|
226 get = function() return ItemAuditor.db.char.qa_extra end,
|
Asa@71
|
227 set = function(info, value)
|
Asa@71
|
228 ItemAuditor.db.char.qa_extra = value
|
Asa@67
|
229 end,
|
Asa@67
|
230 disabled = 'IsQADisabled',
|
Asa@67
|
231 order = 1,
|
Asa@67
|
232 },
|
Asa@67
|
233 refresh_qa = {
|
Asa@67
|
234 type = "execute",
|
Asa@67
|
235 name = "Refresh QA Thresholds",
|
Asa@67
|
236 desc = "Resets all Quick Auctions thresholds",
|
Asa@67
|
237 func = "RefreshQAGroups",
|
Asa@67
|
238 disabled = 'IsQADisabled',
|
Asa@67
|
239 order = 9,
|
Asa@67
|
240 },
|
Asa@67
|
241 }
|
Asa@67
|
242 }
|
Asa@67
|
243
|
Asa@67
|
244 ItemAuditor.Options.args.queue = {
|
Asa@67
|
245 type = "execute",
|
Asa@67
|
246 name = "queue",
|
Asa@67
|
247 desc = "Queue",
|
Asa@67
|
248 func = "Queue",
|
Asa@67
|
249 guiHidden = true,
|
Asa@67
|
250 } |