Mercurial > wow > itemauditor
comparison Modules/Events.lua @ 51:84bfb5469189
Merged and closed ticket7
| author | Asa Ayers <Asa.Ayers@Gmail.com> |
|---|---|
| date | Wed, 21 Jul 2010 01:22:30 -0700 |
| parents | 9ff6a3b02332 |
| children | 9c95158236d1 |
comparison
equal
deleted
inserted
replaced
| 48:508110e7c8ee | 51:84bfb5469189 |
|---|---|
| 222 | 222 |
| 223 function addon:UpdateCurrentInventory() | 223 function addon:UpdateCurrentInventory() |
| 224 self.lastInventory = self:GetCurrentInventory() | 224 self.lastInventory = self:GetCurrentInventory() |
| 225 end | 225 end |
| 226 | 226 |
| 227 local function distributeValue(self, totalValue, targetItems) | |
| 228 | |
| 229 local weights = {} | |
| 230 local totalWeight = 0 | |
| 231 for link, change in pairs(targetItems) do | |
| 232 --[[ | |
| 233 If something has never been seen on the AH, it must not be very valuable. | |
| 234 I'm using 1c so it doesn't have much weight and I can't get a devided by zero error. | |
| 235 The only time I know that this is a problem is when crafting a BOP item, and it | |
| 236 is always crafted 1 at a time, so a weight of 1 will work. | |
| 237 ]] | |
| 238 local ap = (addon:GetAuctionPrice(link) or 1) | |
| 239 totalWeight = totalWeight + ap | |
| 240 weights[link] = ap | |
| 241 end | |
| 242 | |
| 243 local valuePerPoint = totalValue / totalWeight | |
| 244 | |
| 245 for link, change in pairs(targetItems) do | |
| 246 self:SaveValue(link, weights[link] * valuePerPoint, change) | |
| 247 end | |
| 248 end | |
| 249 | |
| 227 function addon:UpdateAudit() | 250 function addon:UpdateAudit() |
| 228 -- self:Debug("UpdateAudit " .. event) | 251 -- self:Debug("UpdateAudit " .. event) |
| 229 local currentInventory = self:GetCurrentInventory() | 252 local currentInventory = self:GetCurrentInventory() |
| 230 local diff = addon:GetInventoryDiff(self.lastInventory, currentInventory) | 253 local diff = addon:GetInventoryDiff(self.lastInventory, currentInventory) |
| 231 | 254 |
| 264 self:SaveValue(link, itemCost * change, change) | 287 self:SaveValue(link, itemCost * change, change) |
| 265 | 288 |
| 266 totalChange = totalChange + (itemCost * abs(change)) | 289 totalChange = totalChange + (itemCost * abs(change)) |
| 267 end | 290 end |
| 268 | 291 |
| 269 local valuePerItem = totalChange / positiveCount | 292 distributeValue(self, totalChange, positive) |
| 270 | |
| 271 for link, change in pairs(positive) do | |
| 272 self:SaveValue(link, valuePerItem * change, change) | |
| 273 end | |
| 274 else | 293 else |
| 275 self:Debug("No match in UpdateAudit.") | 294 self:Debug("No match in UpdateAudit.") |
| 276 end | 295 end |
| 277 | 296 |
| 278 self.lastInventory = currentInventory | 297 self.lastInventory = currentInventory |
