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 fixes for calculating base value |
handle missing values correctly |
||
| (18 intermediate revisions by 3 users not shown) | |||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local statNames = require ('Module:Stats/StatNames') | |||
function p.levelStats(f) | function p.levelStats(f) | ||
| Line 6: | Line 8: | ||
function p.create(args) | function p.create(args) | ||
local statRows = {} | |||
local | |||
local levelCount = 10 | local levelCount = 10 | ||
local useExponentialGain = args.exp ~= nil | local useExponentialGain = args.exp ~= nil | ||
local useGainIndicator = args.gainIndicator ~= nil | |||
local useBaseIndicator = args.baseIndicator ~= nil | |||
for _, | for _, statAbbName in ipairs(statNames) do | ||
local statAbbreviation = | local statAbbreviation = statAbbName[1] | ||
local statValue = args[statAbbreviation] | local statValue = args[statAbbreviation] | ||
if statValue ~= nil and statValue ~= '' then | if statValue ~= nil and statValue ~= '' then | ||
local statName = | local statName = statAbbName[2] | ||
local statValueLast = args[statAbbreviation..levelCount] or statValue | local statValueLast = args[statAbbreviation..levelCount] or statValue | ||
table.insert( | table.insert(statRows, p.StatEntryRow(statName, statValue, statValueLast, levelCount, useExponentialGain, useBaseIndicator, useGainIndicator)) | ||
end | end | ||
end | end | ||
if # | if #statRows == 0 then | ||
return '' | return '' | ||
end | end | ||
local headers = {'<th>Stats</th>'} | local headers = {'<th>Stats</th>'} | ||
if useBaseIndicator then | |||
if useGainIndicator then | |||
table.insert(headers, '<th>Base Gain</th>') | |||
else | |||
table.insert(headers, '<th>Base</th>') | |||
end | |||
elseif useGainIndicator then | |||
table.insert(headers, '<th>Gain</th>') | |||
end | |||
for i=1,levelCount do | for i=1,levelCount do | ||
table.insert(headers, '<th>'..i..'</th>') | table.insert(headers, '<th>'..i..'</th>') | ||
| Line 51: | Line 45: | ||
return '<table class="wikitable right"><tr>'..table.concat(headers, '')..'</tr>'.. | return '<table class="wikitable right"><tr>'..table.concat(headers, '')..'</tr>'.. | ||
table.concat(statRows, '')..'</table>' | |||
end | end | ||
function p.StatEntryRow(name, val, valLast, levelCount, useExponentialGain) | function p.StatEntryRow(name, val, valLast, levelCount, useExponentialGain, useBaseIndicator, useGainIndicator) | ||
local statColumns = {'<td style="text-align:left;">[[File:'..name..'.png|16x16px]] [['..name..']]</td>'} | local statColumns = {'<td style="text-align:left;">[[File:'..name..'.png|16x16px]] [['..name..']]</td>'} | ||
| Line 61: | Line 55: | ||
local valLast, _ = string.match(valLast, '^(%d*%.?%d*) ?(.*)$') | local valLast, _ = string.match(valLast, '^(%d*%.?%d*) ?(.*)$') | ||
if | val = tonumber(val) | ||
if val == | valLast = tonumber(valLast) | ||
if valLast == nil then | |||
valLast = val | |||
end | |||
if useBaseIndicator or useGainIndicator then | |||
local baseIndicatorImage = '' | |||
local gainIndicatorImage = '' | |||
if useBaseIndicator and val ~= nil then | |||
local baseIndicator = 0 | |||
if val > 0 then | |||
if val < 10 then baseIndicator = 1 | |||
elseif val < 50 then baseIndicator = 2 | |||
else baseIndicator = 3 end | |||
end | |||
baseIndicatorImage = '[[File:StatBase'..baseIndicator..'.png|12px]]' | |||
end | |||
if useGainIndicator and val ~= nil and valLast ~= nil then | |||
local gainIndicator = 0 | |||
if valLast > val and val > 0 then | |||
local gainFactor = valLast / val | |||
if gainFactor > 10 then gainIndicator = 3 | |||
elseif gainFactor > 5 then gainIndicator = 2 | |||
elseif gainFactor > 1 then gainIndicator = 1 end | |||
end | end | ||
gainIndicatorImage = ' [[File:StatGain'..gainIndicator..'.png|12px]]' | |||
end | |||
table.insert(statColumns, '<td style="text-align:center;">'..baseIndicatorImage..gainIndicatorImage..'</td>') | |||
end | |||
local rowClass = '' | |||
if val == valLast then | |||
for i=1,levelCount do | |||
table.insert(statColumns, '<td>'..val..unit..'</td>') | |||
end | |||
if useGainIndicator then | |||
rowClass = ' class="grey-from4"' | |||
else | else | ||
rowClass = ' class="grey-from3"' | |||
end | |||
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 = math.floor((valLast - val)/(1-(1/levelCount)^1.5) + 0.5) | ||
local baseValue = valLast - | local baseValue = valLast - gainLastLevel | ||
for i=1,levelCount do | for i=1,levelCount do | ||
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 | ||
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 | ||
end | end | ||
return table.concat(statColumns, '') | return '<tr'..rowClass..'>'..table.concat(statColumns, '')..'</tr>' | ||
end | end | ||
return p | return p | ||
Latest revision as of 18:30, 30 October 2025
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
}}
| Stats | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
|---|---|---|---|---|---|---|---|---|---|---|
| 5 | 10 | 16 | 21 | 26 | 32 | 37 | 42 | 48 | 53 | |
| 11 | 15 | 20 | 24 | 28 | 33 | 37 | 41 | 46 | 50 | |
| 13 | 23 | 32 | 42 | 52 | 61 | 71 | 81 | 90 | 100 | |
| 5% | 5% | 5% | 5% | 5% | 5% | 5% | 5% | 5% | 5% | |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
{{LevelStats
|exp=true
|pw=5|pw10=63
|hp=10|hp10=68
|sh=19|sh10=116
|cr=0%
|pd=0
|md=0
}}
| Stats | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
|---|---|---|---|---|---|---|---|---|---|---|
| 5 | 8 | 13 | 18 | 24 | 31 | 38 | 46 | 54 | 63 | |
| 10 | 13 | 18 | 23 | 29 | 36 | 43 | 51 | 59 | 68 | |
| 19 | 25 | 32 | 41 | 51 | 62 | 75 | 88 | 101 | 116 | |
| 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% | |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
{{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
}}
| Stats | Base Gain | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 5 | 8 | 13 | 18 | 24 | 31 | 38 | 46 | 54 | 63 | ||
| 10 | 13 | 18 | 23 | 29 | 36 | 43 | 51 | 59 | 68 | ||
| 19 | 25 | 32 | 41 | 51 | 62 | 75 | 88 | 101 | 116 | ||
| 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% | ||
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
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 = {}
local statNames = require ('Module:Stats/StatNames')
function p.levelStats(f)
return p.create(f:getParent().args)
end
function p.create(args)
local statRows = {}
local levelCount = 10
local useExponentialGain = args.exp ~= nil
local useGainIndicator = args.gainIndicator ~= nil
local useBaseIndicator = args.baseIndicator ~= nil
for _, statAbbName in ipairs(statNames) do
local statAbbreviation = statAbbName[1]
local statValue = args[statAbbreviation]
if statValue ~= nil and statValue ~= '' then
local statName = statAbbName[2]
local statValueLast = args[statAbbreviation..levelCount] or statValue
table.insert(statRows, p.StatEntryRow(statName, statValue, statValueLast, levelCount, useExponentialGain, useBaseIndicator, useGainIndicator))
end
end
if #statRows == 0 then
return ''
end
local headers = {'<th>Stats</th>'}
if useBaseIndicator then
if useGainIndicator then
table.insert(headers, '<th>Base Gain</th>')
else
table.insert(headers, '<th>Base</th>')
end
elseif useGainIndicator then
table.insert(headers, '<th>Gain</th>')
end
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, useBaseIndicator, useGainIndicator)
local statColumns = {'<td style="text-align:left;">[[File:'..name..'.png|16x16px]] [['..name..']]</td>'}
-- parsing value
local val, unit = string.match(val, '^(%d*%.?%d*) ?(.*)$')
local valLast, _ = string.match(valLast, '^(%d*%.?%d*) ?(.*)$')
val = tonumber(val)
valLast = tonumber(valLast)
if valLast == nil then
valLast = val
end
if useBaseIndicator or useGainIndicator then
local baseIndicatorImage = ''
local gainIndicatorImage = ''
if useBaseIndicator and val ~= nil then
local baseIndicator = 0
if val > 0 then
if val < 10 then baseIndicator = 1
elseif val < 50 then baseIndicator = 2
else baseIndicator = 3 end
end
baseIndicatorImage = '[[File:StatBase'..baseIndicator..'.png|12px]]'
end
if useGainIndicator and val ~= nil and valLast ~= nil then
local gainIndicator = 0
if valLast > val and val > 0 then
local gainFactor = valLast / val
if gainFactor > 10 then gainIndicator = 3
elseif gainFactor > 5 then gainIndicator = 2
elseif gainFactor > 1 then gainIndicator = 1 end
end
gainIndicatorImage = ' [[File:StatGain'..gainIndicator..'.png|12px]]'
end
table.insert(statColumns, '<td style="text-align:center;">'..baseIndicatorImage..gainIndicatorImage..'</td>')
end
local rowClass = ''
if val == valLast then
for i=1,levelCount do
table.insert(statColumns, '<td>'..val..unit..'</td>')
end
if useGainIndicator then
rowClass = ' class="grey-from4"'
else
rowClass = ' class="grey-from3"'
end
else
if useExponentialGain then
-- first calculate true base value, level 1 already has a bonus applied
local gainLastLevel = math.floor((valLast - val)/(1-(1/levelCount)^1.5) + 0.5)
local baseValue = valLast - gainLastLevel
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


