Module:Skill Effect

Jump to navigation Jump to search

Documentation for this module may be created at Module:Skill Effect/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 getName = require('Module:Data/Media/Game')
	if not getSkill.skill[input] then --Error message for invalid skill
		error("Skill \"" .. input .. "\" not defined for " .. game)
	end
	
	if getName.media[game] and getSkill.skill[input].effect_note then
		title = '\n|style="text-align:center;|' .. frame:expandTemplate{ title = 'link', args = { 'game', game } } .. frame:expandTemplate { title = 'exp', args = { getSkill.skill[input].effect_note } }
	elseif getName.media[game] then
		title = '\n|style="text-align:center;|' .. frame:expandTemplate{ title = 'link', args = { 'game', game } }
	end
	
-- Checks if the game is MIP for Bless and Curse, which share an English name with a minor element in MIP 
	if game == 'mip' then
		mip = true
	else
		mip = false
	end

-- Get 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
		attributelink = '\n|style="text-align:center;"|[[List of Minor Elements#' .. attribute .. '|' .. attribute .. ']]'
	elseif getSkill.skill[input].attribute_link then
		attributelink = '\n|style="text-align:center;"|[[' .. getSkill.skill[input].attribute_link .. '|' .. attribute .. ']]'
	elseif attribute ~= '' then
		attributelink = '\n|style="text-align:center;"|[[' .. attribute .. ']]'
	else
		attributelink = '\n|style="text-align:center;"|—'
	end
-- Get skill type such as Magic, Theurgy, Commander skill, etc.
	if getSkill.skill[input].skilltype and getSkill.skill[input].skilltype ~= '' then
		skilltype = '\n|style="text-align:center;"|' .. getSkill.skill[input].skilltype
	else
		skilltype = '\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
		damagetype = '\n|style="text-align:center;"|' .. getSkill.skill[input].damagetype
	else
		damagetype = '\n|style="text-align:center;"|—'
	end
	
-- Get skill's effect
	if getSkill.skill[input].effect and getSkill.skill[input].effect ~= '' then
		effect = '\n|style="text-align:center;"|' .. getSkill.skill[input].effect
	else
		effect = '\n|style="text-align:center;"|—'
	end

-- Get 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 = '\n|style="text-align:center;white-space:nowrap;"|—'
	elseif getSkill.skill[input].cost == '' or getSkill.skill[input].cost == '—' then
		cost = '\n|style="text-align:center;white-space:nowrap;"|' .. '—'
	else
		cost = '\n|style="text-align:center;white-space:nowrap;"|' .. getSkill.skill[input].cost .. costType	
	end

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

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

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

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

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

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

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

-- Get rank
	if getSkill.skill[input].rank and getSkill.skill[input].rank ~= '' then
		rank = '\n|style="text-align:center;white-space:nowrap;"|' .. getSkill.skill[input].rank
	else
		rank = '\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 
		inbattle = '\n|style="text-align:center;"|' .. frame:expandTemplate{ title = 'y' }
	elseif getSkill.skill[input].inbattle and getSkill.skill[input].inbattle:lower() == 'n' then
		inbattle = '\n|style="text-align:center;"|' .. frame:expandTemplate{ title = 'n' }
	else
		inbattle = '\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
		outbattle = '\n|style="text-align:center;"|' .. frame:expandTemplate{ title = 'y' }
	elseif getSkill.skill[input].outbattle and getSkill.skill[input].outbattle:lower() == 'n' then
		outbattle = '\n|style="text-align:center;"|' .. frame:expandTemplate{ title = 'n' }
	else
		outbattle = '\n|style="text-align:center;"|—'
	end
	
-- Output the result of everything we just got
	local output = title .. attributelink .. skilltype .. damagetype .. effect .. cost .. powerlvl .. target .. range .. hit .. power .. crit .. acc .. rank .. inbattle .. outbattle .. '\n|-'
	return output
end

return p