Mercurial > wow > itemauditor
comparison Core.lua @ 10:c79ede3c7b82
Updated version and added a dependency on my modified API for QuickAuctions. Next I need to make that dependency optional
author | Asa Ayers <Asa.Ayers@Gmail.com> |
---|---|
date | Fri, 25 Jun 2010 22:03:44 -0700 |
parents | 374dd1a90d02 |
children | 6a6296dd249f |
comparison
equal
deleted
inserted
replaced
9:374dd1a90d02 | 10:c79ede3c7b82 |
---|---|
19 char = { | 19 char = { |
20 debug = false | 20 debug = false |
21 }, | 21 }, |
22 factionrealm = { | 22 factionrealm = { |
23 item_account = {}, | 23 item_account = {}, |
24 | |
25 items = {}, | 24 items = {}, |
25 AHCut = 0.05, | |
26 }, | 26 }, |
27 } | 27 } |
28 self.db = LibStub("AceDB-3.0"):New("ItemAuditorDB", DB_defaults, true) | 28 self.db = LibStub("AceDB-3.0"):New("ItemAuditorDB", DB_defaults, true) |
29 addonTable.db= self.db | 29 addonTable.db= self.db |
30 self.items = self.db.factionrealm.items | 30 self.items = self.db.factionrealm.items |
47 | 47 |
48 for link, data in pairs(self.db.factionrealm.items) do | 48 for link, data in pairs(self.db.factionrealm.items) do |
49 if self:GetItem(link).count == 0 or self:GetItem(link).invested == 0 then | 49 if self:GetItem(link).count == 0 or self:GetItem(link).invested == 0 then |
50 self:RemoveItem(link) | 50 self:RemoveItem(link) |
51 end | 51 end |
52 -- addon:UpdateQAThreshold(link) | |
53 end | |
54 | |
55 for groupName in pairs(QAAPI:GetGroups()) do | |
56 self:UpdateQAGroup(groupName) | |
52 end | 57 end |
53 end | 58 end |
54 | 59 |
55 function addon:GetCurrentInventory() | 60 function addon:GetCurrentInventory() |
56 local i = {} | 61 local i = {} |
59 | 64 |
60 for bagID = 0, NUM_BAG_SLOTS do | 65 for bagID = 0, NUM_BAG_SLOTS do |
61 bagSize=GetContainerNumSlots(bagID) | 66 bagSize=GetContainerNumSlots(bagID) |
62 for slotID = 0, bagSize do | 67 for slotID = 0, bagSize do |
63 local link= GetContainerItemLink(bagID, slotID); | 68 local link= GetContainerItemLink(bagID, slotID); |
69 link = link and self:GetSafeLink(link) | |
64 | 70 |
65 if link ~= nil and i[link] == nil then | 71 if link ~= nil and i[link] == nil then |
66 i[link] = GetItemCount(link); | 72 i[link] = GetItemCount(link); |
67 end | 73 end |
68 end | 74 end |
179 | 185 |
180 if viewOnly == false and self.items[link] == nil then | 186 if viewOnly == false and self.items[link] == nil then |
181 local itemName = GetItemInfo(link) | 187 local itemName = GetItemInfo(link) |
182 | 188 |
183 self.items[link] = { | 189 self.items[link] = { |
184 count = Altoholic:GetItemCount(self:GetIDFromLink(link)), | 190 count = Altoholic:GetItemCount(self:GetIDFromLink(link)), |
185 invested = abs(self.db.factionrealm.item_account[itemName] or 0), | 191 invested = abs(self.db.factionrealm.item_account[itemName] or 0), |
186 } | 192 } |
187 | 193 |
188 end | 194 end |
189 | 195 |
192 if viewOnly == true and self.items[link] == nil then | 198 if viewOnly == true and self.items[link] == nil then |
193 return {count = 0, invested = 0} | 199 return {count = 0, invested = 0} |
194 elseif viewOnly == true then | 200 elseif viewOnly == true then |
195 return {count = self.items[link].count, invested = self.items[link].invested} | 201 return {count = self.items[link].count, invested = self.items[link].invested} |
196 end | 202 end |
203 self.items[link].count = Altoholic:GetItemCount(self:GetIDFromLink(link)) | |
197 return self.items[link] | 204 return self.items[link] |
198 end | 205 end |
199 | 206 |
200 function addon:RemoveItem(link) | 207 function addon:RemoveItem(link) |
201 self.db.factionrealm.item_account[link] = nil | 208 self.db.factionrealm.item_account[link] = nil |
215 local item = nil | 222 local item = nil |
216 local realLink = self:GetSafeLink(link) | 223 local realLink = self:GetSafeLink(link) |
217 local itemName = nil | 224 local itemName = nil |
218 if realLink == nil then | 225 if realLink == nil then |
219 itemName = link | 226 itemName = link |
220 | |
221 self.db.factionrealm.item_account[itemName] = (self.db.factionrealm.item_account[itemName] or 0) + value | 227 self.db.factionrealm.item_account[itemName] = (self.db.factionrealm.item_account[itemName] or 0) + value |
222 | |
223 item = {invested = self.db.factionrealm.item_account[itemName], count = 1} | 228 item = {invested = self.db.factionrealm.item_account[itemName], count = 1} |
224 else | 229 else |
225 | |
226 item = self:GetItem(realLink) | 230 item = self:GetItem(realLink) |
227 | |
228 item.invested = item.invested + value | 231 item.invested = item.invested + value |
229 | |
230 itemName = GetItemInfo(realLink) | 232 itemName = GetItemInfo(realLink) |
231 end | 233 end |
232 | 234 |
233 if abs(value) > 0 then | 235 if abs(value) > 0 then |
234 self:Debug("Updated price of " .. itemName .. " to " .. utils:FormatMoney(item.invested) .. "(change: " .. utils:FormatMoney(value) .. ")") | 236 self:Debug("Updated price of " .. itemName .. " to " .. utils:FormatMoney(item.invested) .. "(change: " .. utils:FormatMoney(value) .. ")") |
235 end | 237 end |
236 | 238 |
237 if item.invested <= 0 then | 239 if abs(value) > 0 and item.invested <= 0 then |
238 self:Debug("Updated price of " .. itemName .. " to " .. utils:FormatMoney(0)) | 240 self:Debug("Updated price of " .. itemName .. " to " .. utils:FormatMoney(0)) |
239 self:RemoveItem(link) | 241 self:RemoveItem(link) |
240 elseif item.count == 0 then | 242 elseif item.count == 0 and ItemAuditor:GetCurrentInventory() > 0 then |
241 self:Print("You ran out of " .. itemName .. " and never recovered " .. utils:FormatMoney(item.invested)) | 243 self:Print("You ran out of " .. itemName .. " and never recovered " .. utils:FormatMoney(item.invested)) |
242 self:RemoveItem(link) | 244 self:RemoveItem(link) |
245 end | |
246 | |
247 if realLink ~= nil then | |
248 addon:UpdateQAThreshold(realLink) | |
249 end | |
250 end | |
251 --[[ | |
252 | |
253 ItemAuditor:UpdateQAThreshold("item:42646") | |
254 ]] | |
255 function addon:UpdateQAThreshold(link) | |
256 _, link= GetItemInfo(link) | |
257 | |
258 self:UpdateQAGroup(QAAPI:GetItemGroup(link)) | |
259 end | |
260 | |
261 function addon:UpdateQAGroup(groupName) | |
262 if groupName then | |
263 local threshold = 10000 | |
264 | |
265 for link in pairs(QAAPI:GetItemsInGroup(groupName)) do | |
266 local totalCost, itemCost, itemCount = ItemAuditor:GetItemCost(link, 0) | |
267 | |
268 if itemCost > threshold then | |
269 threshold = itemCost | |
270 end | |
271 end | |
272 | |
273 -- Adding the cost of mailing every item once. | |
274 threshold = threshold + 30 | |
275 | |
276 -- add my minimum profit margin 15% | |
277 threshold = threshold * 1.15 | |
278 | |
279 -- add AH Cut | |
280 local keep = 1 - self.db.factionrealm.AHCut | |
281 threshold = threshold/keep | |
282 | |
283 QAAPI:SetGroupThreshold(groupName, ceil(threshold)) | |
243 end | 284 end |
244 end | 285 end |
245 | 286 |
246 local defaultBagDelay = 0.2 | 287 local defaultBagDelay = 0.2 |
247 | 288 |
271 end | 312 end |
272 | 313 |
273 function addon:GetSafeLink(link) | 314 function addon:GetSafeLink(link) |
274 local newLink = nil | 315 local newLink = nil |
275 | 316 |
276 if link ~= string.match(link, '.-:[-0-9]+[:0-9]*') then | 317 if link and link ~= string.match(link, '.-:[-0-9]+[:0-9]*') then |
277 newLink = link and string.match(link, "|H(.-):([-0-9]+):([0-9]+)|h") | 318 newLink = link and string.match(link, "|H(.-):([-0-9]+):([0-9]+)|h") |
278 end | 319 end |
279 if newLink == nil then | 320 if newLink == nil then |
280 local itemID = self:GetItemID(link) | 321 local itemID = self:GetItemID(link) |
281 if itemID ~= nil then | 322 if itemID ~= nil then |