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
ignore empty name and desc, not only nil
wgg>Cadaei
water element icon fix
Line 99: Line 99:
['plant'] = 'Plant',
['plant'] = 'Plant',
['poison'] = 'Poison',
['poison'] = 'Poison',
['water'] = 'Water',
['water'] = 'Water (Element)',
['none'] = nil
['none'] = nil
}
}

Revision as of 22:19, 6 November 2023

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
 0.25x •  1.5s •  50m •  30m
Opens up the door to another dimension summoning dark shadows
Applies fear to all monsters hit.
Decrease  to 1.25s
Decrease  to 1s
Increase
Shade
Physical damageDark
 7s
Walks back and forth until hitting 2 monsters dealing 2 and applies fatigue
Barrier
Support
 6s
Cast Barrier onto the unit above
Applies to more allies

local p = {}

local stats = require('Module:Stats')

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 = {['inline'] = '1',
	                    ['cd'] = args['cd'..index],
		                ['ra'] = args['ra'..index],
		                ['ar'] = args['ar'..index],
		                ['du'] = args['du'..index],
		                ['dm'] = args['dm'..index]
		                }
	local statsDisplay = '<div class="ability-stats">'..stats.create(statValues)..'</div>'
	
	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	
	
	return '<div class="ability-container"><div class="ability-header">'..titleCell..statsDisplay..'</div>'..
	    descriptionRow..upgradeRows..'</div>'
end

function createUpgradeRows(args, index)
    local upgradeTexts = {}
	
	for i = 1,3 do
	    local upgradeText = args['upgrade'..index..'.'..i] or ''
		if upgradeText ~= '' then
		    table.insert(upgradeTexts, '[[File:Upgrade'..i..'.png|26px]] '..upgradeText)
		end
	end
	
	if #upgradeTexts == 0 then
		return ''
	end
	
	return '<div>'..table.concat(upgradeTexts, '</div><div>')..'</div>'
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',
		['damage boost'] = 'Damage boost',
		['selfbuff'] = 'Selfbuff',
		['support'] = 'Support',
		['summoner'] = 'Summoner',
		['dark'] = 'Dark',
		['earth'] = 'Earth',
		['electric'] = 'Electric',
		['fire'] = 'Fire',
		['holy'] = 'Holy',
		['ice'] = 'Ice',
		['plant'] = 'Plant',
		['poison'] = 'Poison',
		['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