Normalize scores, same as StatScores
James Whitehead II [11-29-10 - 20:51]
Normalize scores, same as StatScores
diff --git a/WowheadPoints.lua b/WowheadPoints.lua
index d23e373..335876f 100644
--- a/WowheadPoints.lua
+++ b/WowheadPoints.lua
@@ -389,12 +389,20 @@ local function GetWeights(link)
local scores = {}
for wname, info in pairs(info[class]) do
- local stats = GetItemStats(link)
if not link then
return scores
end
+
+ local stats = GetItemStats(link)
+ if not stats then
+ return scores
+ end
+
+ local total = 0
local score = 0
for stat, weight in pairs(info.weights) do
+ total = total + weight
+
local key, value
if stat == "ARMOR" then
@@ -415,7 +423,7 @@ local function GetWeights(link)
score = score + value * weight
end
- scores[wname] = score
+ scores[wname] = score / total
end
return scores
@@ -448,7 +456,8 @@ local function OnTooltipSetItem(tooltip, ...)
tooltip:AddLine(" ")
tooltip:AddLine("Equipment ratings from Wowhead.com:")
for idx, name in ipairs(sort) do
- tooltip:AddDoubleLine(name .. ":", math.floor(scores[name]), 1.0, 1.0, 1.0)
+ local val = string.format("%0.2f", scores[name])
+ tooltip:AddDoubleLine(name .. ":", val, 1.0, 1.0, 1.0)
end
tooltip:AddLine(" ")
end
@@ -472,3 +481,43 @@ for idx, tooltip in ipairs(tooltips) do
tooltip:HookScript("OnTooltipSetItem", OnTooltipSetItem)
tooltip:HookScript("OnTooltipCleared", OnTooltipCleared)
end
+
+function addon:Enable()
+ -- Calculate the player's 'WowheadGearScore'
+ local slotNames = {
+ "BackSlot",
+ "ChestSlot",
+ "FeetSlot",
+ "Finger0Slot",
+ "Finger1Slot",
+ "HeadSlot",
+ "HandsSlot",
+ "LegsSlot",
+ "NeckSlot",
+ "RangedSlot",
+ "ShoulderSlot",
+ "Trinket0Slot",
+ "Trinket1Slot",
+ "WaistSlot",
+ "WristSlot",
+ "MainHandSlot",
+ "SecondaryHandSlot",
+ }
+
+ -- local gscores = {}
+ -- for idx, slotName in ipairs(slotNames) do
+ -- local slotNum = GetInventorySlotInfo(slotName)
+ -- local link = GetInventoryItemLink("player", slotNum)
+ -- if link then
+ -- local scores = GetWeights(link)
+ -- for name, score in pairs(scores) do
+ -- if not gscores[name] then gscores[name] = 0 end
+ -- gscores[name] = gscores[name] + score
+ -- end
+ -- end
+ -- end
+
+ -- for name, score in pairs(gscores) do
+ -- self:Printf("Your '%s' gearscore is %d", name, score)
+ -- end
+end