Module:GameSkills: Difference between revisions
From SpiritVale Wiki
More actions
No edit summary |
No edit summary |
||
| Line 281: | Line 281: | ||
end | end | ||
local function basisLabel(entry) | local function basisLabel(entry, isHealing) | ||
if isHealing then | |||
return "Healing" | |||
end | |||
local atk = entry and entry["ATK-Based"] | local atk = entry and entry["ATK-Based"] | ||
local matk = entry and entry["MATK-Based"] | local matk = entry and entry["MATK-Based"] | ||
| Line 294: | Line 297: | ||
end | end | ||
local function formatDamageEntry(entry, maxLevel) | -- Damage formatting: | ||
-- - Avoid "nil%" when Base is missing/0 and only Per Level exists. | |||
-- - For non-healing: "100% + 40 / 80 / 120 ... Attack Per Level" | |||
-- - For healing: "10 / 20 / 30 ... Healing Per Level" | |||
local function formatDamageEntry(entry, maxLevel, isHealing) | |||
if type(entry) ~= "table" then | if type(entry) ~= "table" then | ||
return nil | return nil | ||
end | end | ||
local | local baseRaw = entry["Base %"] | ||
local perN = toNum(entry | local perRaw = entry["Per Level %"] | ||
local baseN = toNum(baseRaw) | |||
local perN = toNum(perRaw) | |||
local basis = basisLabel(entry, isHealing) | |||
-- Healing: never show "%" or "nil%". | |||
if isHealing then | |||
-- Prefer per-level expansion if possible | |||
if perN ~= nil and perN ~= 0 and maxLevel and maxLevel > 0 then | |||
local start = (baseN ~= nil) and baseN or 0 | |||
local vals = {} | |||
for lv = 1, maxLevel do | |||
table.insert(vals, fmtNum(start + (perN * lv))) | |||
end | |||
if #vals > 0 then | |||
return string.format("%s %s Per Level", table.concat(vals, " / "), basis) | |||
end | |||
end | |||
-- Fallbacks | |||
if baseN ~= nil and baseN ~= 0 then | |||
return string.format("%s %s", fmtNum(baseN), basis) | |||
end | |||
if perN ~= nil and perN ~= 0 then | |||
return string.format("%s %s Per Level", fmtNum(perN), basis) | |||
end | |||
return nil | return nil | ||
end | end | ||
local | -- Non-healing base display: treat Base 0 as "missing" (so we don't show "0% + ...") | ||
local basePresent = false | |||
if baseN ~= nil then | |||
basePresent = (baseN ~= 0) | |||
else | |||
if baseRaw ~= nil then | |||
local s = tostring(baseRaw) | |||
basePresent = (s ~= "" and s ~= "0" and s ~= "0.0" and s ~= "0.00") | |||
end | |||
end | |||
local baseText = nil | |||
if basePresent then | |||
if baseN ~= nil then | |||
baseText = fmtNum(baseN) .. "%" | |||
else | |||
baseText = tostring(baseRaw) .. "%" | |||
end | |||
end | |||
-- If we have no Per Level scaling (or can't expand), show just Base if present. | |||
if perN == nil or perN == 0 or not maxLevel or maxLevel <= 0 then | if perN == nil or perN == 0 or not maxLevel or maxLevel <= 0 then | ||
return string.format("%s %s", baseText, basis) | if baseText then | ||
return string.format("%s %s", baseText, basis) | |||
end | |||
return nil | |||
end | end | ||
local | -- Expand cumulative list: per * 1..maxLevel | ||
local vals = {} | |||
for lv = 1, maxLevel do | for lv = 1, maxLevel do | ||
table.insert( | table.insert(vals, fmtNum(perN * lv)) | ||
end | |||
local listText = (#vals > 0) and table.concat(vals, " / ") or nil | |||
if not listText then | |||
return baseText | |||
end | |||
-- If Base missing/0: just the list (no "nil% +") | |||
if not baseText then | |||
return string.format("%s %s Per Level", listText, basis) | |||
end | end | ||
return string.format("%s + %s %s Per Level", baseText, listText, basis) | |||
return string.format("%s + %s %s Per Level", baseText, | |||
end | end | ||
local function formatDamageList(list, maxLevel, includeTypePrefix) | local function formatDamageList(list, maxLevel, includeTypePrefix, isHealing) | ||
if type(list) ~= "table" or #list == 0 then | if type(list) ~= "table" or #list == 0 then | ||
return nil | return nil | ||
| Line 330: | Line 392: | ||
for _, d in ipairs(list) do | for _, d in ipairs(list) do | ||
if type(d) == "table" then | if type(d) == "table" then | ||
local txt = formatDamageEntry(d, maxLevel) | local txt = formatDamageEntry(d, maxLevel, isHealing) | ||
if txt then | if txt then | ||
if includeTypePrefix and d.Type and d.Type ~= "" then | if includeTypePrefix and d.Type and d.Type ~= "" then | ||
| Line 347: | Line 409: | ||
end | end | ||
local function formatScaling(list) | -- Scaling should read like: | ||
-- "2% Attack Per Vitality" | |||
-- For pure healing skills: | |||
-- "1% Healing Per Vitality" | |||
local function formatScaling(list, basisOverride) | |||
if type(list) ~= "table" or #list == 0 then | if type(list) ~= "table" or #list == 0 then | ||
return nil | return nil | ||
| Line 358: | Line 424: | ||
local pct = s.Percent | local pct = s.Percent | ||
local pctN = toNum(pct) | local pctN = toNum(pct) | ||
local basis = basisLabel(s) | |||
local basis = basisOverride or basisLabel(s, false) | |||
if pctN ~= nil and pctN ~= 0 then | if pctN ~= nil and pctN ~= 0 then | ||
table.insert(parts, string.format("%s%% %s Per %s", fmtNum(pctN), basis, stat)) | table.insert(parts, string.format("%s%% %s Per %s", fmtNum(pctN), basis, stat)) | ||
elseif pct ~= nil and tostring(pct) ~= "" and tostring(pct) ~= "0" then | elseif pct ~= nil and tostring(pct) ~= "" and tostring(pct) ~= "0" then | ||
| Line 485: | Line 551: | ||
end | end | ||
-- Special Mechanics: | |||
-- If effect block has Type, render like: | |||
-- "Holy Light - Skill Area + 3" | |||
local function formatMechanicEffects(effects) | local function formatMechanicEffects(effects) | ||
if type(effects) ~= "table" then | if type(effects) ~= "table" then | ||
| Line 500: | Line 569: | ||
local block = effects[name] | local block = effects[name] | ||
if type(block) == "table" then | if type(block) == "table" then | ||
local txt = valuePairText(name, block, ", ") | local t = block.Type | ||
if t ~= nil and tostring(t) ~= "" then | |||
local pair = { Base = block.Base, ["Per Level"] = block["Per Level"] } | |||
local amt = valuePairRawText(pair) | |||
if amt then | |||
table.insert(parts, string.format("%s - %s + %s", tostring(t), tostring(name), amt)) | |||
else | |||
table.insert(parts, string.format("%s - %s", tostring(t), tostring(name))) | |||
end | |||
else | |||
local txt = valuePairText(name, block, ", ") | |||
if txt then | |||
table.insert(parts, txt) | |||
end | |||
end | end | ||
end | end | ||
| Line 873: | Line 953: | ||
end | end | ||
local mainText = formatDamageList(mainNonHeal, maxLevel, (#mainNonHeal > 1)) | local flatList = dmg["Flat Damage"] | ||
local reflList = dmg["Reflect Damage"] | |||
local flatHas = (type(flatList) == "table" and #flatList > 0) | |||
local reflHas = (type(reflList) == "table" and #reflList > 0) | |||
-- Determine if this is effectively a "pure healing" skill for scaling wording. | |||
local pureHealing = (#healOnly > 0) and (#mainNonHeal == 0) and (not flatHas) and (not reflHas) | |||
local mainText = formatDamageList(mainNonHeal, maxLevel, (#mainNonHeal > 1), false) | |||
addRow(root, "Main Damage", mainText) | addRow(root, "Main Damage", mainText) | ||
local flatText = formatDamageList( | local flatText = formatDamageList(flatList, maxLevel, false, false) | ||
addRow(root, "Flat Damage", flatText) | addRow(root, "Flat Damage", flatText) | ||
local reflText = formatDamageList( | local reflText = formatDamageList(reflList, maxLevel, false, false) | ||
addRow(root, "Reflect Damage", reflText) | addRow(root, "Reflect Damage", reflText) | ||
local healText = formatDamageList(healOnly, maxLevel, false) | local healText = formatDamageList(healOnly, maxLevel, false, true) | ||
addRow(root, "Healing", healText) | addRow(root, "Healing", healText) | ||
local scaleText = formatScaling(dmg.Scaling) | local scaleText = formatScaling(dmg.Scaling, pureHealing and "Healing" or nil) | ||
addRow(root, "Scaling", scaleText) | addRow(root, "Scaling", scaleText) | ||
end | end | ||
| Line 965: | Line 1,054: | ||
root:addClass("spiritvale-skill-list") | root:addClass("spiritvale-skill-list") | ||
-- | -- On class pages / list mode, hide Users (redundant on that page). | ||
for _, rec in ipairs(matches) do | for _, rec in ipairs(matches) do | ||
root:wikitext(buildInfobox(rec, { showUsers = false })) | root:wikitext(buildInfobox(rec, { showUsers = false })) | ||