Mercurial > wow > itemauditor
comparison Modules/Events.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 |
---|---|
2 local addon = _G[addonName] | 2 local addon = _G[addonName] |
3 | 3 |
4 local utils = addonTable.utils | 4 local utils = addonTable.utils |
5 | 5 |
6 function addon:PLAYER_ENTERING_WORLD() | 6 function addon:PLAYER_ENTERING_WORLD() |
7 addon:ConvertItems() | |
8 DevTools_Dump(ItemAuditor.db.factionrealm.items) | |
9 | |
10 self:RegisterEvent("MAIL_SHOW") | 7 self:RegisterEvent("MAIL_SHOW") |
11 self:RegisterEvent("UNIT_SPELLCAST_START") | 8 self:RegisterEvent("UNIT_SPELLCAST_START") |
12 self:WatchBags() | 9 self:WatchBags() |
10 | |
11 addon:ConvertItems() | |
13 end | 12 end |
14 | 13 |
15 function addon:MAIL_SHOW() | 14 function addon:MAIL_SHOW() |
16 self:Debug("MAIL_SHOW") | 15 self:Debug("MAIL_SHOW") |
17 self.lastMailScan = self:ScanMail() | 16 self.lastMailScan = self:ScanMail() |
79 function addon:UpdateCurrentInventory() | 78 function addon:UpdateCurrentInventory() |
80 self.lastInventory = self:GetCurrentInventory() | 79 self.lastInventory = self:GetCurrentInventory() |
81 end | 80 end |
82 | 81 |
83 function addon:UpdateAudit() | 82 function addon:UpdateAudit() |
84 -- self:Debug("UpdateAudit") | 83 self:Debug("UpdateAudit") |
85 local currentInventory = self:GetCurrentInventory() | 84 local currentInventory = self:GetCurrentInventory() |
86 local diff = addon:GetInventoryDiff(self.lastInventory, currentInventory) | 85 local diff = addon:GetInventoryDiff(self.lastInventory, currentInventory) |
87 -- this is only here for debugging | 86 -- this is only here for debugging |
88 self.lastdiff = diff | 87 self.lastdiff = diff |
89 | 88 |
102 if diff.money > 0 and utils:tcount(positive) > 0 and utils:tcount(negative) == 0 then | 101 if diff.money > 0 and utils:tcount(positive) > 0 and utils:tcount(negative) == 0 then |
103 -- self:Debug("loot") | 102 -- self:Debug("loot") |
104 elseif utils:tcount(diff.items) == 1 then | 103 elseif utils:tcount(diff.items) == 1 then |
105 self:Debug("purchase or sale") | 104 self:Debug("purchase or sale") |
106 | 105 |
107 for itemName, count in pairs(diff.items) do | 106 for link, count in pairs(diff.items) do |
108 self:SaveValue(itemName, diff.money) | 107 self:SaveValue(link, 0 - diff.money) |
109 end | 108 end |
110 elseif utils:tcount(diff.items) > 1 then | 109 elseif utils:tcount(diff.items) > 1 then |
111 | 110 |
112 if utils:tcount(positive) > 0 and utils:tcount(negative) > 0 then | 111 if utils:tcount(positive) > 0 and utils:tcount(negative) > 0 then |
113 -- we must have created/converted something | 112 -- we must have created/converted something |
114 -- self:Debug("conversion") | 113 -- self:Debug("conversion") |
115 local totalChange = 0 | 114 local totalChange = 0 |
116 for itemName, change in pairs(negative) do | 115 for link, change in pairs(negative) do |
117 local _, itemCost, count = self:GetItemCost(itemName, change) | 116 local _, itemCost, count = self:GetItemCost(link, change) |
118 self:SaveValue(itemName, abs(itemCost * change)) | 117 self:SaveValue(link, itemCost * change) |
119 | 118 |
120 totalChange = totalChange + abs(itemCost * change) | 119 totalChange = totalChange + (itemCost * abs(change)) |
121 end | 120 end |
122 | 121 |
123 local valuePerItem = totalChange / positiveCount | 122 local valuePerItem = totalChange / positiveCount |
124 | 123 |
125 for itemName, change in pairs(positive) do | 124 for link, change in pairs(positive) do |
126 self:SaveValue(itemName, 0-abs(valuePerItem * change)) | 125 self:SaveValue(link, valuePerItem * change) |
127 end | 126 end |
128 end | 127 end |
129 end | 128 end |
130 | 129 |
131 self.lastInventory = currentInventory | 130 self.lastInventory = currentInventory |