Module:CryptogullJrOld: Difference between revisions
Jump to navigation
Jump to search
Syntaxaire (talk | contribs) (set 'beta' to default) |
(update for mutation rework) |
||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local decode = require'Module: | local decode = require'Module:Sandbox/User:Teamtoto/LuaModule2/Codes' | ||
function p.Main(frame) | function p.Main(frame) | ||
local buildcode = string.lower(frame.args[1]) | |||
local beta = frame.args['beta'] or '1' | |||
return p.decode(buildcode, beta, frame) | |||
end | |||
function p.decode(buildcode, beta, frame) | |||
local genotype | local genotype | ||
local subtype | local subtype | ||
Line 11: | Line 16: | ||
local bonus = {} | local bonus = {} | ||
local exts = {} | local exts = {} | ||
local beta = | local beta = beta or '1' | ||
if buildcode == nil then | |||
error("A build code must be provided!") | |||
end | |||
buildcode = string.lower(buildcode) | |||
if (string.len(buildcode) >= 8) then | if (string.len(buildcode) >= 8) then | ||
--[Check Genotype Code, and then subtype code] | --[Check Genotype Code, and then subtype code] | ||
Line 46: | Line 56: | ||
local i = 1 | local i = 1 | ||
local extstring = buildcode:sub(9) | local extstring = buildcode:sub(9) | ||
for chars in string.gmatch(extstring, "%w%w") do | previouscode = nil | ||
for chars in string.gmatch(extstring, "[%w#]%w") do | |||
varnum = tonumber(chars:match("#(%d)")) | |||
if varnum ~= nil then | |||
if previouscode == nil or (exts[i-1][2] == "") then | |||
error("Unexpected variant code") | |||
end | |||
-- add 1 to the index because lua is silly | |||
variant = exts[i-1][2][varnum + 1] | |||
-- get the previous extension and append variant to it | |||
exts[i - 1][1] = exts[i - 1][1] .. " (" .. variant .. ")" | |||
previouscode = nil | |||
else | |||
previouscode = chars | |||
exts[i] = decode.getexts(chars, subtypeC) | |||
i = i + 1 | |||
end | |||
end | end | ||
end | end | ||
Line 56: | Line 80: | ||
attributes = p.fixattributes(bonus, attributes) | attributes = p.fixattributes(bonus, attributes) | ||
end | end | ||
output = p.MakeUpSheet(buildcode, genotype, subtype, classcalled, extname, attributes, bonus, exts, frame) | if not frame then | ||
output = {buildcode, genotype, subtype, classcalled, extname, attributes, bonus, exts,} | |||
else | |||
output = p.MakeUpSheet(buildcode, genotype, subtype, classcalled, extname, attributes, bonus, exts, frame) | |||
end | |||
return output | return output | ||
end | end | ||
Line 66: | Line 94: | ||
function p.getbonus(subtype, exts) | function p.getbonus(subtype, exts) | ||
--STR, AGI, TOUGH,INT, WILL, EGO | --STR, AGI, TOUGH,INT, WILL, EGO | ||
local extbonuses = { | local extbonuses = { 0, 0, 0, 0, 0, 0 } | ||
for x, y in | for x, y in pairs(exts) do | ||
mw.logObject(y[1]) | |||
if decode.getStatBonus(y[1]) then | |||
statbonus = decode.getStatBonus(y[1]) | |||
extbonuses[1] = extbonuses[1] + statbonus[1] | |||
extbonuses[2] = extbonuses[2] + statbonus[2] | |||
extbonuses[3] = extbonuses[3] + statbonus[3] | |||
extbonuses[4] = extbonuses[4] + statbonus[4] | |||
extbonuses[5] = extbonuses[5] + statbonus[5] | |||
extbonuses[6] = extbonuses[6] + statbonus[6] | |||
end | |||
end | end | ||
Line 144: | Line 172: | ||
} | } | ||
} | } | ||
end | |||
function p.test() | |||
return p.decode("BCIKMKSEBFBH#0B2") | |||
end | end | ||
return p | return p |