comparison Core.lua @ 7:bbba2fae0f69

Removed some of the extra debugging that isn't neccessary any more and abtracted out the item ids so they can be cached.
author Asa Ayers <Asa.Ayers@Gmail.com>
date Tue, 08 Jun 2010 11:19:16 -0700
parents 5dddd73b2220
children 0271e781b154
comparison
equal deleted inserted replaced
6:5dddd73b2220 7:bbba2fae0f69
60 local diff = {} 60 local diff = {}
61 61
62 for name, count in pairs(current.items) do 62 for name, count in pairs(current.items) do
63 if pastInventory.items[name] == nil then 63 if pastInventory.items[name] == nil then
64 diff[name] = count 64 diff[name] = count
65 self:Debug("1 diff[" .. name .. "]=" .. diff[name]) 65 -- self:Debug("1 diff[" .. name .. "]=" .. diff[name])
66 elseif count - pastInventory.items[name] ~= 0 then 66 elseif count - pastInventory.items[name] ~= 0 then
67 diff[name] = count - pastInventory.items[name] 67 diff[name] = count - pastInventory.items[name]
68 self:Debug("2 diff[" .. name .. "]=" .. diff[name]) 68 -- self:Debug("2 diff[" .. name .. "]=" .. diff[name])
69 end 69 end
70 end 70 end
71 71
72 for name, count in pairs(pastInventory.items) do 72 for name, count in pairs(pastInventory.items) do
73 if current.items[name] == nil then 73 if current.items[name] == nil then
74 diff[name] = -count 74 diff[name] = -count
75 self:Debug("3 diff[" .. name .. "]=" .. diff[name]) 75 -- self:Debug("3 diff[" .. name .. "]=" .. diff[name])
76 elseif current.items[name] - count ~= 0 then 76 elseif current.items[name] - count ~= 0 then
77 diff[name] = current.items[name] - pastInventory.items[name] 77 diff[name] = current.items[name] - pastInventory.items[name]
78 self:Debug("4 diff[" .. name .. "]=" .. diff[name]) 78 -- self:Debug("4 diff[" .. name .. "]=" .. diff[name])
79 end 79 end
80 end 80 end
81 81
82 local moneyDiff = current.money - pastInventory.money 82 local moneyDiff = current.money - pastInventory.money
83 83
100 100
101 local itemTypes = {} 101 local itemTypes = {}
102 for itemIndex = 1, ATTACHMENTS_MAX_RECEIVE do 102 for itemIndex = 1, ATTACHMENTS_MAX_RECEIVE do
103 local itemName, _, count, _, _= GetInboxItem(mailIndex, itemIndex) 103 local itemName, _, count, _, _= GetInboxItem(mailIndex, itemIndex)
104 if itemName ~= nil then 104 if itemName ~= nil then
105 itemTypes[itemName] = (itemTypes[itemName] or 0) + count 105 itemTypdes[itemName] = (itemTypes[itemName] or 0) + count
106 end 106 end
107 end 107 end
108 108
109 if utils:tcount(itemTypes) == 1 then 109 if utils:tcount(itemTypes) == 1 then
110 for itemName, count in pairs(itemTypes) do 110 for itemName, count in pairs(itemTypes) do
139 function addon:SaveValue(item, value) 139 function addon:SaveValue(item, value)
140 local item_account = self.db.factionrealm.item_account 140 local item_account = self.db.factionrealm.item_account
141 141
142 item_account[item] = (item_account[item] or 0) + value 142 item_account[item] = (item_account[item] or 0) + value
143 143
144 self:Debug("Updated price of " .. item .. " to " .. utils:FormatMoney(item_account[item]) .. "(change: " .. utils:FormatMoney(value) .. ")") 144 if abs(value) > 0 then
145 145 self:Debug("Updated price of " .. item .. " to " .. utils:FormatMoney(item_account[item]) .. "(change: " .. utils:FormatMoney(value) .. ")")
146 if item_account[item] >= 0 then 146 end
147
148 if item_account[item] > 0 then
147 self:Debug("Updated price of " .. item .. " to " .. utils:FormatMoney(0)) 149 self:Debug("Updated price of " .. item .. " to " .. utils:FormatMoney(0))
148 item_account[item] = nil 150 item_account[item] = nil
151 elseif item_account[item] < 0 then
152 addon:GetItemCost(itemName)
149 end 153 end
150 end 154 end
151 155
152 local defaultBagDelay = 0.2 156 local defaultBagDelay = 0.2
153 157
174 178
175 function addon:GetItemCost(itemName, countModifier) 179 function addon:GetItemCost(itemName, countModifier)
176 local invested = abs(self.db.factionrealm.item_account[itemName] or 0) 180 local invested = abs(self.db.factionrealm.item_account[itemName] or 0)
177 181
178 if invested > 0 then 182 if invested > 0 then
179 local _, itemLink = GetItemInfo (itemName); 183 local ItemID = utils:GetItemID(itemName)
180 local _, _, _, _, Id = string.find(itemLink, "|?c?f?f?(%x*)|?H?([^:]*):?(%d+):?(%d*):?(%d*):?(%d*):?(%d*):?(%d*):?(%-?%d*):?(%-?%d*):?(%d*)|?h?%[?([^%[%]]*)%]?|?h?|?r?") 184 if ItemID ~= nil then
181 local count = Altoholic:GetItemCount(tonumber(Id)) 185 local count = Altoholic:GetItemCount(tonumber(ItemID))
182 if countModifier ~= nil then 186 if count == 0 then
183 count = count - countModifier 187 self.db.factionrealm.item_account[itemName] = nil
188 self:Print("You ran out of " .. itemName .. " and never recovered " .. utils:FormatMoney(invested))
189 end
190
191 if countModifier ~= nil then
192 count = count - countModifier
193 end
194 if count > 0 then
195 return ceil(invested), ceil(invested/count), count
196 end
184 end 197 end
185 if count == 0 then
186 self.db.factionrealm.item_account[itemName] = nil
187 self:Print("You ran out of " .. itemName .. "and never recovered " .. utils:FormatMoney(invested))
188 return 0, 0, 0
189 end
190 return ceil(invested), ceil(invested/count), count
191 end 198 end
192 return 0, 0, 0 199 return 0, 0, 0
193 end 200 end