Mercurial > wow > itemauditor
comparison Modules/Events.lua @ 23:819bfdc5d73c
More debug messages and added the ability to scroll the debug window.
author | Asa Ayers <Asa.Ayers@Gmail.com> |
---|---|
date | Thu, 08 Jul 2010 23:55:05 -0700 |
parents | ff9a698caebc |
children | 554b30908b33 |
comparison
equal
deleted
inserted
replaced
22:66b7c3f5937e | 23:819bfdc5d73c |
---|---|
16 self.lastMailScan = self:ScanMail() | 16 self.lastMailScan = self:ScanMail() |
17 | 17 |
18 self:UnregisterEvent("MAIL_SHOW") | 18 self:UnregisterEvent("MAIL_SHOW") |
19 self:RegisterEvent("MAIL_CLOSED") | 19 self:RegisterEvent("MAIL_CLOSED") |
20 self:RegisterEvent("MAIL_INBOX_UPDATE") | 20 self:RegisterEvent("MAIL_INBOX_UPDATE") |
21 self:Debug("MAIL_SHOW complete") | |
22 end | 21 end |
23 | 22 |
24 function addon:MAIL_CLOSED() | 23 function addon:MAIL_CLOSED() |
24 self:Debug("MAIL_CLOSED") | |
25 addon:UnregisterEvent("MAIL_CLOSED") | 25 addon:UnregisterEvent("MAIL_CLOSED") |
26 self:MAIL_INBOX_UPDATE() | 26 self:MAIL_INBOX_UPDATE() |
27 self:UnregisterEvent("MAIL_INBOX_UPDATE") | 27 self:UnregisterEvent("MAIL_INBOX_UPDATE") |
28 self:RegisterEvent("MAIL_SHOW") | 28 self:RegisterEvent("MAIL_SHOW") |
29 end | 29 end |
30 | 30 |
31 function addon:MAIL_INBOX_UPDATE() | 31 function addon:MAIL_INBOX_UPDATE() |
32 self:Debug("MAIL_INBOX_UPDATE") | |
32 local newScan = addon:ScanMail() | 33 local newScan = addon:ScanMail() |
33 local diff | 34 local diff |
34 for mailType, collection in pairs(self.lastMailScan) do | 35 for mailType, collection in pairs(self.lastMailScan) do |
35 newScan[mailType] = (newScan[mailType] or {}) | 36 newScan[mailType] = (newScan[mailType] or {}) |
36 for item, total in pairs(collection) do | 37 for item, total in pairs(collection) do |
46 self.lastMailScan = newScan | 47 self.lastMailScan = newScan |
47 end | 48 end |
48 | 49 |
49 function addon:UNIT_SPELLCAST_START(event, target, spell) | 50 function addon:UNIT_SPELLCAST_START(event, target, spell) |
50 if target == "player" and spell == "Milling" or spell == "Prospecting" or spell == "Disenchanting" then | 51 if target == "player" and spell == "Milling" or spell == "Prospecting" or spell == "Disenchanting" then |
52 self:Debug(event .. " " .. spell) | |
51 self:UnwatchBags() | 53 self:UnwatchBags() |
52 self:UpdateCurrentInventory() | 54 self:UpdateCurrentInventory() |
53 self:RegisterEvent("UNIT_SPELLCAST_INTERRUPTED") | 55 self:RegisterEvent("UNIT_SPELLCAST_INTERRUPTED") |
54 self:RegisterEvent("LOOT_CLOSED") | 56 self:RegisterEvent("LOOT_CLOSED") |
55 end | 57 end |
58 --[[ | 60 --[[ |
59 The item should be destroyed before this point, so the last inventory check | 61 The item should be destroyed before this point, so the last inventory check |
60 needs to be kept so it can be combined with the up coming loot. | 62 needs to be kept so it can be combined with the up coming loot. |
61 ]] | 63 ]] |
62 function addon:LOOT_CLOSED() | 64 function addon:LOOT_CLOSED() |
65 self:Debug("LOOT_CLOSED") | |
63 self:UnregisterEvent("LOOT_CLOSED") | 66 self:UnregisterEvent("LOOT_CLOSED") |
64 self:UnregisterEvent("UNIT_SPELLCAST_INTERRUPTED") | 67 self:UnregisterEvent("UNIT_SPELLCAST_INTERRUPTED") |
65 local inventory = self.lastInventory | 68 local inventory = self.lastInventory |
66 self:WatchBags() | 69 self:WatchBags() |
67 self.lastInventory = inventory | 70 self.lastInventory = inventory |
68 end | 71 end |
69 | 72 |
70 function addon:UNIT_SPELLCAST_INTERRUPTED(event, target, spell) | 73 function addon:UNIT_SPELLCAST_INTERRUPTED(event, target, spell) |
71 if target == "player" and spell == "Milling" or spell == "Prospecting" or spell == "Disenchanting" then | 74 if target == "player" and spell == "Milling" or spell == "Prospecting" or spell == "Disenchanting" then |
75 self:Debug(event .. " " .. spell) | |
72 self:UnregisterEvent("UNIT_SPELLCAST_INTERRUPTED") | 76 self:UnregisterEvent("UNIT_SPELLCAST_INTERRUPTED") |
73 self:UnregisterEvent("LOOT_CLOSED") | 77 self:UnregisterEvent("LOOT_CLOSED") |
74 self:WatchBags() | 78 self:WatchBags() |
75 end | 79 end |
76 end | 80 end |
78 function addon:UpdateCurrentInventory() | 82 function addon:UpdateCurrentInventory() |
79 self.lastInventory = self:GetCurrentInventory() | 83 self.lastInventory = self:GetCurrentInventory() |
80 end | 84 end |
81 | 85 |
82 function addon:UpdateAudit() | 86 function addon:UpdateAudit() |
83 -- self:Debug("UpdateAudit") | 87 -- self:Debug("UpdateAudit " .. event) |
84 local currentInventory = self:GetCurrentInventory() | 88 local currentInventory = self:GetCurrentInventory() |
85 local diff = addon:GetInventoryDiff(self.lastInventory, currentInventory) | 89 local diff = addon:GetInventoryDiff(self.lastInventory, currentInventory) |
86 -- this is only here for debugging | |
87 self.lastdiff = diff | |
88 | 90 |
89 local positive, negative = {}, {} | 91 local positive, negative = {}, {} |
90 local positiveCount, negativeCount = 0, 0 | 92 local positiveCount, negativeCount = 0, 0 |
91 for item, count in pairs(diff.items) do | 93 for item, count in pairs(diff.items) do |
92 if count > 0 then | 94 if count > 0 then |
96 negative[item] = count | 98 negative[item] = count |
97 negativeCount = negativeCount + abs(count) | 99 negativeCount = negativeCount + abs(count) |
98 end | 100 end |
99 end | 101 end |
100 | 102 |
103 if positiveCount + negativeCount == 0 then | |
104 return | |
105 end | |
106 | |
101 if diff.money > 0 and self:tcount(positive) > 0 and self:tcount(negative) == 0 then | 107 if diff.money > 0 and self:tcount(positive) > 0 and self:tcount(negative) == 0 then |
102 self:Debug("loot") | 108 self:Debug("loot") |
103 elseif abs(diff.money) > 0 and self:tcount(diff.items) == 1 then | 109 elseif abs(diff.money) > 0 and self:tcount(diff.items) == 1 then |
104 self:Debug("purchase or sale") | 110 self:Debug("purchase or sale") |
105 | 111 |
106 for link, count in pairs(diff.items) do | 112 for link, count in pairs(diff.items) do |
107 self:SaveValue(link, 0 - diff.money) | 113 self:SaveValue(link, 0 - diff.money) |
108 end | 114 end |
109 elseif self:tcount(diff.items) > 1 then | 115 elseif self:tcount(diff.items) > 1 and self:tcount(positive) > 0 and self:tcount(negative) > 0 then |
116 -- we must have created/converted something | |
117 self:Debug("conversion") | |
110 | 118 |
111 if self:tcount(positive) > 0 and self:tcount(negative) > 0 then | 119 local totalChange = 0 |
112 -- we must have created/converted something | 120 for link, change in pairs(negative) do |
113 self:Debug("conversion") | 121 local _, itemCost, count = self:GetItemCost(link, change) |
122 self:SaveValue(link, itemCost * change) | |
114 | 123 |
115 local totalChange = 0 | 124 totalChange = totalChange + (itemCost * abs(change)) |
116 for link, change in pairs(negative) do | |
117 local _, itemCost, count = self:GetItemCost(link, change) | |
118 self:SaveValue(link, itemCost * change) | |
119 | |
120 totalChange = totalChange + (itemCost * abs(change)) | |
121 end | |
122 | |
123 local valuePerItem = totalChange / positiveCount | |
124 | |
125 for link, change in pairs(positive) do | |
126 self:SaveValue(link, valuePerItem * change) | |
127 end | |
128 end | 125 end |
126 | |
127 local valuePerItem = totalChange / positiveCount | |
128 | |
129 for link, change in pairs(positive) do | |
130 self:SaveValue(link, valuePerItem * change) | |
131 end | |
132 else | |
133 self:Debug("No match in UpdateAudit.") | |
129 end | 134 end |
130 | 135 |
131 self.lastInventory = currentInventory | 136 self.lastInventory = currentInventory |
132 addon:WatchBags() | 137 addon:WatchBags() |
133 end | 138 end |