Mobius Final Fantasy Wiki
Advertisement

local p = {}
local browns = {
	'^(HP) ?%+ ?(%d+)$', --Increases HP by X.
	'^(Attack) ?%+ ?(%d+)$', --Increases Attack by X.
	'^(Break Power) ?%+ ?(%d+)$', --Increases Break Power by X.
	'^(Magic) ?%+ ?(%d+%%)$', --Increases Magic by X%.
	'^(Crit Chance) ?%+ ?(%d+%%)$', --Increases Crit Chance by X%.
	'^(Speed) ?%+ ?(%d+)$', --Increases Speed (actions/turn) by X.
	'^(Defense) ?%+ ?(%d+)$',
}
local greens = {
	'^(.-) (New Job)$',
	'^(.-) (New Weapon)$',
	'^(.-%+) (Upgrade)$',
	'^(.- Bis) (Upgrade)$',
	'^(.- X) (Upgrade)$',
	'^(Enhance Ultimate) (Lv%. Up)$',
}
local blues = {
	'^(Ability Chain) ?%+ ?(%d+%%)$', --Using abilities in succession raises damage by X%.
	'^(Ability Salvo) ?%+ ?(%d+%%)$', --The more times you use abilities in a row, the greater the attack power, Magic and Break power of your next attack.
	'^(Armor Break) ?%+ ?(%d+%%)$', --Ability to turn Break gauge red increased by X%.
	'^(Attack Limit Break)$', --Normal attacks deal more than 9999 damage.
	'^(Attuned Chain) ?%+ ?(%d+%%)$', --Using abilities of the same element in succession raises damage by X%.
	'^(Auto%-Charge Ultimate) ?%+ ?(%d+)$', --Charges the Ultimate gauge by X every turn.
	'^(Avert Action Loss) ?%+ ?(%d+%%)$', --Increases resistance to action-lowering abilities by X%.
	'^(Avert Attack Down) ?%+ ?(%d+%%)$', --Increases resistance to Attack-lowering abilities by X%.
	'^(Avert Bio) ?%+ ?(%d+%%)$', --Increases resistance to poison by X%.
	'^(Avert Break Power Down) ?%+ ?(%d+%%)$', --Increases resistance to Break Power-lowering abilities by X%.
	'^(Avert Crit Down) ?%+ ?(%d+%%)$', --Increases resistance to Crit Chance-lowering abilities by X%.
	'^(Avert Defense Down) ?%+ ?(%d+%%)$', --Increases resistance to Defense-lowering abilities by X%.
	'^(Avert Magic Down) ?%+ ?(%d+%%)$', --Increases resistance to Magic-lowering abilities by X%.
	'^(Avert Stun) ?%+ ?(%d+%%)$', --Increases resistance to stuns by X%.
	'^(Avert Unguard) ?%+ ?(%d+%%)$', --Increases resistance to Unguard (nullifies Defense) by X%.
	'^(Barrier Starter)$',
	'^(Boost Starter)$',
	'^(Brave Starter)$',
	'^(Clutch Barrier)$', --Increases Defense when HP is low.
	'^(Clutch Berserk)$', --Increases damage of all attacks when HP is low, at the cost of Defense.
	'^(Clutch Boost)$', --Increases Break Power when HP is low.
	'^(Clutch Brave)$', --Increases Attack when HP is low.
	'^(Clutch Drain)$', --Normal attacks restore HP when HP is low. Ultimates restore HP once.
	'^(Clutch Faith)$', --Increases Magic when HP is low.
	'^(Clutch Haste)$', --Increases actions per turn when HP is low.
	'^(Clutch Regen)$', --Restores HP every turn when HP is low.
	'^(Clutch Snipe)$', --Increases Crit Chance when HP is low.
	'^(Clutch Ultimate Booster)$', --Attacks, abilities, and element drives that consume actions increase the Ultimate gauge when HP is low.
	'^(Clutch Veil)$', --Increases resistance to ailments when HP is low.
	'^(Clutch Wall)$', --Absorbs a set amount of damage when HP is low.
	'^(Counter%-limit) ?%+ ?(%d+)$', --Receiving damage from an enemy increases the Ultimate gauge by X.
	'^(Counterresist) ?%+ ?(%d+)$', --Damage from an enemy adds resistance to that element for one turn. 
	'^(Cross%-Counter) (%(Up to ?(%d+%%)%))$', --Increases damage and Break power the more enemies have previously acted immediately before your action.
	'^(Crystal Seeker) ?%+ ?(%d+)$', --Raises the chance to obtain crystals as drops.
	'^(Drain Starter)$',
	'^(EXP Up) ?%+ ?(%d+%%)$', --Increases EXP gained after battle by X%.
	'^(Element Call: Dark) ?%+ ?(%d+)$', --Dark damage received during dark Element Drives creates orbs.
	'^(Element Call: Earth) ?%+ ?(%d+)$', --Earth damage received during earth Element Drives creates orbs.
	'^(Element Call: Fire) ?%+ ?(%d+)$', --Fire damage received during fire Element Drives creates orbs.
	'^(Element Call: Light) ?%+ ?(%d+)$', --Light damage received during light Element Drives creates orbs.
	'^(Element Call: Water) ?%+ ?(%d+)$', --Water damage received during water Element Drives creates orbs.
	'^(Element Call: Wind) ?%+ ?(%d+)$', --Wind damage received during wind Element Drives creates orbs.
	'^(Element Call Bis) ?%+ ?(%d+)$', -- Resisted attacks create X orb[s].
	'^(Element Generator) ?%+ ?(%d+)$', -- Start turn with X orb[s] drawn.
	'^(Element Starter) ?%+ ?(%d+)$', --Start battle with X orb drawn.
	'^(Elemental Amplification)$', --Increases the chance of drawing the element used by this ability.
	'^(Elemental Break) ?%+ ?(%d+)$', -- Increases number of orbs drawn during Breaks by X.
	'^(Elemental Third Strike) ?%+ ?(%d+)$', --Increases number of orbs drawn by the third normal attack by X.
	'^(Enhance Dark) ?%+ ?(%d+%%)$', --Enhances dark abilities by X%.
	'^(Enhance Earth) ?%+ ?(%d+%%)$', --Enhances earth abilities by X%.
	'^(Enhance Fire) ?%+ ?(%d+%%)$', --Enhances fire abilities by X%.
	'^(Enhance Light) ?%+ ?(%d+%%)$', --Enhances light abilities by X%.
	'^(Enhance Water) ?%+ ?(%d+%%)$', --Enhances water abilities by X%.
	'^(Enhance Wind) ?%+ ?(%d+%%)$', --Enhances wind abilities by X%.
	'^(Enhanced Heal Drive) ?%+ ?(%d+%%)', --Element Drives using life orbs restore X5 more HP.
	'^(Exploit Weakness) ?%+ ?(%d+%%)$', --Increases damage dealt by X% when using weakness element.
	'^(Extended Break) ?%+ ?(%d+)$', --Increases number of actions during Break by X.
	'^(Faith Starter)$',
	'^(Flash Break) ?%+ ?(%d+%%)$', --Break power increased by X% against enemies with full Break gauges.
	'^(Furious Salvo) ?%+ ?(%d+%%)$', --Increases the next attack's Attack and Break Power the more times Attack is used consecutively.
	'^(Haste Starter)$',
	'^(Heal Drive: Dark) ?%+ ?(%d+%%)$', --Dark Element Drives restore X% HP.
	'^(Heal Drive: Earth) ?%+ ?(%d+%%)$', --Earth Element Drives restore X% HP.
	'^(Heal Drive: Fire) ?%+ ?(%d+%%)$', --Fire Element Drives restore X% HP.
	'^(Heal Drive: Light) ?%+ ?(%d+%%)$', --Light Element Drives restore X% HP.
	'^(Heal Drive: Water) ?%+ ?(%d+%%)$', --Water Element Drives restore X% HP.
	'^(Heal Drive: Wind) ?%+ ?(%d+%%)$', --Wind Element Drives restore X% HP.
	'^(Healing Victory) ?%+ ?(%d+%%)$', --Restores X% HP after winning a battle.
	'^(High Roller) ?%+ ?(%d+%%)$', --Increases Break Power in relation to the number of actions remaining.
	'^(Imbue: Boost) ?%+ ?(%d+%%)$', -- Break Power is increased while your weapon is imbued.
	'^(Imbue: Brave) ?%+ ?(%d+%%)$', -- Normal attack damage is increased while your weapon is imbued.
	'^(Improved Criticals) ?%+ ?(%d+%%)$', --Increases critical strike damage by X%.
	'^(Improved Extra Skill Unlock) ?%+ ?(%d+)$', --Slightly improves the chance to unlock extra skills.
	'^(Job Change Recast)', --Lowers your Job Change recast by a turn.
	'^(Kill & Draw) ?%+ ?(%d+)$', --Defeating an enemy draws X element orb(s).
	'^(Life Element Starter) ?%+ ?(%d+)$', --Start battle with X life orbs drawn.
	'^(Mage Lore)$', --Applies Magic bonuses to mage abilities.
	'^(Medic) ?%+ ?(%d+%%)$', --Regenerates X% of HP with every action.
	'^(Monk Lore)$', --Applies Magic bonuses to monk abilities.
	'^(Painful Break) ?%+ ?(%d+%%)$', --Increases damage dealt during Break by X%.
	'^(Piercing Break) ?%+ ?(%d+%%)$', --Increases damage dealt to red Break gauges by X%.
	'^(Power Drive: Dark) ?%+ ?(%d+)$', --Improves dark Element Drive length and potency by X.
	'^(Power Drive: Earth) ?%+ ?(%d+)$', --Improves earth Element Drive length and potency by X.
	'^(Power Drive: Fire) ?%+ ?(%d+)$', --Improves fire Element Drive length and potency by X.
	'^(Power Drive: Light) ?%+ ?(%d+)$', --Improves light Element Drive length and potency by X.
	'^(Power Drive: Water) ?%+ ?(%d+)$', --Improves water Element Drive length and potency by X.
	'^(Power Drive: Wind) ?%+ ?(%d+)$', --Improves wind Element Drive length and potency by X.
	'^(Prismatic Draw) ?%+ ?(%d+%%)$', --Normal attacks have a X% chance to draw prismatic orbs.
	'^(Prismatic Element Generator) ?%+ ?(%d+)$', --Start turn with X prismatic orb(s) drawn.
	'^(Prismatic Element Starter) ?%+ ?(%d+)$', --Start battle with X prismatic orb(s) drawn.
	'^(Prismatic Return) ?%+ ?(%d+%%)$', --Has a X% chance to restore spent orbs as prismatic orbs.
	'^(Quick Break) ?%+ ?(%d+%%)$', --Completely depletes an enemy's Break gauge if it is below X%.
	'^(Ranger Lore)$', --Applies Magic bonuses to ranger abilities.
	'^(Reckoning)$', --Increases ability damage based on how much damage you have received from enemies in the previous two turns.
	'^(Regen Starter)$',
	'^(Resist Dark) ?%+ ?(%d+%%)$', --Increases resistance to dark by X%.
	'^(Resist Earth) ?%+ ?(%d+%%)$', --Increases resistance to earth by X%.
	'^(Resist Fire) ?%+ ?(%d+%%)$', --Increases resistance to fire by X%.
	'^(Resist Light) ?%+ ?(%d+%%)$', --Increases resistance to light by X%.
	'^(Resist Water) ?%+ ?(%d+%%)$', --Increases resistance to water by X%.
	'^(Resist Wind) ?%+ ?(%d+%%)$', --Increases resistance to wind by X%.
	'^(Retribution)$', --Increases attack and break power of attacks based on the damage received from enemies in the previous two turns.
	'^(Reunion) ?%+ ?(%d+%%)$', --Restores a used orb as a prismatic orb X% of the time.
	'^(Risk Taker) ?%+ ?(%d+%%)$', --Attack, Magic, and Break Power increase as your HP decreases.
	'^(Scourge) ?%+ ?(%d+%%)$', --Increases normal attack damage during Break by X%.
	'^(Skilled Duelist) ?%+ ?(%d+%%)$', --Increases all attributes (HP, Attack, Magic, Break Power) by X% when facing an enemy one-on-one.
	'^(Skillseed Up) ?%+ ?(%d+%%)$', --Increases skillseeds gained after battle by X%.
	'^(Sleep Resistance) ?%+ ?(%d+%%)$', --Increases resistance to Sleep by X%.
	'^(Snipe Starter)$',
	'^(Spellsword)$', --Elemental weapon attributes now affect Ultimates.
	'^(Steelguard) ?%+ ?(%d+%%)$', --Increases Defense by X% until end of turn every time you receive damage.
	'^(Ultimate Charge: Abilities) ?%+ ?(%d+)$', --Increases the amount of Ultimate gauge charged when using abilities.
	'^(Ultimate Charger) ?%+ ?(%d+)$', -- Normal attacks increase the Ultimate ability gauge.
	'^(Wall Starter)$',
	'^(Warrior Lore)$', --Applies Magic bonuses to warrior abilities.
}

local style = {
    ["width"] = "100px",
    ["height"] = "123px",
    ["text-align"] = "center",
    ["font-size"] = "13px",
    ["color"] = "white",
    ["position"] = "relative",
    ["background-color"] = "rgba(0,0,0,0.25)",
    ["border-radius"] = "6px",
    ["display"] = "inline-flex",
    ["flex-flow"] = "column",
}

local panelcost = {fire=0, water=0, wind=0, earth=0, light=0, dark=0, crystal=0}

function p.main( frame )
    local bg = frame.args[1]
    local name = frame.args[2]
    local seed = frame.args[3]
    
    local text = p.bgimage( bg ) .. name .. "<br/>" .. p.formatSeed( seed )
    local div = mw.html.create( 'div' )
    div :css( style)
        :wikitext( text )
    return tostring( div )
end

function p.formattab( frame )
	local pframe = frame:getParent()
	local config = frame.args
	local args = pframe.args
	return p._formattab(args)
end

function p.bgimage( bg )
    local image = ""
	if bg == "brown" then
        image = "PanelBrown.png"
    elseif bg == "green" then
        image = "PanelGreen.png"
    elseif bg == "blue" then
        image = "PanelBlue.png"
	else
		return image
    end
    return '<span style="position:absolute; top:0; left:0; z-index:-1;">[[File:'..image..'|100px|link=|'..bg..']]</span>'
end

function p.seed(e)
	local e = mw.ustring.lower(e)
    return '[[File:Seed_'..e..'.png|link=|15px|'..e..']]'
end

function p.formatSeed( seed )
	local seed = mw.ustring.lower(seed or '')
    if seed == '' then
    	return "[[Category:Skillpanels with missing cost]]"
	elseif seed == 'n/a' then
		return ''
	end
    local result = {}
    for v in mw.text.gsplit( seed, ',' ) do
    	local ele, num = string.match( v, '^%s*(.-)%s*x%s*(%d+)%s*$' )
    	if ele == nil or num == nil then
    		return "[[Category:Skillpanels with missing cost]]"
		end
    	local value = '<span>' .. p.seed(ele) .. '×' .. num..'</span>'
    	panelcost[ele] = panelcost[ele] + num
        table.insert(result, value)
    end
    return table.concat(result, '<br/>')
end

function p._formattab( args )
	local panels = {}
	local wikitext = mw.html.create('')
	local panel = wikitext
		:tag('table')
			:addClass('skillpanel-group')
			:attr('cellspacing', 0)
			:attr('cellpadding', 0)
			:newline()
	for row=1,4 do
		local tr = panel:tag('tr')
		for col=1,4 do
			local i = (row - 1) * 4 + col
			local text, cost = args[i..'n'] or '', args[i..'s'] or ''
			local bg, text1, text2 = p.parsepanel(text)
			tr
				:tag('td')
					:wikitext(p.formatpanel(bg, text1, text2, cost))
					:done()
		end
		tr:done():newline()
	end
	panel:done():newline()
	-- Display cost total for skillpanel tab.
	local costTable = {}
	for i,element in ipairs({'fire','water','wind','earth','light','dark','crystal'}) do
		local v = panelcost[element]
		if v > 0 then
			table.insert(costTable, p.seed(element) .. '×' .. v)
		end
	end
	costTable = table.concat(costTable, ' ')
	wikitext:tag('p'):wikitext('Cost:<br/>'..costTable):done()
	
	wikitext:allDone()
	return tostring(wikitext)
end

function p.parsepanel(text)
	local bg = 'grey'
	local name = text
	local text = (text or ''):gsub('<br%s*/?>', ' '):gsub('%s+', ' ')
	text = mw.text.trim(text)
	if text == '' then return bg, name end
	
	local v1, v2
	for i, pat in ipairs(browns) do
		v1, v2 = text:match(pat)
		if v1 then
			local digit, percent = string.match(v2, '^(%d+)(%%?)')
			bg = 'brown'
			if digit then v2 = '+' .. v2 end
			return bg, v1, v2
		end
	end
	for i, pat in ipairs(greens) do
		v1, v2 = text:match(pat)
		if v1 then
			bg = 'green'
			return bg, v1, v2
		end
	end
	for i, pat in ipairs(blues) do
		v1, v2 = text:match(pat)
		if v1 then
			bg = 'blue'
			name = v1
			if v2 then
				local digit, percent = string.match(v2, '^(%d+)(%%?)$')
				if digit then v2 = '+' .. v2 end
			end
			return bg, v1, v2
		end
	end
	return bg, name
end

-- TODO: less inline-styles, more CSS!
function p.formatpanel(bg, text1, text2, seed)
	local bgimg = p.bgimage(bg)
	local div = mw.html.create('div')
    div
    	:addClass('skillpanel')
    	:css(style)
    if bgimg ~= '' then
		div	:addClass('skill'..mw.ustring.lower(bg))
			:wikitext( bgimg )
			:wikitext(' ')
	end
	div
		:tag('span')
			:css({
				['display'] = 'flex',
				['flex'] = 1,
				['flex-direction'] = 'column',
				['margin'] = '4px 0',
				['line-height'] = '16px',
				})
			:wikitext(text1)
			:done()
		:wikitext(' ')
		:tag('span')
			:wikitext(text2 or '')
			:css({
				['display'] = 'flex',
				['flex'] = 1,
				['flex-direction'] = 'column',
				['justify-content'] = 'center',
				['margin'] = '4px 0',
				['line-height'] = '16px',
				})
			:done()
		:wikitext(' ')
		:tag('span')
			:wikitext(p.formatSeed(seed))
			:css({
				['display'] = 'flex',
				['flex'] = 1,
				['flex-direction'] = 'column',
				['justify-content'] = 'flex-end',
				['margin'] = '4px 0',
				['line-height'] = '16px',
				})
			:done()
    return tostring( div )
end

function p.test(frame)
	local args = {
		["1n"] = "Rogue<br/>New Job", ["1s"] = "?",
		["2n"] = "Attack<br/>+3", ["2s"] = "light x10",
		["3n"] = "HP +60", ["3s"] = "fire x5",
		["4n"] = "Enhance Earth+10%", ["4s"] = "earth x50",
		["5n"] = "Break Power+2", ["5s"] = "light x10",
		["6n"] = "Element Starter+1", ["6s"] = "fire x100",
		["7n"] = "Enhance Earth +10%", ["7s"] = "earth x50",
		["8n"] = "Break Power +2", ["8s"] = "light x25",
		["9n"] = "Magic +5%", ["9s"] = "light x10",
		["10n"] = "Element Starter +1", ["10s"] = "light x100",
		["11n"] = "Heal Drive: Fire +2%", ["11s"] = "fire x40",
		["12n"] = "Magic +10%", ["12s"] = "light x40",
		["13n"] = "Enhance Ultimate Lv. Up", ["13s"] = "light x200",
		["14n"] = "HP +60", ["14s"] = "fire x20",
		["15n"] = "Attack +6", ["15s"] = "light x50",
		["16n"] = "Sirius New Weapon", ["16s"] = "crystal x1",
	}
	return p._formattab(args)
	--local frame = frame or mw.getCurrentFrame()
	--return frame:extensionTag( 'tabber', '|-| Test 1 = Foo |-| Test 2 = Bar')
end

return p
Advertisement