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
 
(19 intermediate revisions by the same user not shown)
Line 3: Line 3:
-- Phase 6.5+ (Plug-in Slot Architecture)
-- Phase 6.5+ (Plug-in Slot Architecture)
--
--
-- Standard Hero Layout:
-- Layout:
--  1) hero-title-bar        (TOP BAR, 2 slots: herobar 1..2)
--  Row 1: Slot 1 + Slot 2 (Icon + SkillType)
--  2) hero-description-bar  (description strip)
--  Row 2: Slot 3 + Slot 4 (Description + Placeholder)
--  3) hero-modules row      (4 slots: hero-module-1..4)
--   Row 3: Slot 5 + Slot 6 (SourceType + QuickStats)
--  Row 4: Slot 7 + Slot 8 (SpecialMechanics + LevelSelector)
--
--
-- Requires Common.js:
-- Requires Common.js:
Line 22: Line 23:


local skillsCache
local skillsCache
local eventsCache


-- 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 34: Line 49:
----------------------------------------------------------------------
----------------------------------------------------------------------


-- getArgs: read args from parent frame when invoked from a template.
local function getArgs(frame)
local function getArgs(frame)
local parent = frame:getParent()
local parent = frame:getParent()
Line 39: Line 55:
end
end


-- trim: normalize strings (nil if empty).
local function trim(s)
local function trim(s)
if type(s) ~= "string" then
if type(s) ~= "string" then
Line 47: Line 64:
end
end


-- toNum: convert common scalar/table forms to a Lua number.
local function toNum(v)
local function toNum(v)
if type(v) == "number" then
if type(v) == "number" then
Line 60: Line 78:
end
end


-- clamp: clamp a number into [lo, hi].
local function clamp(n, lo, hi)
local function clamp(n, lo, hi)
if type(n) ~= "number" then
if type(n) ~= "number" then
Line 69: Line 88:
end
end


-- fmtNum: consistent number formatting (trim trailing zeros).
local function fmtNum(n)
local function fmtNum(n)
if type(n) ~= "number" then
if type(n) ~= "number" then
Line 84: Line 104:
end
end


-- 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
 
local function resolveDisplayName(v, kind)
        if v == nil then return nil end
 
        local function firstString(keys, source)
                for _, key in ipairs(keys) do
                        local candidate = source[key]
                        if type(candidate) == "string" and candidate ~= "" then
                                return candidate
                        end
                end
                return nil
        end
 
        if type(v) == "table" then
                local primaryKeys = { "External Name", "Display Name", "Name" }
                local extendedKeys = { "Skill External Name", "Status External Name" }
                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
 
local function resolveEventName(v)
        local resolved = resolveDisplayName(v, "event")
        if type(resolved) == "string" then
                return resolved
        end
        return (resolved ~= nil) and tostring(resolved) or nil
end
 
local function resolveSkillNameFromEvent(ev)
        if type(ev) ~= "table" then
                return resolveDisplayName(ev, "skill") or "Unknown skill"
        end
 
        local displayKeys = {
                "Skill External Name",
                "External Name",
                "Display Name",
                "Name",
                "Skill Name",
        }
 
        for _, key in ipairs(displayKeys) do
                local candidate = resolveDisplayName(ev[key], "skill")
                if candidate then
                        return candidate
                end
        end
 
        local internalKeys = {
                "Skill Internal Name",
                "Skill ID",
                "Internal Name",
                "Internal ID",
                "ID",
        }
 
        for _, key in ipairs(internalKeys) do
                local candidate = ev[key]
                if type(candidate) == "string" and candidate ~= "" then
                        return candidate
                end
        end
 
        return "Unknown skill"
end
end


-- isNoneLike: treat common "none" spellings as empty.
local function isNoneLike(v)
local function isNoneLike(v)
if v == nil then return true end
if v == nil then return true end
Line 99: Line 207:
end
end


-- addRow: add a standard <tr><th>Label</th><td>Value</td></tr> row.
local function addRow(tbl, label, value, rowClass, dataKey)
local function addRow(tbl, label, value, rowClass, dataKey)
if value == nil or value == "" then
if value == nil or value == "" then
Line 113: Line 222:
end
end


-- { Value, Unit } or scalar
-- formatUnitValue: format {Value, Unit} blocks (or scalar) for display.
local function formatUnitValue(v)
local function formatUnitValue(v)
if type(v) == "table" and v.Value ~= nil then
if type(v) == "table" and v.Value ~= nil then
Line 141: Line 250:
----------------------------------------------------------------------
----------------------------------------------------------------------


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


-- isFlatList: true if all values in list are identical.
local function isFlatList(list)
local function isFlatList(list)
if type(list) ~= "table" or #list == 0 then
if type(list) ~= "table" or #list == 0 then
Line 169: Line 280:
end
end


-- isNonZeroScalar: detect if a value is present and not effectively zero.
local function isNonZeroScalar(v)
local function isNonZeroScalar(v)
if v == nil then return false end
if v == nil then return false end
Line 183: Line 295:
end
end


-- isZeroish: aggressively treat common “zero” text forms as zero.
local function isZeroish(v)
local function isZeroish(v)
if v == nil then return true end
if v == nil then return true end
Line 201: Line 314:
end
end


-- valuePairRawText: render Base/Per Level blocks into readable text (fallback).
local function valuePairRawText(block)
local function valuePairRawText(block)
if type(block) ~= "table" then
if type(block) ~= "table" then
Line 234: Line 348:
end
end


-- valuePairDynamicValueOnly: render Base/Per Level blocks using dyn spans where possible.
local function valuePairDynamicValueOnly(block, maxLevel, level)
local function valuePairDynamicValueOnly(block, maxLevel, level)
if type(block) ~= "table" then
if type(block) ~= "table" then
Line 269: Line 384:
----------------------------------------------------------------------
----------------------------------------------------------------------


-- getSkillById: locate a skill by internal ID.
local function getSkillById(id)
local function getSkillById(id)
id = trim(id)
id = trim(id)
Line 276: Line 392:
end
end


-- findSkillByName: locate a skill by external/display name.
local function findSkillByName(name)
local function findSkillByName(name)
name = trim(name)
name = trim(name)
Line 302: Line 419:
----------------------------------------------------------------------
----------------------------------------------------------------------


-- basisLabel: label ATK/MATK basis in legacy damage blocks.
local function basisLabel(entry, isHealing)
local function basisLabel(entry, isHealing)
if isHealing then
if isHealing then
Line 321: Line 439:
end
end


-- formatDamageEntry: legacy percent damage formatting (dynamic by level).
local function formatDamageEntry(entry, maxLevel, level)
local function formatDamageEntry(entry, maxLevel, level)
if type(entry) ~= "table" then
if type(entry) ~= "table" then
Line 372: Line 491:
end
end


-- formatDamageList: render a list of legacy damage entries into <br/> blocks.
local function formatDamageList(list, maxLevel, level, includeTypePrefix)
local function formatDamageList(list, maxLevel, level, includeTypePrefix)
if type(list) ~= "table" or #list == 0 then
if type(list) ~= "table" or #list == 0 then
Line 398: Line 518:
----------------------------------------------------------------------
----------------------------------------------------------------------


-- skillMatchesUser: check if a skill is used by a specific class/monster/summon/event.
local function skillMatchesUser(rec, userName)
local function skillMatchesUser(rec, userName)
if type(rec) ~= "table" or not userName or userName == "" then
if type(rec) ~= "table" or not userName or userName == "" then
Line 429: Line 550:
----------------------------------------------------------------------
----------------------------------------------------------------------


-- isDirectSkillPage: hide Users rows when viewing the skill page itself.
local function isDirectSkillPage(rec)
local function isDirectSkillPage(rec)
if type(rec) ~= "table" then
if type(rec) ~= "table" then
Line 453: Line 575:
----------------------------------------------------------------------
----------------------------------------------------------------------


local HERO_BAR_SLOT_ASSIGNMENT = {
local HERO_SLOT_ASSIGNMENT = {
[1] = "IconName",
[1] = "IconName",
[2] = "SkillType",
[2] = "Description",
}
[3] = "LevelSelector",
 
[4] = "SkillType",
local HERO_MODULE_SLOT_ASSIGNMENT = {
[5] = "SourceType",
[1] = "SourceType",
[6] = "QuickStats",
[2] = "QuickStats",
[7] = "SpecialMechanics",
[3] = "SpecialMechanics",
[8] = "Placeholder",
[4] = "LevelSelector",
}
}


Line 469: Line 590:
----------------------------------------------------------------------
----------------------------------------------------------------------


local function heroBarBox(slot, extraClasses, innerHtml, isEmpty)
-- slotBox: standardized wrapper for all hero card slots.
local function slotBox(slot, extraClasses, innerHtml, opts)
opts = opts or {}
 
local box = mw.html.create("div")
local box = mw.html.create("div")
box:addClass("hero-bar-module")
box:addClass("sv-slot")
box:addClass("hero-bar-module-" .. tostring(slot))
box:addClass("sv-slot--" .. tostring(slot))
box:attr("data-hero-bar-module", tostring(slot))
box:attr("data-hero-slot", tostring(slot))
 
if slot == 2 then
box:addClass("sv-herobar-compact")
end
 
if extraClasses then
if type(extraClasses) == "string" then
box:addClass(extraClasses)
elseif type(extraClasses) == "table" then
for _, c in ipairs(extraClasses) do box:addClass(c) end
end
end
 
if isEmpty then
box:addClass("hero-bar-module-empty")
end


local body = box:tag("div"):addClass("hero-bar-module-body")
if opts.isFull then
if innerHtml and innerHtml ~= "" then
box:addClass("sv-slot--full")
body:wikitext(innerHtml)
end
end
return tostring(box)
end
local function moduleBox(slot, extraClasses, innerHtml, isEmpty)
local box = mw.html.create("div")
box:addClass("hero-module")
box:addClass("hero-module-" .. tostring(slot))
box:attr("data-hero-module", tostring(slot))


if extraClasses then
if extraClasses then
Line 513: Line 611:
end
end


if isEmpty then
if opts.isEmpty then
box:addClass("hero-module-empty")
box:addClass("sv-slot--empty")
end
end


local body = box:tag("div"):addClass("hero-module-body")
local body = box:tag("div"):addClass("sv-slot__body")
if innerHtml and innerHtml ~= "" then
if innerHtml and innerHtml ~= "" then
body:wikitext(innerHtml)
body:wikitext(innerHtml)
Line 529: Line 627:
----------------------------------------------------------------------
----------------------------------------------------------------------


-- formatScalingCompactLines: build compact “Scaling” lines for SourceType.
local function formatScalingCompactLines(scaling)
local function formatScalingCompactLines(scaling)
if type(scaling) ~= "table" then
if type(scaling) ~= "table" then
Line 561: Line 660:
end
end


-- basisWordFromFlags: compute “Attack/Magic/Hybrid” from ATK/MATK booleans.
local function basisWordFromFlags(atkFlag, matkFlag)
local function basisWordFromFlags(atkFlag, matkFlag)
if atkFlag and matkFlag then
if atkFlag and matkFlag then
Line 572: Line 672:
end
end


-- legacyPercentAtLevel: compute “Base% + PerLevel%*level” for legacy entries.
local function legacyPercentAtLevel(entry, level)
local function legacyPercentAtLevel(entry, level)
if type(entry) ~= "table" then
if type(entry) ~= "table" then
Line 597: Line 698:
end
end


-- seriesFromValuePair: normalize Base/Per Level blocks into a level-indexed series.
local function seriesFromValuePair(block, maxLevel)
local function seriesFromValuePair(block, maxLevel)
if type(block) ~= "table" then
if type(block) ~= "table" then
Line 677: Line 779:
end
end


-- displayFromSeries: render a series as fixed text or dynSpan (nil if all “—”).
local function displayFromSeries(series, level)
local function displayFromSeries(series, level)
if type(series) ~= "table" or #series == 0 then
if type(series) ~= "table" or #series == 0 then
Line 699: Line 802:
end
end


local function formatAreaSize(area)
-- formatAreaSize: human readable area sizing for QuickStats.
-- Shows: "<Area Size> (<number>)" e.g. "Medium (4)"
local function formatAreaSize(area, maxLevel, level)
if type(area) ~= "table" then
if type(area) ~= "table" then
return nil
return nil
end
end


local raw = area["Area Size"]
-- Helper: pull a number from scalar/unit/valuepair-ish things.
if raw == nil then
local function extractNumber(v)
return nil
if v == nil then return nil end
end
 
local name, num


if type(raw) == "table" then
-- Unit block {Value, Unit}
name = raw.Name or raw.ID or raw.Value
if type(v) == "table" and v.Value ~= nil then
num  = raw.Value
local n = toNum(v.Value)
if raw.Name or raw.ID then
return n
name = raw.Name or raw.ID
end
end
elseif type(raw) == "string" then
name = raw
elseif type(raw) == "number" then
num = raw
end


if num == nil then
-- ValuePair {Base, Per Level} -> prefer Base at current level if series exists
num = toNum(area["Area Value"]) or toNum(area["Area Size Value"]) or toNum(area["Area Number"]) or toNum(area["Area Radius"])
if type(v) == "table" and (v.Base ~= nil or v["Per Level"] ~= nil) then
end
local s = seriesFromValuePair(v, maxLevel or 1)
 
if type(s) == "table" and #s > 0 then
if name ~= nil then
local idx = clamp(level or 1, 1, #s)
local s = mw.text.trim(tostring(name))
local txt = s[idx]
if s == "" or isNoneLike(s) then
if txt and txt ~= "—" then
-- try parse numeric from string (e.g. "4 tiles" -> 4)
local num = tonumber((mw.ustring.gsub(tostring(txt), "[^0-9%.%-]", "")))
return num
end
end
return nil
return nil
end
end
if mw.ustring.find(s, "%(") then
 
return mw.text.nowiki(s)
-- Plain scalar
if type(v) == "number" then return v end
if type(v) == "string" then
local num = tonumber((mw.ustring.gsub(mw.text.trim(v), "[^0-9%.%-]", "")))
return num
end
end
if num ~= nil and num ~= 0 then
 
return mw.text.nowiki(string.format("%s (%s)", s, fmtNum(num)))
return nil
end
 
-- 1) Read Area Size label/name
local rawSize = area["Area Size"]
if rawSize == nil then
return nil
end
 
local sizeName = nil
if type(rawSize) == "table" then
sizeName = rawSize.Name or rawSize.ID or rawSize.Value
elseif type(rawSize) == "string" then
sizeName = rawSize
elseif type(rawSize) == "number" then
-- uncommon; treat as numeric-only label
sizeName = tostring(rawSize)
end
 
sizeName = sizeName and mw.text.trim(tostring(sizeName)) or nil
if not sizeName or sizeName == "" or isNoneLike(sizeName) then
return nil
end
 
-- 2) Find the numeric “exact number” to append
-- Prefer the explicit Area Distance block, then fall back to other known numeric keys.
local num = nil
 
local dist = area["Area Distance"]
if type(dist) == "table" then
-- Prefer Effective Distance if present and non-zero, else Base
num = extractNumber(dist["Effective Distance"]) or extractNumber(dist.Effective) or extractNumber(dist["Effective"])
if not num or num == 0 then
num = extractNumber(dist.Base) or extractNumber(dist["Base"])
end
end
return mw.text.nowiki(s)
end
end


if num ~= nil and num ~= 0 then
if not num or num == 0 then
return mw.text.nowiki(string.format("(%s)", fmtNum(num)))
num =
extractNumber(area["Area Value"]) or
extractNumber(area["Area Size Value"]) or
extractNumber(area["Area Number"]) or
extractNumber(area["Area Radius"])
end
end


return nil
-- 3) Render
-- If size already contains parentheses, assume it already includes the numeric.
if mw.ustring.find(sizeName, "%(") then
return mw.text.nowiki(sizeName)
end
 
if num and num ~= 0 then
return mw.text.nowiki(string.format("%s (%s)", sizeName, fmtNum(num)))
end
 
return mw.text.nowiki(sizeName)
end
end


-- skillHasAnyDamage: determine if a skill has any meaningful damage (for non-damaging rules).
local function skillHasAnyDamage(rec, maxLevel)
local function skillHasAnyDamage(rec, maxLevel)
if type(rec.Source) == "table" then
if type(rec.Source) == "table" then
Line 771: Line 923:
end
end


-- computeDurationPromotion: promote status-duration into QuickStats when a skill is non-damaging.
local function computeDurationPromotion(rec, maxLevel)
local function computeDurationPromotion(rec, maxLevel)
if type(rec) ~= "table" then return nil end
if type(rec) ~= "table" then return nil end
Line 817: Line 970:
local PLUGINS = {}
local PLUGINS = {}


-- Hero Bar Slot 1: Icon + Name
-- PLUGIN: IconName (Hero Bar Slot 1) - icon + name.
function PLUGINS.IconName(rec, ctx)
function PLUGINS.IconName(rec, ctx)
local icon  = rec.Icon
local icon  = rec.Icon
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
 
local reqWeapons = {}
for _, w in ipairs(reqWeaponsRaw) do
local wn = trim(w)
if wn then table.insert(reqWeapons, mw.text.nowiki(wn)) end
end
 
local reqStances = {}
for _, s in ipairs(reqStancesRaw) do
local sn = trim(s)
if sn then table.insert(reqStances, mw.text.nowiki(sn)) end
end
end


wrap:tag("div")
local hasNotes = (#notesList > 0)
:addClass("spiritvale-infobox-title")
local hasReq = (#reqSkills > 0) or (#reqWeapons > 0) or (#reqStances > 0)
:wikitext(title)


return {
inner = tostring(wrap),
classes = "module-herobar-1",
}
end


-- Reserved placeholder (kept for future)
function PLUGINS.ReservedInfo(rec, ctx)
local wrap = mw.html.create("div")
local wrap = mw.html.create("div")
wrap:addClass("sv-herobar-2-wrap")
wrap:addClass("sv-herobar-1-wrap")
return {
wrap:addClass("sv-tip-scope")
inner = tostring(wrap),
classes = "module-herobar-2",
}
end


-- Module: Level Selector
local iconBox = wrap:tag("div")
function PLUGINS.LevelSelector(rec, ctx)
iconBox:addClass("sv-herobar-icon")
local level = ctx.level or 1
local maxLevel = ctx.maxLevel or 1


local inner = mw.html.create("div")
if icon and icon ~= "" then
inner:addClass("sv-level-ui")
iconBox:wikitext(string.format("[[File:%s|80px|link=]]", icon))
end
 
local textBox = wrap:tag("div")
textBox:addClass("sv-herobar-text")


inner:tag("div")
local titleRow = textBox:tag("div")
:addClass("sv-level-label")
titleRow:addClass("sv-herobar-title-row")
:wikitext("Level <span class=\"sv-level-num\">" .. tostring(level) .. "</span> / " .. tostring(maxLevel))


local slider = inner:tag("div"):addClass("sv-level-slider")
local titleBox = titleRow:tag("div")
titleBox:addClass("spiritvale-infobox-title")
titleBox:wikitext(title)


if tonumber(maxLevel) and tonumber(maxLevel) > 1 then
if hasNotes then
slider:tag("input")
local notesBtn = mw.html.create("span")
:attr("type", "range")
notesBtn:addClass("sv-tip-btn sv-tip-btn--notes")
:attr("min", "1")
notesBtn:attr("role", "button")
:attr("max", tostring(maxLevel))
notesBtn:attr("tabindex", "0")
:attr("value", tostring(level))
notesBtn:attr("data-sv-tip", "notes")
:addClass("sv-level-range")
notesBtn:attr("aria-label", "Notes")
:attr("aria-label", "Skill level select")
notesBtn:attr("aria-expanded", "false")
else
notesBtn:tag("span"):addClass("sv-ico sv-ico--info"):attr("aria-hidden", "true"):wikitext("i")
inner:addClass("sv-level-ui-single")
titleRow:node(notesBtn)
slider:addClass("sv-level-slider-single")
end
end


return {
if hasReq then
inner = tostring(inner),
local pillRow = wrap:tag("div")
classes = "module-level-selector",
pillRow:addClass("sv-pill-row")
}
pillRow:addClass("sv-pill-row--req")
end
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


-- Module: Skill Type
if hasNotes then
local notesContent = wrap:tag("div")
notesContent:addClass("sv-tip-content")
notesContent:attr("data-sv-tip-content", "notes")
notesContent:tag("div"):addClass("sv-tip-title"):wikitext("Notes")
notesContent:tag("div"):wikitext(table.concat(notesList, "<br />"))
end
 
if hasReq then
local reqContent = wrap:tag("div")
reqContent:addClass("sv-tip-content")
reqContent:attr("data-sv-tip-content", "req")
 
if #reqSkills > 0 then
local section = reqContent:tag("div")
section:addClass("sv-tip-section")
section:tag("span"):addClass("sv-tip-label"):wikitext("Required Skills")
section:tag("div"):wikitext(table.concat(reqSkills, "<br />"))
end
 
if #reqWeapons > 0 then
local section = reqContent:tag("div")
section:addClass("sv-tip-section")
section:tag("span"):addClass("sv-tip-label"):wikitext("Required Weapons")
section:tag("div"):wikitext(table.concat(reqWeapons, ", "))
end
 
if #reqStances > 0 then
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 {
inner = tostring(wrap),
classes = "module-icon-name",
}
end
 
-- PLUGIN: SkillType (Hero Bar Slot 2) - 2 rows x 3 cells (desktop + mobile).
-- Rules:
--  - 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)
function PLUGINS.SkillType(rec, ctx)
local typeBlock = (type(rec.Type) == "table") and rec.Type or {}
local typeBlock = (type(rec.Type) == "table") and rec.Type or {}
local hideDamageAndElement = (ctx.nonDamaging == true)
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)
-- valName: extract a display string from typical {Name/ID/Value} objects.
-- NOTE: Includes number support so Hits=2 (number) doesn't get dropped.
local function valName(x)
local function valName(x)
if x == nil then return nil end
if x == nil then return nil end
Line 895: Line 1,137:
if x.ID and x.ID ~= "" then return tostring(x.ID) end
if x.ID and x.ID ~= "" then return tostring(x.ID) end
if x.Value ~= nil then return tostring(x.Value) end
if x.Value ~= nil then return tostring(x.Value) end
end
if type(x) == "number" then
return tostring(x)
end
end
if type(x) == "string" and x ~= "" then
if type(x) == "string" and x ~= "" then
Line 902: Line 1,147:
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 =
local function addChunk(label, rawVal)
typeBlock.Hits or typeBlock["Hits"] or typeBlock["Hit Count"] or typeBlock["Hits Count"] or
local v = valName(rawVal)
mech.Hits or mech["Hits"] or mech["Hit Count"] or mech["Hits Count"] or
if not v or v == "" then return end
effects.Hits or effects["Hits"] or effects["Hit Count"] or effects["Hits Count"] or
added = true
rec.Hits or rec["Hits"]


local chunk = grid:tag("div"):addClass("sv-type-chunk")
if h == nil or isNoneLike(h) then
chunk:tag("div"):addClass("sv-type-label"):wikitext(mw.text.nowiki(label))
return nil
chunk:tag("div"):addClass("sv-type-value"):wikitext(mw.text.nowiki(v))
end
end
 
-- ValuePair-style table (Base/Per Level) => dynamic series
if type(h) == "table" then
if h.Base ~= nil or h["Per Level"] ~= nil or type(h["Per Level"]) == "table" then
return displayFromSeries(seriesFromValuePair(h, maxLevel), level)
end


if not hideDamageAndElement then
-- Unit block {Value, Unit}
addChunk("Damage",  typeBlock.Damage  or typeBlock["Damage Type"])
if h.Value ~= nil then
addChunk("Element", typeBlock.Element or typeBlock["Element Type"])
local t = formatUnitValue(h)
end
return t and mw.text.nowiki(t) or nil
end
 
-- Fallback name extraction
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
if type(x) == "number" then return tostring(x) end
if type(x) == "string" and x ~= "" then return x end
return nil
end


addChunk("Target", typeBlock.Target or typeBlock["Target Type"])
local vn = valName(h)
addChunk("Cast",  typeBlock.Cast  or typeBlock["Cast Type"])
if vn and not isNoneLike(vn) then
return mw.text.nowiki(vn)
end
end


return {
-- Scalar number/string
inner = added and tostring(grid) or "",
if type(h) == "number" then
classes = "module-skill-type",
return mw.text.nowiki(fmtNum(h))
}
end
end
if type(h) == "string" then
local t = trim(h)
return (t and not isNoneLike(t)) and mw.text.nowiki(t) or nil
end


-- Module: SourceType (Modifier + Source + Scaling)
return nil
function PLUGINS.SourceType(rec, ctx)
end
local level = ctx.level or 1
local maxLevel = ctx.maxLevel or 1


local basisWord = nil
-- comboDisplay: render Combo as a compact text block (Type (+ details)).
local sourceKind = nil
local function comboDisplay()
local sourceVal  = nil
local c = (type(mech.Combo) == "table") and mech.Combo or nil
local scaling    = nil
if not c then return nil end


local function sourceValueForLevel(src)
local typ = trim(c.Type)
if type(src) ~= "table" then
if not typ or isNoneLike(typ) then
return nil
return nil
end
end


local per = src["Per Level"]
local details = {}
if type(per) == "table" and #per > 0 then
 
if isFlatList(per) then
local pct = formatUnitValue(c.Percent)
local one  = formatUnitValue(per[1]) or tostring(per[1])
if pct and not isZeroish(pct) then
local show = formatUnitValue(src.Base) or one
table.insert(details, mw.text.nowiki(pct))
return show and mw.text.nowiki(show) or nil
end
end


local series = {}
local dur = formatUnitValue(c.Duration)
for _, v in ipairs(per) do
if dur and not isZeroish(dur) then
table.insert(series, formatUnitValue(v) or tostring(v))
table.insert(details, mw.text.nowiki(dur))
end
return dynSpan(series, level)
end
end


return valuePairDynamicValueOnly(src, maxLevel, level)
if #details > 0 then
return mw.text.nowiki(typ) .. " (" .. table.concat(details, ", ") .. ")"
end
return mw.text.nowiki(typ)
end
end


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


sourceKind = src.Type or ((src.Healing == true) and "Healing") or "Damage"
local added = false
sourceVal  = sourceValueForLevel(src)
 
scaling    = src.Scaling
-- addChunk: add one labeled value cell (key drives CSS ordering).
end
local function addChunk(key, label, valueHtml)
if valueHtml == nil or valueHtml == "" then return end
added = true


-- Fallback to legacy Damage lists if Source absent
local chunk = grid:tag("div")
if (sourceVal == nil or sourceVal == "") and type(rec.Damage) == "table" then
:addClass("sv-type-chunk")
local dmg = rec.Damage
:addClass("sv-type-" .. tostring(key))
scaling = scaling or dmg.Scaling
:attr("data-type-key", tostring(key))


local main = dmg["Main Damage"]
chunk:tag("div")
local refl = dmg["Reflect Damage"]
:addClass("sv-type-label")
local flat = dmg["Flat Damage"]
:wikitext(mw.text.nowiki(label))


if type(main) == "table" and #main > 0 then
chunk:tag("div")
local pick = nil
:addClass("sv-type-value")
for _, d in ipairs(main) do
:wikitext(valueHtml)
if type(d) == "table" and d.Type ~= "Healing" then
end
pick = d
break
end
end
pick = pick or main[1]


if type(pick) == "table" then
-- Damage + Element + Hits bundle (hidden when non-damaging)
local atkFlag = (pick["ATK-Based"] == true)
if not hideDamageBundle then
local matkFlag = (pick["MATK-Based"] == true)
local dmg = valName(typeBlock.Damage or typeBlock["Damage Type"])
basisWord = basisWord or basisWordFromFlags(atkFlag, matkFlag)
local ele  = valName(typeBlock.Element or typeBlock["Element Type"])
local hits = hitsDisplay()


sourceKind = (pick.Type == "Healing") and "Healing" or "Damage"
if dmg and not isNoneLike(dmg) then
sourceVal  = legacyPercentAtLevel(pick, level)
addChunk("damage", "Damage", mw.text.nowiki(dmg))
end
end
elseif type(refl) == "table" and #refl > 0 and type(refl[1]) == "table" then
if ele and not isNoneLike(ele) then
local pick = refl[1]
addChunk("element", "Element", mw.text.nowiki(ele))
local atkFlag  = (pick["ATK-Based"] == true)
end
local matkFlag = (pick["MATK-Based"] == true)
if hits then
basisWord = basisWord or basisWordFromFlags(atkFlag, matkFlag)
addChunk("hits", "Hits", hits)
 
sourceKind = "Reflect"
sourceVal  = legacyPercentAtLevel(pick, level)
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)
 
sourceKind = "Flat"
sourceVal  = legacyPercentAtLevel(pick, level)
end
end
end
end


local scalingLines = formatScalingCompactLines(scaling)
-- Target + Cast
local hasSource    = (sourceVal ~= nil and tostring(sourceVal) ~= "")
local tgt = valName(typeBlock.Target or typeBlock["Target Type"])
local hasScaling  = (type(scalingLines) == "table" and #scalingLines > 0)
local cst = valName(typeBlock.Cast  or typeBlock["Cast Type"])


if (not hasSource) and (not hasScaling) then
if tgt and not isNoneLike(tgt) then
return nil
addChunk("target", "Target", mw.text.nowiki(tgt))
end
if cst and not isNoneLike(cst) then
addChunk("cast", "Cast", mw.text.nowiki(cst))
end
end


local hasMod = (basisWord ~= nil and tostring(basisWord) ~= "")
-- Combo
local combo = comboDisplay()
if combo then
addChunk("combo", "Combo", combo)
end


local extra = { "skill-source-module" }
        return {
table.insert(extra, hasMod and "sv-has-mod" or "sv-no-mod")
                inner = added and tostring(grid) or "",
                classes = "module-skill-type",
        }
end


if hasSource and (not hasScaling) then
-- PLUGIN: Description (Hero Slot 3) - primary description text.
table.insert(extra, "sv-only-source")
function PLUGINS.Description(rec)
elseif hasScaling and (not hasSource) then
        local desc = trim(rec.Description)
table.insert(extra, "sv-only-scaling")
        if not desc then
end
                return nil
        end


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


if hasMod then
        return {
local modCol = wrap:tag("div"):addClass("sv-source-col"):addClass("sv-source-modifier")
                inner = tostring(body),
modCol:tag("div"):addClass("sv-source-pill"):wikitext("Modifier")
                classes = "module-description",
modCol:tag("div"):addClass("sv-modifier-value"):wikitext(mw.text.nowiki(basisWord))
        }
end
end


if hasSource then
-- PLUGIN: Placeholder (Hero Slot 4) - reserved/blank.
local sourceCol = wrap:tag("div"):addClass("sv-source-col"):addClass("sv-source-main")
function PLUGINS.Placeholder()
sourceCol:tag("div"):addClass("sv-source-pill"):wikitext(mw.text.nowiki(sourceKind or "Source"))
        return nil
sourceCol:tag("div"):addClass("sv-source-value"):wikitext(sourceVal)
end
end


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 list = scalingCol:tag("div"):addClass("sv-scaling-list")
-- PLUGIN: SourceType (Hero Module Slot 1) - Modifier + Source + Scaling.
for _, line in ipairs(scalingLines) do
function PLUGINS.SourceType(rec, ctx)
list:tag("div"):addClass("sv-scaling-item"):wikitext(mw.text.nowiki(line))
end
end
 
return {
inner = tostring(wrap),
classes = extra,
}
end
 
-- Module: Quick Stats (3x2)
function PLUGINS.QuickStats(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 basisWord = nil
local bt  = (type(mech["Basic Timings"]) == "table") and mech["Basic Timings"] or {}
local sourceKind = nil
local rc  = (type(mech["Resource Cost"]) == "table") and mech["Resource Cost"] or {}
local sourceVal  = nil
local scaling    = nil


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


-- Range (0 => —)
local per = src["Per Level"]
local rangeVal = nil
if type(per) == "table" and #per > 0 then
if mech.Range ~= nil and not isNoneLike(mech.Range) then
if isFlatList(per) then
local n = toNum(mech.Range)
local one  = formatUnitValue(per[1]) or tostring(per[1])
if n ~= nil then
local show = formatUnitValue(src.Base) or one
if n ~= 0 then
return show and mw.text.nowiki(show) or nil
rangeVal = mw.text.nowiki(formatUnitValue(mech.Range) or tostring(mech.Range))
end
end
else
 
local t = mw.text.trim(tostring(mech.Range))
local series = {}
if t ~= "" and not isNoneLike(t) then
for _, v in ipairs(per) do
rangeVal = mw.text.nowiki(t)
table.insert(series, formatUnitValue(v) or tostring(v))
end
end
return dynSpan(series, level)
end
end
return valuePairDynamicValueOnly(src, maxLevel, level)
end
end


-- Area
if type(rec.Source) == "table" then
local areaVal = formatAreaSize(mech.Area)
local src = rec.Source
local atkFlag  = (src["ATK-Based"] == true)
local matkFlag = (src["MATK-Based"] == true)
basisWord = basisWordFromFlags(atkFlag, matkFlag)


-- Timings
sourceKind = src.Type or ((src.Healing == true) and "Healing") or "Damage"
local castVal = displayFromSeries(seriesFromValuePair(bt["Cast Time"], maxLevel), level)
sourceVal = sourceValueForLevel(src)
local cdVal  = displayFromSeries(seriesFromValuePair(bt["Cooldown"],  maxLevel), level)
scaling    = src.Scaling
local durVal  = displayFromSeries(seriesFromValuePair(bt["Duration"], maxLevel), level)
 
-- Promote status duration if needed
if (durVal == nil) and type(promo) == "table" and type(promo.durationBlock) == "table" then
durVal = displayFromSeries(seriesFromValuePair(promo.durationBlock, maxLevel), level)
end
end


-- Cost: MP + HP
-- Fallback to legacy Damage lists if Source absent
local function labeledSeries(block, label)
if (sourceVal == nil or sourceVal == "") and type(rec.Damage) == "table" then
local s = seriesFromValuePair(block, maxLevel)
local dmg = rec.Damage
if not s then return nil end
scaling = scaling or dmg.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


local mpS = labeledSeries(rc["Mana Cost"], "MP")
local main = dmg["Main Damage"]
local hpS = labeledSeries(rc["Health Cost"], "HP")
local refl = dmg["Reflect Damage"]
local flat = dmg["Flat Damage"]


local costSeries = {}
if type(main) == "table" and #main > 0 then
for lv = 1, maxLevel do
local pick = nil
local mp = mpS and mpS[lv] or ""
for _, d in ipairs(main) do
local hp = hpS and hpS[lv] or "—"
if type(d) == "table" and d.Type ~= "Healing" then
pick = d
break
end
end
pick = pick or main[1]


if mp ~= "—" and hp ~= "" then
if type(pick) == "table" then
costSeries[lv] = mp .. " + " .. hp
local atkFlag  = (pick["ATK-Based"] == true)
elseif mp ~= "—" then
local matkFlag = (pick["MATK-Based"] == true)
costSeries[lv] = mp
basisWord = basisWord or basisWordFromFlags(atkFlag, matkFlag)
elseif hp ~= "" then
costSeries[lv] = hp
else
costSeries[lv] = "—"
end
end


local costVal = displayFromSeries(costSeries, level)
sourceKind = (pick.Type == "Healing") and "Healing" or "Damage"
 
sourceVal  = legacyPercentAtLevel(pick, level)
local grid = mw.html.create("div")
end
grid:addClass("sv-m4-grid")
elseif type(refl) == "table" and #refl > 0 and type(refl[1]) == "table" then
grid:addClass("sv-compact-root")
local pick = refl[1]
local atkFlag  = (pick["ATK-Based"] == true)
local matkFlag = (pick["MATK-Based"] == true)
basisWord = basisWord or basisWordFromFlags(atkFlag, matkFlag)
 
sourceKind = "Reflect"
sourceVal  = legacyPercentAtLevel(pick, level)
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 addCell(label, val)
sourceKind = "Flat"
local cell = grid:tag("div"):addClass("sv-m4-cell")
sourceVal  = legacyPercentAtLevel(pick, level)
cell:tag("div"):addClass("sv-m4-label"):wikitext(mw.text.nowiki(label))
end
cell:tag("div"):addClass("sv-m4-value"):wikitext(val or dash())
end
end


addCell("Range",    rangeVal)
local scalingLines = formatScalingCompactLines(scaling)
addCell("Area",      areaVal)
local hasSource    = (sourceVal ~= nil and tostring(sourceVal) ~= "")
addCell("Cost",      costVal)
local hasScaling  = (type(scalingLines) == "table" and #scalingLines > 0)
addCell("Cast Time", castVal)
addCell("Cooldown",  cdVal)
addCell("Duration",  durVal)


return {
if (not hasSource) and (not hasScaling) then
inner = tostring(grid),
return nil
classes = "module-quick-stats",
end
}
end


-- Module: Special Mechanics (Flags + Special Mechanics + Combo)
local hasMod = (basisWord ~= nil and tostring(basisWord) ~= "")
function PLUGINS.SpecialMechanics(rec, ctx)
local level = ctx.level or 1
local maxLevel = ctx.maxLevel or 1


local mech    = (type(rec) == "table" and type(rec.Mechanics) == "table") and rec.Mechanics or {}
local extra = { "skill-source-module", "module-source-type" }
local effects = (type(mech.Effects) == "table") and mech.Effects or nil
table.insert(extra, hasMod and "sv-has-mod" or "sv-no-mod")
local combo  = (type(mech.Combo) == "table") and mech.Combo or nil
local mods    = (type(rec.Modifiers) == "table") and rec.Modifiers or nil


------------------------------------------------------------------
if hasSource and (not hasScaling) then
-- Flags (flat, de-duped)
table.insert(extra, "sv-only-source")
------------------------------------------------------------------
elseif hasScaling and (not hasSource) then
local flagSet = {}
table.insert(extra, "sv-only-scaling")
end


local function addFlags(sub)
local wrap = mw.html.create("div")
if type(sub) ~= "table" then return end
wrap:addClass("sv-source-grid")
for k, v in pairs(sub) do
wrap:addClass("sv-compact-root")
if v then
flagSet[tostring(k)] = true
end
end
end


if mods then
if hasMod then
addFlags(mods["Movement Modifiers"])
local modCol = wrap:tag("div"):addClass("sv-source-col"):addClass("sv-source-modifier")
addFlags(mods["Combat Modifiers"])
modCol:tag("div"):addClass("sv-source-pill"):wikitext("Modifier")
addFlags(mods["Special Modifiers"])
modCol:tag("div"):addClass("sv-modifier-value"):wikitext(mw.text.nowiki(basisWord))
for k, v in pairs(mods) do
if type(v) == "boolean" and v then
flagSet[tostring(k)] = true
end
end
end
end


local flags = {}
if hasSource then
for k, _ in pairs(flagSet) do table.insert(flags, k) end
local sourceCol = wrap:tag("div"):addClass("sv-source-col"):addClass("sv-source-main")
table.sort(flags)
sourceCol:tag("div"):addClass("sv-source-pill"):wikitext(mw.text.nowiki(sourceKind or "Source"))
sourceCol:tag("div"):addClass("sv-source-value"):wikitext(sourceVal)
end


------------------------------------------------------------------
if hasScaling then
-- Special mechanics (name => value)
local scalingCol = wrap:tag("div"):addClass("sv-source-col"):addClass("sv-source-scaling")
------------------------------------------------------------------
scalingCol:tag("div"):addClass("sv-source-pill"):wikitext("Scaling")
local mechItems = {}


if effects then
local list = scalingCol:tag("div"):addClass("sv-scaling-list")
local keys = {}
for _, line in ipairs(scalingLines) do
for k, _ in pairs(effects) do table.insert(keys, k) end
list:tag("div"):addClass("sv-scaling-item"):wikitext(mw.text.nowiki(line))
table.sort(keys)
end
end


for _, name in ipairs(keys) do
return {
local block = effects[name]
inner = tostring(wrap),
if type(block) == "table" then
classes = extra,
local disp = displayFromSeries(seriesFromValuePair(block, maxLevel), level)
}
local t = trim(block.Type)
end
 
local value = disp


-- If Type exists and is distinct, prefix it (keeps your prior intent)
-- PLUGIN: QuickStats (Hero Module Slot 2) - 3x2 grid (range/area/cost/cast/cd/duration).
if t and not isNoneLike(t) and mw.ustring.lower(t) ~= mw.ustring.lower(tostring(name)) then
-- NOTE: Hits does NOT live here (it lives in SkillType).
if value then
function PLUGINS.QuickStats(rec, ctx)
value = mw.text.nowiki(t) .. ": " .. value
local level = ctx.level or 1
else
local maxLevel = ctx.maxLevel or 1
value = mw.text.nowiki(t)
local promo = ctx.promo
end
end


if value then
local mech = (type(rec) == "table" and type(rec.Mechanics) == "table") and rec.Mechanics or {}
table.insert(mechItems, { label = tostring(name), value = value })
local bt  = (type(mech["Basic Timings"]) == "table") and mech["Basic Timings"] or {}
end
local rc  = (type(mech["Resource Cost"]) == "table") and mech["Resource Cost"] or {}
end
end
end


------------------------------------------------------------------
local function dash() return "—" end
-- Combo (its own group, NOT merged into mechanics)
------------------------------------------------------------------
local comboText = nil
if combo then
local typ = trim(combo.Type)
if typ and not isNoneLike(typ) then
local details = {}


local pct = formatUnitValue(combo.Percent)
-- Range (0 => —)
if pct and not isZeroish(pct) then
local rangeVal = nil
table.insert(details, mw.text.nowiki(pct))
if mech.Range ~= nil and not isNoneLike(mech.Range) then
end
local n = toNum(mech.Range)
 
if n ~= nil then
local dur = formatUnitValue(combo.Duration)
if n ~= 0 then
if dur and not isZeroish(dur) then
rangeVal = mw.text.nowiki(formatUnitValue(mech.Range) or tostring(mech.Range))
table.insert(details, mw.text.nowiki(dur))
end
end
 
else
if #details > 0 then
local t = mw.text.trim(tostring(mech.Range))
comboText = mw.text.nowiki(typ) .. " (" .. table.concat(details, ", ") .. ")"
if t ~= "" and not isNoneLike(t) then
else
rangeVal = mw.text.nowiki(t)
comboText = mw.text.nowiki(typ)
end
end
end
end
end
end


local hasFlags = (#flags > 0)
-- Area
local hasMech  = (#mechItems > 0)
local areaVal = formatAreaSize(mech.Area, maxLevel, level)
local hasCombo = (comboText ~= nil and comboText ~= "")


if (not hasFlags) and (not hasMech) and (not hasCombo) then
-- Timings
local root = mw.html.create("div")
local castVal = displayFromSeries(seriesFromValuePair(bt["Cast Time"], maxLevel), level)
root:addClass("sv-sm-root")
local cdVal  = displayFromSeries(seriesFromValuePair(bt["Cooldown"],  maxLevel), level)
root:addClass("sv-compact-root")
local durVal  = displayFromSeries(seriesFromValuePair(bt["Duration"],  maxLevel), level)
root:tag("div"):addClass("sv-sm-empty"):wikitext("No Special Mechanics")


return {
-- Promote status duration if needed
inner = tostring(root),
if (durVal == nil) and type(promo) == "table" and type(promo.durationBlock) == "table" then
classes = "module-special-mechanics",
durVal = displayFromSeries(seriesFromValuePair(promo.durationBlock, maxLevel), level)
}
end
 
-- Cost: MP + HP
local function labeledSeries(block, label)
local s = seriesFromValuePair(block, maxLevel)
if not s then return nil end
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 count = 0
local mpS = labeledSeries(rc["Mana Cost"], "MP")
if hasFlags then count = count + 1 end
local hpS = labeledSeries(rc["Health Cost"], "HP")
if hasMech  then count = count + 1 end
if hasCombo then count = count + 1 end


------------------------------------------------------------------
local costSeries = {}
-- Layout:
for lv = 1, maxLevel do
-- Desktop:
local mp = mpS and mpS[lv] or ""
--  1 group => centered
local hp = hpS and hpS[lv] or ""
--  2 groups => 2 columns (separate)
--  3 groups => 3 columns (flags | mechanics | combo)
-- Mobile CSS collapses per your rules.
------------------------------------------------------------------
local root = mw.html.create("div")
root:addClass("sv-sm-root")
root:addClass("sv-compact-root")


local layout = root:tag("div"):addClass("sv-sm-layout")
if mp ~= "" and hp ~= "" then
layout:addClass("sv-sm-count-" .. tostring(count))
costSeries[lv] = mp .. " + " .. hp
 
elseif mp ~= "—" then
-- Column 1: Flags
costSeries[lv] = mp
if hasFlags then
elseif hp ~= "" then
local fcol = layout:tag("div"):addClass("sv-sm-col"):addClass("sv-sm-col-flags")
costSeries[lv] = hp
for _, f in ipairs(flags) do
else
fcol:tag("div"):addClass("sv-sm-flag"):wikitext(mw.text.nowiki(f))
costSeries[lv] = ""
end
end
end
end


-- Column 2: Special Mechanics (stacked)
local costVal = displayFromSeries(costSeries, level)
if hasMech then
 
local mcol = layout:tag("div"):addClass("sv-sm-col"):addClass("sv-sm-col-mech")
local grid = mw.html.create("div")
for _, it in ipairs(mechItems) do
grid:addClass("sv-m4-grid")
local one = mcol:tag("div"):addClass("sv-sm-mech")
grid:addClass("sv-compact-root")
one:tag("div"):addClass("sv-sm-label"):wikitext(mw.text.nowiki(it.label))
 
one:tag("div"):addClass("sv-sm-value"):wikitext(it.value or "—")
local function addCell(label, val)
end
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


-- Column 3: Combo (always its own column when present on desktop)
addCell("Range",    rangeVal)
if hasCombo then
addCell("Area",      areaVal)
local ccol = layout:tag("div"):addClass("sv-sm-col"):addClass("sv-sm-col-combo")
addCell("Cost",      costVal)
local one = ccol:tag("div"):addClass("sv-sm-mech"):addClass("sv-sm-combo")
addCell("Cast Time", castVal)
one:tag("div"):addClass("sv-sm-label"):wikitext("Combo")
addCell("Cooldown",  cdVal)
one:tag("div"):addClass("sv-sm-value"):wikitext(comboText or "—")
addCell("Duration",  durVal)
end


return {
return {
inner = tostring(root),
inner = tostring(grid),
classes = "module-special-mechanics",
classes = "module-quick-stats",
}
}
end
end


----------------------------------------------------------------------
-- PLUGIN: SpecialMechanics (Hero Module Slot 3)
-- Generic slot renderers
-- 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
 
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 mods    = (type(rec.Modifiers) == "table") and rec.Modifiers or nil


local function normalizeResult(res)
------------------------------------------------------------------
if res == nil then return nil end
-- Hits guard (we want Hits ONLY in SkillType)
if type(res) == "string" then
------------------------------------------------------------------
return { inner = res, classes = nil }
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
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


local function safeCallPlugin(name, rec, ctx)
------------------------------------------------------------------
local fn = PLUGINS[name]
-- Flags (flat, de-duped)
if type(fn) ~= "function" then
------------------------------------------------------------------
return nil
local flagSet = {}
end
local ok, out = pcall(fn, rec, ctx)
if not ok then
return nil
end
return normalizeResult(out)
end


local function renderHeroBarSlot(slotIndex, rec, ctx)
local denyFlags = {
local pluginName = HERO_BAR_SLOT_ASSIGNMENT[slotIndex]
["self centered"] = true,
if not pluginName then
["self-centred"] = true,
return heroBarBox(slotIndex, nil, "", true)
["bond"] = true,
end
["combo"] = true,
        ["hybrid"] = true,


local res = safeCallPlugin(pluginName, rec, ctx)
-- hits variants
if not res or not res.inner or res.inner == "" then
["hit"] = true,
return heroBarBox(slotIndex, nil, "", true)
["hits"] = true,
end
["hit count"] = true,
 
["hits count"] = true,
return heroBarBox(slotIndex, res.classes, res.inner, false)
["hitcount"] = true,
end
["hitscount"] = true,
}


local function renderModuleSlot(slotIndex, rec, ctx)
local function allowFlag(name)
local pluginName = HERO_MODULE_SLOT_ASSIGNMENT[slotIndex]
if not name then return false end
if not pluginName then
local k = mw.ustring.lower(mw.text.trim(tostring(name)))
return moduleBox(slotIndex, nil, "", true)
if k == "" then return false end
if denyFlags[k] then return false end
return true
end
end


local res = safeCallPlugin(pluginName, rec, ctx)
local function addFlags(sub)
if not res or not res.inner or res.inner == "" then
if type(sub) ~= "table" then return end
return moduleBox(slotIndex, nil, "", true)
for k, v in pairs(sub) do
if v and allowFlag(k) then
flagSet[tostring(k)] = true
end
end
end
end


return moduleBox(slotIndex, res.classes, res.inner, false)
if mods then
end
addFlags(mods["Movement Modifiers"])
 
addFlags(mods["Combat Modifiers"])
----------------------------------------------------------------------
addFlags(mods["Special Modifiers"])
-- UI builders
for k, v in pairs(mods) do
----------------------------------------------------------------------
if type(v) == "boolean" and v and allowFlag(k) then
flagSet[tostring(k)] = true
end
end
end


local function buildHeroBarUI(rec, ctx)
local flags = {}
local bar = mw.html.create("div")
for k, _ in pairs(flagSet) do table.insert(flags, k) end
bar:addClass("hero-bar-grid")
table.sort(flags)
bar:wikitext(renderHeroBarSlot(1, rec, ctx))
bar:wikitext(renderHeroBarSlot(2, rec, ctx))
return tostring(bar)
end


local function buildHeroModulesUI(rec, ctx)
------------------------------------------------------------------
local grid = mw.html.create("div")
-- Special mechanics (name => value)
grid:addClass("hero-modules-grid")
------------------------------------------------------------------
for slot = 1, 4 do
local mechItems = {}
grid:wikitext(renderModuleSlot(slot, rec, ctx))
end
return tostring(grid)
end


local function addHeroModulesRow(tbl, modulesUI)
if effects then
if not modulesUI or modulesUI == "" then
local keys = {}
return
for k, _ in pairs(effects) do table.insert(keys, k) end
end
table.sort(keys)


local row = tbl:tag("tr")
for _, name in ipairs(keys) do
row:addClass("hero-modules-row")
-- 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)


local cell = row:tag("td")
local value = disp
cell:attr("colspan", 2)
 
cell:addClass("hero-modules-cell")
-- If Type exists and is distinct, prefix it.
cell:wikitext(modulesUI)
if t and not isNoneLike(t) and mw.ustring.lower(t) ~= mw.ustring.lower(tostring(name)) then
end
if value then
value = mw.text.nowiki(t) .. ": " .. value
else
value = mw.text.nowiki(t)
end
end


----------------------------------------------------------------------
if value then
-- Infobox builder
table.insert(mechItems, { label = tostring(name), value = value })
----------------------------------------------------------------------
end
end
end
end
end
end


local function buildInfobox(rec, opts)
local hasFlags = (#flags > 0)
opts = opts or {}
local hasMech  = (#mechItems > 0)
local showUsers = (opts.showUsers ~= false)


local maxLevel = tonumber(rec["Max Level"]) or 1
if (not hasFlags) and (not hasMech) then
if maxLevel < 1 then maxLevel = 1 end
local root = mw.html.create("div")
local level = clamp(maxLevel, 1, maxLevel)
root:addClass("sv-sm-root")
root:addClass("sv-compact-root")
root:tag("div"):addClass("sv-sm-empty"):wikitext("No Special Mechanics")


local ctx = {
return {
maxLevel = maxLevel,
inner = tostring(root),
level = level,
classes = "module-special-mechanics",
nonDamaging = false,
}
promo = nil,
}
 
-- Non-damaging hides Damage/Element 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
end


ctx.promo = computeDurationPromotion(rec, maxLevel)
local count = 0
if hasFlags then count = count + 1 end
if hasMech  then count = count + 1 end


local root = mw.html.create("table")
local root = mw.html.create("div")
root:addClass("spiritvale-skill-infobox")
root:addClass("sv-sm-root")
root:addClass("sv-skill-card")
root:addClass("sv-compact-root")
root:attr("data-max-level", tostring(maxLevel))
 
root:attr("data-level", tostring(level))
local layout = root:tag("div"):addClass("sv-sm-layout")
layout:addClass("sv-sm-count-" .. tostring(count))


if opts.inList then
-- Column 1: Flags
root:addClass("sv-skill-inlist")
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


local internalId = trim(rec["Internal Name"] or rec.InternalID or rec.ID)
-- Column 2: Special Mechanics (stacked)
if internalId then
if hasMech then
root:attr("data-skill-id", internalId)
local mcol = layout:tag("div"):addClass("sv-sm-col"):addClass("sv-sm-col-mech")
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
end


local desc  = rec.Description or ""
return {
 
inner = tostring(root),
-- Hero Title Bar
classes = "module-special-mechanics",
local heroRow = root:tag("tr")
}
heroRow:addClass("spiritvale-infobox-main")
end
heroRow:addClass("sv-hero-title-row")
heroRow:addClass("hero-title-bar")


local heroCell = heroRow:tag("th")
-- PLUGIN: LevelSelector (Hero Module Slot 4) - JS level slider.
heroCell:attr("colspan", 2)
function PLUGINS.LevelSelector(rec, ctx)
heroCell:addClass("sv-hero-title-cell")
local level = ctx.level or 1
heroCell:wikitext(buildHeroBarUI(rec, ctx))
local maxLevel = ctx.maxLevel or 1


-- Description Bar
local inner = mw.html.create("div")
if desc ~= "" then
inner:addClass("sv-level-ui")
local descRow = root:tag("tr")
descRow:addClass("spiritvale-infobox-main")
descRow:addClass("sv-hero-desc-row")
descRow:addClass("hero-description-bar")


local descCell = descRow:tag("td")
inner:tag("div")
descCell:attr("colspan", 2)
:addClass("sv-level-label")
descCell:addClass("sv-hero-desc-cell")
:wikitext("Level <span class=\"sv-level-num\">" .. tostring(level) .. "</span> / " .. tostring(maxLevel))


local descInner = descCell:tag("div")
local slider = inner:tag("div"):addClass("sv-level-slider")
descInner:addClass("spiritvale-infobox-main-right-inner")


descInner:tag("div")
if tonumber(maxLevel) and tonumber(maxLevel) > 1 then
:addClass("spiritvale-infobox-description")
slider:tag("input")
:wikitext(string.format("''%s''", desc))
:attr("type", "range")
:attr("min", "1")
:attr("max", tostring(maxLevel))
:attr("value", tostring(level))
:addClass("sv-level-range")
:attr("aria-label", "Skill level select")
else
inner:addClass("sv-level-ui-single")
slider:addClass("sv-level-slider-single")
end
end


-- Modules row
return {
addHeroModulesRow(root, buildHeroModulesUI(rec, ctx))
inner = tostring(inner),
 
classes = "module-level-selector",
-- Users (hide on direct skill page)
}
if showUsers then
end
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")
addRow(root, "Events",  listToText(users.Events),  "sv-row-users", "Users.Events")
end


-- Requirements
----------------------------------------------------------------------
local req = rec.Requirements or {}
-- Generic slot renderers
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
-- normalizeResult: normalize plugin return values into {inner, classes}.
if type(req["Required Skills"]) == "table" and #req["Required Skills"] > 0 then
local function normalizeResult(res)
local skillParts = {}
if res == nil then return nil end
for _, rs in ipairs(req["Required Skills"]) do
if type(res) == "string" then
local nameReq = rs["Skill External Name"] or rs["Skill Internal Name"] or "Unknown"
return { inner = res, classes = nil }
local lvlReq  = rs["Required Level"]
if lvlReq then
table.insert(skillParts, string.format("%s (Lv.%s)", nameReq, lvlReq))
else
table.insert(skillParts, nameReq)
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")
addRow(root, "Required Stances", listToText(req["Required Stances"]), "sv-row-req", "Requirements.Required Stances")
end
end
 
if type(res) == "table" then
-- Mechanics (keep small extras only)
local inner = res.inner
local mech = rec.Mechanics or {}
if type(inner) ~= "string" then
if next(mech) ~= nil then
inner = (inner ~= nil) and tostring(inner) or ""
if mech["Autocast Multiplier"] ~= nil then
addRow(root, "Autocast Multiplier", tostring(mech["Autocast Multiplier"]), "sv-row-mech", "Mechanics.Autocast Multiplier")
end
end
return { inner = inner, classes = res.classes }
end
end
 
return { inner = tostring(res), classes = nil }
-- Legacy damage breakdown (only when Source absent)
end
if type(rec.Source) ~= "table" then
 
local dmg = rec.Damage or {}
-- safeCallPlugin: pcall wrapper to prevent infobox failure on plugin errors.
if next(dmg) ~= nil then
local function safeCallPlugin(name, rec, ctx)
local main = dmg["Main Damage"]
        local fn = PLUGINS[name]
local mainNonHeal, healOnly = {}, {}
        if type(fn) ~= "function" then
 
                return nil
if type(main) == "table" then
        end
for _, d in ipairs(main) do
        local ok, out = pcall(fn, rec, ctx)
if type(d) == "table" and d.Type == "Healing" then
        if not ok then
table.insert(healOnly, d)
                return nil
else
        end
table.insert(mainNonHeal, d)
        return normalizeResult(out)
end
end
end
 
end
-- isEmptySlotContent: true when a slot has no meaningful content.
 
-- NOTE: JS placeholders (sv-dyn spans, slider markup) are considered content.
addRow(root, "Main Damage",    formatDamageList(mainNonHeal, maxLevel, level, (#mainNonHeal > 1)), "sv-row-source", "Damage.Main Damage")
local function isEmptySlotContent(inner)
addRow(root, "Flat Damage",    formatDamageList(dmg["Flat Damage"], maxLevel, level, false),        "sv-row-source", "Damage.Flat Damage")
        if inner == nil then return true end
 
        local raw = tostring(inner)
 
        -- Guard rails for JS-injected regions.
        for _, pat in ipairs({ "sv%-dyn", "data%-series", "sv%-level%-range", "sv%-level%-slider", "sv%-level%-ui" }) do
                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 withoutTags = mw.text.trim(mw.ustring.gsub(trimmed, "<[^>]+>", ""))
        return (withoutTags == "" or withoutTags == "—")
end
 
-- renderHeroSlot: render a standardized hero slot by plugin assignment.
local function renderHeroSlot(slotIndex, rec, ctx)
        local pluginName = HERO_SLOT_ASSIGNMENT[slotIndex]
        if not pluginName then
                return nil
        end
 
        local res = safeCallPlugin(pluginName, rec, ctx)
        if not res or isEmptySlotContent(res.inner) then
                return nil
        end
 
        return {
                inner = res.inner,
                classes = res.classes,
        }
end
 
----------------------------------------------------------------------
-- UI builders
----------------------------------------------------------------------
 
-- buildHeroSlotsUI: build the standardized 4-row slot grid (2 columns).
local function buildHeroSlotsUI(rec, ctx)
        local grid = mw.html.create("div")
        grid:addClass("sv-slot-grid")
 
        local slots = {}
        for slot = 1, 8 do
                slots[slot] = renderHeroSlot(slot, rec, ctx)
        end
 
        local hasSlots = false
        for _, pair in ipairs({ { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 } }) do
                local left  = slots[pair[1]]
                local right = slots[pair[2]]
 
                if left or right then
                        hasSlots = true
 
                        if left and right then
                                grid:wikitext(slotBox(pair[1], left.classes, left.inner, { isEmpty = false }))
                                grid:wikitext(slotBox(pair[2], right.classes, right.inner, { isEmpty = false }))
                        elseif left then
                                grid:wikitext(slotBox(pair[1], left.classes, left.inner, { isFull = true }))
                        elseif right then
                                grid:wikitext(slotBox(pair[2], right.classes, right.inner, { isFull = true }))
                        end
                end
        end
 
        if not hasSlots then
                return ""
        end
 
        return tostring(grid)
end
 
-- addHeroSlotsRow: add the standardized slot grid into the infobox table.
local function addHeroSlotsRow(tbl, slotsUI)
        if not slotsUI or slotsUI == "" then
                return
        end
 
        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
 
----------------------------------------------------------------------
-- Infobox builder
----------------------------------------------------------------------
 
-- buildInfobox: render a single skill infobox.
local function buildInfobox(rec, opts)
opts = opts or {}
local showUsers = (opts.showUsers ~= false)
 
local maxLevel = tonumber(rec["Max Level"]) or 1
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, "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")
addRow(root, "Healing",        formatDamageList(healOnly, maxLevel, level, false),                  "sv-row-source", "Damage.Healing")
Line 1,657: Line 2,074:
end
end


-- Events
        -- Events
local function formatEvents(list)
        local function formatEvents(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 _, ev in ipairs(list) do
                for _, ev in ipairs(list) do
if type(ev) == "table" then
                        if type(ev) == "table" then
local action = ev.Action or "On event"
                                local action = resolveDisplayName(ev.Action, "event") or ev.Action or "On event"
local name  = ev["Skill Internal Name"] or ev["Skill External Name"] or "Unknown skill"
                                local name  = resolveSkillNameFromEvent(ev)
table.insert(parts, string.format("%s → %s", action, name))
                                table.insert(parts, string.format("%s → %s", mw.text.nowiki(action), mw.text.nowiki(name)))
end
                        end
end
                end
return (#parts > 0) and table.concat(parts, "<br />") or nil
                return (#parts > 0) and table.concat(parts, "<br />") or nil
end
        end


local eventsText = formatEvents(rec.Events)
local eventsText = formatEvents(rec.Events)
Line 1,676: 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


Line 1,713: Line 2,125:
end
end


local root = mw.html.create("div")
local out = {}
root:addClass("sv-skill-collection")


for _, rec in ipairs(matches) do
for _, rec in ipairs(matches) do
local item = root:tag("div"):addClass("sv-skill-item")
local title = rec["External Name"] or rec.Name or rec["Internal Name"] or "Unknown Skill"
item:wikitext(buildInfobox(rec, { showUsers = false, inList = true }))
 
-- List mode: emit a raw H3 heading before each standalone card so TOC/anchors work.
table.insert(out, string.format("=== %s ===", title))
 
-- List mode cards are independent (no single wrapper container).
table.insert(out, buildInfobox(rec, { showUsers = false, inList = true }))
end
end


return tostring(root)
return table.concat(out, "\n")
end
end