Module:Sandbox/Mistiryshak6

Jump to navigation Jump to search

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

local getArgument = require('Module:Arguments').getArgument

local p = {}

function p.Main(frame)

	local function redirectIfNeeded(abbr)
		if abbr == "p1" or abbr == "rp" then
			return "mip"
		elseif string.find(abbr, "smt3") then
			return "smt3"
		else
			return abbr	
		end
	end
	
	local args = frame.args
	local game = args[1]:lower()
	local input = args[2]:lower()
	local getSkill = mw.loadData('Module:Data/Skill/' .. redirectIfNeeded(game))
	local getName = mw.loadData('Module:Data/Media/Game')
	if not getSkill.skill[input] then --Error message for invalid skill
		error("Skill \"" .. input .. "\" not defined for " .. game)
	end
	local skillOutput = {''}
	
	local 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
	
	if getName.media[game] and getSkill.skill[input].effect_note then
		if getSkill.skill[input].platform then
			table.insert(skillOutput, '\n|style="text-align:center;|' .. frame:expandTemplate{ title = 'link', args = { 'game', game } } .. frame:expandTemplate { title = 'Exp Plat', args = { getSkill.skill[input].platform } } .. frame:expandTemplate { title = 'exp', args = { getSkill.skill[input].effect_note } })
		else
			table.insert(skillOutput, '\n|style="text-align:center;|' .. frame:expandTemplate{ title = 'link', args = { 'game', game } } .. frame:expandTemplate { title = 'exp', args = { getSkill.skill[input].effect_note } })
		end
	elseif getName.media[game] then
		if getSkill.skill[input].platform then
			table.insert(skillOutput, '\n|style="text-align:center;|' .. frame:expandTemplate{ title = 'link', args = { 'game', game } } .. frame:expandTemplate { title = 'Exp Plat', args = { getSkill.skill[input].platform } })
		else
			table.insert(skillOutput, '\n|style="text-align:center;|' .. frame:expandTemplate{ title = 'link', args = { 'game', game } })
		end
	end
	
-- Checks if the game is MIP for Bless and Curse, which share an English name with a minor element in MIP 
	local mip
	if game == 'mip' then
		mip = true
	else
		mip = false
	end

-- Get attribute
	local attribute
	if getSkill.skill[input].attribute and getSkill.skill[input].attribute ~= '' then 
		attribute = getSkill.skill[input].attribute:lower()
	else
		attribute = ''
	end
-- Checks if attribute has to be rendered in all caps
	if attribute == 'pc' or attribute == 'ps' then
		attribute = attribute:upper()
	else
		attribute = capitalFirst(attribute)
	end
--Get damage attribute if needed
	if getSkill.skill[input].damage_attribute then
		attribute = capitalFirst(getSkill.skill[input].damage_attribute)
	end

-- Table of minor elements, which is checked against the value of 'attribute' to determine if it should link to the minor elements page
	local minorElement = {
		['Attack'] = true,
		['Energy Drain'] = true,
		['Explode'] = true,
		['Fly'] = true,
		['Hand'] = true,
		['Leg'] = true,
		['Needle'] = true,
		['Demon Attack'] = true,
		['Debuff'] = true,
		['PC'] = true,
		['PS'] = true,
		['Arrow'] = true,
		['Fist'] = true,
		['Gravity'] = true,
		['Bless'] = mip,
		['Curse'] = mip,
		['Handgun'] = true,
		['Machinegun'] = true,
		['Miracle'] = true,
		['Occult'] = true,
		['Prayer'] = true,
		['Rifle'] = true,
		['Shotgun'] = true,
		['Sword'] = mip,
		['Two-Hand'] = true,
		['Vs. Boss'] = true,
		['Whip'] = true,
		}
-- Checks if the attribute is a minor element and then links to the proper page
	if minorElement[attribute] == true then
		table.insert(skillOutput, '\n|style="text-align:center;"|[[List of Minor Elements#' .. attribute .. '|' .. attribute .. ']]' )
	elseif getSkill.skill[input].attribute_link then
		table.insert(skillOutput, '\n|style="text-align:center;"|[[' .. getSkill.skill[input].attribute_link .. '|' .. attribute .. ']]' )
	elseif attribute ~= '' then
		table.insert(skillOutput, '\n|style="text-align:center;"|[[' .. attribute .. ']]' )
	else
		table.insert(skillOutput, '\n|style="text-align:center;"|—' )
	end
	attribute = nil
	minorElement = nil
	
-- Get skill type such as Magic, Theurgy, Commander skill, etc.
	if getSkill.skill[input].skilltype and getSkill.skill[input].skilltype ~= '' then
		table.insert(skillOutput, '\n|style="text-align:center;"|' .. getSkill.skill[input].skilltype )
	else
		table.insert(skillOutput, '\n|style="text-align:center;"|—' )
	end
	
-- Get damage type such as Physical, Magic, etc.
	if getSkill.skill[input].damagetype and getSkill.skill[input].damagetype ~= '' then
		table.insert(skillOutput, '\n|style="text-align:center;"|' .. getSkill.skill[input].damagetype )
	else
		table.insert(skillOutput, '\n|style="text-align:center;"|—' )
	end
	
-- Get skill's effect
	if getSkill.skill[input].effect and getSkill.skill[input].effect ~= '' then
		table.insert(skillOutput, '\n|style="text-align:center;"|' .. getSkill.skill[input].effect )
	else
		table.insert(skillOutput, '\n|style="text-align:center;"|—' )
	end

-- Get cost and cost type
	local costType, skillCost
	if getSkill.skill[input].costtype then
		costType = ' ' .. getSkill.skill[input].costtype
	else
		costType = nil
	end
	
	if getSkill.skill[input].cost then
		skillCost = getSkill.skill[input].cost
	else
		skillCost = nil
	end
	
	if (skillCost == '') or (skillCost == '—') or (skillCost == nil) then
		table.insert(skillOutput, '\n|style="text-align:center;white-space:nowrap;"|—' )
	else
		table.insert(skillOutput, '\n|style="text-align:center;white-space:nowrap;"|' .. skillCost .. (costType) )
	end
	skillCost = nil
	costType = nil

-- Get power level
	if getSkill.skill[input].powerlvl and getSkill.skill[input].powerlvl ~= '' then
		table.insert(skillOutput, '\n|style="text-align:center;"|' .. getSkill.skill[input].powerlvl )
	else
		table.insert(skillOutput, '\n|style="text-align:center;"|—' )
	end

-- Get targets	
	if getSkill.skill[input].target and getSkill.skill[input].target ~= '' then
		table.insert(skillOutput, '\n|style="text-align:center;white-space:nowrap;"|' .. frame:preprocess(getSkill.skill[input].target) )
	else
		table.insert(skillOutput, '\n|style="text-align:center;white-space:nowrap;"|—' )
	end

-- Get hit no.
	if getSkill.skill[input].hit and getSkill.skill[input].hit ~= '' then 
		table.insert(skillOutput, '\n|style="text-align:center;"|' .. getSkill.skill[input].hit )
	else
		table.insert(skillOutput, '\n|style="text-align:center;"|—' )
	end

-- Get base power
	if getSkill.skill[input].power and getSkill.skill[input].power ~= '' then
		table.insert(skillOutput, '\n|style="text-align:center;"|' .. getSkill.skill[input].power )
	else
		table.insert(skillOutput, '\n|style="text-align:center;"|—' )
	end

-- Get crit rate
	if getSkill.skill[input].crit and getSkill.skill[input].crit ~= '' then
		table.insert(skillOutput, '\n|style="text-align:center;"|' .. getSkill.skill[input].crit )
	else
		table.insert(skillOutput, '\n|style="text-align:center;"|—' )
	end

-- Get accuracy
	if getSkill.skill[input].acc and getSkill.skill[input].acc  ~= '' then
		table.insert(skillOutput, '\n|style="text-align:center;"|' .. getSkill.skill[input].acc )
	else
		table.insert(skillOutput, '\n|style="text-align:center;"|—' )
	end

-- Get range
	if getSkill.skill[input].range and getSkill.skill[input].range ~= '' then
		table.insert(skillOutput, '\n|style="text-align:center;white-space:nowrap;"|' .. getSkill.skill[input].range )
	else
		table.insert(skillOutput, '\n|style="text-align:center;white-space:nowrap;"|—' )
	end

-- Get rank
	if getSkill.skill[input].rank and getSkill.skill[input].rank ~= '' then
		table.insert(skillOutput, '\n|style="text-align:center;white-space:nowrap;"|' .. getSkill.skill[input].rank )
	else
		table.insert(skillOutput, '\n|style="text-align:center;white-space:nowrap;"|—' )
	end

-- Check if skill can be used in battle or not
	if getSkill.skill[input].inbattle and getSkill.skill[input].inbattle:lower() == 'y' then 
		table.insert(skillOutput, '\n|style="text-align:center;"|' .. frame:expandTemplate{ title = 'y' } )
	elseif getSkill.skill[input].inbattle and getSkill.skill[input].inbattle:lower() == 'n' then
		table.insert(skillOutput, '\n|style="text-align:center;"|' .. frame:expandTemplate{ title = 'n' } )
	else
		table.insert(skillOutput, '\n|style="text-align:center;"|—' )
	end

-- Check if skill can be used outside of battle or not
	if getSkill.skill[input].outbattle and getSkill.skill[input].outbattle:lower() == 'y' then
		table.insert(skillOutput, '\n|style="text-align:center;"|' .. frame:expandTemplate{ title = 'y' } )
	elseif getSkill.skill[input].outbattle and getSkill.skill[input].outbattle:lower() == 'n' then
		table.insert(skillOutput, '\n|style="text-align:center;"|' .. frame:expandTemplate{ title = 'n' } )
	else
		table.insert(skillOutput, '\n|style="text-align:center;"|—' )
	end
	
-- Output the result of everything we just got
	local output = table.concat(skillOutput) .. '\n|-'
	return output
end

return p