comparison Core.lua @ 9:374dd1a90d02

Changed the way things are stored so that items known only by name, usually from AH mail, will be stored by their name, but will get converted if the link is discovered through a tooltip. This version is funcioning again
author Asa Ayers <Asa.Ayers@Gmail.com>
date Fri, 25 Jun 2010 01:17:58 -0700
parents 0271e781b154
children c79ede3c7b82
comparison
equal deleted inserted replaced
8:0271e781b154 9:374dd1a90d02
1 local addonName, addonTable = ...; 1 local addonName, addonTable = ...;
2 _G[addonName] = LibStub("AceAddon-3.0"):NewAddon(addonName, "AceConsole-3.0", "AceEvent-3.0", "AceBucket-3.0") 2 _G[addonName] = LibStub("AceAddon-3.0"):NewAddon(addonName, "AceConsole-3.0", "AceEvent-3.0", "AceBucket-3.0")
3 local addon = _G[addonName] 3 local addon = _G[addonName]
4 addonTable.ItemAuditor = addon
4 5
5 local utils = addonTable.utils 6 local utils = addonTable.utils
6 7
7 8
8 local WHITE = "|cFFFFFFFF" 9 local WHITE = "|cFFFFFFFF"
110 local mailType = utils:GetMailType(msgSubject) 111 local mailType = utils:GetMailType(msgSubject)
111 112
112 results[mailType] = (results[mailType] or {}) 113 results[mailType] = (results[mailType] or {})
113 114
114 if mailType == "NonAHMail" and msgCOD > 0 then 115 if mailType == "NonAHMail" and msgCOD > 0 then
116 --[[
115 mailType = 'COD' 117 mailType = 'COD'
116 results[mailType] = (results[mailType] or {}) 118 results[mailType] = (results[mailType] or {})
117 119
118 local itemTypes = {} 120 local itemTypes = {}
119 for itemIndex = 1, ATTACHMENTS_MAX_RECEIVE do 121 for itemIndex = 1, ATTACHMENTS_MAX_RECEIVE do
128 results[mailType][itemName] = (results[mailType][itemName] or 0) - msgCOD 130 results[mailType][itemName] = (results[mailType][itemName] or 0) - msgCOD
129 end 131 end
130 else 132 else
131 self:Debug("Don't know what to do with more than one item type on COD mail.") 133 self:Debug("Don't know what to do with more than one item type on COD mail.")
132 end 134 end
135 ]]
133 elseif mailType == "CODPayment" then 136 elseif mailType == "CODPayment" then
134 itemName = msgSubject:gsub(utils.SubjectPatterns[mailType], function(item) return item end) 137 itemName = msgSubject:gsub(utils.SubjectPatterns[mailType], function(item) return item end)
135 138
136 results[mailType][itemName] = (results[mailType][itemName] or 0) + msgMoney 139 results[mailType][itemName] = (results[mailType][itemName] or 0) - msgMoney
137 140
138 elseif mailType == "AHSuccess" then 141 elseif mailType == "AHSuccess" then
139 local invoiceType, itemName, playerName, bid, buyout, deposit, consignment = GetInboxInvoiceInfo(mailIndex); 142 local invoiceType, itemName, playerName, bid, buyout, deposit, consignment = GetInboxInvoiceInfo(mailIndex);
140 results[mailType][itemName] = (results[mailType][itemName] or 0) + deposit + buyout - consignment 143 results[mailType][itemName] = (results[mailType][itemName] or 0) - deposit - buyout + consignment
141 144
142 elseif mailType == "AHWon" then 145 elseif mailType == "AHWon" then
143 local invoiceType, itemName, playerName, bid, buyout, deposit, consignment = GetInboxInvoiceInfo(mailIndex); 146 local invoiceType, itemName, playerName, bid, buyout, deposit, consignment = GetInboxInvoiceInfo(mailIndex);
144 results[mailType][itemName] = (results[mailType][itemName] or 0) - bid 147 results[mailType][itemName] = (results[mailType][itemName] or 0) + bid
145 elseif mailType == "AHExpired" or mailType == "AHCancelled" or mailType == "AHOutbid" then 148 elseif mailType == "AHExpired" or mailType == "AHCancelled" or mailType == "AHOutbid" then
146 -- These should be handled when you pay the deposit at the AH 149 -- These should be handled when you pay the deposit at the AH
147 else 150 else
148 self:Debug("Unhandled mail type: " .. mailType) 151 self:Debug("Unhandled mail type: " .. mailType)
149 self:Debug(msgSubject) 152 self:Debug(msgSubject)
151 154
152 end 155 end
153 return results 156 return results
154 end 157 end
155 158
156 function addon:GetItem(link) 159 function addon:GetItem(link, viewOnly)
157 link = utils:GetSafeLink(link) 160 if viewOnly == nil then
158 DevTools_Dump(link) 161 viewOnly = false
159 if self.items[link] == nil then 162 end
160 local itemName = GetItemInfo(link) 163
161 164 local itemName = nil
165 if self:GetSafeLink(link) == nil then
166 itemName = link
167 else
168 link = self:GetSafeLink(link)
169 itemName = GetItemInfo(link)
170 end
171
172 if self.db.factionrealm.item_account[itemName] ~= nil then
162 self.items[link] = { 173 self.items[link] = {
163 count = Altoholic:GetItemCount(utils:GetIDFromLink(link)), 174 count = Altoholic:GetItemCount(utils:GetIDFromLink(link)),
164 invested = abs(self.db.factionrealm.item_account[itemName] or 0), 175 invested = abs(self.db.factionrealm.item_account[itemName] or 0),
165 } 176 }
166 self.db.factionrealm.item_account[itemName] = nil 177 self.db.factionrealm.item_account[itemName] = nil
167 end 178 end
168 179
180 if viewOnly == false and self.items[link] == nil then
181 local itemName = GetItemInfo(link)
182
183 self.items[link] = {
184 count = Altoholic:GetItemCount(self:GetIDFromLink(link)),
185 invested = abs(self.db.factionrealm.item_account[itemName] or 0),
186 }
187
188 end
189
190
191
192 if viewOnly == true and self.items[link] == nil then
193 return {count = 0, invested = 0}
194 elseif viewOnly == true then
195 return {count = self.items[link].count, invested = self.items[link].invested}
196 end
169 return self.items[link] 197 return self.items[link]
170 end 198 end
171 199
172 function addon:RemoveItem(link) 200 function addon:RemoveItem(link)
173 link = utils:GetSafeLink(link) 201 self.db.factionrealm.item_account[link] = nil
174 self.items[link] = nil 202 link = self:GetSafeLink(link)
175 end 203 if link ~= nil then
176 204 self.items[link] = nil
205 end
206 end
207 --[[
208 ItemAuditor:SaveValue('Scroll of Enchant Weapon - Exceptional Spellpower', 1)
209
210 DevTools_Dump(ItemAuditor.db.factionrealm.item_account)
211
212 = ItemAuditor:GetItem('Scroll of Enchant Weapon - Exceptional Spellpower', true).invested
213 ]]
177 function addon:SaveValue(link, value) 214 function addon:SaveValue(link, value)
178 local item_account = self.db.factionrealm.item_account 215 local item = nil
179 216 local realLink = self:GetSafeLink(link)
180 local item = self:GetItem(link) 217 local itemName = nil
181 218 if realLink == nil then
182 item.invested = item.invested + value 219 itemName = link
183 220
184 local itemName = GetItemInfo(link) 221 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}
224 else
225
226 item = self:GetItem(realLink)
227
228 item.invested = item.invested + value
229
230 itemName = GetItemInfo(realLink)
231 end
232
185 if abs(value) > 0 then 233 if abs(value) > 0 then
186 self:Debug("Updated price of " .. itemName .. " to " .. utils:FormatMoney(item.invested) .. "(change: " .. utils:FormatMoney(value) .. ")") 234 self:Debug("Updated price of " .. itemName .. " to " .. utils:FormatMoney(item.invested) .. "(change: " .. utils:FormatMoney(value) .. ")")
187 end 235 end
188 236
189 if item.invested > 0 then 237 if item.invested <= 0 then
190 self:Debug("Updated price of " .. itemName .. " to " .. utils:FormatMoney(0)) 238 self:Debug("Updated price of " .. itemName .. " to " .. utils:FormatMoney(0))
191 self:RemoveItem(link) 239 self:RemoveItem(link)
192 end 240 elseif item.count == 0 then
193
194 if item.count == 0 then
195 self:Print("You ran out of " .. itemName .. " and never recovered " .. utils:FormatMoney(item.invested)) 241 self:Print("You ran out of " .. itemName .. " and never recovered " .. utils:FormatMoney(item.invested))
196 self:RemoveItem(link) 242 self:RemoveItem(link)
197 end 243 end
198 end 244 end
199 245
218 self:UnregisterBucket(self.watch_handle) 264 self:UnregisterBucket(self.watch_handle)
219 self.watch_handle = nil 265 self.watch_handle = nil
220 end 266 end
221 end 267 end
222 268
269 function addon:GetItemID(itemName)
270 return utils:GetItemID(itemName)
271 end
272
273 function addon:GetSafeLink(link)
274 local newLink = nil
275
276 if link ~= string.match(link, '.-:[-0-9]+[:0-9]*') then
277 newLink = link and string.match(link, "|H(.-):([-0-9]+):([0-9]+)|h")
278 end
279 if newLink == nil then
280 local itemID = self:GetItemID(link)
281 if itemID ~= nil then
282 _, newLink = GetItemInfo(itemID)
283 return self:GetSafeLink(newLink)
284 end
285 end
286 return newLink and string.gsub(newLink, ":0:0:0:0:0:0", "")
287 end
288
289 function addon:GetIDFromLink(link)
290 local _, _, _, _, Id = string.find(link, "|?c?f?f?(%x*)|?H?([^:]*):?(%d+):?(%d*):?(%d*):?(%d*):?(%d*):?(%d*):?(%-?%d*):?(%-?%d*):?(%d*)|?h?%[?([^%[%]]*)%]?|?h?|?r?")
291 return tonumber(Id)
292 end
293
223 function addon:GetItemCost(link, countModifier) 294 function addon:GetItemCost(link, countModifier)
224 local item = self:GetItem(link) 295 local item = self:GetItem(link, true)
225 296
226 local invested = item.invested 297 if item.invested > 0 then
227 298 local count = item.count
228 if invested > 0 then 299
229 local ItemID = utils:GetIDFromLink(link) 300 if countModifier ~= nil then
230 if ItemID ~= nil then 301 count = count - countModifier
231 local count = self:GetItem(link).count 302 end
232 303 if count > 0 then
233 if countModifier ~= nil then 304 return ceil(item.invested), ceil(item.invested/item.count), count
234 count = count - countModifier 305 end
235 end 306
236 if count > 0 then
237 return ceil(invested), ceil(invested/count), count
238 end
239 end
240 end 307 end
241 return 0, 0, 0 308 return 0, 0, 0
242 end 309 end