Module:Traits: Difference between revisions

From Elwiki
No edit summary
m (add i18n)
 
(73 intermediate revisions by 2 users not shown)
Line 1: Line 1:
-- pystart
require('Module:CommonFunctions')
require('Module:CommonFunctions')
local i18n = require('Module:I18n')
local getArgs = require('Module:Arguments').getArgs
local getArgs = require('Module:Arguments').getArgs
local getTranslations = i18n.getTranslations
local p = {}
local p = {}


-- Main process
-- Main process
function p.main(frame)
function p.main(frame)
     local args = getArgs(frame);
     local args = getArgs(frame)
    local tr = getTranslations(frame, 'Template:Traits', args.lang, true)
    local is_rose = args[1] == 'Rose' and args.ecp == 'true'
 
    function translate(key)
        return i18n.translate(tr, key)
    end


     -- Argument init
     -- Argument init
Line 20: Line 29:


     -- Dictionary for headers
     -- Dictionary for headers
     local headers = {'MP Usage', 'Cooldown', 'Duration', 'MP Recovery', 'Max Hits'}
     local prop = {  
     local properties = {'mp_cost', 'cooldown', 'duration', 'mp_cost'}
        is_rose and translate('ECP Usage') or translate('MP Usage'),
     local header_dict = {
        translate('Cooldown'),
         [1] = {'Light', 'Critical', 'Reversed'},
        translate('Duration'),
         [2] = {'Heavy', 'Haste', 'Regenerating (2)', 'Ruthless', 'Powerful', 'Reversed'},
        is_rose and translate('ECP Recovery') or translate('MP Recovery'),
         [3] = {'Killing Blow (1)'},
        translate('Max Hits'),
         [4] = {'Regenerating (1)'},
        translate('Effects'),
         [5] = {'Useful'}
    }
 
     local prop_short = { 'mp', 'cd', 'duration', 'mp_recovery', 'hits', 'effects', 'chance' }
 
     local OPTIONS = {
         lang_suffix = args.lang and ('/' .. args.lang) or '',
        lang_append = args.lang ~= nil and args.lang ~= ''
    }
 
    local STR = {
        LIGHT = 'Light',
        CRITICAL = 'Critical',
        REVERSED = 'Reversed',
         HEAVY = 'Heavy',
        HASTE = 'Haste',
        REGEN1 = 'Regenerating (1)',
        REGEN2 = 'Regenerating (2)',
        KB1 = 'Killing Blow (1)',
        KB2 = 'Killing Blow (2)',
        RUTHLESS = 'Ruthless',
        POWERFUL = 'Powerful',
        USEFUL = 'Useful',
        SEC = 'Seconds',
        MP = 'MP',
         ECP = 'ECP',
         PERSISTENT = 'Persistent',
         PERSISTENT2 = 'Persistent2'
    }
 
    local details = {
        { STR.LIGHT, STR.CRITICAL, STR.REVERSED },
        { STR.HEAVY, STR.HASTE,    STR.REGEN2,  STR.RUTHLESS, STR.POWERFUL, STR.REVERSED },
        { STR.KB1 },
        { STR.REGEN1 },
        { STR.USEFUL, STR.PERSISTENT2 },
        { STR.KB2 }
     }
     }


     -- Default values
     -- Default values
     local default_trait_values = {
     local DEFAULT = {
         Heavy = {
         [STR.HEAVY] = {
             multi_cooldown = 120
             cd = 120
        },
        [STR.LIGHT] = {
            mp = 80
        },
        [STR.CRITICAL] = {
            mp = (args['def_ignore1'] ~= nil or args['def_ignore2'] ~= nil) and 100 or 120
         },
         },
         Light = {
         [STR.HASTE] = {
             multi_mp_cost = 80
             cd = 80
         },
         },
         Critical = {
         [STR.RUTHLESS] = {
             multi_mp_cost = 120
             cd = 200
         },
         },
         Haste = {
         [STR.POWERFUL] = {
             multi_cooldown = 80
             cd = 150
         },
         },
         Ruthless = {
         [STR.REGEN1] = {
             multi_cooldown = 200
             chance = 50,
            mp = 50
         },
         },
         Powerful = {
         [STR.REGEN2] = {
             multi_cooldown = 150
             chance = 50,
            cd = 50
        },
        [STR.REVERSED] = {
            mp = 60,
            cd = 150
        },
        [STR.USEFUL] = {
            dmg = 80
        },
        [STR.PERSISTENT2] = {
            dmg = 100
         }
         }
     }
     }


    -- Define the class blueprint for traits.
    Trait = {}
    function Trait:new(t)
        t = t or {}
        -- Define all values taken from arguments.
        t.details_mp_cost = {
            [1] = args.mp,
            [2] = args.mp_pvp,
            [3] = args.mp_enhanced
        }
        t.details_cooldown = {
            [1] = args.cd,
            [2] = args.cd_pvp,
            [3] = args.cd_enhanced
        }
        t.details_duration = {
            [1] = args.duration,
            [2] = args.duration_pvp,
            [3] = args.duration_enhanced
        }
        -- Automatic math and pvp/enhanced check
        local has_multiple_rows;
        t.multiple_rows = {}
        for k, v in pairs(t) do
            if string.find(k, 'details_') then
                for k2, v2 in pairs(v) do
                    local kind = k:gsub('details_', '')
                    if (t.multiple_rows[kind] == nil) then
                        t.multiple_rows[kind] = {}
                    end
                    if (k2 == 2) then
                        t.multiple_rows[kind]['pvp'] = true
                    elseif (k2 == 3) then
                        t.multiple_rows[kind]['enhanced'] = true
                    end
                    t[k][k2] = frame:preprocess('{{#expr: ' .. v2 .. '}}')
                end
            end
        end
        -- Solution for custom headers
        for k, v in pairs(args) do
            if string.find(k, 'detail') then
                if t.multiple_rows[k] == nil then
                    t.multiple_rows[k] = {}
                end
                if string.find(k, '_pvp') then
                    local kind = k:gsub('_pvp', '')
                    t.multiple_rows[kind] = {}
                    t.multiple_rows[kind]['pvp'] = true
                elseif string.find(k, '_enhanced') then
                    local kind = k:gsub('_enhanced', '')
                    t.multiple_rows[kind] = {}
                    t.multiple_rows[kind]['enhanced'] = true
                end
            end
        end
        -- Check if multiple_rows property has ANY values in the 2nd depth
        for k, v in pairs(t.multiple_rows) do
            if next(v) ~= nil then
                has_multiple_rows = true
            end
        end
        -- Figure out how many columns there is to span
        local mode_colspan = 0
        if has_multiple_rows and t.index == 1 then
            mode_colspan = 1
            t.mode_row = true
        end
        t.colspan = 1
        t.colspan = t.colspan + table.matches(header_dict, t.name) + mode_colspan
        -- Get multipliers from args
        t.multi_mp_cost = args['mp' .. t.index] or default_multiplier
        t.multi_cooldown = args['cd' .. t.index] or default_multiplier
        t.multi_duration = args['duration' .. t.index] or default_multiplier
        t.chance = args['chance' .. t.index]
        t.unnamed_2 = args['desc1_trait' .. t.index]
        t.unnamed_3 = args['desc2_trait' .. t.index]
        -- Set defaults for generic trait values.
        local default = default_trait_values[t.name]
        if (default ~= nil) then
            for k, v in pairs(default) do
                if (t[k] == default_multiplier) then
                    t[k] = v
                end
            end
        end
        -- Figure out if there are any pvp or enhanced values
        for k, v in pairs(t.multiple_rows) do
            for k2, v2 in pairs(v) do
                if k2 == 'pvp' and v2 == true then
                    t.has_pvp = true
                end
                if k2 == 'enhanced' and v2 == true then
                    t.has_enhanced = true
                end
            end
        end
        self.__index = self
        setmetatable(t, self)
        return t
    end
    function Trait:onError(message)
        assert(false, message)
    end
    -- Calculation method
    function Trait:calc()
        for k, v in pairs(self) do
            if (string.find(k, 'details_')) then
                local current_data = k:gsub('details_', '')
                local current_multiplier = self['multi_' .. current_data]
                -- Handle errors
                if not next(v) and current_multiplier ~= default_multiplier then
                    self:onError("Cannot calculate the '" .. current_data .. "' property that is not defined")
                end
                local requires_current_data
                for k1, v1 in pairs(header_dict) do
                    for k2, v2 in pairs(v1) do
                        if v2 == self.name and properties[k1] == current_data then
                            requires_current_data = true
                        end
                    end
                end
                if current_multiplier == default_multiplier and next(v) ~= nil and requires_current_data then
                    self:onError("Cannot calculate the '" .. current_data .. "' property: " .. self.name ..
                                    " trait description is not enough")
                end
                for k2, v2 in pairs(v) do
                    self[k][k2] = current_multiplier / 100 * v2
                    if current_data == 'mp_cost' then
                        self[k][k2] = self[k][k2] .. ' MP'
                    else
                        self[k][k2] = self[k][k2] .. ' Seconds'
                    end
                end
            end
        end
        return self
    end
    local trait_left = Trait:new({
        name = traits[1],
        index = 1
    })
    local trait_right = Trait:new({
        name = traits[2],
        index = 2
    })
    -- Get table head color
     local function color(char)
     local function color(char)
         char = char or args[1] or args.char
         char = char or args[1] or args.char or 'Elsword'
         return frame:expandTemplate{
         return char:gsub('/', '')
            title = 'ColorSel',
            args = {'CharLight', char}
        }:gsub("#", "#")
     end
     end


    -- Main block
     local trait_table = mw.html.create('div'):attr('class', 'content-table'):tag('table'):attr({
     local trait_table = mw.html.create('div'):attr('class', 'content-table'):tag('table'):attr({
         ['cellpadding'] = '5',
         cellpadding = '5',
         ['border'] = '1'
         border = '1',
        class = 'colortable-' .. color()
     }):css({
     }):css({
         ['border-collapse'] = 'collapse',
         ['border-collapse'] = 'collapse',
Line 240: Line 128:
     })
     })


     function newtr()
     function new_row()
         return trait_table:tag('tr'):css('background-color', color())
         return trait_table:tag('tr')
     end
     end


     local thead = newtr()
    -- headers
     local tr = newtr()
     local tr1 = new_row()
     local tr_2 = newtr()
     local tr2 = new_row()
     local tr3 = new_row()


     -- Header spawning method
     local has_pvp_values = false
     function Trait:do_headers()
     for k, v in pairs(args) do
         local function getCustomHeader(spawn)
         if string.find(k, '_pvp') then
            local i = 1
            has_pvp_values = true
            while true do
            break
                local custom_header = args['header' .. i .. '_trait' .. self.index]
                if custom_header ~= nil then
                    if spawn then
                        tr_2:tag('th'):wikitext(custom_header)
                    end
                    i = i + 1
                else
                    break
                end
            end
            return i - 1
         end
         end
    end


         thead:tag('th'):attr('colspan', self.colspan + getCustomHeader()):wikitext(self.name .. ' ' .. skill)
    local tr4
 
    -- If pvp values exist, we need the row to place them.
         if self.mode_row then
    if has_pvp_values and not tr4 then
            if self.has_enhanced == true then
        tr4 = new_row()
                tr_2:tag('th'):wikitext('Stage')
         -- Add indicator headers
             else
        tr1:tag('th'):wikitext(translate('Mode')):attr('rowspan', 2)
                tr_2:tag('th'):wikitext('Mode')
         tr3:tag('td'):wikitext(frame:expandTemplate {
            end
             title = translate('PvE')
           
         })
         end
         tr4:tag('td'):wikitext(frame:expandTemplate {
 
            title = translate('PvP')
         tr_2:tag('th'):wikitext('Attribute Effect')
        })
    end


         local has_details = table.matches(header_dict, self.name);
    -- Loop through 2 input traits.
    for trait_count, trait_name in ipairs(traits) do
         local th = tr1:tag('th'):wikitext(trait_name:gsub(translate(STR.PERSISTENT) .. 2, translate(STR.PERSISTENT)) .. ' ' .. skill);
        local th_effect;
        local th_skilltext;
        local default_value = DEFAULT[trait_name] or {};


         if has_details then
         -- Check if detail fields are required and which.
             if self.multi_mp_cost ~= default_multiplier then
        for detail_key, detail in ipairs(details) do
                 if self.name == 'Regenerating (1)' then
             if not th_effect then
                    tr_2:tag('th'):wikitext('MP Recovery')
                 th_effect = tr2:tag('th'):wikitext(translate('Attribute Effect'));
                else
                    tr_2:tag('th'):wikitext('MP Usage')
                end
             end
             end
             if self.multi_cooldown ~= default_multiplier then
             if indexOf(trait_name, detail) then
                 tr_2:tag('th'):wikitext('Cooldown')
                 local th_detail = tr2:tag('th'):wikitext(translate(prop[detail_key]));
            end
                 th:attr('colspan', tonumber(th:getAttr('colspan') or 1) + 1)
            if self.multi_duration ~= default_multiplier then
                 tr_2:tag('th'):wikitext('Duration')
            end
            if self.name == 'Useful' then
                tr_2:tag('th'):wikitext('Max Hits')
             end
             end
         end
         end
        getCustomHeader(true)
    end
    trait_left:do_headers()
    trait_right:do_headers()
    trait_left:calc()
    trait_right:calc()


    function Trait:do_content(tr, mode)
        -- Unnamed argument.
        local unnamed = split(args[3 + trait_count]);
        local MP_ARG = args['mp' .. trait_count] or args['mp_recovery' .. trait_count] or default_value['mp_recovery'] or
            default_value['mp'];
        local ECP_ARG = nil


        -- Generate appropriate headers on the left
         if is_rose then
         if self.mode_row then
             unnamed[2] = unnamed[1] or args['mp' .. trait_count]
             if mode then
            ECP_ARG = unnamed[1] or args['mp' .. trait_count]
                if self.has_enhanced == true then
             MP_ARG = nil
                    if mode == 'enhanced' then
                        tr:tag('td'):wikitext("'''[Enhanced]'''")
                    end
                elseif mode == 'pvp' then
                    tr:tag('td'):wikitext(frame:expandTemplate{
                        title = 'PvP'
                    })
                end
             else
                if self.has_enhanced == true then
                    tr:tag('td'):wikitext("'''Normal'''")
                else
                    tr:tag('td'):wikitext(frame:expandTemplate{
                        title = 'PvE'
                    })
                end
            end
         end
         end


         -- Generate trait descriptions
         -- Append contents.
         if not mode then
         for detail_key, detail in ipairs(details) do
            local rowspan = 1
            if not th_skilltext then
            if next(self.multiple_rows) ~= nil then
                th_skilltext = tr3:tag('td'):attr('rowspan', has_pvp_values and 2 or 1):wikitext(frame:expandTemplate {
                 rowspan = 2
                    title = translate('SkillText'),
                    args = {
                        trait_name,
                        unnamed[1],
                        unnamed[2],
                        MP = args['def_ignore' .. trait_count] ~= nil and 'Energy' or MP_ARG,
                        ECP = ECP_ARG,
                        CD = args['cd' .. trait_count] or default_value['cd'],
                        DURATION = args['duration' .. trait_count],
                        CHANCE = args['chance' .. trait_count] or default_value['chance'],
                        DAMAGE = args['dmg' .. trait_count] or default_value['dmg'],
                        DEF_IGNORE = args['def_ignore' .. trait_count],
                        DEF_IGNORE_PVP = args['pvp_def_ignore' .. trait_count]
                    }
                 });
             end
             end
            tr:tag('td'):wikitext(frame:expandTemplate{
                title = 'SkillText',
                args = {
                    self.name,
                    self.unnamed_2,
                    self.unnamed_3,
                    MP = self.multi_mp_cost,
                    CD = self.multi_cooldown,
                    DURATION = self.multi_duration,
                    CHANCE = self.chance
                }
            }):attr('rowspan', rowspan)
        end


        -- Fill cells with values
            function doDetail()
        local function addIfMultiExists(param_tbl)
                for _, modeSuffix in ipairs({ '', '_pvp' }) do
            for k, v in ipairs(param_tbl) do
                    if indexOf(trait_name, detail) then
                if (self['multi_' .. v] ~= default_multiplier) then
                        local short_detail = prop_short[detail_key]
                    local info;
                        local short_detail_improved = short_detail
                        local is_pvp = modeSuffix == '_pvp'


                    if mode == 'enhanced' then
                        -- Fix Regen 1.
                         info = self['details_' .. v][3]
                        if short_detail == 'mp_recovery' then
                    elseif mode == 'pvp' then
                            short_detail_improved = 'mp'
                         info = self['details_' .. v][2]
                        end
                    else
 
                         info = self['details_' .. v][1]
                         local detail_content = args[short_detail_improved .. trait_count]
                    end
                        local multiplier = detail_content or default_value[short_detail_improved] or 100
                        local suffix = ''
                        if short_detail_improved == 'mp' then
                            suffix = STR.MP
                            if is_rose then
                                suffix = STR.ECP
                            end
                         elseif short_detail == 'cd' or short_detail == 'duration' then
                            suffix = STR.SEC
                        end
                         suffix = suffix and (' ' .. suffix) or ''


                    if (info ~= nil) then
                         local base_detail = args[short_detail_improved .. modeSuffix]
                         local td = tr:tag('td'):wikitext(info)


                         if next(self.multiple_rows[v]) ~= nil then
                         local function calcEndValue(base)
                             td:attr('rowspan', 1)
                            local end_value;
                        else
                            if base and tonumber(base) == nil then
                             td:attr('rowspan', 2)
                                end_value = base
                             else
                                end_value = (tonumber(multiplier) / 100) * tonumber(base or -1)
                            end
                             if tonumber(end_value) ~= nil and tonumber(end_value) < 0 then
                                end_value = '-'
                            end
                            return end_value .. suffix
                         end
                         end
                    end


                end
                        local end_value = calcEndValue(base_detail)
            end
 
        end
                        local enhanced_detail = args[short_detail_improved .. modeSuffix .. '_enhanced']
                        if enhanced_detail ~= nil then
                            end_value = end_value .. "<br/>'''" .. frame:expandTemplate {
                                title = 'Tt',
                                args = { calcEndValue(enhanced_detail) .. "'''",
                                    translate("Final Enhanced Skill") }
                            }
                        end


        addIfMultiExists({'mp_cost', 'cooldown', 'duration'})
                        if (is_pvp and base_detail) or not is_pvp then
                            local detail_text = end_value
                            if end_value == '-' and args['detail' .. trait_count] then
                                detail_text = args
                                    ['detail' .. trait_count]
                            end


        -- Custom data support
                            local detail_cell = (is_pvp and tr4 or tr3):tag('td'):wikitext(detail_text):attr('rowspan', has_pvp_values and (not args[short_detail_improved .. '_pvp']) and 2 or 1);
        local function getCustomContent()
            local i = 1
            local y = 1
            while true do
                local mode_str = mode or ''
                if mode_str ~= '' then
                    mode_str = '_' .. mode_str
                end
                local custom_content_arg = 'detail' .. i .. '_trait' .. self.index .. mode_str;
                local custom_content = args[custom_content_arg]
                if custom_content ~= nil then
                    local rowspan = 1
                    for k, v in pairs(self.multiple_rows) do
                        if k == custom_content_arg and next(v) == nil then
                            rowspan = 2
                         end
                         end
                    end
                    tr:tag('td'):wikitext(custom_content):attr('rowspan', rowspan)
                    i = i + 1
                else
                    y = y + 1
                    if (y == 5) then
                        break
                    else
                        i = i + 1
                     end
                     end
                 end
                 end
             end
             end
            doDetail()
         end
         end
        getCustomContent()
     end
     end
    local tr = trait_table:tag('tr')
    trait_left:do_content(tr)
    trait_right:do_content(tr)
    local tr_2 = trait_table:tag('tr')
    -- Will use the same table row. Enhanced + pvp not supported for now.
    trait_left:do_content(tr_2, 'enhanced')
    trait_right:do_content(tr_2, 'enhanced')
    trait_left:do_content(tr_2, 'pvp')
    trait_right:do_content(tr_2, 'pvp')


     return tostring(trait_table);
     return tostring(trait_table);
    -- return dump(trait_left) .. '<br><br>' .. dump(trait_right);
end
end


return p
return p
-- pyend

Latest revision as of 00:43, 15 March 2024

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

-- pystart
require('Module:CommonFunctions')
local i18n = require('Module:I18n')
local getArgs = require('Module:Arguments').getArgs
local getTranslations = i18n.getTranslations
local p = {}

-- Main process
function p.main(frame)
    local args = getArgs(frame)
    local tr = getTranslations(frame, 'Template:Traits', args.lang, true)
    local is_rose = args[1] == 'Rose' and args.ecp == 'true'

    function translate(key)
        return i18n.translate(tr, key)
    end

    -- Argument init
    local traits = args[3] or args.traits
    if (traits == nil) then
        traits = '-, -'
    end
    traits = split(traits);
    for k, v in ipairs(traits) do
        traits[k] = trim(v)
    end
    local skill = args[2] or args.skill
    local default_multiplier = 100

    -- Dictionary for headers
    local prop = { 
        is_rose and translate('ECP Usage') or translate('MP Usage'),
        translate('Cooldown'),
        translate('Duration'),
        is_rose and translate('ECP Recovery') or translate('MP Recovery'),
        translate('Max Hits'),
        translate('Effects'),
    }

    local prop_short = { 'mp', 'cd', 'duration', 'mp_recovery', 'hits', 'effects', 'chance' }

    local OPTIONS = {
        lang_suffix = args.lang and ('/' .. args.lang) or '',
        lang_append = args.lang ~= nil and args.lang ~= ''
    }

    local STR = {
        LIGHT = 'Light',
        CRITICAL = 'Critical',
        REVERSED = 'Reversed',
        HEAVY = 'Heavy',
        HASTE = 'Haste',
        REGEN1 = 'Regenerating (1)',
        REGEN2 = 'Regenerating (2)',
        KB1 = 'Killing Blow (1)',
        KB2 = 'Killing Blow (2)',
        RUTHLESS = 'Ruthless',
        POWERFUL = 'Powerful',
        USEFUL = 'Useful',
        SEC = 'Seconds',
        MP = 'MP',
        ECP = 'ECP',
        PERSISTENT = 'Persistent',
        PERSISTENT2 = 'Persistent2'
    }

    local details = {
        { STR.LIGHT, STR.CRITICAL, STR.REVERSED },
        { STR.HEAVY, STR.HASTE,    STR.REGEN2,  STR.RUTHLESS, STR.POWERFUL, STR.REVERSED },
        { STR.KB1 },
        { STR.REGEN1 },
        { STR.USEFUL, STR.PERSISTENT2 },
        { STR.KB2 }
    }

    -- Default values
    local DEFAULT = {
        [STR.HEAVY] = {
            cd = 120
        },
        [STR.LIGHT] = {
            mp = 80
        },
        [STR.CRITICAL] = {
            mp = (args['def_ignore1'] ~= nil or args['def_ignore2'] ~= nil) and 100 or 120
        },
        [STR.HASTE] = {
            cd = 80
        },
        [STR.RUTHLESS] = {
            cd = 200
        },
        [STR.POWERFUL] = {
            cd = 150
        },
        [STR.REGEN1] = {
            chance = 50,
            mp = 50
        },
        [STR.REGEN2] = {
            chance = 50,
            cd = 50
        },
        [STR.REVERSED] = {
            mp = 60,
            cd = 150
        },
        [STR.USEFUL] = {
            dmg = 80
        },
        [STR.PERSISTENT2] = {
            dmg = 100
        }
    }

    local function color(char)
        char = char or args[1] or args.char or 'Elsword'
        return char:gsub('/', '')
    end

    local trait_table = mw.html.create('div'):attr('class', 'content-table'):tag('table'):attr({
        cellpadding = '5',
        border = '1',
        class = 'colortable-' .. color()
    }):css({
        ['border-collapse'] = 'collapse',
        ['text-align'] = 'center'
    })

    function new_row()
        return trait_table:tag('tr')
    end

    -- headers
    local tr1 = new_row()
    local tr2 = new_row()
    local tr3 = new_row()

    local has_pvp_values = false
    for k, v in pairs(args) do
        if string.find(k, '_pvp') then
            has_pvp_values = true
            break
        end
    end

    local tr4
    -- If pvp values exist, we need the row to place them.
    if has_pvp_values and not tr4 then
        tr4 = new_row()
        -- Add indicator headers
        tr1:tag('th'):wikitext(translate('Mode')):attr('rowspan', 2)
        tr3:tag('td'):wikitext(frame:expandTemplate {
            title = translate('PvE')
        })
        tr4:tag('td'):wikitext(frame:expandTemplate {
            title = translate('PvP')
        })
    end

    -- Loop through 2 input traits.
    for trait_count, trait_name in ipairs(traits) do
        local th = tr1:tag('th'):wikitext(trait_name:gsub(translate(STR.PERSISTENT) .. 2, translate(STR.PERSISTENT)) .. ' ' .. skill);
        local th_effect;
        local th_skilltext;
        local default_value = DEFAULT[trait_name] or {};

        -- Check if detail fields are required and which.
        for detail_key, detail in ipairs(details) do
            if not th_effect then
                th_effect = tr2:tag('th'):wikitext(translate('Attribute Effect'));
            end
            if indexOf(trait_name, detail) then
                local th_detail = tr2:tag('th'):wikitext(translate(prop[detail_key]));
                th:attr('colspan', tonumber(th:getAttr('colspan') or 1) + 1)
            end
        end

        -- Unnamed argument.
        local unnamed = split(args[3 + trait_count]);
        local MP_ARG = args['mp' .. trait_count] or args['mp_recovery' .. trait_count] or default_value['mp_recovery'] or
            default_value['mp'];
        local ECP_ARG = nil

        if is_rose then
            unnamed[2] = unnamed[1] or args['mp' .. trait_count]
            ECP_ARG = unnamed[1] or args['mp' .. trait_count]
            MP_ARG = nil
        end

        -- Append contents.
        for detail_key, detail in ipairs(details) do
            if not th_skilltext then
                th_skilltext = tr3:tag('td'):attr('rowspan', has_pvp_values and 2 or 1):wikitext(frame:expandTemplate {
                    title = translate('SkillText'),
                    args = {
                        trait_name,
                        unnamed[1],
                        unnamed[2],
                        MP = args['def_ignore' .. trait_count] ~= nil and 'Energy' or MP_ARG,
                        ECP = ECP_ARG,
                        CD = args['cd' .. trait_count] or default_value['cd'],
                        DURATION = args['duration' .. trait_count],
                        CHANCE = args['chance' .. trait_count] or default_value['chance'],
                        DAMAGE = args['dmg' .. trait_count] or default_value['dmg'],
                        DEF_IGNORE = args['def_ignore' .. trait_count],
                        DEF_IGNORE_PVP = args['pvp_def_ignore' .. trait_count]
                    }
                });
            end

            function doDetail()
                for _, modeSuffix in ipairs({ '', '_pvp' }) do
                    if indexOf(trait_name, detail) then
                        local short_detail = prop_short[detail_key]
                        local short_detail_improved = short_detail
                        local is_pvp = modeSuffix == '_pvp'

                        -- Fix Regen 1.
                        if short_detail == 'mp_recovery' then
                            short_detail_improved = 'mp'
                        end

                        local detail_content = args[short_detail_improved .. trait_count]
                        local multiplier = detail_content or default_value[short_detail_improved] or 100
                        local suffix = ''
                        if short_detail_improved == 'mp' then
                            suffix = STR.MP
                            if is_rose then
                                suffix = STR.ECP
                            end
                        elseif short_detail == 'cd' or short_detail == 'duration' then
                            suffix = STR.SEC
                        end
                        suffix = suffix and (' ' .. suffix) or ''

                        local base_detail = args[short_detail_improved .. modeSuffix]

                        local function calcEndValue(base)
                            local end_value;
                            if base and tonumber(base) == nil then
                                end_value = base
                            else
                                end_value = (tonumber(multiplier) / 100) * tonumber(base or -1)
                            end
                            if tonumber(end_value) ~= nil and tonumber(end_value) < 0 then
                                end_value = '-'
                            end
                            return end_value .. suffix
                        end

                        local end_value = calcEndValue(base_detail)

                        local enhanced_detail = args[short_detail_improved .. modeSuffix .. '_enhanced']
                        if enhanced_detail ~= nil then
                            end_value = end_value .. "<br/>'''" .. frame:expandTemplate {
                                title = 'Tt',
                                args = { calcEndValue(enhanced_detail) .. "'''",
                                    translate("Final Enhanced Skill") }
                            }
                        end

                        if (is_pvp and base_detail) or not is_pvp then
                            local detail_text = end_value
                            if end_value == '-' and args['detail' .. trait_count] then
                                detail_text = args
                                    ['detail' .. trait_count]
                            end

                            local detail_cell = (is_pvp and tr4 or tr3):tag('td'):wikitext(detail_text):attr('rowspan', has_pvp_values and (not args[short_detail_improved .. '_pvp']) and 2 or 1);
                        end
                    end
                end
            end

            doDetail()
        end
    end

    return tostring(trait_table);
end

return p
-- pyend