Please note that some information on this wiki is still based on the demo version.
If you notice any errors, feel free to correct them.

Module:Abilities: Difference between revisions

From Super Fantasy Kingdom Official Wiki
wgg>Cadaei
option for subAbility, header highlighting for non subAbility
changed poison to in game name: toxic
 
(29 intermediate revisions by 4 users not shown)
Line 1: Line 1:
local p = {}
local p = {}


local statNames = require ('Module:Stats/StatNames')
local stats = require('Module:Stats')
local stats = require('Module:Stats')
local gridCreation = require('Module:Abilities/Grid')


function p.abilities(f)
function p.abilities(f)
Line 8: Line 10:
             
             
function p.create(args)
function p.create(args)
      
     local result = ''
local result = ''
-- currently there are up to 2 abilities and sometimes a sub ability
-- currently there are up to 2 abilities and sometimes a sub ability
for abilityIndex = 1,3 do
for abilityIndex = 1,3 do
Line 16: Line 17:
if string.len(result) == 0 then
if string.len(result) == 0 then
return ''
    return ''
end
end
return '<table class="wikitable">'..result..'</table>'
return '<div class="ability-supercontainer">'..result..'</div>'
end
end


function abilityRow(args, index)
function abilityRow(args, index)
if args['name'..index] == nil and args['desc'..index] == nil then
if (args['name'..index] or '') == '' and (args['desc'..index] or '') == '' then
return ''
return ''
end
-- no border-top for first entry, other abilities are separated by a 2px border
local topRowStyle = 'border-top:2px solid black;'
if index == 1 then
    topRowStyle = 'border-top:none;'
end
-- sub abilities left-padded
local leftPadded = ''
local nameTag = 'th'
if args['subAbility'..index] ~= nil then
leftPadded = 'padding-left:2em;'
nameTag = 'td'
end
end
Line 44: Line 31:
local abilityType = p.combatIcon(args['abilityType'..index])
local abilityType = p.combatIcon(args['abilityType'..index])
local element = p.combatIcon(args['element'..index])
local element = p.combatIcon(args['element'..index])
local titleCell = '<'..nameTag..' style="'..topRowStyle..leftPadded..'">'
local titleCell = ''
if name ~= nil or abilityType ~= nil or element ~= nil then
if name ~= nil or abilityType ~= nil or element ~= nil then
titleCell = titleCell..'<b><big>'..(name or '')..'</big></b> '..(abilityType or '')..(element or '')
titleCell = '<div class="ability-name">'..(name or '')..'</div><div class="ability-icons">'..
(abilityType or '')..(element or '')..'</div>'
end
end
titleCell = titleCell..'</'..nameTag..'>'
local statValues = {['inline'] = '1',
local statValues = {['align']='center'}
                    ['cd'] = args['cd'..index],
for _,s in ipairs(statNames) do
                ['ra'] = args['ra'..index],
if args[s[1]..index] ~= nil then
                ['ar'] = args['ar'..index],
statValues[s[1]] = args[s[1]..index]
                ['du'] = args['du'..index],
end
                ['dm'] = args['dm'..index]
end
                }
local statsDisplay = '<td style="text-align:right;'..topRowStyle..leftPadded..'">'..stats.create(statValues)..'</td>'
local statsDisplay = '<div class="ability-stats">'..stats.create(statValues)..'</div>'
local grid = ''
if args['grid'..index..'.mark'] ~= nil then
grid = '<div class="ability-grid">'..gridCreation.create({['mark'] = args['grid'..index..'.mark'], ['markSource'] = args['grid'..index..'.markSource']})..'</div>'
end
local descriptionRow = ''
local descriptionRow = ''
local descriptionText = args['desc'..index] or ''
local descriptionText = args['desc'..index] or ''
if descriptionText ~= '' then
if descriptionText ~= '' then
    descriptionRow = '<tr><td colspan=2 style="border-top:none;padding-top:0">'..descriptionText..'</td></tr>'
    descriptionRow = '<div class="ability-description">'..descriptionText..'</div>'
end
end
local upgradeRows = createUpgradeRows(args, index)
local upgradeRows = createUpgradeRows(args, index)
if upgradeRows ~= '' then
if upgradeRows ~= '' then
    upgradeRows = '<tr><td colspan=2>'..upgradeRows..'</td></tr>'
    upgradeRows = '<div class="ability-upgrades">'..upgradeRows..'</div>'
end
end
return '<tr>'..titleCell..statsDisplay..'</tr>'..
local subAbilityClass = ''
    descriptionRow..upgradeRows
if args['subAbility'..index] == '1' or args['subAbility'..index] == 'true' then
subAbilityClass = ' ability-subability'
end
return '<div class="ability-container'..subAbilityClass..'"><div class="ability-header">'..titleCell..'</div>'..
  '<div class="ability-body"><div>'.. descriptionRow..upgradeRows..'</div><div>'..grid..statsDisplay..'</div></div>'..'</div>'
end
end


Line 79: Line 76:
for i = 1,3 do
for i = 1,3 do
    local upgradeText = args['upgrade'..index..'.'..i] or ''
    local upgradeText = args['upgrade'..index..'.'..i] or ''
if upgradeText ~= '' then
    -- some upgrades change the grid, then show that
    table.insert(upgradeTexts, '[[File:Upgrade'..i..'.png|26px]] '..upgradeText)
    local upgradeGrid = args['upgrade'..index..'.'..i..'grid'] or ''
end
    if upgradeGrid ~= '' or upgradeText ~= '' then
    if upgradeGrid ~= '' then
    table.insert(upgradeTexts, '<div style="display: flex;"><div>[[File:Upgrade'..i..'.png|26px]] '..upgradeText..
    '</div><div style="margin-left: auto;">'..gridCreation.create({['mark'] = upgradeGrid})..'</div></div>')
    else
    table.insert(upgradeTexts, '<div>[[File:Upgrade'..i..'.png|26px]] '..upgradeText..'</div>')
    end
    end
end
if #upgradeTexts == 0 then
return ''
end
end
return table.concat(upgradeTexts, '<br/>')
return table.concat(upgradeTexts, '')
end
end


Line 98: Line 106:
['magical damage'] = 'Magical damage',
['magical damage'] = 'Magical damage',
['magical'] = 'Magical damage',
['magical'] = 'Magical damage',
['damage boost'] = 'Damage boost',
['self boost'] = 'Self boost',
['selfbuff'] = 'Selfbuff',
['buff'] = 'Buff',
['support'] = 'Support',
['support'] = 'Support',
['summoner'] = 'Summoner',
['summoner'] = 'Summoner',
['holy'] = 'Holy',
['dark'] = 'Dark',
['electric'] = 'Electric',
['fire'] = 'Fire',
['fire'] = 'Fire',
['ice'] = 'Ice',
['light'] = 'Light',
['plant'] = 'Plant',
['plant'] = 'Plant',
['poison'] = 'Poison',
['toxic'] = 'Toxic',
['dark'] = 'Dark',
['rock'] = 'Rock (element)',
['electric'] = 'Electric',
['water'] = 'Water (element)',
['none'] = nil
['none'] = nil
}
}

Latest revision as of 15:20, 27 June 2026

Creates an ability table with upgrades for a unit. (Code at Module:Abilities).

The ability grids are created with the submodule Module:Abilities/Grid, see there for infos about creating the grid.

{{abilities
|name1=Tentacles
|abilityType1 = Magical
|element1 = Dark
|dm1= 0.25x
|cd1=1.5s
|ra1=50m
|ar1=30m
|ta1=Random
|desc1=Opens up the door to another dimension summoning dark shadows<br/> Applies {{effect|fear}} to all monsters hit.
|upgrade1.1= Decrease {{stat|cd|to 1.25s}}
|upgrade1.2= Decrease {{stat|cd|to 1s}}
|upgrade1.3= Increase {{stat|ar}}
|name2 = Shade
|subAbility2=true
|abilityType2 = Physical
|element2 = dark
|sp2=5
|pi2=2
|du2=7s
|desc2 = Walks back and forth until hitting 2 monsters dealing 2 {{stat|dm}} and applies {{effect|fatigue}}
|name3=Barrier
|abilityType3 = Support
|cd3=6s
|desc3=Cast {{Effect|Barrier}} onto the unit above
|grid3.mark=8
|upgrade3.3= Applies to more allies
|upgrade3.3grid=7,8,9
}}
}}
Tentacles
Magical damageDark
Opens up the door to another dimension summoning dark shadows
Applies fear to all monsters hit.
Decrease  to 1.25s
Decrease  to 1s
Increase
 0.25x
 1.5s
 50m
 Random
 30m
Shade
Physical damageDark
Walks back and forth until hitting 2 monsters dealing 2 and applies fatigue
 7s
 5
 2
Barrier
Support
Cast Barrier onto the unit above
Applies to more allies
 6s

local p = {}

local statNames = require ('Module:Stats/StatNames')
local stats = require('Module:Stats')
local gridCreation = require('Module:Abilities/Grid')

function p.abilities(f)
	return p.create(f:getParent().args)
end
		             
function p.create(args)
    local result = ''
	-- currently there are up to 2 abilities and sometimes a sub ability
	for abilityIndex = 1,3 do
	    result = result .. abilityRow(args, abilityIndex)
	end
	
	if string.len(result) == 0 then
	    return ''
	end
	
	return '<div class="ability-supercontainer">'..result..'</div>'
end

function abilityRow(args, index)
	if (args['name'..index] or '') == '' and (args['desc'..index] or '') == '' then
		return ''
	end
	
	local name = args['name'..index]
	local abilityType = p.combatIcon(args['abilityType'..index])
	local element = p.combatIcon(args['element'..index])
	local titleCell = ''
	if name ~= nil or abilityType ~= nil or element ~= nil then
		titleCell = '<div class="ability-name">'..(name or '')..'</div><div class="ability-icons">'..
		(abilityType or '')..(element or '')..'</div>'
	end
	
	local statValues = {['align']='center'}
	for _,s in ipairs(statNames) do
		if args[s[1]..index] ~= nil then
			statValues[s[1]] = args[s[1]..index]
		end
	end
	
	local statsDisplay = '<div class="ability-stats">'..stats.create(statValues)..'</div>'
	
	local grid = ''
	if args['grid'..index..'.mark'] ~= nil then
		grid = '<div class="ability-grid">'..gridCreation.create({['mark'] = args['grid'..index..'.mark'], ['markSource'] = args['grid'..index..'.markSource']})..'</div>'
	end
	
	local descriptionRow = ''
	local descriptionText = args['desc'..index] or ''
	if descriptionText ~= '' then
	    descriptionRow = '<div class="ability-description">'..descriptionText..'</div>'
	end
	
	local upgradeRows = createUpgradeRows(args, index)
	if upgradeRows ~= '' then
	    upgradeRows = '<div class="ability-upgrades">'..upgradeRows..'</div>'
	end
	
	local subAbilityClass = ''
	if args['subAbility'..index] == '1' or args['subAbility'..index] == 'true' then
		subAbilityClass = ' ability-subability'
	end
	
	return '<div class="ability-container'..subAbilityClass..'"><div class="ability-header">'..titleCell..'</div>'..
	   '<div class="ability-body"><div>'.. descriptionRow..upgradeRows..'</div><div>'..grid..statsDisplay..'</div></div>'..'</div>'
end

function createUpgradeRows(args, index)
    local upgradeTexts = {}
	
	for i = 1,3 do
	    local upgradeText = args['upgrade'..index..'.'..i] or ''
	    -- some upgrades change the grid, then show that
	    local upgradeGrid = args['upgrade'..index..'.'..i..'grid'] or ''
	    if upgradeGrid ~= '' or upgradeText ~= '' then
	    	if upgradeGrid ~= '' then
	    		table.insert(upgradeTexts, '<div style="display: flex;"><div>[[File:Upgrade'..i..'.png|26px]] '..upgradeText..
	    			'</div><div style="margin-left: auto;">'..gridCreation.create({['mark'] = upgradeGrid})..'</div></div>')
	    	else
	    		table.insert(upgradeTexts, '<div>[[File:Upgrade'..i..'.png|26px]] '..upgradeText..'</div>')
	    	end
	    end
	end
	
	if #upgradeTexts == 0 then
		return ''
	end
	
	return table.concat(upgradeTexts, '')
end

function p.combatIcon(name)
	if name == nil or name == '' then
		return nil
	end
	
	-- attack types, passive types, elements
	local combatIcons = {
		['physical damage'] = 'Physical damage',
		['physical'] = 'Physical damage',
		['magical damage'] = 'Magical damage',
		['magical'] = 'Magical damage',
		['self boost'] = 'Self boost',
		['selfbuff'] = 'Selfbuff',
		['buff'] = 'Buff',
		['support'] = 'Support',
		['summoner'] = 'Summoner',
		['dark'] = 'Dark',
		['electric'] = 'Electric',
		['fire'] = 'Fire',
		['ice'] = 'Ice',
		['light'] = 'Light',
		['plant'] = 'Plant',
		['toxic'] = 'Toxic',
		['rock'] = 'Rock (element)',
		['water'] = 'Water (element)',
		['none'] = nil
	}
	
	local result = combatIcons[string.lower(name)]
	if result ~= nil then
		return '[[File:'..result..'.png|16x16px|class=itemlink|alt='..result..'|link='..result..']]'
	end
	
	return name
end

return p