comparison Core.lua @ 26:75d917ccd942

Fixed Bug #9 - If existing items have 0c invested, increase them all to match the first transaction that changes their price.
author Asa Ayers <Asa.Ayers@Gmail.com>
date Wed, 14 Jul 2010 00:28:44 -0700
parents 554b30908b33
children 34daa46b644a
comparison
equal deleted inserted replaced
24:554b30908b33 26:75d917ccd942
164 end 164 end
165 ]] 165 ]]
166 elseif mailType == "CODPayment" then 166 elseif mailType == "CODPayment" then
167 itemName = msgSubject:gsub(utils.SubjectPatterns[mailType], function(item) return item end) 167 itemName = msgSubject:gsub(utils.SubjectPatterns[mailType], function(item) return item end)
168 168
169 results[mailType][itemName] = (results[mailType][itemName] or 0) - msgMoney 169 results[mailType][itemName] = (results[mailType][itemName] or {total=0,count=0})
170 results[mailType][itemName].total = results[mailType][itemName].total - msgMoney
170 171
171 elseif mailType == "AHSuccess" then 172 elseif mailType == "AHSuccess" then
172 local invoiceType, itemName, playerName, bid, buyout, deposit, consignment = GetInboxInvoiceInfo(mailIndex); 173 local invoiceType, itemName, playerName, bid, buyout, deposit, consignment = GetInboxInvoiceInfo(mailIndex);
173 results[mailType][itemName] = (results[mailType][itemName] or 0) - deposit - buyout + consignment 174 results[mailType][itemName] = (results[mailType][itemName] or {total=0,count=0})
175 results[mailType][itemName].total = results[mailType][itemName].total - deposit - buyout + consignment
176
174 177
175 elseif mailType == "AHWon" then 178 elseif mailType == "AHWon" then
176 local invoiceType, itemName, playerName, bid, buyout, deposit, consignment = GetInboxInvoiceInfo(mailIndex); 179 local invoiceType, itemName, playerName, bid, buyout, deposit, consignment = GetInboxInvoiceInfo(mailIndex);
177 results[mailType][itemName] = (results[mailType][itemName] or 0) + bid 180 results[mailType][itemName] = (results[mailType][itemName] or {total=0,count=0})
181 results[mailType][itemName].total = results[mailType][itemName].total + bid
182
183 local count = select(3, GetInboxItem(1,1))
184 results[mailType][itemName].count = results[mailType][itemName].count + count
178 elseif mailType == "AHExpired" or mailType == "AHCancelled" or mailType == "AHOutbid" then 185 elseif mailType == "AHExpired" or mailType == "AHCancelled" or mailType == "AHOutbid" then
179 -- These should be handled when you pay the deposit at the AH 186 -- These should be handled when you pay the deposit at the AH
180 else 187 else
181 -- self:Debug("Unhandled mail type: " .. mailType) 188 -- self:Debug("Unhandled mail type: " .. mailType)
182 -- self:Debug(msgSubject) 189 -- self:Debug(msgSubject)
183 end 190 end
184 191
185 end 192 end
186 193
187 for mailType, collection in pairs(results) do 194 for mailType, collection in pairs(results) do
188 for item, total in pairs(collection) do 195 for item, data in pairs(collection) do
189 self:Debug(format("|cFF00FF00MailScan|r: %s - %s - %s", mailType, item, total)) 196 self:Debug(format("|cFF00FF00MailScan|r: %s - %s - %s x %s", mailType, item, data.total, data.count))
190 end 197 end
191 end 198 end
192 199
193 return results 200 return results
194 end 201 end
244 else 251 else
245 self:Debug('Failed to convert link' .. tostring(link)) 252 self:Debug('Failed to convert link' .. tostring(link))
246 end 253 end
247 end 254 end
248 255
249 function addon:SaveValue(link, value) 256 function addon:SaveValue(link, value, countChange)
250 self:Debug(format("SaveValue(%s, %s)", tostring(link), value)) 257 self:Debug("SaveValue(%s, %s, %s)", tostring(link), value, (countChange or 'default'))
258 countChange = countChange or 0
251 local item = nil 259 local item = nil
252 local realLink = self:GetSafeLink(link) 260 local realLink = self:GetSafeLink(link)
253 local itemName = nil 261 local itemName = nil
254 if realLink == nil then 262 if realLink == nil then
263 itemName = link
255 self:Debug('SaveValue: GetSafeLink failed, falling back to storing by name: ' .. tostring(itemName)) 264 self:Debug('SaveValue: GetSafeLink failed, falling back to storing by name: ' .. tostring(itemName))
256 itemName = link
257 self.db.factionrealm.item_account[itemName] = (self.db.factionrealm.item_account[itemName] or 0) + value 265 self.db.factionrealm.item_account[itemName] = (self.db.factionrealm.item_account[itemName] or 0) + value
258 item = {invested = self.db.factionrealm.item_account[itemName], count = 1} 266 item = {invested = self.db.factionrealm.item_account[itemName], count = 1}
259 else 267 else
260 268
261 item = self:GetItem(realLink) 269 item = self:GetItem(realLink)
262 item.invested = item.invested + value 270 item.invested = item.invested + value
263 itemName = GetItemInfo(realLink) 271 itemName = GetItemInfo(realLink)
272 end
273
274 if value > 0 and countChange > 0 and item.invested == value and item.count ~= countChange then
275 local costPerItem = value / countChange
276 value = costPerItem * item.count
277 item.invested = value
278 self:Print("You already owned %s %s with an unknown price, so they have also been updated to %s each", (item.count - countChange), itemName, self:FormatMoney(costPerItem))
264 end 279 end
265 280
266 if abs(value) > 0 then 281 if abs(value) > 0 then
267 if item.invested < 0 then 282 if item.invested < 0 then
268 if self.db.profile.messages.cost_updates then 283 if self.db.profile.messages.cost_updates then