Mercurial > wow > itemauditor
comparison Modules/Events.lua @ 63:e7d287cc3b02
Replaced all instances of addon with ItemAuditor and I moved ItemAuditor out of the global namespace. The conversion was mostly a search/replace offering no new functionality. That will come in a later commit.
author | Asa Ayers <Asa.Ayers@Gmail.com> |
---|---|
date | Tue, 27 Jul 2010 17:58:33 -0700 |
parents | c6c98fc1be8e |
children | 64166ba5209a |
comparison
equal
deleted
inserted
replaced
62:70dc84df13b3 | 63:e7d287cc3b02 |
---|---|
1 local addonName, addonTable = ...; | 1 local ItemAuditor = select(2, ...) |
2 local addon = _G[addonName] | 2 local Events = ItemAuditor:NewModule("Events", "AceEvent-3.0") |
3 | 3 |
4 function addon:OnEnable() | 4 function ItemAuditor:OnEnable() |
5 self:RegisterEvent("MAIL_SHOW") | 5 self:RegisterEvent("MAIL_SHOW") |
6 self:RegisterEvent("UNIT_SPELLCAST_START") | 6 self:RegisterEvent("UNIT_SPELLCAST_START") |
7 addon:UpdateCurrentInventory() | 7 ItemAuditor:UpdateCurrentInventory() |
8 self:WatchBags() | 8 self:WatchBags() |
9 | 9 |
10 self:SetEnabled(nil, self.db.profile.addon_enabled) | 10 self:SetEnabled(nil, self.db.profile.ItemAuditor_enabled) |
11 end | 11 end |
12 | 12 |
13 function addon:OnDisable() | 13 function ItemAuditor:OnDisable() |
14 self:UnwatchBags() | 14 self:UnwatchBags() |
15 self:UnregisterAllEvents() | 15 self:UnregisterAllEvents() |
16 addon:HideAllFrames() | 16 ItemAuditor:HideAllFrames() |
17 end | 17 end |
18 | 18 |
19 function addon:MAIL_SHOW() | 19 function ItemAuditor:MAIL_SHOW() |
20 self:Debug("MAIL_SHOW") | 20 self:Debug("MAIL_SHOW") |
21 self:UnwatchBags() | 21 self:UnwatchBags() |
22 addon:UpdateCurrentInventory() | 22 ItemAuditor:UpdateCurrentInventory() |
23 self.lastMailScan = self:ScanMail() | 23 self.lastMailScan = self:ScanMail() |
24 | 24 |
25 self:UnregisterEvent("MAIL_SHOW") | 25 self:UnregisterEvent("MAIL_SHOW") |
26 self:RegisterEvent("MAIL_CLOSED") | 26 self:RegisterEvent("MAIL_CLOSED") |
27 self:RegisterEvent("MAIL_INBOX_UPDATE") | 27 self:RegisterEvent("MAIL_INBOX_UPDATE") |
29 self:GenerateBlankOutbox() | 29 self:GenerateBlankOutbox() |
30 | 30 |
31 self:RegisterEvent("MAIL_SUCCESS") | 31 self:RegisterEvent("MAIL_SUCCESS") |
32 end | 32 end |
33 | 33 |
34 function addon:GenerateBlankOutbox() | 34 function ItemAuditor:GenerateBlankOutbox() |
35 self.mailOutbox = { | 35 self.mailOutbox = { |
36 from = UnitName("player"), | 36 from = UnitName("player"), |
37 to = "", | 37 to = "", |
38 subject = "", | 38 subject = "", |
39 link = '', | 39 link = '', |
122 end | 122 end |
123 | 123 |
124 return Orig_SendMail(recipient, subject, body, ...) | 124 return Orig_SendMail(recipient, subject, body, ...) |
125 end | 125 end |
126 | 126 |
127 function addon:MAIL_SUCCESS(event) | 127 function ItemAuditor:MAIL_SUCCESS(event) |
128 skipCODTracking = false | 128 skipCODTracking = false |
129 for link, data in pairs(attachedItems) do | 129 for link, data in pairs(attachedItems) do |
130 self:SaveValue(link, data.price, data.count) | 130 self:SaveValue(link, data.price, data.count) |
131 end | 131 end |
132 if self.mailOutbox.COD > 0 then | 132 if self.mailOutbox.COD > 0 then |
138 | 138 |
139 | 139 |
140 self:GenerateBlankOutbox() | 140 self:GenerateBlankOutbox() |
141 end | 141 end |
142 | 142 |
143 function addon:MAIL_CLOSED() | 143 function ItemAuditor:MAIL_CLOSED() |
144 self:Debug("MAIL_CLOSED") | 144 self:Debug("MAIL_CLOSED") |
145 addon:UnregisterEvent("MAIL_CLOSED") | 145 ItemAuditor:UnregisterEvent("MAIL_CLOSED") |
146 self:MAIL_INBOX_UPDATE() | 146 self:MAIL_INBOX_UPDATE() |
147 self:UnregisterEvent("MAIL_INBOX_UPDATE") | 147 self:UnregisterEvent("MAIL_INBOX_UPDATE") |
148 self:RegisterEvent("MAIL_SHOW") | 148 self:RegisterEvent("MAIL_SHOW") |
149 self:WatchBags() | 149 self:WatchBags() |
150 end | 150 end |
151 | 151 |
152 local storedCountDiff | 152 local storedCountDiff |
153 function addon:MAIL_INBOX_UPDATE() | 153 function ItemAuditor:MAIL_INBOX_UPDATE() |
154 self:Debug("MAIL_INBOX_UPDATE") | 154 self:Debug("MAIL_INBOX_UPDATE") |
155 local newScan = addon:ScanMail() | 155 local newScan = ItemAuditor:ScanMail() |
156 local diff | 156 local diff |
157 | 157 |
158 for mailType, collection in pairs(self.lastMailScan) do | 158 for mailType, collection in pairs(self.lastMailScan) do |
159 newScan[mailType] = (newScan[mailType] or {}) | 159 newScan[mailType] = (newScan[mailType] or {}) |
160 for itemName, data in pairs(collection) do | 160 for itemName, data in pairs(collection) do |
185 end | 185 end |
186 | 186 |
187 self.lastMailScan = newScan | 187 self.lastMailScan = newScan |
188 end | 188 end |
189 | 189 |
190 function addon:UNIT_SPELLCAST_START(event, target, spell) | 190 function ItemAuditor:UNIT_SPELLCAST_START(event, target, spell) |
191 if target == "player" and spell == "Milling" or spell == "Prospecting" or spell == "Disenchanting" then | 191 if target == "player" and spell == "Milling" or spell == "Prospecting" or spell == "Disenchanting" then |
192 self:Debug(event .. " " .. spell) | 192 self:Debug(event .. " " .. spell) |
193 self:UnwatchBags() | 193 self:UnwatchBags() |
194 self:UpdateCurrentInventory() | 194 self:UpdateCurrentInventory() |
195 self:RegisterEvent("UNIT_SPELLCAST_INTERRUPTED") | 195 self:RegisterEvent("UNIT_SPELLCAST_INTERRUPTED") |
199 | 199 |
200 --[[ | 200 --[[ |
201 The item should be destroyed before this point, so the last inventory check | 201 The item should be destroyed before this point, so the last inventory check |
202 needs to be kept so it can be combined with the up coming loot. | 202 needs to be kept so it can be combined with the up coming loot. |
203 ]] | 203 ]] |
204 function addon:LOOT_CLOSED() | 204 function ItemAuditor:LOOT_CLOSED() |
205 self:Debug("LOOT_CLOSED") | 205 self:Debug("LOOT_CLOSED") |
206 self:UnregisterEvent("LOOT_CLOSED") | 206 self:UnregisterEvent("LOOT_CLOSED") |
207 self:UnregisterEvent("UNIT_SPELLCAST_INTERRUPTED") | 207 self:UnregisterEvent("UNIT_SPELLCAST_INTERRUPTED") |
208 local inventory = self.lastInventory | 208 local inventory = self.lastInventory |
209 self:WatchBags() | 209 self:WatchBags() |
210 self.lastInventory = inventory | 210 self.lastInventory = inventory |
211 end | 211 end |
212 | 212 |
213 function addon:UNIT_SPELLCAST_INTERRUPTED(event, target, spell) | 213 function ItemAuditor:UNIT_SPELLCAST_INTERRUPTED(event, target, spell) |
214 if target == "player" and spell == "Milling" or spell == "Prospecting" or spell == "Disenchanting" then | 214 if target == "player" and spell == "Milling" or spell == "Prospecting" or spell == "Disenchanting" then |
215 self:Debug(event .. " " .. spell) | 215 self:Debug(event .. " " .. spell) |
216 self:UnregisterEvent("UNIT_SPELLCAST_INTERRUPTED") | 216 self:UnregisterEvent("UNIT_SPELLCAST_INTERRUPTED") |
217 self:UnregisterEvent("LOOT_CLOSED") | 217 self:UnregisterEvent("LOOT_CLOSED") |
218 self:WatchBags() | 218 self:WatchBags() |
219 end | 219 end |
220 end | 220 end |
221 | 221 |
222 function addon:UpdateCurrentInventory() | 222 function ItemAuditor:UpdateCurrentInventory() |
223 self.lastInventory = self:GetCurrentInventory() | 223 self.lastInventory = self:GetCurrentInventory() |
224 end | 224 end |
225 | 225 |
226 local function distributeValue(self, totalValue, targetItems) | 226 local function distributeValue(self, totalValue, targetItems) |
227 | 227 |
232 If something has never been seen on the AH, it must not be very valuable. | 232 If something has never been seen on the AH, it must not be very valuable. |
233 I'm using 1c so it doesn't have much weight and I can't get a devided by zero error. | 233 I'm using 1c so it doesn't have much weight and I can't get a devided by zero error. |
234 The only time I know that this is a problem is when crafting a BOP item, and it | 234 The only time I know that this is a problem is when crafting a BOP item, and it |
235 is always crafted 1 at a time, so a weight of 1 will work. | 235 is always crafted 1 at a time, so a weight of 1 will work. |
236 ]] | 236 ]] |
237 local ap = (addon:GetAuctionPrice(link) or 1) * change | 237 local ap = (ItemAuditor:GetAuctionPrice(link) or 1) * change |
238 totalWeight = totalWeight + ap | 238 totalWeight = totalWeight + ap |
239 weights[link] = ap | 239 weights[link] = ap |
240 end | 240 end |
241 | 241 |
242 for link, change in pairs(targetItems) do | 242 for link, change in pairs(targetItems) do |
243 local value = totalValue * (weights[link]/totalWeight) | 243 local value = totalValue * (weights[link]/totalWeight) |
244 self:SaveValue(link, value, change) | 244 self:SaveValue(link, value, change) |
245 end | 245 end |
246 end | 246 end |
247 | 247 |
248 function addon:UpdateAudit() | 248 function ItemAuditor:UpdateAudit() |
249 -- self:Debug("UpdateAudit " .. event) | 249 -- self:Debug("UpdateAudit " .. event) |
250 local currentInventory = self:GetCurrentInventory() | 250 local currentInventory = self:GetCurrentInventory() |
251 local diff = addon:GetInventoryDiff(self.lastInventory, currentInventory) | 251 local diff = ItemAuditor:GetInventoryDiff(self.lastInventory, currentInventory) |
252 | 252 |
253 local positive, negative = {}, {} | 253 local positive, negative = {}, {} |
254 local positiveCount, negativeCount = 0, 0 | 254 local positiveCount, negativeCount = 0, 0 |
255 for item, count in pairs(diff.items) do | 255 for item, count in pairs(diff.items) do |
256 if count > 0 then | 256 if count > 0 then |
291 else | 291 else |
292 self:Debug("No match in UpdateAudit.") | 292 self:Debug("No match in UpdateAudit.") |
293 end | 293 end |
294 | 294 |
295 self.lastInventory = currentInventory | 295 self.lastInventory = currentInventory |
296 addon:WatchBags() | 296 ItemAuditor:WatchBags() |
297 end | 297 end |