Module:Traits: Difference between revisions
From Elwiki
No edit summary Tag: Manual revert |
No edit summary |
||
Line 1: | Line 1: | ||
-- pystart | |||
require('Module:CommonFunctions') | require('Module:CommonFunctions') | ||
local getArgs = require('Module:Arguments').getArgs | local getArgs = require('Module:Arguments').getArgs | ||
Line 20: | Line 21: | ||
-- Dictionary for headers | -- Dictionary for headers | ||
local | local prop = {'MP Usage', 'Cooldown', 'Duration', 'MP Recovery', 'Max Hits'} | ||
local | |||
local | local prop_short = {'mp', 'cd', 'duration', 'mp_recovery', 'dmg', 'chance'} | ||
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' | |||
} | } | ||
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}} | |||
-- Default values | -- Default values | ||
local | local DEFAULT = { | ||
[STR.HEAVY] = { | |||
cd = 120 | |||
}, | |||
[STR.LIGHT] = { | |||
mp = 80 | |||
}, | |||
[STR.CRITICAL] = { | |||
mp = 120, | |||
def = 50 | |||
}, | |||
[STR.HASTE] = { | |||
cd = 80 | |||
}, | |||
[STR.RUTHLESS] = { | |||
cd = 200 | |||
}, | }, | ||
[STR.POWERFUL] = { | |||
cd = 150 | |||
}, | }, | ||
[STR.REGEN1] = { | |||
chance = 50, | |||
mp_recovery = 50 | |||
}, | }, | ||
[STR.REGEN2] = { | |||
chance = 50, | |||
cd = 50 | |||
}, | }, | ||
[STR.REVERSED] = { | |||
mp = 50, | |||
cd = 150 | |||
}, | }, | ||
[STR.USEFUL] = { | |||
dmg = 80 | |||
} | } | ||
} | } | ||
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 char:gsub('/', '') | return char:gsub('/', '') | ||
end | end | ||
Line 237: | Line 98: | ||
}) | }) | ||
function | function new_row() | ||
return trait_table:tag('tr') | return trait_table:tag('tr') | ||
end | end | ||
-- headers | |||
local | local tr1 = new_row() | ||
local | local tr2 = new_row() | ||
local tr3 = new_row() | |||
local | -- Loop through 2 input traits. | ||
for trait_count, trait_name in ipairs(traits) do | |||
local th = tr1:tag('th'):wikitext(trait_name .. ' ' .. skill); | |||
local th_effect; | |||
local th_skilltext; | |||
local detail_list = {} | |||
local default_value = DEFAULT[trait_name] or {}; | |||
if | -- 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('Attribute Effect'); | |||
if | |||
end | end | ||
if | if indexOf(trait_name, detail) then | ||
local th_detail = tr2:tag('th'):wikitext(prop[detail_key]); | |||
th:attr('colspan', tonumber(th:getAttr('colspan') or 1) + 1) | |||
end | end | ||
end | end | ||
-- Unnamed argument. | |||
local unnamed = split(args[3 + trait_count]); | |||
-- Append contents. | |||
for detail_key, detail in ipairs(details) do | |||
if not th_skilltext then | |||
th_skilltext = tr3:tag('td'):wikitext(frame:expandTemplate{ | |||
title = 'SkillText', | |||
-- | args = { | ||
trait_name, | |||
if | unnamed[1], | ||
unnamed[2], | |||
MP = args['mp' .. trait_count] or args['mp_recovery' .. trait_count] or default_value['mp'] or | |||
default_value['mp_recovery'], | |||
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'] | |||
} | |||
}); | |||
} | |||
end | end | ||
if indexOf(trait_name, detail) then | |||
local short_detail = prop_short[detail_key] | |||
local detail_content = args[short_detail .. trait_count] | |||
local multiplier = detail_content or default_value[short_detail] | |||
if multiplier ~= nil then | |||
if | local suffix = '' | ||
if short_detail == 'mp' or short_detail == 'mp_recovery' then | |||
suffix = STR.MP | |||
elseif short_detail == 'cd' or short_detail == 'duration' then | |||
suffix = STR.SEC | |||
if | |||
local | |||
if | |||
elseif | |||
end | end | ||
local end_value = (tonumber(multiplier) / 100) * tonumber(args[short_detail] or 0); | |||
if end_value <= 0 then | |||
end_value = '-' | |||
end | end | ||
local detail_cell = tr3:tag('td'):wikitext(end_value .. suffix); | |||
end | end | ||
end | end | ||
end | end | ||
end | end | ||
return tostring(trait_table); | return tostring(trait_table); | ||
end | end | ||
return p | return p | ||
-- pyend |
Revision as of 22:47, 28 October 2022
Documentation for this module may be created at Module:Traits/doc
-- pystart
require('Module:CommonFunctions')
local getArgs = require('Module:Arguments').getArgs
local p = {}
-- Main process
function p.main(frame)
local args = getArgs(frame);
-- 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 = {'MP Usage', 'Cooldown', 'Duration', 'MP Recovery', 'Max Hits'}
local prop_short = {'mp', 'cd', 'duration', 'mp_recovery', 'dmg', 'chance'}
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'
}
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}}
-- Default values
local DEFAULT = {
[STR.HEAVY] = {
cd = 120
},
[STR.LIGHT] = {
mp = 80
},
[STR.CRITICAL] = {
mp = 120,
def = 50
},
[STR.HASTE] = {
cd = 80
},
[STR.RUTHLESS] = {
cd = 200
},
[STR.POWERFUL] = {
cd = 150
},
[STR.REGEN1] = {
chance = 50,
mp_recovery = 50
},
[STR.REGEN2] = {
chance = 50,
cd = 50
},
[STR.REVERSED] = {
mp = 50,
cd = 150
},
[STR.USEFUL] = {
dmg = 80
}
}
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()
-- Loop through 2 input traits.
for trait_count, trait_name in ipairs(traits) do
local th = tr1:tag('th'):wikitext(trait_name .. ' ' .. skill);
local th_effect;
local th_skilltext;
local detail_list = {}
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('Attribute Effect');
end
if indexOf(trait_name, detail) then
local th_detail = tr2:tag('th'):wikitext(prop[detail_key]);
th:attr('colspan', tonumber(th:getAttr('colspan') or 1) + 1)
end
end
-- Unnamed argument.
local unnamed = split(args[3 + trait_count]);
-- Append contents.
for detail_key, detail in ipairs(details) do
if not th_skilltext then
th_skilltext = tr3:tag('td'):wikitext(frame:expandTemplate{
title = 'SkillText',
args = {
trait_name,
unnamed[1],
unnamed[2],
MP = args['mp' .. trait_count] or args['mp_recovery' .. trait_count] or default_value['mp'] or
default_value['mp_recovery'],
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']
}
});
end
if indexOf(trait_name, detail) then
local short_detail = prop_short[detail_key]
local detail_content = args[short_detail .. trait_count]
local multiplier = detail_content or default_value[short_detail]
if multiplier ~= nil then
local suffix = ''
if short_detail == 'mp' or short_detail == 'mp_recovery' then
suffix = STR.MP
elseif short_detail == 'cd' or short_detail == 'duration' then
suffix = STR.SEC
end
local end_value = (tonumber(multiplier) / 100) * tonumber(args[short_detail] or 0);
if end_value <= 0 then
end_value = '-'
end
local detail_cell = tr3:tag('td'):wikitext(end_value .. suffix);
end
end
end
end
return tostring(trait_table);
end
return p
-- pyend