Fandom

Fire Emblem Wiki

Module:CharStat

5,333pages on
this wiki
Add New Page
Talk0
--This module is invoked by Template:CharStat
 
local p = {}
local getArgs = require('Module:Arguments').getArgs
local getColor = require('Module:Color').colorByGame
local common = require('Module:Common')
local stats = {
    -- character stats
    {'Level',   '\n![[Level]]'},
    {'HP',      '\n![[HP]]'},
    {'EP',      '\n![[EP]]'},
    {'Str',     '\n![[Strength|Str]]'},
    {'Mag',     '\n![[Magic (stat)|Mag]]'},
        {'Mnd', '\n![[Magic (stat)|Mnd]]'},
    {'Skl',     '\n![[Skill (stat)|Skl]]'},
    {'Spd',     '\n![[Speed (stat)|Spd]]'},
        {'Agl', '\n![[Speed (stat)|Agl]]'},
    {'Lck',     '\n![[Luck|Lck]]'},
    {'Def',     '\n![[Defense|Def]]'},
    {'Res',     '\n![[Resistance|Res]]'},
    {'Con',     '\n![[Constitution|Con]]'},
        {'Bld', '\n![[Constitution|Bld]]'},
    {'Wt',      '\n![[Weight (character stat)|Wt]]'},
    {'Wlv',     '\n![[Weapon Level|Wlv]]'},
    {'Move',    '\n![[Movement|Mov]]'},
    {'Lead',    '\n![[Leadership|Lead]]'},
        {'LS',  '\n![[Leadership|LS]]'},
    {'MS',      '\n![[Movement Star|MS]]'},
    {'PC',      '\n![[Pursuit Critical Coefficient|PC]]'},
    {'Gold',    '\n![[Gold]]'}
}
 
local others = {
    {'Magic',   '[[Magic]]'},
    {'Skills',  '[[Skills]]'},
    {'Skill',   '[[Skills]]'},
    {'Weapon',  '[[Weapon Rank|Weapon]]'},
    {'Item',    'Starting Items'},
}
 
local resistances = {
    'sword', 'lance', 'axe', 'bow',
    'fire', 'ice', 'thunder', 'wind', 'light', 'dark'
}
 
function p.main(frame)
    args = getArgs(frame)
    if(pcall(p._main, args)) then
        return p._main(args)
    else
        return '<span style="color: red">Missing \'game\' parameter. See [[Template:CharStat]] for more info.</span>'
    end
end
 
function p._main(args)
    local game = string.lower(mw.text.trim(args.game))
    local class = common.colorLinks(game)
    local out, colspan, colspan1
    local columns, col = '', ''
    local nCols, oCols = 0, 0
    local color = getColor[game]
 
    ----------------- Char stats columns iteration -----------------
    -- Headers
    for i = 1, #stats do
        if(common.isnotNil(args[stats[i][1]])) then
            columns = columns..stats[i][2]
            nCols = nCols + 1
        end
    end
    -- Datas
    columns = columns..'\n|-class="s-cells"'
    for i = 1, #stats do
        if(common.isnotNil(args[stats[i][1]])) then
            columns = columns..'\n| '..args[stats[i][1]] end
    end
    -- Assign colspan
    colspan = nCols
    col = col..'\n!colspan="4"|'
    if(common.isnotNil(args['Holy Blood'])) then
        col = col..'[[Holy Blood]]'
        colspan = nCols - 4
    elseif(common.isnotNil(args['Aff'])) then
        col = col..'[[Affinity]]'
        colspan = nCols - 4
    elseif(common.isnotNil(args['Group'])) then
        col = col..'Group'
        colspan = nCols - 4
    end
 
 
    ---------------------- TOKYO MIRAGE SESSIONS ♯FE ----------------------
    if(game == 'tms') then
        colspan = 10
        -------------------- Resistances -------------------
        -- Headers
        columns = columns..'\n|-bgcolor='..color..' class='..class
        for i = 1, #resistances do
            columns = columns..'\n!'..
            mw.getCurrentFrame():expandTemplate{
                title = 'Weapon',
                args = { 'tms', resistances[i] }
            }
        end
 
        columns = columns..'\n|-class="s-cells"'
        -- Datas
        for i = 1, #resistances do
            columns = columns..'\n| '..common.setDefault(args[resistances[i]], '--')
        end
 
        -------------------- Skills & Items -------------------
        columns = 
            columns..'\n|-bgcolor='..
            color..' class='..class..
            '\n!colspan=7| Skills'..
            '\n!colspan=3| Items'..
            '\n|-'..
            '\n!colspan=3|Command'..
            '\n!colspan=2|Session'..
            '\n!colspan=2|Passive'..
            '\n|colspan=3 rowspan=2|\n'..common.setDefault(args['items'], '--')..
            '\n|-'..
            '\n|colspan=3|\n'..common.setDefault(args['command'], '--')..
            '\n|colspan=2|\n'..common.setDefault(args['session'], '--')..
            '\n|colspan=2|\n'..common.setDefault(args['passive'], '--')
    end
 
 
    ------------------- Other columns iteration ----------------------
    -- Assign colspan
    local n = 0-- colspan identifier for the last column
    for i = 1, #others do
        if(common.isnotNil(args[others[i][1]])) then oCols = oCols + 1 end
    end
    if(nCols % oCols ~= 0) then n = 1 end
    colspan1 = nCols / oCols
    -- Headers
    columns = columns..'\n|-bgcolor='..color..' class='..class
    for i = 1, #others do
        if(common.isnotNil(args[others[i][1]])) then
            columns = columns..'\n!colspan='
            if(i == #others) then
                columns = columns..(colspan1+n)
            else
                columns = columns..colspan1
            end
            columns = columns..'|'..others[i][2]
        end
    end
    -- Datas
    columns = columns..'\n|-'
    for i = 1, #others do
        if(common.isnotNil(args[others[i][1]])) then
            columns = columns..'\n|colspan='
            if(i == #others) then
                columns = columns..(colspan1+n)
            else
                columns = columns..colspan1
            end
            columns = columns..'|\n'..args[others[i][1]]
        end
    end
 
 
    ----------------------- Final output --------------------------
    out =
    '{| class="statbox" style="text-align: center"'..
    '\n|-bgcolor='..color..' class='..class..
    '\n!colspan='..colspan..'|Starting Class'
 
    if(common.isnotNil(args['Holy Blood']) or common.isnotNil(args['Aff']) or common.isnotNil(args['Group'])) then
        out = out..col end
 
    out = out..'\n|-\n|colspan='..colspan..'| '..common.setDefault(args['image'])
 
    if(common.isnotNil(args['Holy Blood'])) then
        out = out..'\n|colspan="4"| '..args['Holy Blood']
    elseif(common.isnotNil(args['Aff'])) then
        out = out..'\n|colspan="4"| '..args['Aff']
    elseif(common.isnotNil(args['Group'])) then
        out = out..'\n|colspan="4"| '..args['Group']
    end
 
    out = out..
    '\n|-bgcolor='..color..' class='..class..
        columns..
    '\n|}'
 
    return out
end
 
return p
--[[Category:Modules]]

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Also on Fandom

Random Wiki