Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Join the Playtest on Steam Now: SpiritVale

Module:GameSkills: Difference between revisions

From SpiritVale Wiki
No edit summary
No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 23: Line 23:


local skillsCache
local skillsCache
local eventsCache


-- getSkills: lazy-load + cache skill dataset from GameData.
-- getSkills: lazy-load + cache skill dataset from GameData.
local function getSkills()
local function getSkills()
if not skillsCache then
        if not skillsCache then
skillsCache = GameData.loadSkills()
                skillsCache = GameData.loadSkills()
end
        end
return skillsCache
        return skillsCache
end
 
local function getEvents()
        if eventsCache == nil then
                if type(GameData.loadEvents) == "function" then
                        eventsCache = GameData.loadEvents()
                else
                        eventsCache = false
                end
        end
 
        return eventsCache
end
end


Line 93: Line 106:
-- listToText: join an array into a readable string.
-- listToText: join an array into a readable string.
local function listToText(list, sep)
local function listToText(list, sep)
if type(list) ~= "table" or #list == 0 then
        if type(list) ~= "table" or #list == 0 then
return nil
                return nil
end
        end
return table.concat(list, sep or ", ")
        return table.concat(list, sep or ", ")
end
end


-- isNoneLike: treat common "none" spellings as empty.
local function resolveDisplayName(v, kind)
local function isNoneLike(v)
        if v == nil then return nil end
if v == nil then return true end
local s = mw.text.trim(tostring(v))
if s == "" then return true end
s = mw.ustring.lower(s)
return (s == "none" or s == "no" or s == "n/a" or s == "na" or s == "null")
end


-- addRow: add a standard <tr><th>Label</th><td>Value</td></tr> row.
        local function firstString(keys, source)
local function addRow(tbl, label, value, rowClass, dataKey)
                for _, key in ipairs(keys) do
if value == nil or value == "" then
                        local candidate = source[key]
return
                        if type(candidate) == "string" and candidate ~= "" then
end
                                return candidate
                        end
                end
                return nil
        end


local row = tbl:tag("tr")
        if type(v) == "table" then
row:addClass("sv-row")
                local primaryKeys = { "External Name", "Display Name", "Name" }
if rowClass then row:addClass(rowClass) end
                local extendedKeys = { "Skill External Name", "Status External Name" }
if dataKey then row:attr("data-field", dataKey) end
                local internalKeys = { "Internal Name", "Internal ID", "ID", "InternalID", "Skill Internal Name", "InternalID" }
 
                return firstString(primaryKeys, v)
                        or firstString(extendedKeys, v)
                        or firstString(internalKeys, v)
        end
 
        if type(v) == "string" then
                if kind == "event" then
                        local events = getEvents()
                        if events and events.byId and events.byId[v] then
                                local mapped = resolveDisplayName(events.byId[v], "event")
                                if mapped then
                                        return mapped
                                end
                        end
                end
 
                return v
        end
 
        return tostring(v)
end


row:tag("th"):wikitext(label):done()
local function resolveEventName(v)
row:tag("td"):wikitext(value):done()
        local resolved = resolveDisplayName(v, "event")
        if type(resolved) == "string" then
                return resolved
        end
        return (resolved ~= nil) and tostring(resolved) or nil
end
end


-- formatUnitValue: format {Value, Unit} blocks (or scalar) for display.
local function resolveSkillNameFromEvent(ev)
local function formatUnitValue(v)
        if type(ev) ~= "table" then
if type(v) == "table" and v.Value ~= nil then
                return resolveDisplayName(ev, "skill") or "Unknown skill"
local unit = v.Unit
        end
local val  = v.Value
 
        local displayKeys = {
                "Skill External Name",
                "External Name",
                "Display Name",
                "Name",
                "Skill Name",
        }


if unit == "percent_decimal" or unit == "percent_whole" or unit == "percent" then
        for _, key in ipairs(displayKeys) do
return tostring(val) .. "%"
                local candidate = resolveDisplayName(ev[key], "skill")
elseif unit == "seconds" then
                if candidate then
return tostring(val) .. "s"
                        return candidate
elseif unit == "meters" then
                end
return tostring(val) .. "m"
        end
elseif unit == "tiles" then
return tostring(val) .. " tiles"
elseif unit and unit ~= "" then
return tostring(val) .. " " .. tostring(unit)
else
return tostring(val)
end
end


return (v ~= nil) and tostring(v) or nil
        local internalKeys = {
end
                "Skill Internal Name",
                "Skill ID",
                "Internal Name",
                "Internal ID",
                "ID",
        }


----------------------------------------------------------------------
        for _, key in ipairs(internalKeys) do
-- Dynamic spans (JS-driven)
                local candidate = ev[key]
----------------------------------------------------------------------
                if type(candidate) == "string" and candidate ~= "" then
                        return candidate
                end
        end


-- dynSpan: render a JS-updated span for a level series.
        return "Unknown skill"
local function dynSpan(series, level)
end
if type(series) ~= "table" or #series == 0 then
return nil
end


level = clamp(level or #series, 1, #series)
-- isNoneLike: treat common "none" spellings as empty.
local function isNoneLike(v)
if v == nil then return true end
local s = mw.text.trim(tostring(v))
if s == "" then return true end
s = mw.ustring.lower(s)
return (s == "none" or s == "no" or s == "n/a" or s == "na" or s == "null")
end


local span = mw.html.create("span")
-- addRow: add a standard <tr><th>Label</th><td>Value</td></tr> row.
span:addClass("sv-dyn")
local function addRow(tbl, label, value, rowClass, dataKey)
span:attr("data-series", mw.text.jsonEncode(series))
if value == nil or value == "" then
span:wikitext(mw.text.nowiki(series[level] or ""))
return
end
 
local row = tbl:tag("tr")
row:addClass("sv-row")
if rowClass then row:addClass(rowClass) end
if dataKey then row:attr("data-field", dataKey) end


return tostring(span)
row:tag("th"):wikitext(label):done()
row:tag("td"):wikitext(value):done()
end
end


-- isFlatList: true if all values in list are identical.
-- formatUnitValue: format {Value, Unit} blocks (or scalar) for display.
local function isFlatList(list)
local function formatUnitValue(v)
if type(list) ~= "table" or #list == 0 then
if type(v) == "table" and v.Value ~= nil then
return false
local unit = v.Unit
end
local val  = v.Value
local first = tostring(list[1])
 
for i = 2, #list do
if unit == "percent_decimal" or unit == "percent_whole" or unit == "percent" then
if tostring(list[i]) ~= first then
return tostring(val) .. "%"
return false
elseif unit == "seconds" then
return tostring(val) .. "s"
elseif unit == "meters" then
return tostring(val) .. "m"
elseif unit == "tiles" then
return tostring(val) .. " tiles"
elseif unit and unit ~= "" then
return tostring(val) .. " " .. tostring(unit)
else
return tostring(val)
end
end
end
end
return true
 
return (v ~= nil) and tostring(v) or nil
end
end


-- isNonZeroScalar: detect if a value is present and not effectively zero.
----------------------------------------------------------------------
local function isNonZeroScalar(v)
-- Dynamic spans (JS-driven)
if v == nil then return false end
----------------------------------------------------------------------
if type(v) == "number" then return v ~= 0 end
if type(v) == "string" then
local n = tonumber(v)
if n == nil then return v ~= "" end
return n ~= 0
end
if type(v) == "table" and v.Value ~= nil then
return isNonZeroScalar(v.Value)
end
return true
end


-- isZeroish: aggressively treat common “zero” text forms as zero.
-- dynSpan: render a JS-updated span for a level series.
local function isZeroish(v)
local function dynSpan(series, level)
if v == nil then return true end
if type(series) ~= "table" or #series == 0 then
if type(v) == "number" then return v == 0 end
return nil
if type(v) == "table" and v.Value ~= nil then
return isZeroish(v.Value)
end
end


local s = mw.text.trim(tostring(v))
level = clamp(level or #series, 1, #series)
if s == "" then return true end
if s == "0" or s == "0.0" or s == "0.00" then return true end
if s == "0s" or s == "0 s" then return true end
if s == "0m" or s == "0 m" then return true end
if s == "0%" or s == "0 %" then return true end


local n = tonumber((mw.ustring.gsub(s, "[^0-9%.%-]", "")))
local span = mw.html.create("span")
return (n ~= nil and n == 0)
span:addClass("sv-dyn")
span:attr("data-series", mw.text.jsonEncode(series))
span:wikitext(mw.text.nowiki(series[level] or ""))
 
return tostring(span)
end
end


-- valuePairRawText: render Base/Per Level blocks into readable text (fallback).
-- isFlatList: true if all values in list are identical.
local function valuePairRawText(block)
local function isFlatList(list)
if type(block) ~= "table" then
if type(list) ~= "table" or #list == 0 then
return nil
return false
end
local first = tostring(list[1])
for i = 2, #list do
if tostring(list[i]) ~= first then
return false
end
end
end
return true
end


local base = block.Base
-- isNonZeroScalar: detect if a value is present and not effectively zero.
local per  = block["Per Level"]
local function isNonZeroScalar(v)
 
if v == nil then return false end
if type(per) == "table" then
if type(v) == "number" then return v ~= 0 end
if #per == 0 then
if type(v) == "string" then
return formatUnitValue(base)
local n = tonumber(v)
end
if n == nil then return v ~= "" end
if isFlatList(per) then
return n ~= 0
return formatUnitValue(base) or tostring(per[1])
end
 
local vals = {}
for _, v in ipairs(per) do
table.insert(vals, formatUnitValue(v) or tostring(v))
end
return (#vals > 0) and table.concat(vals, " / ") or nil
end
end
 
if type(v) == "table" and v.Value ~= nil then
local baseText = formatUnitValue(base)
return isNonZeroScalar(v.Value)
local perText  = formatUnitValue(per)
 
if baseText and perText and isNonZeroScalar(per) then
return string.format("%s (Per Level: %s)", baseText, perText)
end
end
 
return true
return baseText or perText
end
end


-- valuePairDynamicValueOnly: render Base/Per Level blocks using dyn spans where possible.
-- isZeroish: aggressively treat common “zero” text forms as zero.
local function valuePairDynamicValueOnly(block, maxLevel, level)
local function isZeroish(v)
if v == nil then return true end
if type(v) == "number" then return v == 0 end
if type(v) == "table" and v.Value ~= nil then
return isZeroish(v.Value)
end
 
local s = mw.text.trim(tostring(v))
if s == "" then return true end
if s == "0" or s == "0.0" or s == "0.00" then return true end
if s == "0s" or s == "0 s" then return true end
if s == "0m" or s == "0 m" then return true end
if s == "0%" or s == "0 %" then return true end
 
local n = tonumber((mw.ustring.gsub(s, "[^0-9%.%-]", "")))
return (n ~= nil and n == 0)
end
 
-- valuePairRawText: render Base/Per Level blocks into readable text (fallback).
local function valuePairRawText(block)
if type(block) ~= "table" then
if type(block) ~= "table" then
return nil
return nil
Line 260: Line 325:
if type(per) == "table" then
if type(per) == "table" then
if #per == 0 then
if #per == 0 then
local baseText = formatUnitValue(base)
return formatUnitValue(base)
return baseText and mw.text.nowiki(baseText) or nil
end
end
if isFlatList(per) then
if isFlatList(per) then
local one  = formatUnitValue(per[1]) or tostring(per[1])
return formatUnitValue(base) or tostring(per[1])
local show = formatUnitValue(base) or one
end
return show and mw.text.nowiki(show) or nil
end


local series = {}
local vals = {}
for _, v in ipairs(per) do
for _, v in ipairs(per) do
table.insert(series, formatUnitValue(v) or tostring(v))
table.insert(vals, formatUnitValue(v) or tostring(v))
end
end
return dynSpan(series, level)
return (#vals > 0) and table.concat(vals, " / ") or nil
end
end


local txt = valuePairRawText(block)
local baseText = formatUnitValue(base)
return txt and mw.text.nowiki(txt) or nil
local perText  = formatUnitValue(per)
end


----------------------------------------------------------------------
if baseText and perText and isNonZeroScalar(per) then
-- Lookups
return string.format("%s (Per Level: %s)", baseText, perText)
----------------------------------------------------------------------
end


-- getSkillById: locate a skill by internal ID.
return baseText or perText
local function getSkillById(id)
id = trim(id)
if not id then return nil end
local dataset = getSkills()
return (dataset.byId or {})[id]
end
end


-- findSkillByName: locate a skill by external/display name.
-- valuePairDynamicValueOnly: render Base/Per Level blocks using dyn spans where possible.
local function findSkillByName(name)
local function valuePairDynamicValueOnly(block, maxLevel, level)
name = trim(name)
if type(block) ~= "table" then
if not name then return nil end
return nil
end


local dataset = getSkills()
local base = block.Base
local byName = dataset.byName or {}
local per  = block["Per Level"]


if byName[name] then
if type(per) == "table" then
return byName[name]
if #per == 0 then
end
local baseText = formatUnitValue(base)
 
return baseText and mw.text.nowiki(baseText) or nil
for _, rec in ipairs(dataset.records or {}) do
if type(rec) == "table" then
if rec["External Name"] == name or rec.Name == name or rec["Display Name"] == name then
return rec
end
end
end
end


return nil
if isFlatList(per) then
local one  = formatUnitValue(per[1]) or tostring(per[1])
local show = formatUnitValue(base) or one
return show and mw.text.nowiki(show) or nil
end
 
local series = {}
for _, v in ipairs(per) do
table.insert(series, formatUnitValue(v) or tostring(v))
end
return dynSpan(series, level)
end
 
local txt = valuePairRawText(block)
return txt and mw.text.nowiki(txt) or nil
end
end


----------------------------------------------------------------------
----------------------------------------------------------------------
-- Legacy damage helpers
-- Lookups
----------------------------------------------------------------------
----------------------------------------------------------------------


-- basisLabel: label ATK/MATK basis in legacy damage blocks.
-- getSkillById: locate a skill by internal ID.
local function basisLabel(entry, isHealing)
local function getSkillById(id)
if isHealing then
id = trim(id)
return "Healing"
if not id then return nil end
end
local dataset = getSkills()
return (dataset.byId or {})[id]
end


local atk  = entry and entry["ATK-Based"]
-- findSkillByName: locate a skill by external/display name.
local matk = entry and entry["MATK-Based"]
local function findSkillByName(name)
name = trim(name)
if not name then return nil end
 
local dataset = getSkills()
local byName = dataset.byName or {}
 
if byName[name] then
return byName[name]
end


if atk and matk then
for _, rec in ipairs(dataset.records or {}) do
return "Attack/Magic Attack"
if type(rec) == "table" then
elseif atk then
if rec["External Name"] == name or rec.Name == name or rec["Display Name"] == name then
return "Attack"
return rec
elseif matk then
end
return "Magic Attack"
end
end
end


return "Damage"
return nil
end
end


-- formatDamageEntry: legacy percent damage formatting (dynamic by level).
----------------------------------------------------------------------
local function formatDamageEntry(entry, maxLevel, level)
-- Legacy damage helpers
if type(entry) ~= "table" then
----------------------------------------------------------------------
 
-- basisLabel: label ATK/MATK basis in legacy damage blocks.
local function basisLabel(entry, isHealing)
if isHealing then
return "Healing"
end
 
local atk  = entry and entry["ATK-Based"]
local matk = entry and entry["MATK-Based"]
 
if atk and matk then
return "Attack/Magic Attack"
elseif atk then
return "Attack"
elseif matk then
return "Magic Attack"
end
 
return "Damage"
end
 
-- formatDamageEntry: legacy percent damage formatting (dynamic by level).
local function formatDamageEntry(entry, maxLevel, level)
if type(entry) ~= "table" then
return nil
return nil
end
end
Line 876: Line 975:
local title = rec["External Name"] or rec.Name or rec["Internal Name"] or "Unknown Skill"
local title = rec["External Name"] or rec.Name or rec["Internal Name"] or "Unknown Skill"


local wrap = mw.html.create("div")
local notesList = {}
wrap:addClass("sv-herobar-1-wrap")
if type(rec.Notes) == "table" then
for _, note in ipairs(rec.Notes) do
local n = trim(note)
if n then
table.insert(notesList, mw.text.nowiki(n))
end
end
elseif type(rec.Notes) == "string" then
local n = trim(rec.Notes)
if n then
notesList = { mw.text.nowiki(n) }
end
end
 
local req = rec.Requirements or {}
local reqSkillsRaw = (type(req["Required Skills"]) == "table") and req["Required Skills"] or {}
local reqWeaponsRaw = (type(req["Required Weapons"]) == "table") and req["Required Weapons"] or {}
local reqStancesRaw = (type(req["Required Stances"]) == "table") and req["Required Stances"] or {}


if icon and icon ~= "" then
local reqSkills = {}
wrap:tag("div")
for _, rs in ipairs(reqSkillsRaw) do
:addClass("sv-herobar-icon")
if type(rs) == "table" then
:wikitext(string.format("[[File:%s|80px|link=]]", icon))
local nameReq = rs["Skill External Name"] or rs["Skill Internal Name"] or "Unknown"
local lvlReq  = rs["Required Level"]
if lvlReq then
table.insert(reqSkills, string.format("%s (Lv.%s)", mw.text.nowiki(nameReq), mw.text.nowiki(tostring(lvlReq))))
else
table.insert(reqSkills, mw.text.nowiki(nameReq))
end
end
end
end


wrap:tag("div")
local reqWeapons = {}
:addClass("spiritvale-infobox-title")
for _, w in ipairs(reqWeaponsRaw) do
:wikitext(title)
local wn = trim(w)
if wn then table.insert(reqWeapons, mw.text.nowiki(wn)) end
end


return {
local reqStances = {}
inner = tostring(wrap),
for _, s in ipairs(reqStancesRaw) do
classes = "module-icon-name",
local sn = trim(s)
}
if sn then table.insert(reqStances, mw.text.nowiki(sn)) end
end
end


-- PLUGIN: SkillType (Hero Bar Slot 2) - 2 rows x 3 cells (desktop + mobile).
local hasNotes = (#notesList > 0)
-- Rules:
local hasReq = (#reqSkills > 0) or (#reqWeapons > 0) or (#reqStances > 0)
--  - If skill is non-damaging, hide Damage/Element/Hits.
--  - If Hits is empty, hide Hits.
--  - If Combo is empty, hide Combo.
-- Ordering:
--  - Desktop: Damage, Element, Hits, Target, Cast, Combo
--  - Mobile:  Damage, Element, Target, Cast, Hits, Combo (CSS reorder)
function PLUGINS.SkillType(rec, ctx)
local typeBlock = (type(rec.Type) == "table") and rec.Type or {}
local mech      = (type(rec.Mechanics) == "table") and rec.Mechanics or {}


local level    = ctx.level or 1
local maxLevel = ctx.maxLevel or 1


local hideDamageBundle = (ctx.nonDamaging == true)
local wrap = mw.html.create("div")
wrap:addClass("sv-herobar-1-wrap")
wrap:addClass("sv-tip-scope")


-- valName: extract a display string from typical {Name/ID/Value} objects.
local iconBox = wrap:tag("div")
-- NOTE: Includes number support so Hits=2 (number) doesn't get dropped.
iconBox:addClass("sv-herobar-icon")
local function valName(x)
 
if x == nil then return nil end
if icon and icon ~= "" then
if type(x) == "table" then
iconBox:wikitext(string.format("[[File:%s|80px|link=]]", icon))
if x.Name and x.Name ~= "" then return tostring(x.Name) end
if x.ID and x.ID ~= "" then return tostring(x.ID) end
if x.Value ~= nil then return tostring(x.Value) end
end
if type(x) == "number" then
return tostring(x)
end
if type(x) == "string" and x ~= "" then
return x
end
return nil
end
end


-- hitsDisplay: find + render Hits from multiple possible structured locations.
local textBox = wrap:tag("div")
local function hitsDisplay()
textBox:addClass("sv-herobar-text")
local effects = (type(mech.Effects) == "table") and mech.Effects or {}


local h =
local titleRow = textBox:tag("div")
typeBlock.Hits or typeBlock["Hits"] or typeBlock["Hit Count"] or typeBlock["Hits Count"] or
titleRow:addClass("sv-herobar-title-row")
mech.Hits or mech["Hits"] or mech["Hit Count"] or mech["Hits Count"] or
effects.Hits or effects["Hits"] or effects["Hit Count"] or effects["Hits Count"] or
rec.Hits or rec["Hits"]


if h == nil or isNoneLike(h) then
local titleBox = titleRow:tag("div")
return nil
titleBox:addClass("spiritvale-infobox-title")
end
titleBox:wikitext(title)


-- ValuePair-style table (Base/Per Level) => dynamic series
if hasNotes then
if type(h) == "table" then
local notesBtn = mw.html.create("span")
if h.Base ~= nil or h["Per Level"] ~= nil or type(h["Per Level"]) == "table" then
notesBtn:addClass("sv-tip-btn sv-tip-btn--notes")
return displayFromSeries(seriesFromValuePair(h, maxLevel), level)
notesBtn:attr("role", "button")
end
notesBtn:attr("tabindex", "0")
notesBtn:attr("data-sv-tip", "notes")
notesBtn:attr("aria-label", "Notes")
notesBtn:attr("aria-expanded", "false")
notesBtn:tag("span"):addClass("sv-ico sv-ico--info"):attr("aria-hidden", "true"):wikitext("i")
titleRow:node(notesBtn)
end
 
if hasReq then
local pillRow = wrap:tag("div")
pillRow:addClass("sv-pill-row")
pillRow:addClass("sv-pill-row--req")
local pill = pillRow:tag("span")
pill:addClass("sv-pill sv-pill--req sv-tip-btn")
pill:attr("role", "button")
pill:attr("tabindex", "0")
pill:attr("data-sv-tip", "req")
pill:attr("aria-label", "Requirements")
pill:attr("aria-expanded", "false")
pill:wikitext("Requirements")
end


-- Unit block {Value, Unit}
if hasNotes then
if h.Value ~= nil then
local notesContent = wrap:tag("div")
local t = formatUnitValue(h)
notesContent:addClass("sv-tip-content")
return t and mw.text.nowiki(t) or nil
notesContent:attr("data-sv-tip-content", "notes")
end
notesContent:tag("div"):addClass("sv-tip-title"):wikitext("Notes")
notesContent:tag("div"):wikitext(table.concat(notesList, "<br />"))
end


-- Fallback name extraction
if hasReq then
local function valName(x)
local reqContent = wrap:tag("div")
if x == nil then return nil end
reqContent:addClass("sv-tip-content")
if type(x) == "table" then
reqContent:attr("data-sv-tip-content", "req")
if x.Name and x.Name ~= "" then return tostring(x.Name) end
if x.ID and x.ID ~= "" then return tostring(x.ID) end
if x.Value ~= nil then return tostring(x.Value) end
end
if type(x) == "number" then return tostring(x) end
if type(x) == "string" and x ~= "" then return x end
return nil
end


local vn = valName(h)
if #reqSkills > 0 then
if vn and not isNoneLike(vn) then
local section = reqContent:tag("div")
return mw.text.nowiki(vn)
section:addClass("sv-tip-section")
end
section:tag("span"):addClass("sv-tip-label"):wikitext("Required Skills")
section:tag("div"):wikitext(table.concat(reqSkills, "<br />"))
end
end


-- Scalar number/string
if #reqWeapons > 0 then
if type(h) == "number" then
local section = reqContent:tag("div")
return mw.text.nowiki(fmtNum(h))
section:addClass("sv-tip-section")
section:tag("span"):addClass("sv-tip-label"):wikitext("Required Weapons")
section:tag("div"):wikitext(table.concat(reqWeapons, ", "))
end
end
if type(h) == "string" then
 
local t = trim(h)
if #reqStances > 0 then
return (t and not isNoneLike(t)) and mw.text.nowiki(t) or nil
local section = reqContent:tag("div")
section:addClass("sv-tip-section")
section:tag("span"):addClass("sv-tip-label"):wikitext("Required Stances")
section:tag("div"):wikitext(table.concat(reqStances, ", "))
end
end
return nil
end
end


-- comboDisplay: render Combo as a compact text block (Type (+ details)).
return {
local function comboDisplay()
inner = tostring(wrap),
local c = (type(mech.Combo) == "table") and mech.Combo or nil
classes = "module-icon-name",
if not c then return nil end
}
end


local typ = trim(c.Type)
-- PLUGIN: SkillType (Hero Bar Slot 2) - 2 rows x 3 cells (desktop + mobile).
if not typ or isNoneLike(typ) then
-- Rules:
return nil
--  - If skill is non-damaging, hide Damage/Element/Hits.
end
--  - If Hits is empty, hide Hits.
--  - If Combo is empty, hide Combo.
-- Ordering:
--  - Desktop: Damage, Element, Hits, Target, Cast, Combo
--  - Mobile:  Damage, Element, Target, Cast, Hits, Combo (CSS reorder)
function PLUGINS.SkillType(rec, ctx)
local typeBlock = (type(rec.Type) == "table") and rec.Type or {}
local mech      = (type(rec.Mechanics) == "table") and rec.Mechanics or {}


local details = {}
local level    = ctx.level or 1
local maxLevel = ctx.maxLevel or 1


local pct = formatUnitValue(c.Percent)
local hideDamageBundle = (ctx.nonDamaging == true)
if pct and not isZeroish(pct) then
table.insert(details, mw.text.nowiki(pct))
end


local dur = formatUnitValue(c.Duration)
-- valName: extract a display string from typical {Name/ID/Value} objects.
if dur and not isZeroish(dur) then
-- NOTE: Includes number support so Hits=2 (number) doesn't get dropped.
table.insert(details, mw.text.nowiki(dur))
local function valName(x)
if x == nil then return nil end
if type(x) == "table" then
if x.Name and x.Name ~= "" then return tostring(x.Name) end
if x.ID and x.ID ~= "" then return tostring(x.ID) end
if x.Value ~= nil then return tostring(x.Value) end
end
end
 
if type(x) == "number" then
if #details > 0 then
return tostring(x)
return mw.text.nowiki(typ) .. " (" .. table.concat(details, ", ") .. ")"
end
if type(x) == "string" and x ~= "" then
return x
end
end
return mw.text.nowiki(typ)
return nil
end
end


local grid = mw.html.create("div")
-- hitsDisplay: find + render Hits from multiple possible structured locations.
grid:addClass("sv-type-grid")
local function hitsDisplay()
grid:addClass("sv-compact-root")
local effects = (type(mech.Effects) == "table") and mech.Effects or {}


local added = false
local h =
typeBlock.Hits or typeBlock["Hits"] or typeBlock["Hit Count"] or typeBlock["Hits Count"] or
mech.Hits or mech["Hits"] or mech["Hit Count"] or mech["Hits Count"] or
effects.Hits or effects["Hits"] or effects["Hit Count"] or effects["Hits Count"] or
rec.Hits or rec["Hits"]


-- addChunk: add one labeled value cell (key drives CSS ordering).
if h == nil or isNoneLike(h) then
local function addChunk(key, label, valueHtml)
return nil
if valueHtml == nil or valueHtml == "" then return end
end
added = true


local chunk = grid:tag("div")
-- ValuePair-style table (Base/Per Level) => dynamic series
:addClass("sv-type-chunk")
if type(h) == "table" then
:addClass("sv-type-" .. tostring(key))
if h.Base ~= nil or h["Per Level"] ~= nil or type(h["Per Level"]) == "table" then
:attr("data-type-key", tostring(key))
return displayFromSeries(seriesFromValuePair(h, maxLevel), level)
end


chunk:tag("div")
-- Unit block {Value, Unit}
:addClass("sv-type-label")
if h.Value ~= nil then
:wikitext(mw.text.nowiki(label))
local t = formatUnitValue(h)
return t and mw.text.nowiki(t) or nil
end


chunk:tag("div")
-- Fallback name extraction
:addClass("sv-type-value")
local function valName(x)
:wikitext(valueHtml)
if x == nil then return nil end
end
if type(x) == "table" then
if x.Name and x.Name ~= "" then return tostring(x.Name) end
if x.ID and x.ID ~= "" then return tostring(x.ID) end
if x.Value ~= nil then return tostring(x.Value) end
end
if type(x) == "number" then return tostring(x) end
if type(x) == "string" and x ~= "" then return x end
return nil
end


-- Damage + Element + Hits bundle (hidden when non-damaging)
local vn = valName(h)
if not hideDamageBundle then
if vn and not isNoneLike(vn) then
local dmg  = valName(typeBlock.Damage or typeBlock["Damage Type"])
return mw.text.nowiki(vn)
local ele  = valName(typeBlock.Element or typeBlock["Element Type"])
end
local hits = hitsDisplay()
end


if dmg and not isNoneLike(dmg) then
-- Scalar number/string
addChunk("damage", "Damage", mw.text.nowiki(dmg))
if type(h) == "number" then
return mw.text.nowiki(fmtNum(h))
end
end
if ele and not isNoneLike(ele) then
if type(h) == "string" then
addChunk("element", "Element", mw.text.nowiki(ele))
local t = trim(h)
end
return (t and not isNoneLike(t)) and mw.text.nowiki(t) or nil
if hits then
addChunk("hits", "Hits", hits)
end
end
return nil
end
end


-- Target + Cast
-- comboDisplay: render Combo as a compact text block (Type (+ details)).
local tgt = valName(typeBlock.Target or typeBlock["Target Type"])
local function comboDisplay()
local cst = valName(typeBlock.Cast  or typeBlock["Cast Type"])
local c = (type(mech.Combo) == "table") and mech.Combo or nil
if not c then return nil end


if tgt and not isNoneLike(tgt) then
local typ = trim(c.Type)
addChunk("target", "Target", mw.text.nowiki(tgt))
if not typ or isNoneLike(typ) then
end
return nil
if cst and not isNoneLike(cst) then
end
addChunk("cast", "Cast", mw.text.nowiki(cst))
end


-- Combo
local details = {}
local combo = comboDisplay()
if combo then
addChunk("combo", "Combo", combo)
end


        return {
local pct = formatUnitValue(c.Percent)
                inner = added and tostring(grid) or "",
if pct and not isZeroish(pct) then
                classes = "module-skill-type",
table.insert(details, mw.text.nowiki(pct))
        }
end
end


-- PLUGIN: Description (Hero Slot 3) - primary description text.
local dur = formatUnitValue(c.Duration)
function PLUGINS.Description(rec)
if dur and not isZeroish(dur) then
        local desc = trim(rec.Description)
table.insert(details, mw.text.nowiki(dur))
        if not desc then
end
                return nil
 
        end
if #details > 0 then
return mw.text.nowiki(typ) .. " (" .. table.concat(details, ", ") .. ")"
end
return mw.text.nowiki(typ)
end


        local body = mw.html.create("div")
local grid = mw.html.create("div")
        body:addClass("sv-description")
grid:addClass("sv-type-grid")
        body:wikitext(string.format("''%s''", desc))
grid:addClass("sv-compact-root")


        return {
local added = false
                inner = tostring(body),
                classes = "module-description",
        }
end


-- PLUGIN: Placeholder (Hero Slot 4) - reserved/blank.
-- addChunk: add one labeled value cell (key drives CSS ordering).
function PLUGINS.Placeholder()
local function addChunk(key, label, valueHtml)
        return nil
if valueHtml == nil or valueHtml == "" then return end
end
added = true


local chunk = grid:tag("div")
:addClass("sv-type-chunk")
:addClass("sv-type-" .. tostring(key))
:attr("data-type-key", tostring(key))


-- PLUGIN: SourceType (Hero Module Slot 1) - Modifier + Source + Scaling.
chunk:tag("div")
function PLUGINS.SourceType(rec, ctx)
:addClass("sv-type-label")
local level = ctx.level or 1
:wikitext(mw.text.nowiki(label))
local maxLevel = ctx.maxLevel or 1


local basisWord = nil
chunk:tag("div")
local sourceKind = nil
:addClass("sv-type-value")
local sourceVal  = nil
:wikitext(valueHtml)
local scaling    = nil
end


-- sourceValueForLevel: dynamic formatting for structured Source blocks.
-- Damage + Element + Hits bundle (hidden when non-damaging)
local function sourceValueForLevel(src)
if not hideDamageBundle then
if type(src) ~= "table" then
local dmg  = valName(typeBlock.Damage or typeBlock["Damage Type"])
return nil
local ele  = valName(typeBlock.Element or typeBlock["Element Type"])
local hits = hitsDisplay()
 
if dmg and not isNoneLike(dmg) then
addChunk("damage", "Damage", mw.text.nowiki(dmg))
end
if ele and not isNoneLike(ele) then
addChunk("element", "Element", mw.text.nowiki(ele))
end
end
 
if hits then
local per = src["Per Level"]
addChunk("hits", "Hits", hits)
if type(per) == "table" and #per > 0 then
if isFlatList(per) then
local one  = formatUnitValue(per[1]) or tostring(per[1])
local show = formatUnitValue(src.Base) or one
return show and mw.text.nowiki(show) or nil
end
 
local series = {}
for _, v in ipairs(per) do
table.insert(series, formatUnitValue(v) or tostring(v))
end
return dynSpan(series, level)
end
end
return valuePairDynamicValueOnly(src, maxLevel, level)
end
end


if type(rec.Source) == "table" then
-- Target + Cast
local src = rec.Source
local tgt = valName(typeBlock.Target or typeBlock["Target Type"])
local atkFlag  = (src["ATK-Based"] == true)
local cst = valName(typeBlock.Cast  or typeBlock["Cast Type"])
local matkFlag = (src["MATK-Based"] == true)
basisWord = basisWordFromFlags(atkFlag, matkFlag)


sourceKind = src.Type or ((src.Healing == true) and "Healing") or "Damage"
if tgt and not isNoneLike(tgt) then
sourceVal  = sourceValueForLevel(src)
addChunk("target", "Target", mw.text.nowiki(tgt))
scaling    = src.Scaling
end
if cst and not isNoneLike(cst) then
addChunk("cast", "Cast", mw.text.nowiki(cst))
end
end


-- Fallback to legacy Damage lists if Source absent
-- Combo
if (sourceVal == nil or sourceVal == "") and type(rec.Damage) == "table" then
local combo = comboDisplay()
local dmg = rec.Damage
if combo then
scaling = scaling or dmg.Scaling
addChunk("combo", "Combo", combo)
end


local main = dmg["Main Damage"]
        return {
local refl = dmg["Reflect Damage"]
                inner = added and tostring(grid) or "",
local flat = dmg["Flat Damage"]
                classes = "module-skill-type",
        }
end


if type(main) == "table" and #main > 0 then
-- PLUGIN: Description (Hero Slot 3) - primary description text.
local pick = nil
function PLUGINS.Description(rec)
for _, d in ipairs(main) do
        local desc = trim(rec.Description)
if type(d) == "table" and d.Type ~= "Healing" then
        if not desc then
pick = d
                return nil
break
        end
end
end
pick = pick or main[1]


if type(pick) == "table" then
        local body = mw.html.create("div")
local atkFlag  = (pick["ATK-Based"] == true)
        body:addClass("sv-description")
local matkFlag = (pick["MATK-Based"] == true)
        body:wikitext(string.format("''%s''", desc))
basisWord = basisWord or basisWordFromFlags(atkFlag, matkFlag)


sourceKind = (pick.Type == "Healing") and "Healing" or "Damage"
        return {
sourceVal  = legacyPercentAtLevel(pick, level)
                inner = tostring(body),
end
                classes = "module-description",
elseif type(refl) == "table" and #refl > 0 and type(refl[1]) == "table" then
        }
local pick = refl[1]
end
local atkFlag  = (pick["ATK-Based"] == true)
local matkFlag = (pick["MATK-Based"] == true)
basisWord = basisWord or basisWordFromFlags(atkFlag, matkFlag)


sourceKind = "Reflect"
-- PLUGIN: Placeholder (Hero Slot 4) - reserved/blank.
sourceVal  = legacyPercentAtLevel(pick, level)
function PLUGINS.Placeholder()
elseif type(flat) == "table" and #flat > 0 and type(flat[1]) == "table" then
        return nil
local pick = flat[1]
end
local atkFlag  = (pick["ATK-Based"] == true)
local matkFlag = (pick["MATK-Based"] == true)
basisWord = basisWord or basisWordFromFlags(atkFlag, matkFlag)


sourceKind = "Flat"
sourceVal  = legacyPercentAtLevel(pick, level)
end
end


local scalingLines = formatScalingCompactLines(scaling)
-- PLUGIN: SourceType (Hero Module Slot 1) - Modifier + Source + Scaling.
local hasSource    = (sourceVal ~= nil and tostring(sourceVal) ~= "")
function PLUGINS.SourceType(rec, ctx)
local hasScaling  = (type(scalingLines) == "table" and #scalingLines > 0)
local level = ctx.level or 1
local maxLevel = ctx.maxLevel or 1


if (not hasSource) and (not hasScaling) then
local basisWord = nil
return nil
local sourceKind = nil
end
local sourceVal  = nil
local scaling    = nil


local hasMod = (basisWord ~= nil and tostring(basisWord) ~= "")
-- sourceValueForLevel: dynamic formatting for structured Source blocks.
local function sourceValueForLevel(src)
if type(src) ~= "table" then
return nil
end


local extra = { "skill-source-module", "module-source-type" }
local per = src["Per Level"]
table.insert(extra, hasMod and "sv-has-mod" or "sv-no-mod")
if type(per) == "table" and #per > 0 then
if isFlatList(per) then
local one  = formatUnitValue(per[1]) or tostring(per[1])
local show = formatUnitValue(src.Base) or one
return show and mw.text.nowiki(show) or nil
end


if hasSource and (not hasScaling) then
local series = {}
table.insert(extra, "sv-only-source")
for _, v in ipairs(per) do
elseif hasScaling and (not hasSource) then
table.insert(series, formatUnitValue(v) or tostring(v))
table.insert(extra, "sv-only-scaling")
end
return dynSpan(series, level)
end
 
return valuePairDynamicValueOnly(src, maxLevel, level)
end
end


local wrap = mw.html.create("div")
if type(rec.Source) == "table" then
wrap:addClass("sv-source-grid")
local src = rec.Source
wrap:addClass("sv-compact-root")
local atkFlag  = (src["ATK-Based"] == true)
local matkFlag = (src["MATK-Based"] == true)
basisWord = basisWordFromFlags(atkFlag, matkFlag)


if hasMod then
sourceKind = src.Type or ((src.Healing == true) and "Healing") or "Damage"
local modCol = wrap:tag("div"):addClass("sv-source-col"):addClass("sv-source-modifier")
sourceVal  = sourceValueForLevel(src)
modCol:tag("div"):addClass("sv-source-pill"):wikitext("Modifier")
scaling    = src.Scaling
modCol:tag("div"):addClass("sv-modifier-value"):wikitext(mw.text.nowiki(basisWord))
end
end


if hasSource then
-- Fallback to legacy Damage lists if Source absent
local sourceCol = wrap:tag("div"):addClass("sv-source-col"):addClass("sv-source-main")
if (sourceVal == nil or sourceVal == "") and type(rec.Damage) == "table" then
sourceCol:tag("div"):addClass("sv-source-pill"):wikitext(mw.text.nowiki(sourceKind or "Source"))
local dmg = rec.Damage
sourceCol:tag("div"):addClass("sv-source-value"):wikitext(sourceVal)
scaling = scaling or dmg.Scaling
end


if hasScaling then
local main = dmg["Main Damage"]
local scalingCol = wrap:tag("div"):addClass("sv-source-col"):addClass("sv-source-scaling")
local refl = dmg["Reflect Damage"]
scalingCol:tag("div"):addClass("sv-source-pill"):wikitext("Scaling")
local flat = dmg["Flat Damage"]


local list = scalingCol:tag("div"):addClass("sv-scaling-list")
if type(main) == "table" and #main > 0 then
for _, line in ipairs(scalingLines) do
local pick = nil
list:tag("div"):addClass("sv-scaling-item"):wikitext(mw.text.nowiki(line))
for _, d in ipairs(main) do
end
if type(d) == "table" and d.Type ~= "Healing" then
end
pick = d
break
end
end
pick = pick or main[1]


return {
if type(pick) == "table" then
inner = tostring(wrap),
local atkFlag  = (pick["ATK-Based"] == true)
classes = extra,
local matkFlag = (pick["MATK-Based"] == true)
}
basisWord = basisWord or basisWordFromFlags(atkFlag, matkFlag)
end


-- PLUGIN: QuickStats (Hero Module Slot 2) - 3x2 grid (range/area/cost/cast/cd/duration).
sourceKind = (pick.Type == "Healing") and "Healing" or "Damage"
-- NOTE: Hits does NOT live here (it lives in SkillType).
sourceVal  = legacyPercentAtLevel(pick, level)
function PLUGINS.QuickStats(rec, ctx)
end
local level = ctx.level or 1
elseif type(refl) == "table" and #refl > 0 and type(refl[1]) == "table" then
local maxLevel = ctx.maxLevel or 1
local pick = refl[1]
local promo = ctx.promo
local atkFlag  = (pick["ATK-Based"] == true)
local matkFlag = (pick["MATK-Based"] == true)
basisWord = basisWord or basisWordFromFlags(atkFlag, matkFlag)


local mech = (type(rec) == "table" and type(rec.Mechanics) == "table") and rec.Mechanics or {}
sourceKind = "Reflect"
local bt  = (type(mech["Basic Timings"]) == "table") and mech["Basic Timings"] or {}
sourceVal  = legacyPercentAtLevel(pick, level)
local rc  = (type(mech["Resource Cost"]) == "table") and mech["Resource Cost"] or {}
elseif type(flat) == "table" and #flat > 0 and type(flat[1]) == "table" then
local pick = flat[1]
local atkFlag  = (pick["ATK-Based"] == true)
local matkFlag = (pick["MATK-Based"] == true)
basisWord = basisWord or basisWordFromFlags(atkFlag, matkFlag)


local function dash() return "—" end
sourceKind = "Flat"
 
sourceVal  = legacyPercentAtLevel(pick, level)
-- Range (0 => —)
local rangeVal = nil
if mech.Range ~= nil and not isNoneLike(mech.Range) then
local n = toNum(mech.Range)
if n ~= nil then
if n ~= 0 then
rangeVal = mw.text.nowiki(formatUnitValue(mech.Range) or tostring(mech.Range))
end
else
local t = mw.text.trim(tostring(mech.Range))
if t ~= "" and not isNoneLike(t) then
rangeVal = mw.text.nowiki(t)
end
end
end
end
end


-- Area
local scalingLines = formatScalingCompactLines(scaling)
local areaVal = formatAreaSize(mech.Area, maxLevel, level)
local hasSource    = (sourceVal ~= nil and tostring(sourceVal) ~= "")
local hasScaling  = (type(scalingLines) == "table" and #scalingLines > 0)


-- Timings
if (not hasSource) and (not hasScaling) then
local castVal = displayFromSeries(seriesFromValuePair(bt["Cast Time"], maxLevel), level)
return nil
local cdVal  = displayFromSeries(seriesFromValuePair(bt["Cooldown"],  maxLevel), level)
end
local durVal  = displayFromSeries(seriesFromValuePair(bt["Duration"],  maxLevel), level)


-- Promote status duration if needed
local hasMod = (basisWord ~= nil and tostring(basisWord) ~= "")
if (durVal == nil) and type(promo) == "table" and type(promo.durationBlock) == "table" then
 
durVal = displayFromSeries(seriesFromValuePair(promo.durationBlock, maxLevel), level)
local extra = { "skill-source-module", "module-source-type" }
end
table.insert(extra, hasMod and "sv-has-mod" or "sv-no-mod")


-- Cost: MP + HP
if hasSource and (not hasScaling) then
local function labeledSeries(block, label)
table.insert(extra, "sv-only-source")
local s = seriesFromValuePair(block, maxLevel)
elseif hasScaling and (not hasSource) then
if not s then return nil end
table.insert(extra, "sv-only-scaling")
local any = false
for i, v in ipairs(s) do
if v ~= "" then
s[i] = tostring(v) .. " " .. label
any = true
else
s[i] = "—"
end
end
return any and s or nil
end
end


local mpS = labeledSeries(rc["Mana Cost"], "MP")
local wrap = mw.html.create("div")
local hpS = labeledSeries(rc["Health Cost"], "HP")
wrap:addClass("sv-source-grid")
wrap:addClass("sv-compact-root")


local costSeries = {}
if hasMod then
for lv = 1, maxLevel do
local modCol = wrap:tag("div"):addClass("sv-source-col"):addClass("sv-source-modifier")
local mp = mpS and mpS[lv] or ""
modCol:tag("div"):addClass("sv-source-pill"):wikitext("Modifier")
local hp = hpS and hpS[lv] or ""
modCol:tag("div"):addClass("sv-modifier-value"):wikitext(mw.text.nowiki(basisWord))
end


if mp ~= "" and hp ~= "" then
if hasSource then
costSeries[lv] = mp .. " + " .. hp
local sourceCol = wrap:tag("div"):addClass("sv-source-col"):addClass("sv-source-main")
elseif mp ~= "" then
sourceCol:tag("div"):addClass("sv-source-pill"):wikitext(mw.text.nowiki(sourceKind or "Source"))
costSeries[lv] = mp
sourceCol:tag("div"):addClass("sv-source-value"):wikitext(sourceVal)
elseif hp ~= "" then
costSeries[lv] = hp
else
costSeries[lv] = ""
end
end
end


local costVal = displayFromSeries(costSeries, level)
if hasScaling then
local scalingCol = wrap:tag("div"):addClass("sv-source-col"):addClass("sv-source-scaling")
scalingCol:tag("div"):addClass("sv-source-pill"):wikitext("Scaling")


local grid = mw.html.create("div")
local list = scalingCol:tag("div"):addClass("sv-scaling-list")
grid:addClass("sv-m4-grid")
for _, line in ipairs(scalingLines) do
grid:addClass("sv-compact-root")
list:tag("div"):addClass("sv-scaling-item"):wikitext(mw.text.nowiki(line))
 
end
local function addCell(label, val)
local cell = grid:tag("div"):addClass("sv-m4-cell")
cell:tag("div"):addClass("sv-m4-label"):wikitext(mw.text.nowiki(label))
cell:tag("div"):addClass("sv-m4-value"):wikitext(val or dash())
end
end
addCell("Range",    rangeVal)
addCell("Area",      areaVal)
addCell("Cost",      costVal)
addCell("Cast Time", castVal)
addCell("Cooldown",  cdVal)
addCell("Duration",  durVal)


return {
return {
inner = tostring(grid),
inner = tostring(wrap),
classes = "module-quick-stats",
classes = extra,
}
}
end
end


-- PLUGIN: SpecialMechanics (Hero Module Slot 3)
-- PLUGIN: QuickStats (Hero Module Slot 2) - 3x2 grid (range/area/cost/cast/cd/duration).
-- Shows:
-- NOTE: Hits does NOT live here (it lives in SkillType).
--  - Flags (deduped)
function PLUGINS.QuickStats(rec, ctx)
--  - Special mechanics (mech.Effects)
-- NOTE: Combo lives in SkillType (Hero Bar Slot 2).
function PLUGINS.SpecialMechanics(rec, ctx)
local level = ctx.level or 1
local level = ctx.level or 1
local maxLevel = ctx.maxLevel or 1
local maxLevel = ctx.maxLevel or 1
local promo = ctx.promo


local mech   = (type(rec) == "table" and type(rec.Mechanics) == "table") and rec.Mechanics or {}
local mech = (type(rec) == "table" and type(rec.Mechanics) == "table") and rec.Mechanics or {}
local effects = (type(mech.Effects) == "table") and mech.Effects or nil
local bt  = (type(mech["Basic Timings"]) == "table") and mech["Basic Timings"] or {}
local mods    = (type(rec.Modifiers) == "table") and rec.Modifiers or nil
local rc  = (type(mech["Resource Cost"]) == "table") and mech["Resource Cost"] or {}


------------------------------------------------------------------
local function dash() return "" end
-- Hits guard (we want Hits ONLY in SkillType)
------------------------------------------------------------------
local function isHitsKey(name)
if not name then return false end
local k = mw.ustring.lower(mw.text.trim(tostring(name)))
return (
k == "hit" or
k == "hits" or
k == "hit count" or
k == "hits count" or
k == "hitcount" or
k == "hitscount"
)
end


------------------------------------------------------------------
-- Range (0 => —)
-- Flags (flat, de-duped)
local rangeVal = nil
------------------------------------------------------------------
if mech.Range ~= nil and not isNoneLike(mech.Range) then
local flagSet = {}
local n = toNum(mech.Range)
if n ~= nil then
if n ~= 0 then
rangeVal = mw.text.nowiki(formatUnitValue(mech.Range) or tostring(mech.Range))
end
else
local t = mw.text.trim(tostring(mech.Range))
if t ~= "" and not isNoneLike(t) then
rangeVal = mw.text.nowiki(t)
end
end
end


local denyFlags = {
-- Area
["self centered"] = true,
local areaVal = formatAreaSize(mech.Area, maxLevel, level)
["self-centred"] = true,
["bond"] = true,
["combo"] = true,
        ["hybrid"] = true,


-- hits variants
-- Timings
["hit"] = true,
local castVal = displayFromSeries(seriesFromValuePair(bt["Cast Time"], maxLevel), level)
["hits"] = true,
local cdVal  = displayFromSeries(seriesFromValuePair(bt["Cooldown"], maxLevel), level)
["hit count"] = true,
local durVal  = displayFromSeries(seriesFromValuePair(bt["Duration"], maxLevel), level)
["hits count"] = true,
["hitcount"] = true,
["hitscount"] = true,
}


local function allowFlag(name)
-- Promote status duration if needed
if not name then return false end
if (durVal == nil) and type(promo) == "table" and type(promo.durationBlock) == "table" then
local k = mw.ustring.lower(mw.text.trim(tostring(name)))
durVal = displayFromSeries(seriesFromValuePair(promo.durationBlock, maxLevel), level)
if k == "" then return false end
if denyFlags[k] then return false end
return true
end
end


local function addFlags(sub)
-- Cost: MP + HP
if type(sub) ~= "table" then return end
local function labeledSeries(block, label)
for k, v in pairs(sub) do
local s = seriesFromValuePair(block, maxLevel)
if v and allowFlag(k) then
if not s then return nil end
flagSet[tostring(k)] = true
local any = false
for i, v in ipairs(s) do
if v ~= "—" then
s[i] = tostring(v) .. " " .. label
any = true
else
s[i] = "—"
end
end
end
end
return any and s or nil
end
end


if mods then
local mpS = labeledSeries(rc["Mana Cost"], "MP")
addFlags(mods["Movement Modifiers"])
local hpS = labeledSeries(rc["Health Cost"], "HP")
addFlags(mods["Combat Modifiers"])
 
addFlags(mods["Special Modifiers"])
local costSeries = {}
for k, v in pairs(mods) do
for lv = 1, maxLevel do
if type(v) == "boolean" and v and allowFlag(k) then
local mp = mpS and mpS[lv] or "—"
flagSet[tostring(k)] = true
local hp = hpS and hpS[lv] or "—"
end
 
if mp ~= "—" and hp ~= "" then
costSeries[lv] = mp .. " + " .. hp
elseif mp ~= "—" then
costSeries[lv] = mp
elseif hp ~= "" then
costSeries[lv] = hp
else
costSeries[lv] = "—"
end
end
end
end


local flags = {}
local costVal = displayFromSeries(costSeries, level)
for k, _ in pairs(flagSet) do table.insert(flags, k) end
table.sort(flags)


------------------------------------------------------------------
local grid = mw.html.create("div")
-- Special mechanics (name => value)
grid:addClass("sv-m4-grid")
------------------------------------------------------------------
grid:addClass("sv-compact-root")
local mechItems = {}
 
local function addCell(label, val)
local cell = grid:tag("div"):addClass("sv-m4-cell")
cell:tag("div"):addClass("sv-m4-label"):wikitext(mw.text.nowiki(label))
cell:tag("div"):addClass("sv-m4-value"):wikitext(val or dash())
end


if effects then
addCell("Range",    rangeVal)
local keys = {}
addCell("Area",      areaVal)
for k, _ in pairs(effects) do table.insert(keys, k) end
addCell("Cost",     costVal)
table.sort(keys)
addCell("Cast Time", castVal)
addCell("Cooldown", cdVal)
addCell("Duration",  durVal)


for _, name in ipairs(keys) do
return {
-- Skip Hits completely (it belongs in SkillType)
inner = tostring(grid),
if not isHitsKey(name) then
classes = "module-quick-stats",
local block = effects[name]
}
if type(block) == "table" then
end
-- Also skip if the block's Type is "Hits" (some data may encode it that way)
if not isHitsKey(block.Type) then
local disp = displayFromSeries(seriesFromValuePair(block, maxLevel), level)
local t = trim(block.Type)


local value = disp
-- PLUGIN: SpecialMechanics (Hero Module Slot 3)
-- Shows:
--  - Flags (deduped)
--  - Special mechanics (mech.Effects)
-- NOTE: Combo lives in SkillType (Hero Bar Slot 2).
function PLUGINS.SpecialMechanics(rec, ctx)
local level = ctx.level or 1
local maxLevel = ctx.maxLevel or 1


-- If Type exists and is distinct, prefix it.
local mech    = (type(rec) == "table" and type(rec.Mechanics) == "table") and rec.Mechanics or {}
if t and not isNoneLike(t) and mw.ustring.lower(t) ~= mw.ustring.lower(tostring(name)) then
local effects = (type(mech.Effects) == "table") and mech.Effects or nil
if value then
local mods    = (type(rec.Modifiers) == "table") and rec.Modifiers or nil
value = mw.text.nowiki(t) .. ": " .. value
else
value = mw.text.nowiki(t)
end
end


if value then
------------------------------------------------------------------
table.insert(mechItems, { label = tostring(name), value = value })
-- Hits guard (we want Hits ONLY in SkillType)
end
------------------------------------------------------------------
end
local function isHitsKey(name)
end
if not name then return false end
end
local k = mw.ustring.lower(mw.text.trim(tostring(name)))
end
return (
k == "hit" or
k == "hits" or
k == "hit count" or
k == "hits count" or
k == "hitcount" or
k == "hitscount"
)
end
end


local hasFlags = (#flags > 0)
------------------------------------------------------------------
local hasMech  = (#mechItems > 0)
-- Flags (flat, de-duped)
------------------------------------------------------------------
local flagSet = {}


if (not hasFlags) and (not hasMech) then
local denyFlags = {
local root = mw.html.create("div")
["self centered"] = true,
root:addClass("sv-sm-root")
["self-centred"] = true,
root:addClass("sv-compact-root")
["bond"] = true,
root:tag("div"):addClass("sv-sm-empty"):wikitext("No Special Mechanics")
["combo"] = true,
        ["hybrid"] = true,
 
-- hits variants
["hit"] = true,
["hits"] = true,
["hit count"] = true,
["hits count"] = true,
["hitcount"] = true,
["hitscount"] = true,
}


return {
local function allowFlag(name)
inner = tostring(root),
if not name then return false end
classes = "module-special-mechanics",
local k = mw.ustring.lower(mw.text.trim(tostring(name)))
}
if k == "" then return false end
if denyFlags[k] then return false end
return true
end
end


local count = 0
local function addFlags(sub)
if hasFlags then count = count + 1 end
if type(sub) ~= "table" then return end
if hasMech  then count = count + 1 end
for k, v in pairs(sub) do
if v and allowFlag(k) then
flagSet[tostring(k)] = true
end
end
end


local root = mw.html.create("div")
if mods then
root:addClass("sv-sm-root")
addFlags(mods["Movement Modifiers"])
root:addClass("sv-compact-root")
addFlags(mods["Combat Modifiers"])
 
addFlags(mods["Special Modifiers"])
local layout = root:tag("div"):addClass("sv-sm-layout")
for k, v in pairs(mods) do
layout:addClass("sv-sm-count-" .. tostring(count))
if type(v) == "boolean" and v and allowFlag(k) then
 
flagSet[tostring(k)] = true
-- Column 1: Flags
end
if hasFlags then
local fcol = layout:tag("div"):addClass("sv-sm-col"):addClass("sv-sm-col-flags")
for _, f in ipairs(flags) do
fcol:tag("div"):addClass("sv-sm-flag"):wikitext(mw.text.nowiki(f))
end
end
end
end


-- Column 2: Special Mechanics (stacked)
local flags = {}
if hasMech then
for k, _ in pairs(flagSet) do table.insert(flags, k) end
local mcol = layout:tag("div"):addClass("sv-sm-col"):addClass("sv-sm-col-mech")
table.sort(flags)
for _, it in ipairs(mechItems) do
local one = mcol:tag("div"):addClass("sv-sm-mech")
one:tag("div"):addClass("sv-sm-label"):wikitext(mw.text.nowiki(it.label))
one:tag("div"):addClass("sv-sm-value"):wikitext(it.value or "—")
end
end


return {
------------------------------------------------------------------
inner = tostring(root),
-- Special mechanics (name => value)
classes = "module-special-mechanics",
------------------------------------------------------------------
}
local mechItems = {}
end


-- PLUGIN: LevelSelector (Hero Module Slot 4) - JS level slider.
if effects then
function PLUGINS.LevelSelector(rec, ctx)
local keys = {}
local level = ctx.level or 1
for k, _ in pairs(effects) do table.insert(keys, k) end
local maxLevel = ctx.maxLevel or 1
table.sort(keys)


local inner = mw.html.create("div")
for _, name in ipairs(keys) do
inner:addClass("sv-level-ui")
-- Skip Hits completely (it belongs in SkillType)
if not isHitsKey(name) then
local block = effects[name]
if type(block) == "table" then
-- Also skip if the block's Type is "Hits" (some data may encode it that way)
if not isHitsKey(block.Type) then
local disp = displayFromSeries(seriesFromValuePair(block, maxLevel), level)
local t = trim(block.Type)


inner:tag("div")
local value = disp
:addClass("sv-level-label")
:wikitext("Level <span class=\"sv-level-num\">" .. tostring(level) .. "</span> / " .. tostring(maxLevel))


local slider = inner:tag("div"):addClass("sv-level-slider")
-- If Type exists and is distinct, prefix it.
if t and not isNoneLike(t) and mw.ustring.lower(t) ~= mw.ustring.lower(tostring(name)) then
if value then
value = mw.text.nowiki(t) .. ": " .. value
else
value = mw.text.nowiki(t)
end
end


if tonumber(maxLevel) and tonumber(maxLevel) > 1 then
if value then
slider:tag("input")
table.insert(mechItems, { label = tostring(name), value = value })
:attr("type", "range")
end
:attr("min", "1")
end
:attr("max", tostring(maxLevel))
end
:attr("value", tostring(level))
end
:addClass("sv-level-range")
end
:attr("aria-label", "Skill level select")
else
inner:addClass("sv-level-ui-single")
slider:addClass("sv-level-slider-single")
end
end


return {
local hasFlags = (#flags > 0)
inner = tostring(inner),
local hasMech  = (#mechItems > 0)
classes = "module-level-selector",
}
end


----------------------------------------------------------------------
if (not hasFlags) and (not hasMech) then
-- Generic slot renderers
local root = mw.html.create("div")
----------------------------------------------------------------------
root:addClass("sv-sm-root")
root:addClass("sv-compact-root")
root:tag("div"):addClass("sv-sm-empty"):wikitext("No Special Mechanics")


-- normalizeResult: normalize plugin return values into {inner, classes}.
return {
local function normalizeResult(res)
inner = tostring(root),
if res == nil then return nil end
classes = "module-special-mechanics",
if type(res) == "string" then
}
return { inner = res, classes = nil }
end
end
if type(res) == "table" then
local inner = res.inner
if type(inner) ~= "string" then
inner = (inner ~= nil) and tostring(inner) or ""
end
return { inner = inner, classes = res.classes }
end
return { inner = tostring(res), classes = nil }
end


-- safeCallPlugin: pcall wrapper to prevent infobox failure on plugin errors.
local count = 0
local function safeCallPlugin(name, rec, ctx)
if hasFlags then count = count + 1 end
        local fn = PLUGINS[name]
if hasMech  then count = count + 1 end
        if type(fn) ~= "function" then
 
                return nil
local root = mw.html.create("div")
        end
root:addClass("sv-sm-root")
        local ok, out = pcall(fn, rec, ctx)
root:addClass("sv-compact-root")
        if not ok then
                return nil
        end
        return normalizeResult(out)
end


-- isEmptySlotContent: true when a slot has no meaningful content.
local layout = root:tag("div"):addClass("sv-sm-layout")
-- NOTE: JS placeholders (sv-dyn spans, slider markup) are considered content.
layout:addClass("sv-sm-count-" .. tostring(count))
local function isEmptySlotContent(inner)
        if inner == nil then return true end


        local raw = tostring(inner)
-- Column 1: Flags
if hasFlags then
local fcol = layout:tag("div"):addClass("sv-sm-col"):addClass("sv-sm-col-flags")
for _, f in ipairs(flags) do
fcol:tag("div"):addClass("sv-sm-flag"):wikitext(mw.text.nowiki(f))
end
end


        -- Guard rails for JS-injected regions.
-- Column 2: Special Mechanics (stacked)
        for _, pat in ipairs({ "sv%-dyn", "data%-series", "sv%-level%-range", "sv%-level%-slider", "sv%-level%-ui" }) do
if hasMech then
                if mw.ustring.find(raw, pat) then
local mcol = layout:tag("div"):addClass("sv-sm-col"):addClass("sv-sm-col-mech")
                        return false
for _, it in ipairs(mechItems) do
                end
local one = mcol:tag("div"):addClass("sv-sm-mech")
        end
one:tag("div"):addClass("sv-sm-label"):wikitext(mw.text.nowiki(it.label))
one:tag("div"):addClass("sv-sm-value"):wikitext(it.value or "—")
end
end


        local trimmed = mw.text.trim(raw)
return {
        if trimmed == "" or trimmed == "—" then
inner = tostring(root),
                return true
classes = "module-special-mechanics",
        end
}
 
        local withoutTags = mw.text.trim(mw.ustring.gsub(trimmed, "<[^>]+>", ""))
        return (withoutTags == "" or withoutTags == "—")
end
end


-- renderHeroSlot: render a standardized hero slot by plugin assignment.
-- PLUGIN: LevelSelector (Hero Module Slot 4) - JS level slider.
local function renderHeroSlot(slotIndex, rec, ctx)
function PLUGINS.LevelSelector(rec, ctx)
        local pluginName = HERO_SLOT_ASSIGNMENT[slotIndex]
local level = ctx.level or 1
        if not pluginName then
local maxLevel = ctx.maxLevel or 1
                return nil
        end


        local res = safeCallPlugin(pluginName, rec, ctx)
local inner = mw.html.create("div")
        if not res or isEmptySlotContent(res.inner) then
inner:addClass("sv-level-ui")
                return nil
        end


        return {
inner:tag("div")
                inner = res.inner,
:addClass("sv-level-label")
                classes = res.classes,
:wikitext("Level <span class=\"sv-level-num\">" .. tostring(level) .. "</span> / " .. tostring(maxLevel))
        }
end


----------------------------------------------------------------------
local slider = inner:tag("div"):addClass("sv-level-slider")
-- UI builders
----------------------------------------------------------------------


-- buildHeroSlotsUI: build the standardized 4-row slot grid (2 columns).
if tonumber(maxLevel) and tonumber(maxLevel) > 1 then
local function buildHeroSlotsUI(rec, ctx)
slider:tag("input")
        local grid = mw.html.create("div")
:attr("type", "range")
        grid:addClass("sv-slot-grid")
:attr("min", "1")
 
:attr("max", tostring(maxLevel))
        local slots = {}
:attr("value", tostring(level))
        for slot = 1, 8 do
:addClass("sv-level-range")
                slots[slot] = renderHeroSlot(slot, rec, ctx)
:attr("aria-label", "Skill level select")
        end
else
inner:addClass("sv-level-ui-single")
slider:addClass("sv-level-slider-single")
end


        local hasSlots = false
return {
        for _, pair in ipairs({ { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 } }) do
inner = tostring(inner),
                local left  = slots[pair[1]]
classes = "module-level-selector",
                local right = slots[pair[2]]
}
end


                if left or right then
----------------------------------------------------------------------
                        hasSlots = true
-- Generic slot renderers
----------------------------------------------------------------------


                        if left and right then
-- normalizeResult: normalize plugin return values into {inner, classes}.
                                grid:wikitext(slotBox(pair[1], left.classes, left.inner, { isEmpty = false }))
local function normalizeResult(res)
                                grid:wikitext(slotBox(pair[2], right.classes, right.inner, { isEmpty = false }))
if res == nil then return nil end
                        elseif left then
if type(res) == "string" then
                                grid:wikitext(slotBox(pair[1], left.classes, left.inner, { isFull = true }))
return { inner = res, classes = nil }
                        elseif right then
end
                                grid:wikitext(slotBox(pair[2], right.classes, right.inner, { isFull = true }))
if type(res) == "table" then
                        end
local inner = res.inner
                end
if type(inner) ~= "string" then
        end
inner = (inner ~= nil) and tostring(inner) or ""
 
end
        if not hasSlots then
return { inner = inner, classes = res.classes }
                return ""
end
        end
return { inner = tostring(res), classes = nil }
 
        return tostring(grid)
end
end


-- addHeroSlotsRow: add the standardized slot grid into the infobox table.
-- safeCallPlugin: pcall wrapper to prevent infobox failure on plugin errors.
local function addHeroSlotsRow(tbl, slotsUI)
local function safeCallPlugin(name, rec, ctx)
         if not slotsUI or slotsUI == "" then
        local fn = PLUGINS[name]
                 return
         if type(fn) ~= "function" then
                 return nil
        end
        local ok, out = pcall(fn, rec, ctx)
        if not ok then
                return nil
         end
         end
 
         return normalizeResult(out)
         local row = tbl:tag("tr")
        row:addClass("sv-slot-row")
 
        local cell = row:tag("td")
        cell:attr("colspan", 2)
        cell:addClass("sv-slot-cell")
        cell:wikitext(slotsUI)
end
end


----------------------------------------------------------------------
-- isEmptySlotContent: true when a slot has no meaningful content.
-- Infobox builder
-- NOTE: JS placeholders (sv-dyn spans, slider markup) are considered content.
----------------------------------------------------------------------
local function isEmptySlotContent(inner)
        if inner == nil then return true end


-- buildInfobox: render a single skill infobox.
        local raw = tostring(inner)
local function buildInfobox(rec, opts)
opts = opts or {}
local showUsers = (opts.showUsers ~= false)


local maxLevel = tonumber(rec["Max Level"]) or 1
        -- Guard rails for JS-injected regions.
if maxLevel < 1 then maxLevel = 1 end
        for _, pat in ipairs({ "sv%-dyn", "data%-series", "sv%-level%-range", "sv%-level%-slider", "sv%-level%-ui" }) do
local level = clamp(maxLevel, 1, maxLevel)
                if mw.ustring.find(raw, pat) then
                        return false
                end
        end
 
        local trimmed = mw.text.trim(raw)
        if trimmed == "" or trimmed == "—" then
                return true
        end


local ctx = {
        local withoutTags = mw.text.trim(mw.ustring.gsub(trimmed, "<[^>]+>", ""))
maxLevel = maxLevel,
        return (withoutTags == "" or withoutTags == "—")
level = level,
end
nonDamaging = false,
promo = nil,
}


-- Non-damaging hides Damage/Element/Hits in SkillType
-- renderHeroSlot: render a standardized hero slot by plugin assignment.
do
local function renderHeroSlot(slotIndex, rec, ctx)
local dmgVal = nil
        local pluginName = HERO_SLOT_ASSIGNMENT[slotIndex]
if type(rec.Type) == "table" then
        if not pluginName then
dmgVal = rec.Type.Damage or rec.Type["Damage Type"]
                return nil
if type(dmgVal) == "table" then
        end
dmgVal = dmgVal.Name or dmgVal.ID or dmgVal.Value
end
end
ctx.nonDamaging = isNoneLike(dmgVal) or (not skillHasAnyDamage(rec, maxLevel))
end


ctx.promo = computeDurationPromotion(rec, maxLevel)
        local res = safeCallPlugin(pluginName, rec, ctx)
        if not res or isEmptySlotContent(res.inner) then
                return nil
        end


local root = mw.html.create("table")
        return {
root:addClass("spiritvale-skill-infobox")
                inner = res.inner,
root:addClass("sv-skill-card")
                classes = res.classes,
root:attr("data-max-level", tostring(maxLevel))
        }
root:attr("data-level", tostring(level))
end


if opts.inList then
----------------------------------------------------------------------
root:addClass("sv-skill-inlist")
-- UI builders
end
----------------------------------------------------------------------


local internalId = trim(rec["Internal Name"] or rec.InternalID or rec.ID)
-- buildHeroSlotsUI: build the standardized 4-row slot grid (2 columns).
if internalId then
local function buildHeroSlotsUI(rec, ctx)
root:attr("data-skill-id", internalId)
        local grid = mw.html.create("div")
end
        grid:addClass("sv-slot-grid")


-- Standardized slot grid
        local slots = {}
addHeroSlotsRow(root, buildHeroSlotsUI(rec, ctx))
        for slot = 1, 8 do
                slots[slot] = renderHeroSlot(slot, rec, ctx)
        end


-- Users (hide on direct skill page)
        local hasSlots = false
if showUsers then
        for _, pair in ipairs({ { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 } }) do
local users = rec.Users or {}
                local left  = slots[pair[1]]
addRow(root, "Classes",  listToText(users.Classes), "sv-row-users", "Users.Classes")
                local right = slots[pair[2]]
addRow(root, "Summons", listToText(users.Summons), "sv-row-users", "Users.Summons")
addRow(root, "Monsters", listToText(users.Monsters), "sv-row-users", "Users.Monsters")
addRow(root, "Events",  listToText(users.Events),  "sv-row-users", "Users.Events")
end


-- Requirements
                if left or right then
local req = rec.Requirements or {}
                        hasSlots = true
local hasReq =
(type(req["Required Skills"]) == "table" and #req["Required Skills"] > 0) or
(type(req["Required Weapons"]) == "table" and #req["Required Weapons"] > 0) or
(type(req["Required Stances"]) == "table" and #req["Required Stances"] > 0)


if hasReq then
                        if left and right then
if type(req["Required Skills"]) == "table" and #req["Required Skills"] > 0 then
                                grid:wikitext(slotBox(pair[1], left.classes, left.inner, { isEmpty = false }))
local skillParts = {}
                                grid:wikitext(slotBox(pair[2], right.classes, right.inner, { isEmpty = false }))
for _, rs in ipairs(req["Required Skills"]) do
                        elseif left then
local nameReq = rs["Skill External Name"] or rs["Skill Internal Name"] or "Unknown"
                                grid:wikitext(slotBox(pair[1], left.classes, left.inner, { isFull = true }))
local lvlReq  = rs["Required Level"]
                        elseif right then
if lvlReq then
                                grid:wikitext(slotBox(pair[2], right.classes, right.inner, { isFull = true }))
table.insert(skillParts, string.format("%s (Lv.%s)", nameReq, lvlReq))
                        end
else
                end
table.insert(skillParts, nameReq)
        end
end
end
addRow(root, "Required Skills", table.concat(skillParts, ", "), "sv-row-req", "Requirements.Required Skills")
end


addRow(root, "Required Weapons", listToText(req["Required Weapons"]), "sv-row-req", "Requirements.Required Weapons")
        if not hasSlots then
addRow(root, "Required Stances", listToText(req["Required Stances"]), "sv-row-req", "Requirements.Required Stances")
                return ""
end
        end


-- Mechanics (keep small extras only)
        return tostring(grid)
local mech = rec.Mechanics or {}
end
if next(mech) ~= nil then
if mech["Autocast Multiplier"] ~= nil then
addRow(root, "Autocast Multiplier", tostring(mech["Autocast Multiplier"]), "sv-row-mech", "Mechanics.Autocast Multiplier")
end
end


-- Legacy damage breakdown (only when Source absent)
-- addHeroSlotsRow: add the standardized slot grid into the infobox table.
if type(rec.Source) ~= "table" then
local function addHeroSlotsRow(tbl, slotsUI)
local dmg = rec.Damage or {}
        if not slotsUI or slotsUI == "" then
if next(dmg) ~= nil then
                return
local main = dmg["Main Damage"]
        end
local mainNonHeal, healOnly = {}, {}
 
 
        local row = tbl:tag("tr")
if type(main) == "table" then
        row:addClass("sv-slot-row")
for _, d in ipairs(main) do
 
if type(d) == "table" and d.Type == "Healing" then
        local cell = row:tag("td")
table.insert(healOnly, d)
        cell:attr("colspan", 2)
else
        cell:addClass("sv-slot-cell")
table.insert(mainNonHeal, d)
        cell:wikitext(slotsUI)
end
end
end
 
end
----------------------------------------------------------------------
 
-- Infobox builder
addRow(root, "Main Damage",    formatDamageList(mainNonHeal, maxLevel, level, (#mainNonHeal > 1)), "sv-row-source", "Damage.Main Damage")
----------------------------------------------------------------------
addRow(root, "Flat Damage",    formatDamageList(dmg["Flat Damage"], maxLevel, level, false),        "sv-row-source", "Damage.Flat Damage")
 
addRow(root, "Reflect Damage", formatDamageList(dmg["Reflect Damage"], maxLevel, level, false),    "sv-row-source", "Damage.Reflect Damage")
-- buildInfobox: render a single skill infobox.
addRow(root, "Healing",        formatDamageList(healOnly, maxLevel, level, false),                  "sv-row-source", "Damage.Healing")
local function buildInfobox(rec, opts)
end
opts = opts or {}
end
local showUsers = (opts.showUsers ~= false)
 
 
-- Status rows
local maxLevel = tonumber(rec["Max Level"]) or 1
local function formatStatusApplications(list, suppressDurationIndex)
if maxLevel < 1 then maxLevel = 1 end
local level = clamp(maxLevel, 1, maxLevel)
 
local ctx = {
maxLevel = maxLevel,
level = level,
nonDamaging = false,
promo = nil,
}
 
-- Non-damaging hides Damage/Element/Hits in SkillType
do
local dmgVal = nil
if type(rec.Type) == "table" then
dmgVal = rec.Type.Damage or rec.Type["Damage Type"]
if type(dmgVal) == "table" then
dmgVal = dmgVal.Name or dmgVal.ID or dmgVal.Value
end
end
ctx.nonDamaging = isNoneLike(dmgVal) or (not skillHasAnyDamage(rec, maxLevel))
end
 
ctx.promo = computeDurationPromotion(rec, maxLevel)
 
local root = mw.html.create("table")
root:addClass("spiritvale-skill-infobox")
root:addClass("sv-skill-card")
root:attr("data-max-level", tostring(maxLevel))
root:attr("data-level", tostring(level))
 
if opts.inList then
root:addClass("sv-skill-inlist")
end
 
local internalId = trim(rec["Internal Name"] or rec.InternalID or rec.ID)
if internalId then
root:attr("data-skill-id", internalId)
end
 
-- Standardized slot grid
addHeroSlotsRow(root, buildHeroSlotsUI(rec, ctx))
 
-- Users (hide on direct skill page)
        if showUsers then
                local users = rec.Users or {}
                addRow(root, "Classes",  listToText(users.Classes),  "sv-row-users", "Users.Classes")
                addRow(root, "Summons",  listToText(users.Summons),  "sv-row-users", "Users.Summons")
                addRow(root, "Monsters", listToText(users.Monsters), "sv-row-users", "Users.Monsters")
                do
                        local eventsList = {}
                        if type(users.Events) == "table" then
                                for _, ev in ipairs(users.Events) do
                                        local name = resolveEventName(ev) or ev
                                        if name ~= nil then
                                                table.insert(eventsList, mw.text.nowiki(tostring(name)))
                                        end
                                end
                        end
                        addRow(root, "Events", listToText(eventsList), "sv-row-users", "Users.Events")
                end
        end
 
        -- Mechanics (keep small extras only)
        local mech = rec.Mechanics or {}
        if next(mech) ~= nil then
                if mech["Autocast Multiplier"] ~= nil then
                        addRow(root, "Autocast Multiplier", tostring(mech["Autocast Multiplier"]), "sv-row-mech", "Mechanics.Autocast Multiplier")
                end
        end
 
-- Legacy damage breakdown (only when Source absent)
if type(rec.Source) ~= "table" then
local dmg = rec.Damage or {}
if next(dmg) ~= nil then
local main = dmg["Main Damage"]
local mainNonHeal, healOnly = {}, {}
 
if type(main) == "table" then
for _, d in ipairs(main) do
if type(d) == "table" and d.Type == "Healing" then
table.insert(healOnly, d)
else
table.insert(mainNonHeal, d)
end
end
end
 
addRow(root, "Main Damage",    formatDamageList(mainNonHeal, maxLevel, level, (#mainNonHeal > 1)), "sv-row-source", "Damage.Main Damage")
addRow(root, "Flat Damage",    formatDamageList(dmg["Flat Damage"], maxLevel, level, false),        "sv-row-source", "Damage.Flat Damage")
addRow(root, "Reflect Damage", formatDamageList(dmg["Reflect Damage"], maxLevel, level, false),    "sv-row-source", "Damage.Reflect Damage")
addRow(root, "Healing",        formatDamageList(healOnly, maxLevel, level, false),                  "sv-row-source", "Damage.Healing")
end
end
 
-- Status rows
local function formatStatusApplications(list, suppressDurationIndex)
if type(list) ~= "table" or #list == 0 then return nil end
 
local parts = {}
for idx, s in ipairs(list) do
if type(s) == "table" then
local typ  = s.Type or s.Scope or "Target"
local name = s["Status External Name"] or s["Status Internal Name"] or "Unknown status"
local seg = tostring(typ) .. " – " .. tostring(name)
local detail = {}
 
if idx ~= suppressDurationIndex and type(s.Duration) == "table" then
local t = valuePairDynamicValueOnly(s.Duration, maxLevel, level)
if t then table.insert(detail, "Duration: " .. t) end
end
 
if type(s.Chance) == "table" then
local t = valuePairDynamicValueOnly(s.Chance, maxLevel, level)
if t then table.insert(detail, "Chance: " .. t) end
end
 
if #detail > 0 then
seg = seg .. " (" .. table.concat(detail, ", ") .. ")"
end
 
table.insert(parts, seg)
end
end
 
return (#parts > 0) and table.concat(parts, "<br />") or nil
end
 
local function formatStatusRemoval(list)
if type(list) ~= "table" or #list == 0 then return nil end
if type(list) ~= "table" or #list == 0 then return nil end


local parts = {}
local parts = {}
for idx, s in ipairs(list) do
for _, r in ipairs(list) do
if type(s) == "table" then
if type(r) == "table" then
local typ  = s.Type or s.Scope or "Target"
local names = r["Status External Name"]
local name = s["Status External Name"] or s["Status Internal Name"] or "Unknown status"
local label
local seg = tostring(typ) .. " " .. tostring(name)
 
local detail = {}
if type(names) == "table" then
 
label = table.concat(names, ", ")
if idx ~= suppressDurationIndex and type(s.Duration) == "table" then
elseif type(names) == "string" then
local t = valuePairDynamicValueOnly(s.Duration, maxLevel, level)
label = names
if t then table.insert(detail, "Duration: " .. t) end
else
label = "Status"
end
end


if type(s.Chance) == "table" then
local amt = valuePairRawText(r)
local t = valuePairDynamicValueOnly(s.Chance, maxLevel, level)
amt = amt and mw.text.nowiki(amt) or nil
if t then table.insert(detail, "Chance: " .. t) end
end


if #detail > 0 then
local seg = mw.text.nowiki(label)
seg = seg .. " (" .. table.concat(detail, ", ") .. ")"
if amt then
seg = seg .. " " .. amt
end
end
table.insert(parts, seg)
table.insert(parts, seg)
end
end
Line 1,833: Line 2,066:
end
end


local function formatStatusRemoval(list)
local suppressIdx = (type(ctx.promo) == "table") and ctx.promo.suppressDurationIndex or nil
if type(list) ~= "table" or #list == 0 then return nil end
local statusApps = formatStatusApplications(rec["Status Applications"], suppressIdx)
local statusRem  = formatStatusRemoval(rec["Status Removal"])
if statusApps or statusRem then
addRow(root, "Applies", statusApps, "sv-row-status", "Status Applications")
addRow(root, "Removes", statusRem,  "sv-row-status", "Status Removal")
end


local parts = {}
        -- Events
for _, r in ipairs(list) do
        local function formatEvents(list)
if type(r) == "table" then
                if type(list) ~= "table" or #list == 0 then return nil end
local names = r["Status External Name"]
                local parts = {}
local label
                for _, ev in ipairs(list) do
 
                        if type(ev) == "table" then
if type(names) == "table" then
                                local action = resolveDisplayName(ev.Action, "event") or ev.Action or "On event"
label = table.concat(names, ", ")
                                local name  = resolveSkillNameFromEvent(ev)
elseif type(names) == "string" then
                                table.insert(parts, string.format("%s → %s", mw.text.nowiki(action), mw.text.nowiki(name)))
label = names
                        end
else
                end
label = "Status"
                return (#parts > 0) and table.concat(parts, "<br />") or nil
end
        end
 
local amt = valuePairRawText(r)
amt = amt and mw.text.nowiki(amt) or nil
 
local seg = mw.text.nowiki(label)
if amt then
seg = seg .. " – " .. amt
end
table.insert(parts, seg)
end
end
 
return (#parts > 0) and table.concat(parts, "<br />") or nil
end
 
local suppressIdx = (type(ctx.promo) == "table") and ctx.promo.suppressDurationIndex or nil
local statusApps = formatStatusApplications(rec["Status Applications"], suppressIdx)
local statusRem  = formatStatusRemoval(rec["Status Removal"])
if statusApps or statusRem then
addRow(root, "Applies", statusApps, "sv-row-status", "Status Applications")
addRow(root, "Removes", statusRem,  "sv-row-status", "Status Removal")
end
 
-- Events
local function formatEvents(list)
if type(list) ~= "table" or #list == 0 then return nil end
local parts = {}
for _, ev in ipairs(list) do
if type(ev) == "table" then
local action = ev.Action or "On event"
local name  = ev["Skill Internal Name"] or ev["Skill External Name"] or "Unknown skill"
table.insert(parts, string.format("%s → %s", action, name))
end
end
return (#parts > 0) and table.concat(parts, "<br />") or nil
end


local eventsText = formatEvents(rec.Events)
local eventsText = formatEvents(rec.Events)
Line 1,891: Line 2,093:
end
end


-- Notes
return tostring(root)
if type(rec.Notes) == "table" and #rec.Notes > 0 then
addRow(root, "Notes", table.concat(rec.Notes, "<br />"), "sv-row-meta", "Notes")
end
 
return tostring(root)
end
end