Quantcast

auto destroy fixed, minor bug fixes

ckaotik [03-14-10 - 13:38]
auto destroy fixed, minor bug fixes
Filename
core.lua
lootmanager.lua
options.lua
diff --git a/core.lua b/core.lua
index df80e79..be0d99c 100644
--- a/core.lua
+++ b/core.lua
@@ -851,13 +851,16 @@ function BrokerGarbage:FindSlotToDelete(itemID, ignoreFullStack)
 		end
 	end

-	-- recommend the location with the largest ratio that is NOT a specialty bag
+	-- recommend the location with the largest count or ratio that is NOT a specialty bag
 	table.sort(locations, function(a,b)
-		if a.bagType == 0 and b.bagType ~= 0 then
-			return true
+		if a.bagType ~= b.bagType then
+			return a.bagType == 0
 		else
-			-- return a.ratio > b.ratio
-			return a.count < b.count
+			if a.count == b.count then
+				return a.ratio > b.ratio
+			else
+				return a.count < b.count
+			end
 		end
 	end)
 	return locations
@@ -880,7 +883,6 @@ function BrokerGarbage:Delete(itemLink, bag, slot)
 	BG_GlobalDB.itemsDropped = BG_GlobalDB.itemsDropped + 1

 	BrokerGarbage:Print(format(BrokerGarbage.locale.itemDeleted, itemLink))
-	BrokerGarbage:Debug(itemLink.." deleted. (bag "..bag..", slot "..slot..")")
 end

 -- scans your inventory for possible junk items and updates LDB display
@@ -966,8 +968,8 @@ function BrokerGarbage:ScanInventory()

 							local limited = BrokerGarbage:Find(limitedItemsChecked, itemID)
 							if not limited then
-								if BG_GlobalDB.include[itemID] and type(BG_GlobalDB.include[itemID]) == "number"
-									or BG_LocalDB.include[itemID] and type(BG_LocalDB.include[itemID]) == "number" then
+								if (BG_GlobalDB.include[itemID] and type(BG_GlobalDB.include[itemID]) == "number")
+									or (BG_LocalDB.include[itemID] and type(BG_LocalDB.include[itemID]) == "number") then

 									-- this is a limited item - only check it once
 									tinsert(limitedItemsChecked, itemID)
diff --git a/lootmanager.lua b/lootmanager.lua
index 1e50c89..a821fe7 100644
--- a/lootmanager.lua
+++ b/lootmanager.lua
@@ -324,6 +324,7 @@ end
 local LootFrame_UpdateButton_orig = LootFrame_UpdateButton
 function LootFrame_UpdateButton(index)
 	LootFrame_UpdateButton_orig(index)
+	if not BG_GlobalDB.useLootManager then return end

 	local slot = (LOOTFRAME_NUMBUTTONS * (LootFrame.page - 1)) + index
 	_, itemName, quantity,  quality, locked = GetLootSlotInfo(slot)
@@ -343,23 +344,21 @@ end
 -- ---------------------------------------------------------
 -- for use in CHAT_MSG_LOOT event - destroys watched items as needed
 function BrokerGarbage:AutoDestroy()
-	local count
+	local count = GetItemCount(itemID)
+	if not count or count == 1 then return end
 	local location = {}

 	for itemID,maxCount in pairs(BrokerGarbage:JoinTables(BG_LocalDB.include, BG_GlobalDB.include)) do
-		if type(itemID) == "number" and type(maxCount) == number then
-			count = GetItemCount(itemID)
-
+		count = 0
+		if type(itemID) == "number" and type(maxCount) == "number" then
 			-- delete excess items
-			local i = 1
 			location = BrokerGarbage:FindSlotToDelete(itemID)
-			while count > maxCount do
-				-- save the last stack, even if it itself is over our treshold (for stackable items)
-				if i == #location then break end
-				BrokerGarbage:Delete(GetItemInfo(itemID), location[i].bag, location[i].slot)
-
-				count = GetItemCount(itemID)
-				i = i + 1
+			for i = #location, 1, -1 do
+				if count >= maxCount then
+					BrokerGarbage:Delete(GetItemInfo(itemID), location[i].bag, location[i].slot)
+				else
+					count = count + location[i].count
+				end
 			end
 		end
 	end
diff --git a/options.lua b/options.lua
index 1eb3d48..9a0122b 100644
--- a/options.lua
+++ b/options.lua
@@ -1222,21 +1222,30 @@ local function ShowListOptions(frame)
 		elseif self == promote then
 			for i, button in pairs(BrokerGarbage.listButtons.exclude) do
 				if button:GetChecked() then
-					BG_GlobalDB.exclude[button.itemID] = BG_LocalDB.exclude[button.itemID]
+					if not BG_GlobalDB.exclude[button.itemID] then
+						BG_GlobalDB.exclude[button.itemID] = BG_LocalDB.exclude[button.itemID]
+						BG_LocalDB.exclude[button.itemID] = nil
+					end
 				end
 			end
 			BrokerGarbage:ListOptionsUpdate("exclude")
 		elseif self == promote3 then
 			for i, button in pairs(BrokerGarbage.listButtons.include) do
 				if button:GetChecked() then
-					BG_GlobalDB.include[button.itemID] = BG_LocalDB.include[button.itemID]
+					if not BG_GlobalDB.include[button.itemID] then
+						BG_GlobalDB.include[button.itemID] = BG_LocalDB.include[button.itemID]
+						BG_LocalDB.include[button.itemID] = nil
+					end
 				end
 			end
 			BrokerGarbage:ListOptionsUpdate("include")
 		elseif self == promote3 then
 			for i, button in pairs(BrokerGarbage.listButtons.autosell) do
 				if button:GetChecked() then
-					BG_GlobalDB.autoSellList[button.itemID] = BG_LocalDB.autoSellList[button.itemID]
+					if not BG_GlobalDB.autoSellList[button.itemID] then
+						BG_GlobalDB.autoSellList[button.itemID] = BG_LocalDB.autoSellList[button.itemID]
+						BG_LocalDB.autoSellList[button.itemID] = nil
+					end
 				end
 			end
 			BrokerGarbage:ListOptionsUpdate("autosell")