Mercurial > wow > itemauditor
comparison Modules/Events.lua @ 39:003de902ae64
Implemented COD mail. This loses the ability to track postage, but that will be restored next.
| author | Asa Ayers <Asa.Ayers@Gmail.com> |
|---|---|
| date | Mon, 19 Jul 2010 20:16:40 -0700 |
| parents | e27d13095b49 |
| children | 5273038322d7 |
comparison
equal
deleted
inserted
replaced
| 38:e27d13095b49 | 39:003de902ae64 |
|---|---|
| 1 local addonName, addonTable = ...; | 1 local addonName, addonTable = ...; |
| 2 local addon = _G[addonName] | 2 local addon = _G[addonName] |
| 3 | |
| 4 local utils = addonTable.utils | |
| 5 | 3 |
| 6 function addon:OnEnable() | 4 function addon:OnEnable() |
| 7 self:RegisterEvent("MAIL_SHOW") | 5 self:RegisterEvent("MAIL_SHOW") |
| 8 self:RegisterEvent("UNIT_SPELLCAST_START") | 6 self:RegisterEvent("UNIT_SPELLCAST_START") |
| 9 addon:UpdateCurrentInventory() | 7 addon:UpdateCurrentInventory() |
| 18 addon:HideAllFrames() | 16 addon:HideAllFrames() |
| 19 end | 17 end |
| 20 | 18 |
| 21 function addon:MAIL_SHOW() | 19 function addon:MAIL_SHOW() |
| 22 self:Debug("MAIL_SHOW") | 20 self:Debug("MAIL_SHOW") |
| 21 self:UnwatchBags() | |
| 23 addon:UpdateCurrentInventory() | 22 addon:UpdateCurrentInventory() |
| 24 self.lastMailScan = self:ScanMail() | 23 self.lastMailScan = self:ScanMail() |
| 25 | 24 |
| 26 self:UnregisterEvent("MAIL_SHOW") | 25 self:UnregisterEvent("MAIL_SHOW") |
| 27 self:RegisterEvent("MAIL_CLOSED") | 26 self:RegisterEvent("MAIL_CLOSED") |
| 28 self:RegisterEvent("MAIL_INBOX_UPDATE") | 27 self:RegisterEvent("MAIL_INBOX_UPDATE") |
| 28 | |
| 29 self:GenerateBlankOutbox() | |
| 30 | |
| 31 self:RegisterEvent("MAIL_SUCCESS") | |
| 32 end | |
| 33 | |
| 34 function addon:GenerateBlankOutbox() | |
| 35 self.mailOutbox = { | |
| 36 from = UnitName("player"), | |
| 37 to = "", | |
| 38 subject = "", | |
| 39 link = '', | |
| 40 count = 0, | |
| 41 COD = 0, | |
| 42 key = random(10000), | |
| 43 sent = 0, | |
| 44 } | |
| 45 | |
| 46 if self.db.factionrealm.outbound_cod[self.mailOutbox.key] ~= nil then | |
| 47 return self:GenerateBlankOutbox() | |
| 48 end | |
| 49 end | |
| 50 | |
| 51 local Orig_SendMail = SendMail | |
| 52 | |
| 53 function SendMail(recipient, subject, body, ...) | |
| 54 local self = ItemAuditor | |
| 55 self:GenerateBlankOutbox() | |
| 56 | |
| 57 self:Debug(format("[To: %s] [Subject: %s]", recipient, subject)) | |
| 58 | |
| 59 self.mailOutbox.COD = GetSendMailCOD() | |
| 60 | |
| 61 if self.mailOutbox.COD == 0 then | |
| 62 self:Debug("Non-COD mail") | |
| 63 return Orig_SendMail(recipient, subject, body, ...) | |
| 64 end | |
| 65 | |
| 66 subject = format("[IA: %s] %s", self.mailOutbox.key, subject) | |
| 67 self.mailOutbox.subject = subject | |
| 68 self.mailOutbox.to = recipient | |
| 69 | |
| 70 self.mailOutbox.count = 0 | |
| 71 local link | |
| 72 for index = 1, 12 do | |
| 73 local itemName, _, itemCount = GetSendMailItem(index) | |
| 74 local newLink = GetSendMailItemLink(index) | |
| 75 | |
| 76 if link == nil then | |
| 77 link = newLink | |
| 78 end | |
| 79 | |
| 80 if newLink ~= nil and self:GetIDFromLink(newLink) ~= self:GetIDFromLink(link) then | |
| 81 self:Print(self:GetIDFromLink(newLink)) | |
| 82 self:Print(self:GetIDFromLink(link)) | |
| 83 | |
| 84 self:Print("WARNING: ItemAuditor can't track COD mail with more than one item type.") | |
| 85 self:GenerateBlankOutbox() | |
| 86 return | |
| 87 end | |
| 88 self.mailOutbox.link = link | |
| 89 self.mailOutbox.count = self.mailOutbox.count + itemCount | |
| 90 | |
| 91 end | |
| 92 | |
| 93 -- self:MAIL_SUCCESS("Mock Success") | |
| 94 return Orig_SendMail(recipient, subject, body, ...) | |
| 95 end | |
| 96 | |
| 97 function addon:MAIL_SUCCESS(event) | |
| 98 | |
| 99 if self.mailOutbox.COD > 0 then | |
| 100 self:Debug(format("MAIL_SUCCESS %d [To: %s] [Subject: %s] [COD: %s]", self.mailOutbox.key, self.mailOutbox.to, self.mailOutbox.subject, self.mailOutbox.COD)) | |
| 101 | |
| 102 self.mailOutbox.sent = time() | |
| 103 self.db.factionrealm.outbound_cod[self.mailOutbox.key] = self.mailOutbox | |
| 104 end | |
| 105 | |
| 106 self.mailOutbox = { | |
| 107 to = "", | |
| 108 subject = "", | |
| 109 items = {}, | |
| 110 COD = 0, | |
| 111 } | |
| 29 end | 112 end |
| 30 | 113 |
| 31 function addon:MAIL_CLOSED() | 114 function addon:MAIL_CLOSED() |
| 32 self:Debug("MAIL_CLOSED") | 115 self:Debug("MAIL_CLOSED") |
| 33 addon:UnregisterEvent("MAIL_CLOSED") | 116 addon:UnregisterEvent("MAIL_CLOSED") |
| 34 self:MAIL_INBOX_UPDATE() | 117 self:MAIL_INBOX_UPDATE() |
| 35 self:UnregisterEvent("MAIL_INBOX_UPDATE") | 118 self:UnregisterEvent("MAIL_INBOX_UPDATE") |
| 36 self:RegisterEvent("MAIL_SHOW") | 119 self:RegisterEvent("MAIL_SHOW") |
| 120 self:WatchBags() | |
| 37 end | 121 end |
| 38 | 122 |
| 39 local storedCountDiff | 123 local storedCountDiff |
| 40 function addon:MAIL_INBOX_UPDATE() | 124 function addon:MAIL_INBOX_UPDATE() |
| 41 self:Debug("MAIL_INBOX_UPDATE") | 125 self:Debug("MAIL_INBOX_UPDATE") |
| 42 local newScan = addon:ScanMail() | 126 local newScan = addon:ScanMail() |
| 43 local diff | 127 local diff |
| 128 | |
| 44 for mailType, collection in pairs(self.lastMailScan) do | 129 for mailType, collection in pairs(self.lastMailScan) do |
| 45 newScan[mailType] = (newScan[mailType] or {}) | 130 newScan[mailType] = (newScan[mailType] or {}) |
| 46 for itemName, data in pairs(collection) do | 131 for itemName, data in pairs(collection) do |
| 47 newScan[mailType][itemName] = (newScan[mailType][itemName] or {total=0,count=0}) | 132 newScan[mailType][itemName] = (newScan[mailType][itemName] or {total=0,count=0}) |
| 48 local totalDiff = data.total - newScan[mailType][itemName].total | 133 local totalDiff = data.total - newScan[mailType][itemName].total |
| 55 if countDiff ~= 0 then | 140 if countDiff ~= 0 then |
| 56 storedCountDiff = countDiff | 141 storedCountDiff = countDiff |
| 57 end | 142 end |
| 58 | 143 |
| 59 if totalDiff ~= 0 then | 144 if totalDiff ~= 0 then |
| 145 if mailType == "CODPayment" then | |
| 146 local trackID | |
| 147 trackID, itemName= strsplit("|", itemName, 2) | |
| 148 self.db.factionrealm.outbound_cod[tonumber(trackID)] = nil | |
| 149 self:Debug("Removing COD Tracker: " .. trackID) | |
| 150 end | |
| 60 self:SaveValue(itemName, totalDiff, storedCountDiff) | 151 self:SaveValue(itemName, totalDiff, storedCountDiff) |
| 61 storedCountDiff = 0 | 152 storedCountDiff = 0 |
| 62 end | 153 end |
| 63 | 154 |
| 64 end | 155 end |
