Quantcast

Actually calculate weights

Kevin Lyles [09-26-09 - 16:39]
Actually calculate weights
Filename
WeightsWatcher.lua
diff --git a/WeightsWatcher.lua b/WeightsWatcher.lua
index 7cdab66..cdcd1c8 100644
--- a/WeightsWatcher.lua
+++ b/WeightsWatcher.lua
@@ -110,6 +110,16 @@ function WeightsWatcher:displayItemStats(tooltip, ttname)
 			socketBonusActive = false
 		end

+		for class, weights in pairs(ww_charVars.activeWeights) do
+			if ww_vars.weightsList[class] then
+				for _, weight in pairs(weights) do
+					if ww_vars.weightsList[class][weight] then
+						tooltip:AddDoubleLine(weight, WeightsWatcher:calculateWeight(normalStats, socketBonusActive, socketBonusStat, gemStats, ww_vars.weightsList[class][weight]))
+					end
+				end
+			end
+		end
+
 		tooltip:Show()
 	end
 end
@@ -137,6 +147,33 @@ function WeightsWatcher:matchesSocket(gemColor, socketColor)
 	return false
 end

+function WeightsWatcher:calculateWeight(normalStats, socketBonusActive, socketBonusStat, gemStats, weightsScale)
+	local weight, name, value = 0
+
+	for _, value in pairs(normalStats) do
+		weight = weight + WeightsWatcher:getWeight(value, weightsScale)
+	end
+	if socketBonusActive then
+		weight = weight + WeightsWatcher:getWeight(socketBonusStat, weightsScale)
+	end
+	for _, value in pairs(gemStats) do
+		for _, value in pairs(value[2]) do
+			weight = weight + WeightsWatcher:getWeight(value, weightsScale)
+		end
+	end
+	return weight
+end
+
+function WeightsWatcher:getWeight(stat, weightsScale)
+	local name, value = unpack(stat)
+	name = string.lower(name)
+	if weightsScale[name] then
+		return weightsScale[name] * value
+	else
+		return 0
+	end
+end
+
 function WeightsWatcher:getGemStats(...)
 	local stats, stat, lastGem
 	local statTable = {}