Difference between revisions of "Module:Stat Factors Table"
Jump to navigation
Jump to search
Arcangelus (talk | contribs) (Creating module for the template "Stat Factors Table Row". Slightly different implementation from test, so it may take a few edits to get working.) |
Arcangelus (talk | contribs) m |
||
Line 1: | Line 1: | ||
local getArgs = require('Module:Arguments').getArgs | local getArgs = require('Module:Arguments').getArgs | ||
local p = {} | local p = {} | ||
− | + | local wrap = {} -- Holds wrapper functions that process arguments from #invoke. These act as intemediary between functions meant for #invoke and functions meant for Lua. | |
--Stat Factors Table Row | --Stat Factors Table Row | ||
− | function | + | function wrap.TableRow(argumento) |
local args = getArgs(argumento) | local args = getArgs(argumento) | ||
return p._TableRow(args) | return p._TableRow(args) |
Revision as of 18:03, 11 August 2024
This module is meant to be used by Template:Stat Factors Table Row, which in turn is meant to be used alogside Template:Stat Factors Table.
This module returns the rows used in said table. It accept 8 inputs: skillBase, skillBonus, statMin, statMax, capImportance, capLimit, resultCols, LV, Ln
Any value not given is assumed 0. There are exceptions for the default values of Stat Maximum (99999999) and statMin (0), both of which are defined on Template:Stat Factors Table.
This can probably be further improved. Regardless, this represents a 71% improvement over the ParserFunctions method.
local getArgs = require('Module:Arguments').getArgs local p = {} local wrap = {} -- Holds wrapper functions that process arguments from #invoke. These act as intemediary between functions meant for #invoke and functions meant for Lua. --Stat Factors Table Row function wrap.TableRow(argumento) local args = getArgs(argumento) return p._TableRow(args) end function p._TableRow(skillBase, skillBonus, statMin, statMax, capImportance, capLimit, resultCols, LV, Ln) argumentos={skillBase,skillBonus,statMin,statMax,capImportance,capLimit,resultCols,LV,Ln} for i = 1,8 do --This should prevent errors if a number is not defined. if type(argumentos[i])~='number' then argumentos[i]=0 end end -- Do note that statMin, statMax are handled by "Template:Stat Factors Table". -- While I could set fallbacks, I decided against it. if tonumber(Ln)==nil then --Sanitizes input and allows for 0. factor = skillBase + skillBonus * LV else factor = Ln end local Pval = math.min(math.max(factor,statMin),statMax) R_Pval = tostring(math.floor(Pval*10000+0.5)/100).."%" -- This formats the number as a 2 digit percent value, rounded up. if tonumber(resultCols)>1 then Pval = factor * ( 1 + capImportance * math.min(capLimit-1, 0.25)) Pval = math.min(math.max(Pval,statMin),statMax) R_Sval="<td>"..tostring(math.floor(Pval*10000+0.5)/100).."% </td>" else R_Sval="" end if tonumber(resultCols)>2 then Pval = factor * ( 1 + capImportance * math.min(capLimit-1, 0.5)) Pval = math.min(math.max(Pval,statMin),statMax) R_Tval="<td>"..tostring(math.floor(Pval*10000+0.5)/100).."% </td>" else R_Tval="" end return "|-\r\n!"..LV.."\r\n|"..R_Pval..R_Sval..R_Tval end -- END OF MODULE