Module:ItemTables: Difference between revisions

Added replacement string for legendary item costs
LVL (talk | contribs)
Fixed Witchmail showing up in ability cooldown reduction by adding a dead stat override
Line 69: Line 69:
friendly_to_internal["dash distance"] = { "GroundDashReductionPercent", "AirMoveIncreasePercent" }
friendly_to_internal["dash distance"] = { "GroundDashReductionPercent", "AirMoveIncreasePercent" }
friendly_to_internal["damage reduction"] = { "OutgoingDamagePenaltyPercent", "DeathImmunityDamageReduction" }
friendly_to_internal["damage reduction"] = { "OutgoingDamagePenaltyPercent", "DeathImmunityDamageReduction" }
-- Override dead/hidden stats that exist in data but don't actually work in‑game.
-- Keys are item Names, values are tables of { [internalStatName] = replacementValue }
local deadStatOverrides = {
    ["Witchmail"] = { CooldownReduction = "0" }
}
-- Helper to resolve a stat value, applying any dead‑stat override if defined.
local function resolveStatValue(itemName, t)
    if deadStatOverrides[itemName.Name] and deadStatOverrides[itemName.Name][t] ~= nil then
        return deadStatOverrides[itemName.Name][t]
    end
    return itemName[t]
end


-- Returns a table of internal properties  
-- Returns a table of internal properties  
Line 178: Line 192:
for _, v in pairs(data) do
for _, v in pairs(data) do
for _, t in ipairs(listofKeysTable) do
for _, t in ipairs(listofKeysTable) do
if v[t] ~= nil and v["IsDisabled"] == false and v["Name"] ~= nil and v[t] ~= "0" and v[t] ~= "0m" and v[t] ~= "" then
local statValue = resolveStatValue(v, t)
if statValue ~= nil and v["IsDisabled"] == false and v["Name"] ~= nil and statValue ~= "0" and statValue ~= "0m" and statValue ~= "" then
table.insert(filteredData, v)
table.insert(filteredData, v)
break
break
Line 204: Line 219:
local rowspanTracker = {}
local rowspanTracker = {}


for _, itemName in ipairs(filteredData) do  
for _, itemName in ipairs(filteredData) do  
local display = frame:expandTemplate{
local display = frame:expandTemplate{
title = 'ItemIcon',
title = 'ItemIcon',
args = { itemName["Name"] }
args = { itemName["Name"] }
}
}


local statCount = 0
local statCount = 0
for _, t in pairs(listofKeysTable) do
for _, t in pairs(listofKeysTable) do
if(itemName[t] ~= nil and itemName[t] ~= "0") then
local statVal = resolveStatValue(itemName, t)
statCount = statCount + 1
if(statVal ~= nil and statVal ~= "0") then
statCount = statCount + 1
end
end
end
end
if statCount == 0 then statCount = 1 end
if statCount == 0 then statCount = 1 end
rowspanTracker[itemName["Name"]] = statCount
rowspanTracker[itemName["Name"]] = statCount


local firstStat = true
local firstStat = true
for _, t in pairs(listofKeysTable) do
for _, t in pairs(listofKeysTable) do
if(itemName[t] ~= nil and itemName[t] ~= "0") then
local statValue = resolveStatValue(itemName, t)
if(statValue ~= nil and statValue ~= "0") then
-- Handles complex stat values from the JSON data.
-- Handles complex stat values from the JSON data.
-- A stat can be a simple value (e.g., "BonusMoveSpeed": "1") or a table containing
if type(statValue) == 'table' and statValue.Value ~= nil then
-- scaling info (e.g., "BonusFireRate": { "Value": 10, "Scale": ... }).
statValue = statValue.Value
-- This code checks if the stat is a table and extracts the base numerical value from its 'Value' key.
end
local statValue = itemName[t]
 
if type(statValue) == 'table' and statValue.Value ~= nil then
copyVar = copyVar:gsub("^%l", string.upper)
statValue = statValue.Value
end


copyVar = copyVar:gsub("^%l", string.upper)
local categoryDisplay
if itemName["Slot"] == "Armor" then
categoryDisplay = frame:expandTemplate{
title = 'ItemType',
args = { "Armor", "Vitality" }
}
elseif itemName["Slot"] == "Tech" then
categoryDisplay = frame:expandTemplate{
title = 'ItemType',
args = { "Tech", "Spirit" }
}
else
categoryDisplay = frame:expandTemplate{
title = 'ItemType',
args = { "Weapon", "Weapon" }
}
end


local categoryDisplay
local tableData = mw.html.create('tr')
if itemName["Slot"] == "Armor" then
categoryDisplay = frame:expandTemplate{
title = 'ItemType',
args = { "Armor", "Vitality" }
}
elseif itemName["Slot"] == "Tech" then
categoryDisplay = frame:expandTemplate{
title = 'ItemType',
args = { "Tech", "Spirit" }
}
else
categoryDisplay = frame:expandTemplate{
title = 'ItemType',
args = { "Weapon", "Weapon" }
}
end


local tableData = mw.html.create('tr')
if firstStat then
tableData
:tag('td'):attr('rowspan', statCount):wikitext(display):done()
:tag('td'):attr('rowspan', statCount):wikitext(
(get_cost(itemName["Name"]) == 9999)
and "Legendary"
or commas._add(get_cost(itemName["Name"]))
):done()
:tag('td'):attr('rowspan', statCount):wikitext(categoryDisplay):done()
firstStat = false
end


if firstStat then
tableData:tag('td'):wikitext(signPrefix(statValue) .. appendSuffix(t) .. " " .. copyVar):done()
tableData
table.insert(requirements, tableData)
:tag('td'):attr('rowspan', statCount):wikitext(display):done()
-- Replace "9999" cost with "Legendary"
:tag('td'):attr('rowspan', statCount):wikitext(
                        (get_cost(itemName["Name"]) == 9999)
                        and "Legendary"
                        or commas._add(get_cost(itemName["Name"]))
                    ):done()
:tag('td'):attr('rowspan', statCount):wikitext(categoryDisplay):done()
firstStat = false
end
end
tableData:tag('td'):wikitext(signPrefix(statValue) .. appendSuffix(t) .. " " .. copyVar):done()
table.insert(requirements, tableData)
end
end
end
end
end


for _, row in ipairs(requirements) do
for _, row in ipairs(requirements) do