comparison Core.lua @ 6:5dddd73b2220

Removed dependency on postal. It was only being used to determine the mail type which has been moved into ItemAuditor so I can support CODPayments. Paying for COD items works, but getting the payments back can't reliably associate the payment with an item yet.
author Asa Ayers <Asa.Ayers@Gmail.com>
date Wed, 26 May 2010 22:41:47 -0700
parents 7d0f4ebedf8c
children bbba2fae0f69
comparison
equal deleted inserted replaced
5:7d0f4ebedf8c 6:5dddd73b2220
83 83
84 return {items = diff, money = moneyDiff} 84 return {items = diff, money = moneyDiff}
85 end 85 end
86 86
87 87
88
88 function addon:ScanMail() 89 function addon:ScanMail()
89 local results = {} 90 local results = {}
90 for mailIndex = 1, GetInboxNumItems() or 0 do 91 for mailIndex = 1, GetInboxNumItems() or 0 do
91 local sender, msgSubject, msgMoney, msgCOD, _, msgItem, _, _, msgText, _, isGM = select(3, GetInboxHeaderInfo(mailIndex)) 92 local sender, msgSubject, msgMoney, msgCOD, _, msgItem, _, _, msgText, _, isGM = select(3, GetInboxHeaderInfo(mailIndex))
92 local mailType = Postal:GetMailType(msgSubject) 93 local mailType = utils:GetMailType(msgSubject)
93 94
95 results[mailType] = (results[mailType] or {})
96
94 if mailType == "NonAHMail" and msgCOD > 0 then 97 if mailType == "NonAHMail" and msgCOD > 0 then
95 -- Don't know how to handle these yet 98 mailType = 'COD'
99 results[mailType] = (results[mailType] or {})
96 100
97 local itemTypes = {} 101 local itemTypes = {}
98 for itemIndex = 1, ATTACHMENTS_MAX_RECEIVE do 102 for itemIndex = 1, ATTACHMENTS_MAX_RECEIVE do
99 local itemName, _, count, _, _= GetInboxItem(mailIndex, itemIndex) 103 local itemName, _, count, _, _= GetInboxItem(mailIndex, itemIndex)
100 if itemName ~= nil then 104 if itemName ~= nil then
102 end 106 end
103 end 107 end
104 108
105 if utils:tcount(itemTypes) == 1 then 109 if utils:tcount(itemTypes) == 1 then
106 for itemName, count in pairs(itemTypes) do 110 for itemName, count in pairs(itemTypes) do
107 results[itemName] = (results[itemName] or 0) - msgCOD 111 results[mailType][itemName] = (results[mailType][itemName] or 0) - msgCOD
108 end 112 end
109 else 113 else
110 self:Debug("Don't know what to do with more than one item type on COD mail.") 114 self:Debug("Don't know what to do with more than one item type on COD mail.")
111 end 115 end
116 elseif mailType == "CODPayment" then
117 itemName = msgSubject:gsub(utils.SubjectPatterns[mailType], function(item) return item end)
112 118
119 results[mailType][itemName] = (results[mailType][itemName] or 0) + msgMoney
113 120
114 elseif mailType == "AHSuccess" then 121 elseif mailType == "AHSuccess" then
115 local invoiceType, itemName, playerName, bid, buyout, deposit, consignment = GetInboxInvoiceInfo(mailIndex); 122 local invoiceType, itemName, playerName, bid, buyout, deposit, consignment = GetInboxInvoiceInfo(mailIndex);
116 results[itemName] = (results[itemName] or 0) + deposit + buyout - consignment 123 results[mailType][itemName] = (results[mailType][itemName] or 0) + deposit + buyout - consignment
117 124
118 elseif mailType == "AHWon" then 125 elseif mailType == "AHWon" then
119 local invoiceType, itemName, playerName, bid, buyout, deposit, consignment = GetInboxInvoiceInfo(mailIndex); 126 local invoiceType, itemName, playerName, bid, buyout, deposit, consignment = GetInboxInvoiceInfo(mailIndex);
120 results[itemName] = (results[itemName] or 0) - bid 127 results[mailType][itemName] = (results[mailType][itemName] or 0) - bid
121 elseif mailType == "AHExpired" or mailType == "AHCancelled" or mailType == "AHOutbid" then 128 elseif mailType == "AHExpired" or mailType == "AHCancelled" or mailType == "AHOutbid" then
122 -- These should be handled when you pay the deposit at the AH 129 -- These should be handled when you pay the deposit at the AH
123 else 130 else
124 self:Debug("Unhandled mail type: " .. mailType) 131 self:Debug("Unhandled mail type: " .. mailType)
125 self:Debug(msgSubject) 132 self:Debug(msgSubject)
129 return results 136 return results
130 end 137 end
131 138
132 function addon:SaveValue(item, value) 139 function addon:SaveValue(item, value)
133 local item_account = self.db.factionrealm.item_account 140 local item_account = self.db.factionrealm.item_account
134 if item_account[item] == nil then 141
135 item_account[item] = 0 142 item_account[item] = (item_account[item] or 0) + value
136 end 143
137 item_account[item] = item_account[item] + value 144 self:Debug("Updated price of " .. item .. " to " .. utils:FormatMoney(item_account[item]) .. "(change: " .. utils:FormatMoney(value) .. ")")
138 145
139 if item_account[item] >= 0 then 146 if item_account[item] >= 0 then
147 self:Debug("Updated price of " .. item .. " to " .. utils:FormatMoney(0))
140 item_account[item] = nil 148 item_account[item] = nil
141 end 149 end
142 end 150 end
143 151
144 local defaultBagDelay = 0.2 152 local defaultBagDelay = 0.2