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:LevelStats: Difference between revisions

From Super Fantasy Kingdom Official Wiki
wgg>Cadaei
dim repeating values
wgg>Cadaei
dim repeating values
Line 62: Line 62:
local valLast, _  = string.match(valLast, '^(%d*%.?%d*) ?(.*)$')
local valLast, _  = string.match(valLast, '^(%d*%.?%d*) ?(.*)$')
if useExponentialGain then
if val == valLast then
if val == valLast then
for i=1,levelCount do
for i=1,levelCount do
table.insert(statColumns, '<td>'..val..unit..'</td>')
table.insert(statColumns, '<td>'..val..unit..'</td>')
end
end
rowClass = ' class="grey-from3"'
rowClass = ' class="grey-from3"'
else
else
if useExponentialGain then
-- first calculate true base value, level 1 already has a bonus applied
-- first calculate true base value, level 1 already has a bonus applied
local gainLastLevel = (valLast - val)/(1-(1/levelCount)^1.5)
local gainLastLevel = (valLast - val)/(1-(1/levelCount)^1.5)
Line 75: Line 75:
table.insert(statColumns, '<td>'..(baseValue + math.floor(gainLastLevel * (i/levelCount)^1.5 + 0.5))..unit..'</td>')
table.insert(statColumns, '<td>'..(baseValue + math.floor(gainLastLevel * (i/levelCount)^1.5 + 0.5))..unit..'</td>')
end
end
end
else
else
-- stat value increase linearly by level
-- stat value increase linearly by level
local gainPerLevel = (valLast - val)/(levelCount-1)
local gainPerLevel = (valLast - val)/(levelCount-1)
for i=0,levelCount-1 do
table.insert(statColumns, '<td>'..(val + math.floor(i*gainPerLevel + 0.5))..unit..'</td>')
for i=0,levelCount-1 do
end
table.insert(statColumns, '<td>'..(val + math.floor(i*gainPerLevel + 0.5))..unit..'</td>')
end
end
end
end

Revision as of 20:03, 1 November 2023

Displays a stat table for units for multiple levels. Parameter names are the stat abbreviations, for the first level just the two letters, for the 10th level the stat abbreviation with suffix 10, e.g. dm=5 for damage 5 in level 1 and dm10=20 for damage 20 in level 10. Values are interpreted linerarly for the other levels.

For units use exp=true for exponential stat growth.

To display a gain indicator, use gainIndicator=true.

{{LevelStats
|pw=5|pw10=53
|hp=11|hp10=50
|sh=13|sh10=100
|cr=5%
|pd=0
|md=0
}}
Stats12345678910
Health11152024283337414650
Shield132332425261718190100
Critical Chance5%5%5%5%5%5%5%5%5%5%
Physical Defense0000000000
Magical Defense0000000000
{{LevelStats
|exp=true
|pw=5|pw10=63
|hp=10|hp10=68
|sh=19|sh10=116
|cr=0%
|pd=0
|md=0
}}
Stats12345678910
Health10131823293643515968
Shield1925324151637588102116
Critical Chance0%0%0%0%0%0%0%0%0%0%
Physical Defense0000000000
Magical Defense0000000000
{{LevelStats
|exp=true
|baseIndicator=true
|gainIndicator=true
|pw=5|pw10=63
|hp=10|hp10=68
|sh=19|sh10=116
|cr=0%
|pd=0
|md=0
}}
Stats12345678910
Health10131823293643515968
Shield1925324151637588102116
Critical Chance0%0%0%0%0%0%0%0%0%0%
Physical Defense0000000000
Magical Defense0000000000
for copy pasting units

{{LevelStats
|exp=true
|baseIndicator=true
|gainIndicator=true
|pw=  |pw10=
|hp=  |hp10=
|ma=  |ma10=
|sh=  |sh10=
|rg=  |rg10=
|cr=0%
|pd=0
|md=0
}}

Code at Module:LevelStats, doc at Template:LevelStats/doc.


local p = {}

function p.levelStats(f)
	return p.create(f:getParent().args)
end

function p.create(args)	
	-- argument name and full name (also used for icon name)
	local possibleStats = {
		{"dm", "Damage"},
		{"hp", "Health"},
		{"sh", "Shield"},
		{"cr", "Critical Chance"},
		{"pd", "Physical Defense"},
		{"md", "Magical Defense"},
		{"cd", "Cooldown"},
		{"ra", "Range"},
		{"ar", "Area"},
		{"kb", "Knockback"},
		{"sp", "Speed"},
		{"du", "Duration"},
		{"gr", "Greed"},
		{"rr", "Reroll"},
		{"ba", "Banish"},
		{"cu", "Curse"}
		}
	
	local statRows = {}
	
	local levelCount = 10
	local useExponentialGain = args.exp ~= nil
	
	for _, statNames in ipairs(possibleStats) do
		local statAbbreviation = statNames[1]
		local statValue = args[statAbbreviation]
		if statValue ~= nil and statValue ~= '' then
			local statName = statNames[2]
			local statValueLast = args[statAbbreviation..levelCount] or statValue
			table.insert(statRows, p.StatEntryRow(statName, statValue, statValueLast, levelCount, useExponentialGain))
		end
	end
	
	if #statRows == 0 then
	  return ''
	end
	
	local headers = {'<th>Stats</th>'}
	for i=1,levelCount do
		table.insert(headers, '<th>'..i..'</th>')
	end
	
	return '<table class="wikitable right"><tr>'..table.concat(headers, '')..'</tr>'..
	  table.concat(statRows, '')..'</table>'
end

function p.StatEntryRow(name, val, valLast, levelCount, useExponentialGain)
	local statColumns = {'<td style="text-align:left;">[[File:'..name..'.png|16x16px]] [['..name..']]</td>'}
	local rowClass = ''
	
	-- parsing value
	local val, unit  = string.match(val, '^(%d*%.?%d*) ?(.*)$')
	local valLast, _  = string.match(valLast, '^(%d*%.?%d*) ?(.*)$')
	
	if val == valLast then
		for i=1,levelCount do
			table.insert(statColumns, '<td>'..val..unit..'</td>')
		end
		rowClass = ' class="grey-from3"'
	else
		if useExponentialGain then
			-- first calculate true base value, level 1 already has a bonus applied
			local gainLastLevel = (valLast - val)/(1-(1/levelCount)^1.5)
			local baseValue = valLast - math.floor(gainLastLevel + 0.5)
			for i=1,levelCount do
				table.insert(statColumns, '<td>'..(baseValue + math.floor(gainLastLevel * (i/levelCount)^1.5 + 0.5))..unit..'</td>')
			end
		else
			-- stat value increase linearly by level
			local gainPerLevel = (valLast - val)/(levelCount-1)
			for i=0,levelCount-1 do
				table.insert(statColumns, '<td>'..(val + math.floor(i*gainPerLevel + 0.5))..unit..'</td>')
			end
		end
	end
	
	return '<tr'..rowClass..'>'..table.concat(statColumns, '')..'</tr>'
end

return p