Mobius Final Fantasy Wiki
m (show plus in table if fast-learner.)
m (Undo revision 42587 by BryghtShadow (talk) Wait, I read the table wrong >_<)
Line 92: Line 92:
 
local row = {}
 
local row = {}
 
local m = multis[level]
 
local m = multis[level]
 
table.insert(row, level)
if fast then
 
table.insert(row, level .. '+')
 
else
 
table.insert(row, level)
 
end
 
 
if show_attack then
 
if show_attack then
 
table.insert(row, round(attack * m))
 
table.insert(row, round(attack * m))

Revision as of 09:17, 7 August 2017

Tests

YesY All tests passed.

Name Expected Actual
YesY testFastSupportLevels
YesY testFastWarriorLevels
YesY testNormalSupportLevels
YesY testNormalWarriorLevels

local p = {}
local black = '★'
local white = '☆'
local function round(n)
	return math.floor(n + 0.5)
end
function p._main(args)
	local args = args
	local rarity = args.rarity or ''
	local attack = args.attack or ''
	local breakpower = args.breakpower or ''
	local critchance = args.critchance or ''
	local const_breakpower = args.const_breakpower or ''
	const_breakpower = const_breakpower == 'y'
	if rarity == '' then
		mw.log('ability stat: "rarity" argument is null or empty')
		return ''
	end
	local multis = {1.0, 1.1, 1.2, 1.3, 1.4, 1.7, 2.0, 2.3, 2.6, 3.0}
	
	local fast = false
	local rarities = {}
	for a,b in string.gmatch(rarity, '(-?%d+)(%+?)') do
		a = tonumber(a)
		if a < 1 or 5 < a then
			error("Rarity outside the range of 1~5: "..a..b)
		elseif b == '+' then
			fast = true
		end
		table.insert(rarities, a)
	end
	table.sort(rarities)
	if attack == '' then
		attack = 0
	else
		attack = tonumber(attack)
	end
	if breakpower == '' then
		breakpower = 0
	else
		breakpower = tonumber(breakpower)
	end
	if critchance ~= '' then
		local total = tonumber(critchance)
		local _, black_count, white_count
		if total == nil then
			_, black_count = string.gsub(critchance, black, '')
			_, white_count = string.gsub(critchance, white, '')
			total = black_count + white_count * 10
		end
		white_count = math.floor(total / 10)
		black_count = total % 10
		critchance = string.rep(white, white_count) .. string.rep(black, black_count)
	end
	-- If attack is 0, then it's a support ability.
	-- If break is 0, then it's a support ability.
	local support = attack == 0 or breakpower == 0
	local show_attack = attack > 0
	local show_breakpower = breakpower > 0
	local show_critchance = critchance ~= ''
	-- TODO: Find a better way to determine whether to display Cooldowns.
	--       To handle cases where critchance > 0 and cooldown > 0.
	local show_cooldown = support or (fast and critchance == '')
	
	local columns = {}
	local rows = {}
	local level
	local m, c -- y = mx + c
	if support then
		m = 1
		c = 1
	else
		m = 2
		c = 0
	end
	local levels = {}
	if fast then
		for i, rarity in ipairs(rarities) do
			table.insert(levels, rarity * m + c)
		end
	else
		for level=1, rarities[#rarities] * m + c do
			table.insert(levels, level)
		end
	end
	table.insert(columns, 'ALv.')
	if show_attack then table.insert(columns, 'Attack') end
	if show_breakpower then table.insert(columns, 'Break Power') end
	if show_critchance then table.insert(columns, 'Crit Chance') end
	if show_cooldown then table.insert(columns, 'Cooldown') end
	for i,level in ipairs(levels) do
		local row = {}
		local m = multis[level]
		table.insert(row, level)
		if show_attack then
			table.insert(row, round(attack * m))
		end
		if show_breakpower then
			if const_breakpower then
				table.insert(row, breakpower)
			else
				table.insert(row, round(breakpower * m))
			end
		end
		if show_critchance then
			table.insert(row, critchance)
		end
		if show_cooldown then
			local cooldown
			if support then
				cooldown = 9 - level
			elseif fast then
				-- so far, max CD for non-support fast-learner ability is 2.
				cooldown = math.max(2, 6 - math.floor(level / 2))
			end
			table.insert(row, cooldown)
		end
		table.insert(rows, row)
	end

	local wikitable, tr
	
	wikitable = mw.html.create('table'):addClass('wikitable'):newline()
	tr = mw.html.create('tr')
	for i,th in ipairs(columns) do
		tr:tag('th'):wikitext(th)
	end
	wikitable:node(tr):newline()
	for i,row in ipairs(rows) do
		tr = mw.html.create('tr')
		for j,td in ipairs(row) do
			tr:tag('td'):wikitext(td)
		end
		wikitable:node(tr):newline()
	end
	return tostring(wikitable)
end

function p.main(frame)
	local pframe = frame:getParent()
	local config = frame.args
	local args = pframe.args
	return p._main(args)
end

return p