comparison Modules/Events.lua @ 5:7d0f4ebedf8c

work in progress: I added Prospecting and Disenchanting and AHOutbid mail and I also changed the initialization to quit forcing debug every time ItemAuditor loads and have begun to implement the COD mail scanning.
author Asa Ayers <Asa.Ayers@Gmail.com>
date Wed, 26 May 2010 21:26:24 -0700
parents c940b527ccab
children 5dddd73b2220
comparison
equal deleted inserted replaced
4:c940b527ccab 5:7d0f4ebedf8c
41 41
42 self.lastMailScan = newScan 42 self.lastMailScan = newScan
43 end 43 end
44 44
45 function addon:UNIT_SPELLCAST_START(event, target, spell) 45 function addon:UNIT_SPELLCAST_START(event, target, spell)
46 if target == "player" and spell == "Milling" then 46 if target == "player" and spell == "Milling" or spell == "Prospecting" or spell == "Disenchanting" then
47 self:UnwatchBags() 47 self:UnwatchBags()
48 self:UpdateCurrentInventory() 48 self:UpdateCurrentInventory()
49 self:RegisterEvent("UNIT_SPELLCAST_INTERRUPTED") 49 self:RegisterEvent("UNIT_SPELLCAST_INTERRUPTED")
50 self:RegisterEvent("LOOT_CLOSED") 50 self:RegisterEvent("LOOT_CLOSED")
51 end 51 end
62 self:WatchBags() 62 self:WatchBags()
63 self.lastInventory = inventory 63 self.lastInventory = inventory
64 end 64 end
65 65
66 function addon:UNIT_SPELLCAST_INTERRUPTED(event, target, spell) 66 function addon:UNIT_SPELLCAST_INTERRUPTED(event, target, spell)
67 if target == "player" and spell == "Milling" then 67 if target == "player" and spell == "Milling" or spell == "Prospecting" or spell == "Disenchanting" then
68 self:UnregisterEvent("UNIT_SPELLCAST_INTERRUPTED") 68 self:UnregisterEvent("UNIT_SPELLCAST_INTERRUPTED")
69 self:UnregisterEvent("LOOT_CLOSED") 69 self:UnregisterEvent("LOOT_CLOSED")
70 self:WatchBags() 70 self:WatchBags()
71 end 71 end
72 end 72 end
80 local currentInventory = self:GetCurrentInventory() 80 local currentInventory = self:GetCurrentInventory()
81 local diff = addon:GetInventoryDiff(self.lastInventory, currentInventory) 81 local diff = addon:GetInventoryDiff(self.lastInventory, currentInventory)
82 -- this is only here for debugging 82 -- this is only here for debugging
83 self.lastdiff = diff 83 self.lastdiff = diff
84 84
85 if abs(diff.money) > 0 and utils:tcount(diff.items) == 1 then 85 local positive, negative = {}, {}
86 local positiveCount, negativeCount = 0, 0
87 for item, count in pairs(diff.items) do
88 if count > 0 then
89 positive[item] = count
90 positiveCount = positiveCount + count
91 elseif count < 0 then
92 negative[item] = count
93 negativeCount = negativeCount + abs(count)
94 end
95 end
96
97 if diff.money > 0 and utils:tcount(positive) > 0 and utils:tcount(negative) == 0 then
98 self:Debug("loot")
99 elseif abs(diff.money) > 0 and utils:tcount(diff.items) == 1 then
86 self:Debug("purchase or sale") 100 self:Debug("purchase or sale")
87 101
88 for itemName, count in pairs(diff.items) do 102 for itemName, count in pairs(diff.items) do
89 self:SaveValue(itemName, diff.money) 103 self:SaveValue(itemName, diff.money)
90 end 104 end
91 elseif utils:tcount(diff.items) > 1 then 105 elseif utils:tcount(diff.items) > 1 then
92 local positive, negative = {}, {}
93 local positiveCount, negativeCount = 0, 0
94 for item, count in pairs(diff.items) do
95 if count > 0 then
96 positive[item] = count
97 positiveCount = positiveCount + count
98 elseif count < 0 then
99 negative[item] = count
100 negativeCount = negativeCount + abs(count)
101 end
102 end
103 106
104 if utils:tcount(positive) > 0 and utils:tcount(negative) > 0 then 107 if utils:tcount(positive) > 0 and utils:tcount(negative) > 0 then
105 -- we must have created/converted something 108 -- we must have created/converted something
106 self:Debug("conversion") 109 self:Debug("conversion")
107 local totalChange = 0 110 local totalChange = 0