Fire Emblem Wiki
Advertisement
Fire Emblem Wiki

Documentation for this module may be created at Module:WeaponStat/doc

--This module is invoked by Template:WeaponStat

local wps = {}
local getArgs = require('Module:Arguments').getArgs
local getColor = require('Module:Color').colorByGame
local common = require('Module:Common')
local cols = {
    --Weapon stats
    wlv =   '\n![[Weapon Level|WLv]]',
    rank =  '\n![[Weapon Rank|Rank]]',
    uses =  '\n![[Usage|Uses]]',
    whp =   '\n![[Usage|WHp]]',
    mt =    '\n![[Might|Mt]]',
    power = '\n![[Might|Power]]',
    hit =   '\n![[Hit%|Hit]]',
    crt =   '\n![[Critical Rate|Crt]]',
    rng =   '\n![[Range|Rng]]',
    wt =    '\n![[Weight (weapon stat)|Wt]]',
    wex =   '\n![[Weapon Experience|WEx]]',
    worth = '\n![[Cost|Worth]]',
    avoid = '\n![[Evade|Avoid]]',
    sp =    '\n![[SP]]',
    rarity ='\n![[Rarity]]'
}
local res = {
    'sword', 'lance', 'axe', 'bow',
    'fire', 'ice', 'thunder', 'wind', 'light', 'dark'
}

function wps.main(frame)
	local args = getArgs(frame)
	if(pcall(wps._main, args)) then
        return wps._main(args)
    else
        return '<span style="color:red">Missing \'game\' parameter. See [[Template:WeaponStat]] for more info.</span>'
    end
end

function wps._main(args)
    local game = string.lower(args.game)
    local class = common.colorLinks(game)
    local color = getColor[game]
    local out, columns, n_cols,
          top_colspan, bot_colspan,
          maxiter, maxcnt
    
    -- HEADERS
    if(string.match(game, 'fe')) then
        --------------------- Fire Emblem games --------------------------
        i = tonumber(string.sub(game, 3))   -- FE installment
        if (i == nil) then
            n_cols = 4
            columns = 
                cols.mt..
                cols.rng..
                cols.sp..
                cols.rarity
        else
            if (i == 1 or i == 3) then
                n_cols = 8
                columns =
                    cols.wlv..
                    cols.uses..
                    cols.mt..
                    cols.hit..
                    cols.crt..
                    cols.rng..
                    cols.wt..
                    cols.worth
            elseif (i == 2 or i == 15) then
                n_cols = 5
                columns =
                    cols.mt..
                    cols.hit..
                    cols.crt..
                    cols.rng..
                    cols.wt
            elseif (i == 4) then
                n_cols = 7
                columns =
                    cols.rank..
                    cols.uses..
                    cols.mt..
                    cols.hit..
                    cols.rng..
                    cols.wt..
                    cols.worth
            elseif (i >= 5 and i <= 11) then
                n_cols = 9
                columns =
                    cols.rank..
                    cols.uses..
                    cols.mt..
                    cols.hit..
                    cols.crt..
                    cols.rng..
                    cols.wt..
                    cols.wex..
                    cols.worth
            elseif (i == 12 or i == 13) then
                n_cols = 8
                columns =
                    cols.rank..
                    cols.uses..
                    cols.mt..
                    cols.hit..
                    cols.crt..
                    cols.rng..
                    cols.wex..
                    cols.worth
            else
                n_cols = 9
                columns =
                    cols.rank..
                    cols.uses..
                    cols.mt..
                    cols.hit..
                    cols.crt..
                    cols.avoid..
                    cols.rng..
                    cols.wex..
                    cols.worth
                    
            end
        end
    elseif( game == 'ts' ) then
        ------------------------- TearRing Saga  ---------------------------
        n_cols = 8
        columns =
            cols.wlv..
            cols.whp..
            cols.power..
            cols.hit..
            cols.crt..
            cols.rng..
            cols.wt..
            cols.worth
    elseif( game == 'tms' ) then
        ---------------------- Tokyo Mirage Sessions -----------------------
        n_cols = 1 + #res
        columns = cols.power
        for i = 1, #res do
            columns = columns..'\n!'..
            mw.getCurrentFrame():expandTemplate{
                title = 'Weapon',
                args = { 'tms', res[i] }
            }
        end
    elseif( game == 'few' ) then
        ---------------------- Fire Emblem Warriors -----------------------
        n_cols = 3
        columns =
            cols.rank..
            cols.mt..
            cols.worth
    end
    
    -- DATA
    maxiter = n_cols + 2
    top_colspan = math.floor(n_cols / 2)
    top_colspan1 = top_colspan
    bot_colspan = n_cols
    if( n_cols % 2 ~= 0 ) then top_colspan1 = top_colspan + 1 end
    
    columns = columns..'\n|-class="s-cells"'
    for cnt = 3, maxiter do
        columns = columns..'\n| '..common.setDefault(args[tonumber(cnt)])
        maxcnt = cnt + 1
    end
    
    
    -- OUTPUT
    out =
        '{| class="statbox"'..
        '\n|-bgcolor='..color..' class='..class..
        '\n!colspan='.. top_colspan1 ..'|Name'..
        '\n!colspan='.. top_colspan     ..'|[[Weapon Type|Type]]'..
        '\n|-'..
        '\n|colspan='.. top_colspan1 ..'|\n'..common.setDefault(args[1])..
        '\n|colspan='.. top_colspan     ..'|\n'..common.setDefault(args[2])..
        '\n|-bgcolor='..color..' class='..class..
        
        columns..
        
        '\n|-'
    
    
    if( game == 'tms') then
        bot_colspan = math.floor(n_cols / 3)
        bot_colspan1 = bot_colspan + 2
        out = out..
            '\n!bgcolor='..color..' class='..class..' colspan='..bot_colspan..'|Effect'..
            '\n!bgcolor='..color..' class='..class..' colspan='..bot_colspan..'|Skills'..
            '\n!bgcolor='..color..' class='..class..' colspan='..bot_colspan1..'|Performa Required'..
            '\n|-'..
            '\n|colspan='..bot_colspan..'|\n'..common.setDefault(args[maxcnt])..
            '\n|colspan='..bot_colspan..'|\n'..common.setDefault(args[maxcnt + 1])..
            '\n|colspan='..bot_colspan1..'|\n'..common.setDefault(args[maxcnt + 2])
    else
        out = out..
        '\n!bgcolor='..color..' class='..class..' colspan='..bot_colspan..'|Effect'..
        '\n|-'..
        '\n|colspan='..bot_colspan..'|\n'..common.setDefault(args[maxcnt])
    end
        
    return out..'\n|}'
end

return wps
--[[Category:Modules]]
Advertisement