Quantcast

Added backend option to choose ideal gems to obey socket colors

Kevin Lyles [11-21-09 - 04:29]
Added backend option to choose ideal gems to obey socket colors
Added strict option to never break socket colors
Filename
Upgrade.lua
WeightsWatcher.lua
defaults.lua
diff --git a/Upgrade.lua b/Upgrade.lua
index b578325..c8aae27 100644
--- a/Upgrade.lua
+++ b/Upgrade.lua
@@ -124,6 +124,18 @@ noop_down = [[
 	end
 ]]

+function upgradeAccountForceGemColors(vars)
+	if vars.options.breakSocketColors == nil then
+		vars.options.breakSocketColors = true
+	end
+	if vars.options.neverBreakSocketColors == nil then
+		vars.options.neverBreakSocketColors = false
+	end
+
+	vars.dataMinorVersion = 9
+	return vars
+end
+
 function upgradeAccountHideModKeyHints(vars)
 	if vars.options.tooltip.hideHints == nil then
 		vars.options.tooltip.hideHints = false
@@ -295,6 +307,7 @@ upgradeAccountFunctions = {
 		[5] = function(vars) return noop_up(vars) end,
 		[6] = function(vars) return upgradeAccountShowClassNames(vars) end,
 		[7] = function(vars) return upgradeAccountHideModKeyHints(vars) end,
+		[8] = function(vars) return upgradeAccountForceGemColors(vars) end,
 	},
 }

@@ -307,6 +320,7 @@ downgradeAccountFunctions = {
 		[6] = noop_down,
 		[7] = noop_down,
 		[8] = noop_down,
+		[9] = noop_down,
 	},
 }

diff --git a/WeightsWatcher.lua b/WeightsWatcher.lua
index d848201..3e12c46 100644
--- a/WeightsWatcher.lua
+++ b/WeightsWatcher.lua
@@ -146,6 +146,9 @@ function WeightsWatcher:cacheItemStats(link)
 				end
 				for _, weight in pairs(ww_charVars.activeWeights[class]) do
 					if ww_vars.weightsList[class][weight] then
+						local socketBonusWeight = ww_vars.weightsList[class][weight][string.lower(socketBonusStat[1])]
+						local breakSocketColors = ww_vars.options.breakSocketColors or (not ww_vars.options.neverBreakSocketColors and (not socketBonusWeight or socketBonusWeight <= 0))
+
 						if not ww_weightIdealCache[class][weight] then
 							ww_weightIdealCache[class][weight] = {}
 						end
@@ -155,28 +158,30 @@ function WeightsWatcher:cacheItemStats(link)

 							bestGems = {}
 							bestGemsIgnoreSocket = {}
-							socketBonusActive = true
-							for _, stat in pairs(sockets) do
-								local gemId, _, gemIdIgnoreSocket = WeightsWatcher:bestGemsForSocket(stat, socketBonusStat, ww_vars.weightsList[class][weight], ww_vars.options.gemQualityLimit)
-								if gemIdIgnoreSocket ~= 0 then
-									if not WeightsWatcher:matchesSocket(GemIds[gemIdIgnoreSocket][1], stat) then
-										socketBonusActive = false
-									end
-									if gemId ~= 0 then
-										table.insert(bestGems, gemId)
+							for _, color in pairs(sockets) do
+								gemId, _, gemIdIgnoreSocket = WeightsWatcher:bestGemsForSocket(color, socketBonusStat, ww_vars.weightsList[class][weight], ww_vars.options.gemQualityLimit)
+
+								if gemId ~= 0 then
+									table.insert(bestGems, gemId)
+								end
+								if breakSocketColors then
+									if gemIdIgnoreSocket ~= 0 then
+										table.insert(bestGemsIgnoreSocket, gemIdIgnoreSocket)
 									end
-									table.insert(bestGemsIgnoreSocket, gemIdIgnoreSocket)
 								end
 							end
 							gemStats = WeightsWatcher:getGemStats(bestGems)
 							gemStatsIgnoreSockets = WeightsWatcher:getGemStats(bestGemsIgnoreSocket)
 							local weightVal, weightValIgnoreSockets
 							weightVal = WeightsWatcher:calculateWeight(normalStats, true, socketBonusStat, gemStats, ww_vars.weightsList[class][weight])
-							weightValIgnoreSockets = WeightsWatcher:calculateWeight(normalStats, socketBonusActive, socketBonusStat, gemStatsIgnoreSockets, ww_vars.weightsList[class][weight])
+							if breakSocketColors then
+								gemStatsIgnoreSockets = WeightsWatcher:getGemStats(bestGemsIgnoreSocket)
+								weightValIgnoreSockets = WeightsWatcher:calculateWeight(normalStats, false, socketBonusStat, gemStatsIgnoreSockets, ww_vars.weightsList[class][weight])

-							if weightVal < weightValIgnoreSockets then
-								weightVal = weightValIgnoreSockets
-								gemStats = gemStatsIgnoreSockets
+								if weightVal < weightValIgnoreSockets then
+									weightVal = weightValIgnoreSockets
+									gemStats = gemStatsIgnoreSockets
+								end
 							end
 							ww_weightIdealCache[class][weight][bareLink].gemStats = gemStats
 							ww_weightIdealCache[class][weight][bareLink].score = weightVal
diff --git a/defaults.lua b/defaults.lua
index 59aa8bb..f40684c 100644
--- a/defaults.lua
+++ b/defaults.lua
@@ -102,7 +102,7 @@ keyDetectors = {

 defaultVars = {
 	dataMajorVersion = 0,
-	dataMinorVersion = 8,
+	dataMinorVersion = 9,
 	weightsList = {
 		[1] = "DEATHKNIGHT",
 		[2] = "DRUID",
@@ -495,6 +495,8 @@ defaultVars = {
 		},
 	},
 	options = {
+		breakSocketColors = true,
+		neverBreakSocketColors = false,
 		normalizeWeights = true,
 		gemQualityLimit = 9,
 		showClassNames = "Others",