Mercurial > wow > itemauditor
comparison Modules/Events.lua @ 40:5273038322d7 release
Updated the way postage was counted so that if you mail multiple items at once, they will all have the postage counted. I also removed the 30c for postage from how QA thresholds are calculated now that they will be counted every time.
author | Asa Ayers <Asa.Ayers@Gmail.com> |
---|---|
date | Mon, 19 Jul 2010 20:55:50 -0700 |
parents | 003de902ae64 |
children | 1ff3b83b104c |
comparison
equal
deleted
inserted
replaced
39:003de902ae64 | 40:5273038322d7 |
---|---|
46 if self.db.factionrealm.outbound_cod[self.mailOutbox.key] ~= nil then | 46 if self.db.factionrealm.outbound_cod[self.mailOutbox.key] ~= nil then |
47 return self:GenerateBlankOutbox() | 47 return self:GenerateBlankOutbox() |
48 end | 48 end |
49 end | 49 end |
50 | 50 |
51 local attachedItems = {} | |
51 local Orig_SendMail = SendMail | 52 local Orig_SendMail = SendMail |
52 | 53 |
53 function SendMail(recipient, subject, body, ...) | 54 function SendMail(recipient, subject, body, ...) |
54 local self = ItemAuditor | 55 local self = ItemAuditor |
55 self:GenerateBlankOutbox() | 56 self:GenerateBlankOutbox() |
56 | 57 |
57 self:Debug(format("[To: %s] [Subject: %s]", recipient, subject)) | 58 self:Debug(format("[To: %s] [Subject: %s]", recipient, subject)) |
58 | 59 |
59 self.mailOutbox.COD = GetSendMailCOD() | 60 self.mailOutbox.COD = GetSendMailCOD() |
60 | 61 |
61 if self.mailOutbox.COD == 0 then | 62 attachedItems = {} |
62 self:Debug("Non-COD mail") | 63 local totalStacks = 0 |
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 | 64 local link |
72 for index = 1, 12 do | 65 for index = 1, ATTACHMENTS_MAX_SEND do |
73 local itemName, _, itemCount = GetSendMailItem(index) | 66 local itemName, _, itemCount = GetSendMailItem(index) |
74 local newLink = GetSendMailItemLink(index) | 67 local newLink = GetSendMailItemLink(index) |
75 | 68 |
76 if link == nil then | 69 if newLink ~= nil then |
77 link = newLink | 70 newLink = self:GetSafeLink(newLink) |
78 end | 71 totalStacks = totalStacks + 1 |
79 | 72 attachedItems[newLink] = (attachedItems[newLink] or {stacks = 0, count = 0}) |
80 if newLink ~= nil and self:GetIDFromLink(newLink) ~= self:GetIDFromLink(link) then | 73 attachedItems[newLink].stacks = attachedItems[newLink].stacks + 1 |
81 self:Print(self:GetIDFromLink(newLink)) | 74 attachedItems[newLink].count = attachedItems[newLink].count + itemCount |
82 self:Print(self:GetIDFromLink(link)) | 75 attachedItems[newLink].price = 0 -- This is a placeholder for below. |
83 | 76 end |
84 self:Print("WARNING: ItemAuditor can't track COD mail with more than one item type.") | 77 end |
78 local pricePerStack = GetSendMailPrice() / totalStacks | |
79 for link, data in pairs(attachedItems) do | |
80 data.price = pricePerStack * data.stacks | |
81 end | |
82 | |
83 if self.mailOutbox.COD > 0 then | |
84 if self:tcount(attachedItems) > 1 then | |
85 self:Print("ERROR: ItemAuditor can't track COD mail with more than one item type.") | |
85 self:GenerateBlankOutbox() | 86 self:GenerateBlankOutbox() |
87 -- I need to make a prompt so the user can send the mail without interference | |
86 return | 88 return |
87 end | 89 end |
88 self.mailOutbox.link = link | 90 self:Debug("COD mail") |
89 self.mailOutbox.count = self.mailOutbox.count + itemCount | 91 |
90 | 92 subject = format("[IA: %s] %s", self.mailOutbox.key, subject) |
91 end | 93 self.mailOutbox.subject = subject |
92 | 94 self.mailOutbox.to = recipient |
93 -- self:MAIL_SUCCESS("Mock Success") | 95 |
96 -- At this point we know there is only one item | |
97 for link, data in pairs(attachedItems) do | |
98 self.mailOutbox.link = link | |
99 self.mailOutbox.count = data.count | |
100 end | |
101 else | |
102 self:Debug("Non-COD mail") | |
103 end | |
104 | |
94 return Orig_SendMail(recipient, subject, body, ...) | 105 return Orig_SendMail(recipient, subject, body, ...) |
95 end | 106 end |
96 | 107 |
97 function addon:MAIL_SUCCESS(event) | 108 function addon:MAIL_SUCCESS(event) |
98 | 109 for link, data in pairs(attachedItems) do |
110 self:SaveValue(link, data.price, data.count) | |
111 end | |
99 if self.mailOutbox.COD > 0 then | 112 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)) | 113 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 | 114 |
102 self.mailOutbox.sent = time() | 115 self.mailOutbox.sent = time() |
103 self.db.factionrealm.outbound_cod[self.mailOutbox.key] = self.mailOutbox | 116 self.db.factionrealm.outbound_cod[self.mailOutbox.key] = self.mailOutbox |
104 end | 117 end |
105 | 118 |
106 self.mailOutbox = { | 119 |
107 to = "", | 120 self:GenerateBlankOutbox() |
108 subject = "", | |
109 items = {}, | |
110 COD = 0, | |
111 } | |
112 end | 121 end |
113 | 122 |
114 function addon:MAIL_CLOSED() | 123 function addon:MAIL_CLOSED() |
115 self:Debug("MAIL_CLOSED") | 124 self:Debug("MAIL_CLOSED") |
116 addon:UnregisterEvent("MAIL_CLOSED") | 125 addon:UnregisterEvent("MAIL_CLOSED") |