Quantcast

second step to fix selling issues

ckaotik [05-12-10 - 06:14]
second step to fix selling issues
Filename
core.lua
helper.lua
diff --git a/core.lua b/core.lua
index 96f2109..61a7343 100644
--- a/core.lua
+++ b/core.lua
@@ -646,7 +646,7 @@ function BrokerGarbage:ScanInventory()
 							or BG_GlobalDB.autoSellList[itemID] or BG_LocalDB.autoSellList[itemID] then
 							-- AutoSell
 							isSell = true
-							force = true
+							force = false

 							value = vendorPrice
 							if value then value = value * count end
@@ -656,7 +656,7 @@ function BrokerGarbage:ScanInventory()
 							((isVendor and not isExclude) or BG_GlobalDB.forceVendorPrice[itemID]) then
 							-- Force Vendor Price List item
 							isVendor = true
-							force = true
+							force = false

 							value = vendorPrice
 							if value then value = value * count end
@@ -703,8 +703,9 @@ function BrokerGarbage:ScanInventory()
 									force = force,
 								})

-							elseif quality > BG_GlobalDB.dropQuality and source == BrokerGarbage.tagUnusableGear then
-								tinsert(BrokerGarbage.sellGear, {
+							elseif quality > BG_GlobalDB.dropQuality and
+								(source == BrokerGarbage.tagUnusableGear or source == BrokerGarbage.tagVendorList) then
+								tinsert(BrokerGarbage.sellItems, {
 									bag = container,
 									slot = slot,
 									itemID = itemID,
@@ -745,7 +746,10 @@ function BrokerGarbage:GetCheapest(number)
 		local skip = false

 		for _, usedTable in pairs(cheapestItems) do
-			if usedTable == itemTable then skip = true end
+			if usedTable == itemTable then
+				skip = true
+				break
+			end
 		end

 		if not skip and itemTable.force then
@@ -753,7 +757,12 @@ function BrokerGarbage:GetCheapest(number)
 		end
 	end
 	table.sort(temp, function(a, b)
-		return a.value < b.value
+		-- put included items even prior to forced vendor price items
+		if (a.source == b.source) or (a.source ~= BrokerGarbage.tagInclude and b.source ~= BrokerGarbage.tagInclude) then
+			return a.value < b.value
+		else
+			return a.source == BrokerGarbage.tagInclude
+		end
 	end)

 	if #temp <= number then
@@ -799,10 +808,13 @@ end
 -- when at a merchant this will clear your bags of junk (gray quality) and items on your autoSellList
 function BrokerGarbage:AutoSell()
 	if BG_GlobalDB.autoSellToVendor or self == _G["BrokerGarbage_SellIcon"] then
+		if self == _G["BrokerGarbage_SellIcon"] then
+			BrokerGarbage:Debug("AutoSell was triggered by a click on Sell Icon.", BrokerGarbage:FormatMoney(sellValue), BrokerGarbage:FormatMoney(BrokerGarbage.toSellValue))
+		end
 		local i = 1
 		local skip
 		sellValue = 0
-		for _, itemTable in pairs(BrokerGarbage:JoinTables(BrokerGarbage.inventory, BrokerGarbage.sellGear)) do
+		for _, itemTable in pairs(BrokerGarbage:JoinSimpleTables(BrokerGarbage.inventory, BrokerGarbage.sellItems)) do
 			local sellByString, excludeByString = false, false
 			local temp, checkTable

@@ -872,6 +884,7 @@ function BrokerGarbage:AutoSell()
 					locked = true
 				end

+				BrokerGarbage:Debug("Selling", itemTable.itemID)
 				sellValue = sellValue + itemTable.value
 				BG_GlobalDB.moneyEarned = BG_GlobalDB.moneyEarned + itemTable.value
 				BG_LocalDB.moneyEarned = BG_LocalDB.moneyEarned + itemTable.value
@@ -884,8 +897,6 @@ function BrokerGarbage:AutoSell()
 		end

 		if self == _G["BrokerGarbage_SellIcon"] then
-			BrokerGarbage:Debug("AutoSell was triggered by a click on Sell Icon.", BrokerGarbage:FormatMoney(sellValue), BrokerGarbage:FormatMoney(toSellValue))
-
 			if sellValue == 0 and BG_GlobalDB.reportNothingToSell then
 				BrokerGarbage:Print(BrokerGarbage.locale.reportNothingToSell)
 			elseif sellValue ~= 0 and not BG_GlobalDB.autoSellToVendor then
diff --git a/helper.lua b/helper.lua
index 7da63b3..de57773 100644
--- a/helper.lua
+++ b/helper.lua
@@ -1,6 +1,6 @@
 _, BrokerGarbage = ...

-local debug = false		-- set this to 'true' to get your chatframe spammed :D
+local debug = true		-- set this to 'true' to get your chatframe spammed :D


 -- Addon Basics
@@ -32,7 +32,7 @@ function BrokerGarbage:Find(table, value)
 	return false
 end

--- joins any number of tables together, one after the other. elements within the input-tables will get mixed, though
+-- joins any number of non-basic index tables together, one after the other. elements within the input-tables will get mixed, though
 function BrokerGarbage:JoinTables(...)
 	local result = {}
 	local tab
@@ -49,6 +49,23 @@ function BrokerGarbage:JoinTables(...)
 	return result
 end

+-- joins numerically indexed tables
+function BrokerGarbage:JoinSimpleTables(...)
+	local result = {}
+	local tab, i, j
+
+	for i=1,select("#", ...) do
+		tab = select(i, ...)
+		if tab then
+			for _, value in pairs(tab) do
+				tinsert(result, value)
+			end
+		end
+	end
+
+	return result
+end
+
 function BrokerGarbage:Count(table)
   local i = 0
   for _, _ in pairs(table) do i = i + 1 end