Module:Skill
Jump to navigation
Jump to search
Documentation for this module may be created at Module:Skill/doc
local getArgument = require('Module:Arguments').getArgument local p = {} function capitalFirst(str) -- Allows capitalization of the first letter of each word in a string; adapted from (https://stackoverflow.com/questions/20284515/capitalize-first-letter-of-every-word-in-lua) return (str:gsub("(%l)(%w*)", function(a,b) return string.upper(a)..b end)) end function p.Main(frame) local args = frame.args local game = args[1]:lower() local input = args[2]:lower() local getSkill = require('Module:Data/Skill/' .. game) local iconPage = mw.title.makeTitle('Module', 'Data/Icon/' .. game) -- Creates information about a given page -- 1 SKILL NAME -- 1.1 SKILL POTENTIAL IN SMT5 if game == 'smt5' or game == 'smt5v' then -- Check if game is Shin Megami Tensei V, so that the Skill Potential can be added to the name if string.sub(input, -2, -2) == '-' or string.sub(input, -2, -2) == '+' then skillPotential = ' ' .. string.sub(input, -2, -1) skillPotentialStore = string.sub(input, -2, -1) input = string.sub(input, 1, -4) else skillPotential = '' end else skillPotential = '' end if not getSkill.skill[input] then --Error message for invalid skill error("Skill \"" .. input .. "\" not defined for " .. game) end -- 1.2 SKILL LINK if getSkill.skill[input] and getSkill.skill[input].link then -- Check if an alternate link for a page is set in skill data name = '[[' .. getSkill.skill[input].link .. '|' .. getSkill.skill[input].name .. ']]' .. skillPotential else name = '[[' .. getSkill.skill[input].name .. ']]' .. skillPotential end -- 3 NAME AND ATTRIBUTE -- 3.1 NAME NOTE if getSkill.skill[input] and getSkill.skill[input].name_note then namenote = frame:expandTemplate{ title = 'exp', args = { getSkill.skill[input].name_note } } else namenote = '' end if game == 'mip' and getSkill.skill[input] and getSkill.skill[input].rpname then rpname = ' / ' .. getSkill.skill[input].rpname else rpname = '' end -- 4.1 FOR DESUM if game == 'desum' then if getSkill.skill[input] and getSkill.skill[input].attribute_link then nameattribute = '\n|style="text-align:left; white-space:nowrap"|' .. require('Module:Data/Icon/desum').icon[getSkill.skill[input].desumicon] .. '<small> </small>' .. name .. namenote .. '\n|style="text-align:center;"|' .. '[[' .. getSkill.skill[input].attribute_link .. '|' .. capitalFirst(getSkill.skill[input].attribute:lower()) .. ']]' else nameattribute = '\n|style="text-align:left; white-space:nowrap"|' .. require('Module:Data/Icon/desum').icon[getSkill.skill[input].desumicon] .. '<small> </small>' .. name .. namenote .. '\n|style="text-align:center;"|' .. '[[' .. capitalFirst(getSkill.skill[input].attribute:lower()) .. ']]' end -- 4.2 FOR OTHER GAMES else -- 4.3 SET ATTRIBUTE OUTPUT if getSkill.skill[input].attribute then attribute = getSkill.skill[input].attribute:lower() else attribute = '' end if attribute == 'pc' or attribute == 'ps' then attributeout = attribute:upper() else attributeout = capitalFirst(attribute) end -- 4.4 IF ICON PAGE EXISTS if iconPage.exists == true then getIcon = require('Module:Data/Icon/' .. game) if getIcon.icon[attribute] then -- Check if attribute is set in skill data nameattribute = '\n|style="text-align:left;"|' .. getIcon.icon[attribute] .. ' ' .. name .. rpname .. namenote -- Set icon elseif getSkill.skill[input] and getSkill.skill[input].attribute_link then nameattribute = '\n|style="text-align:center;"|' .. name .. namenote .. '\n|style="text-align:center;"|' .. '[[' .. getSkill.skill[input].attribute_link .. '|' .. attributeout .. ']]' else nameattribute = '\n|style="text-align:center;"|' .. name .. namenote .. '\n|style="text-align:center;"|' .. '[[' .. attributeout .. ']]' end -- 4.5 IF ICON PAGE DOES NOT EXIST elseif attribute == nil or attribute == '' or attribute == '—' then nameattribute = '\n|style="text-align:center;"|' .. name .. namenote .. '\n|style="text-align:center;"|' .. '—' elseif getSkill.skill[input] and getSkill.skill[input].attribute_link then nameattribute = '\n|style="text-align:center;"|' .. name .. namenote .. '\n|style="text-align:center;"|' .. '[[' .. getSkill.skill[input].attribute_link .. '|' .. attributeout .. ']]' else nameattribute = '\n|style="text-align:center;"|' .. name .. namenote .. '\n|style="text-align:center;"|' .. '[[' .. attributeout .. ']]' end end -- 5 COST AND COST TYPE if getSkill.skill[input].costtype then costType = ' ' .. getSkill.skill[input].costtype else costType = '' end if getSkill.skill[input].cost == nil then cost = '' elseif getSkill.skill[input].cost == '' or getSkill.skill[input].cost == '—' then cost = '\n|style="text-align:center;"|' .. '—' -- 5.1 FOR SMT5 elseif type(getSkill.skill[input].cost) ~= "string" and skillPotentialStore then -- Check if game is Shin Megami Tensei V, as that game has multipliers based on Skill Potential values, as listed below if getSkill.skill[input].attribute == 'support' or getSkill.skill[input].attribute == 'healing' then -- For support skills skillPotentialStore = skillPotentialStore .. 'hs' end costCalc = getSkill.skill[input].cost * require('Module:Data/Skill_Potential/' .. game).skillPotential[skillPotentialStore] if math.fmod(costCalc,1) > 0.95 then costOut = math.ceil(costCalc) else costOut = math.floor(costCalc) end cost = '\n|style="text-align:center;"|' .. costOut .. costType -- Set cost type with multiplier -- 5.2 FOR OTHER GAMES else cost = '\n|style="text-align:center;"|' .. getSkill.skill[input].cost .. costType end -- 6 RANGE if game ~= 'pq1' and game ~= 'pq2' and game ~= 'desum' and game ~= 'sh1' and getSkill.skill[input] and getSkill.skill[input].range then -- Check if the skill has a range parameter; omit if not range = '\n|style="text-align:center;"|' .. getSkill.skill[input].range else range = '' end -- 7 LEVEL if args[3] and game ~= 'mip' then -- Check if a parameter for the level is set by the user, otherwise omit it if args[3] == '' then level = '' elseif args[3] == '-' then level = '\n|style="text-align:center;"|' .. 'Innate' else level = '\n|style="text-align:center;"|' .. args[3] end else level = '' end -- 8 RANK AND INHERITANCE IN MIP if game == 'mip' and args[3] and args[3] ~= '' then -- Check if game is Megami Ibunroku Persona, and if an inherit value is set. if args[3]:lower() == 'y' then rank = '' inherit = '\n|style="text-align:center;"|<span style="color:lime;">✔</span>' elseif args[3]:lower() == 'n' then rank = '' inherit = '\n|style="text-align:center;"|<span style="color:red;">✘</span>' else rank = '\n|style="text-align:center;"|' .. args[3] inherit = '' cost = '' -- REMOVES COST end else rank = '' inherit = '' end -- 9 DESCRIPTION OR EFFECT if getSkill.skill[input] and getSkill.skill[input].description then description = '\n|style="text-align:left;"|' ..getSkill.skill[input].description elseif getSkill.skill[input] and getSkill.skill[input].effect then description = '\n|style="text-align:left;"|' .. getSkill.skill[input].effect else description = '' end -- 10 FINAL OUTPUT local output = rank .. nameattribute .. cost .. range .. description .. level .. inherit .. '\n|-' return output end return p