106 lines
5.3 KiB
Lua
106 lines
5.3 KiB
Lua
-- Source item armor for original 70334 item tooltips (Claude lane, 2026-11-21).
|
|
-- The 70334 client computes cloth..plate armor from ItemArmor curves by item
|
|
-- level/quality/slot; it has no per-item armor field. Turtle items whose real
|
|
-- armor differs from that curve (cosmetics at 0 armor, item-level-0 items) are
|
|
-- listed in GatewaySourceItemArmorData. The native "<n> Armor" line is replaced
|
|
-- with the source value, or dropped when the source armor is 0. Character
|
|
-- sheet armor stays server-driven. Same TooltipDataProcessor line pre-call
|
|
-- route as SourceWeaponDamage.lua; fails closed on any API difference.
|
|
local states = setmetatable({}, {__mode = "k"})
|
|
local diagnostics = {tooltips = 0, replaced = 0, dropped = 0, inserted = 0, errors = 0}
|
|
local insertMissing
|
|
GatewaySourceItemArmorDiagnostics = diagnostics
|
|
|
|
local function public(value)
|
|
if type(issecretvalue) == "function" then
|
|
local ok, hidden = pcall(issecretvalue, value)
|
|
if not ok or hidden then return false end
|
|
end
|
|
return true
|
|
end
|
|
|
|
local function integer(value, low, high)
|
|
return public(value) and type(value) == "number" and value == value and
|
|
value >= low and value <= high and value % 1 == 0
|
|
end
|
|
|
|
-- Item level 0 items have no native armor line at all. For a listed positive
|
|
-- source armor, insert one line after the stock slot/material line, once per
|
|
-- tooltip data table (removed again if the same table is re-processed).
|
|
local inserted = setmetatable({}, {__mode = "k"})
|
|
local materials = {Cloth = true, Leather = true, Mail = true, Plate = true}
|
|
insertMissing = function(tooltip, data, armor)
|
|
if not public(data.lines) or type(data.lines) ~= "table" or #data.lines > 1024 then return end
|
|
local own = inserted[data]
|
|
if own then
|
|
for i = #data.lines, 1, -1 do if data.lines[i] == own then table.remove(data.lines, i) end end
|
|
inserted[data] = nil
|
|
end
|
|
if armor <= 0 then return end
|
|
local anchor
|
|
for i, line in ipairs(data.lines) do
|
|
if not public(line) or type(line) ~= "table" then return end
|
|
local left, right = line.leftText, line.rightText
|
|
if not public(left) or not public(right) then return end
|
|
if type(left) == "string" and left:match("^%d+ Armor$") then return end
|
|
if not anchor and type(right) == "string" and materials[right] then anchor = i end
|
|
end
|
|
if not anchor then return end
|
|
local line = {type = 0, leftText = string.format("%d Armor", armor), leftColor = data.lines[anchor].leftColor, wrapText = false}
|
|
table.insert(data.lines, anchor + 1, line)
|
|
inserted[data] = line
|
|
states[tooltip].done = true
|
|
diagnostics.inserted = (diagnostics.inserted or 0) + 1
|
|
end
|
|
|
|
local function prepare(tooltip, data)
|
|
if not public(tooltip) or type(tooltip) ~= "table" then return end
|
|
states[tooltip] = nil
|
|
if not public(data) or type(data) ~= "table" or not integer(data.type, 0, 0) or not integer(data.id, 1, 2147483647) then return end
|
|
local profile = GatewaySourceItemArmorData
|
|
if not public(profile) or type(profile) ~= "table" or profile.schemaVersion ~= 1 or profile.locale ~= "enUS" or
|
|
type(GetLocale) ~= "function" or GetLocale() ~= "enUS" or not public(profile.items) or type(profile.items) ~= "table" then return end
|
|
local armor = profile.items[data.id]
|
|
if not integer(armor, 0, 65535) then return end
|
|
if type(C_Item) ~= "table" or type(C_Item.GetItemInfoInstant) ~= "function" then return end
|
|
local ok, foundID, classID = pcall(function()
|
|
local id, _, _, _, _, class = C_Item.GetItemInfoInstant(data.id)
|
|
return id, class
|
|
end)
|
|
if not ok or foundID ~= data.id or classID ~= 4 then return end
|
|
states[tooltip] = {armor = armor, done = false}
|
|
diagnostics.tooltips = diagnostics.tooltips + 1
|
|
insertMissing(tooltip, data, armor)
|
|
end
|
|
|
|
local function replaceLine(tooltip, line)
|
|
local state = states[tooltip]
|
|
if not state or state.done or not public(line) or type(line) ~= "table" or not integer(line.type, 0, 0) then return end
|
|
local left = line.leftText
|
|
if not public(left) or type(left) ~= "string" or not left:match("^%d+ Armor$") then return end
|
|
state.done = true
|
|
if state.armor > 0 then
|
|
if type(tooltip.AddLine) ~= "function" then return end
|
|
tooltip:AddLine(string.format("%d Armor", state.armor), 1, 1, 1, false)
|
|
diagnostics.replaced = diagnostics.replaced + 1
|
|
else
|
|
diagnostics.dropped = diagnostics.dropped + 1
|
|
end
|
|
return true
|
|
end
|
|
|
|
pcall(function()
|
|
if type(TooltipDataProcessor) ~= "table" or type(TooltipDataProcessor.AddTooltipPreCall) ~= "function" or
|
|
type(TooltipDataProcessor.AddLinePreCall) ~= "function" or type(Enum) ~= "table" or
|
|
type(Enum.TooltipDataType) ~= "table" or Enum.TooltipDataType.Item ~= 0 or
|
|
type(Enum.TooltipDataLineType) ~= "table" or Enum.TooltipDataLineType.None ~= 0 then return end
|
|
TooltipDataProcessor.AddTooltipPreCall(Enum.TooltipDataType.Item, function(tooltip, data)
|
|
if not pcall(prepare, tooltip, data) then diagnostics.errors = diagnostics.errors + 1 end
|
|
end)
|
|
TooltipDataProcessor.AddLinePreCall(Enum.TooltipDataLineType.None, function(tooltip, line)
|
|
local ok, consumed = pcall(replaceLine, tooltip, line)
|
|
if not ok then diagnostics.errors = diagnostics.errors + 1; return end
|
|
return consumed
|
|
end)
|
|
end)
|