Mercurial > wow > itemauditor
comparison Modules/QuickAuctions.lua @ 63:e7d287cc3b02
Replaced all instances of addon with ItemAuditor and I moved ItemAuditor out of the global namespace. The conversion was mostly a search/replace offering no new functionality. That will come in a later commit.
author | Asa Ayers <Asa.Ayers@Gmail.com> |
---|---|
date | Tue, 27 Jul 2010 17:58:33 -0700 |
parents | 70dc84df13b3 |
children | e92a5adf75bf |
comparison
equal
deleted
inserted
replaced
62:70dc84df13b3 | 63:e7d287cc3b02 |
---|---|
1 local addonName, addonTable = ...; | 1 local ItemAuditor = select(2, ...) |
2 local addon = _G[addonName] | 2 local QuickAuctions= ItemAuditor:NewModule("QuickAuctions") |
3 | 3 |
4 --[[ | 4 --[[ |
5 This is simply for compatibility while I change the QA API. Once | 5 This is simply for compatibility while I change the QA API. Once |
6 my changes get merged into the main project, this can go away. | 6 my changes get merged into the main project, this can go away. |
7 ]] | 7 ]] |
19 end | 19 end |
20 end | 20 end |
21 | 21 |
22 | 22 |
23 | 23 |
24 function addon:IsQACompatible() | 24 function ItemAuditor:IsQACompatible() |
25 return (QAAPI ~= nil and QAAPI.GetGroupConfig ~= nil) | 25 return (QAAPI ~= nil and QAAPI.GetGroupConfig ~= nil) |
26 end | 26 end |
27 | 27 |
28 function addon:IsQAEnabled() | 28 function ItemAuditor:IsQAEnabled() |
29 return addon:IsQACompatible() and ItemAuditor.db.char.use_quick_auctions | 29 return ItemAuditor:IsQACompatible() and ItemAuditor.db.char.use_quick_auctions |
30 end | 30 end |
31 | 31 |
32 function addon:IsQADisabled() | 32 function ItemAuditor:IsQADisabled() |
33 return not self:IsQAEnabled() | 33 return not self:IsQAEnabled() |
34 end | 34 end |
35 | 35 |
36 function addon:SetQAEnabled(info, value) | 36 function ItemAuditor:SetQAEnabled(info, value) |
37 ItemAuditor.db.char.use_quick_auctions = value | 37 ItemAuditor.db.char.use_quick_auctions = value |
38 end | 38 end |
39 | 39 |
40 function addon:RefreshQAGroups() | 40 function ItemAuditor:RefreshQAGroups() |
41 if not addon.IsQAEnabled() then | 41 if not ItemAuditor.IsQAEnabled() then |
42 return | 42 return |
43 end | 43 end |
44 for groupName in pairs(QAAPI:GetGroups()) do | 44 for groupName in pairs(QAAPI:GetGroups()) do |
45 self:UpdateQAGroup(groupName) | 45 self:UpdateQAGroup(groupName) |
46 end | 46 end |
47 end | 47 end |
48 | 48 |
49 function addon:UpdateQAThreshold(link) | 49 function ItemAuditor:UpdateQAThreshold(link) |
50 if not addon.IsQAEnabled() then | 50 if not ItemAuditor.IsQAEnabled() then |
51 return | 51 return |
52 end | 52 end |
53 _, link= GetItemInfo(link) | 53 _, link= GetItemInfo(link) |
54 | 54 |
55 self:UpdateQAGroup(QAAPI:GetItemGroup(link)) | 55 self:UpdateQAGroup(QAAPI:GetItemGroup(link)) |
56 end | 56 end |
57 | |
58 addon.profit_margin = 1.15 | |
59 | 57 |
60 local function calculateQAThreshold(copper) | 58 local function calculateQAThreshold(copper) |
61 if copper == 0 then | 59 if copper == 0 then |
62 copper = 1 | 60 copper = 1 |
63 end | 61 end |
64 | 62 |
65 -- add my minimum profit margin | 63 -- add my minimum profit margin |
66 -- GetAuctionThreshold returns a percent as a whole number. This will convert 25 to 1.25 | 64 -- GetAuctionThreshold returns a percent as a whole number. This will convert 25 to 1.25 |
67 copper = copper * (1+addon:GetAuctionThreshold()) | 65 copper = copper * (1+ItemAuditor:GetAuctionThreshold()) |
68 | 66 |
69 -- add AH Cut | 67 -- add AH Cut |
70 local keep = 1 - addon:GetAHCut() | 68 local keep = 1 - ItemAuditor:GetAHCut() |
71 return copper/keep | 69 return copper/keep |
72 end | 70 end |
73 | 71 |
74 function addon:UpdateQAGroup(groupName) | 72 function ItemAuditor:UpdateQAGroup(groupName) |
75 if not addon.IsQAEnabled() then | 73 if not ItemAuditor.IsQAEnabled() then |
76 return | 74 return |
77 end | 75 end |
78 if groupName then | 76 if groupName then |
79 local threshold = 0 | 77 local threshold = 0 |
80 | 78 |
89 QAAPI:SetGroupConfig(groupName, 'threshold', ceil(threshold)) | 87 QAAPI:SetGroupConfig(groupName, 'threshold', ceil(threshold)) |
90 end | 88 end |
91 end | 89 end |
92 | 90 |
93 local function isProfitable(data) | 91 local function isProfitable(data) |
94 if addon.IsQAEnabled() then | 92 if ItemAuditor.IsQAEnabled() then |
95 local QAGroup = QAAPI:GetItemGroup(data.link) | 93 local QAGroup = QAAPI:GetItemGroup(data.link) |
96 if QAGroup ~= nil then | 94 if QAGroup ~= nil then |
97 local currentInvested, _, currentCount = addon:GetItemCost(data.link) | 95 local currentInvested, _, currentCount = ItemAuditor:GetItemCost(data.link) |
98 local threshold, postCap, perAuction = QAAPI:GetGroupConfig(QAGroup) | 96 local threshold, postCap, perAuction = QAAPI:GetGroupConfig(QAGroup) |
99 local stackSize = postCap * perAuction | 97 local stackSize = postCap * perAuction |
100 | 98 |
101 stackSize = stackSize / GetTradeSkillNumMade(data.tradeSkillIndex) | 99 stackSize = stackSize / GetTradeSkillNumMade(data.tradeSkillIndex) |
102 | 100 |
118 ItemAuditor:RegisterCraftingDecider('IA QuickAuctions', isProfitable) | 116 ItemAuditor:RegisterCraftingDecider('IA QuickAuctions', isProfitable) |
119 | 117 |
120 --[[ | 118 --[[ |
121 This is based on KTQ | 119 This is based on KTQ |
122 ]] | 120 ]] |
123 function addon:Queue() | 121 function ItemAuditor:Queue() |
124 if LSW == nil then | 122 if LSW == nil then |
125 self:Print("This feature requires LilSparky's Workshop.") | 123 self:Print("This feature requires LilSparky's Workshop.") |
126 return | 124 return |
127 end | 125 end |
128 if Skillet == nil then | 126 if Skillet == nil then |
135 self:Print("This feature requires Auctionator, Auctioneer, AuctionLite, or AuctionMaster.") | 133 self:Print("This feature requires Auctionator, Auctioneer, AuctionLite, or AuctionMaster.") |
136 return | 134 return |
137 end | 135 end |
138 | 136 |
139 | 137 |
140 if addon.IsQAEnabled() then | 138 if ItemAuditor.IsQAEnabled() then |
141 self:Debug("Auction Threshold: %d%%", self:GetAuctionThreshold()*100 ) | 139 self:Debug("Auction Threshold: %d%%", self:GetAuctionThreshold()*100 ) |
142 end | 140 end |
143 self:Debug(format("Crafting Threshold: %s", self:FormatMoney(self:GetCraftingThreshold()))) | 141 self:Debug(format("Crafting Threshold: %s", self:FormatMoney(self:GetCraftingThreshold()))) |
144 local profitableItems = {} | 142 local profitableItems = {} |
145 local profitableIndex = 1 | 143 local profitableIndex = 1 |
163 _, itemLink= GetItemInfo(itemId) | 161 _, itemLink= GetItemInfo(itemId) |
164 | 162 |
165 | 163 |
166 -- if QA isn't enabled, this will just return nil | 164 -- if QA isn't enabled, this will just return nil |
167 local QAGroup = nil | 165 local QAGroup = nil |
168 if addon.IsQAEnabled() then | 166 if ItemAuditor.IsQAEnabled() then |
169 QAGroup = QAAPI:GetItemGroup(itemLink) | 167 QAGroup = QAAPI:GetItemGroup(itemLink) |
170 if QAGroup ~= nil then | 168 if QAGroup ~= nil then |
171 local threshold, postCap, perAuction = QAAPI:GetGroupConfig(QAGroup) | 169 local threshold, postCap, perAuction = QAAPI:GetGroupConfig(QAGroup) |
172 stackSize = postCap * perAuction | 170 stackSize = postCap * perAuction |
173 stackSize = stackSize / GetTradeSkillNumMade(i) | 171 stackSize = stackSize / GetTradeSkillNumMade(i) |
186 local toQueue = stackSize - count | 184 local toQueue = stackSize - count |
187 local newCost = 0 | 185 local newCost = 0 |
188 for reagentId = 1, GetTradeSkillNumReagents(i) do | 186 for reagentId = 1, GetTradeSkillNumReagents(i) do |
189 _, _, reagentCount = GetTradeSkillReagentInfo(i, reagentId); | 187 _, _, reagentCount = GetTradeSkillReagentInfo(i, reagentId); |
190 reagentLink = GetTradeSkillReagentItemLink(i, reagentId) | 188 reagentLink = GetTradeSkillReagentItemLink(i, reagentId) |
191 newCost = newCost + addon:GetReagentCost(reagentLink, reagentCount) | 189 newCost = newCost + ItemAuditor:GetReagentCost(reagentLink, reagentCount) |
192 end | 190 end |
193 | 191 |
194 local currentInvested, _, currentCount = addon:GetItemCost(itemLink) | 192 local currentInvested, _, currentCount = ItemAuditor:GetItemCost(itemLink) |
195 local newThreshold = (newCost + currentInvested) / (currentCount + toQueue) | 193 local newThreshold = (newCost + currentInvested) / (currentCount + toQueue) |
196 | 194 |
197 if addon.IsQAEnabled() then | 195 if ItemAuditor.IsQAEnabled() then |
198 newThreshold = calculateQAThreshold(newThreshold) | 196 newThreshold = calculateQAThreshold(newThreshold) |
199 else | 197 else |
200 -- if quick auctions isn't enabled, this will cause the decision to rely | 198 -- if quick auctions isn't enabled, this will cause the decision to rely |
201 -- completly on the crafting threshold | 199 -- completly on the crafting threshold |
202 newThreshold = 0 | 200 newThreshold = 0 |
203 end | 201 end |
204 local currentPrice = addon:GetAuctionPrice(itemLink) or 0 | 202 local currentPrice = ItemAuditor:GetAuctionPrice(itemLink) or 0 |
205 numChecked = numChecked + 1 | 203 numChecked = numChecked + 1 |
206 | 204 |
207 if newThreshold < currentPrice and (currentPrice - newCost) > self:GetCraftingThreshold() then | 205 if newThreshold < currentPrice and (currentPrice - newCost) > self:GetCraftingThreshold() then |
208 | 206 |
209 profitableItems[profitableIndex] = { | 207 profitableItems[profitableIndex] = { |
213 toQueue = toQueue, | 211 toQueue = toQueue, |
214 profit = (currentPrice - newCost) * toQueue | 212 profit = (currentPrice - newCost) * toQueue |
215 } | 213 } |
216 profitableIndex = profitableIndex + 1 | 214 profitableIndex = profitableIndex + 1 |
217 else | 215 else |
218 local skipMessage = format("Skipping %s x%s. Profit: %s ", itemLink, toQueue, addon:FormatMoney(currentPrice - newCost)) | 216 local skipMessage = format("Skipping %s x%s. Profit: %s ", itemLink, toQueue, ItemAuditor:FormatMoney(currentPrice - newCost)) |
219 if ItemAuditor.db.profile.messages.queue_skip then | 217 if ItemAuditor.db.profile.messages.queue_skip then |
220 self:Print(skipMessage) | 218 self:Print(skipMessage) |
221 else | 219 else |
222 self:Debug(format("Skipping %s x%s. Profit: %s ", itemLink, toQueue, addon:FormatMoney(currentPrice - newCost))) | 220 self:Debug(format("Skipping %s x%s. Profit: %s ", itemLink, toQueue, ItemAuditor:FormatMoney(currentPrice - newCost))) |
223 end | 221 end |
224 end | 222 end |
225 end | 223 end |
226 end | 224 end |
227 end | 225 end |
238 end | 236 end |
239 self:Print(format("%d items checked", numChecked)) | 237 self:Print(format("%d items checked", numChecked)) |
240 self:Print(format("%d queued", numAdded)) | 238 self:Print(format("%d queued", numAdded)) |
241 end | 239 end |
242 | 240 |
243 function addon:GetReagentCost(link, total) | 241 function ItemAuditor:GetReagentCost(link, total) |
244 local totalCost = 0 | 242 local totalCost = 0 |
245 | 243 |
246 if Skillet:VendorSellsReagent(link) then | 244 if Skillet:VendorSellsReagent(link) then |
247 local _, _, _, _, _, _, _, _, _, _, itemVendorPrice = GetItemInfo (link); | 245 local _, _, _, _, _, _, _, _, _, _, itemVendorPrice = GetItemInfo (link); |
248 totalCost = itemVendorPrice * total | 246 totalCost = itemVendorPrice * total |
249 total = 0 | 247 total = 0 |
250 end | 248 end |
251 | 249 |
252 | 250 |
253 local investedTotal, investedPerItem, count = addon:GetItemCost(link) | 251 local investedTotal, investedPerItem, count = ItemAuditor:GetItemCost(link) |
254 | 252 |
255 if count > 0 then | 253 if count > 0 then |
256 if total <= count then | 254 if total <= count then |
257 totalCost = investedPerItem * total | 255 totalCost = investedPerItem * total |
258 total = 0 | 256 total = 0 |
268 -- local itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType, _, _, _, _, itemVendorPrice = GetItemInfo (link); | 266 -- local itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType, _, _, _, _, itemVendorPrice = GetItemInfo (link); |
269 | 267 |
270 return totalCost + (ahPrice * total) | 268 return totalCost + (ahPrice * total) |
271 end | 269 end |
272 | 270 |
273 function addon:GetAuctionPrice(itemLink) | 271 function ItemAuditor:GetAuctionPrice(itemLink) |
274 if GetAuctionBuyout ~= nil then | 272 if GetAuctionBuyout ~= nil then |
275 return GetAuctionBuyout(itemLink) | 273 return GetAuctionBuyout(itemLink) |
276 elseif AucAdvanced and AucAdvanced.Version then | 274 elseif AucAdvanced and AucAdvanced.Version then |
277 local _, _, _, _, _, lowBuy= AucAdvanced.Modules.Util.SimpleAuction.Private.GetItems(itemLink) | 275 local _, _, _, _, _, lowBuy= AucAdvanced.Modules.Util.SimpleAuction.Private.GetItems(itemLink) |
278 return lowBuy | 276 return lowBuy |
279 end | 277 end |
280 return nil | 278 return nil |
281 end | 279 end |
282 | 280 |
283 function addon:AddToQueue(skillId,skillIndex, toQueue) | 281 function ItemAuditor:AddToQueue(skillId,skillIndex, toQueue) |
284 if Skillet == nil then | 282 if Skillet == nil then |
285 self:Print("Skillet not loaded") | 283 self:Print("Skillet not loaded") |
286 return | 284 return |
287 end | 285 end |
288 if Skillet.QueueCommandIterate ~= nil then | 286 if Skillet.QueueCommandIterate ~= nil then |