8,756
edits
Syntaxaire (talk | contribs) (set 'beta' to default) |
mNo edit summary |
||
(6 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local decode = require'Module:CryptogullJr/Codes' | local decode = require'Module:CryptogullJr/Codes' | ||
local utilTable = require('Module:Table Utility') | |||
function p.Main(frame) | function p.Main(frame) | ||
local buildcode = frame.args['code'] | |||
local beta = frame.args['beta'] or '1' | |||
local title = frame.args['title'] | |||
return p.decode(buildcode, beta, title) | |||
end | |||
function p.decode(buildcode, beta, title) | |||
local genotype | local genotype | ||
local subtype | local subtype | ||
Line 11: | Line 18: | ||
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 18: | Line 30: | ||
if (genotypeC == 'a') then | if (genotypeC == 'a') then | ||
genotype = "True Kin" | genotype = "True Kin" | ||
classcalled = "Caste | classcalled = "Caste" | ||
extname = "Implants | extname = "Implants" | ||
subtype = decode.TrueKinSubtype(subtypeC) | subtype = decode.TrueKinSubtype(subtypeC) | ||
elseif (genotypeC == 'b') then | elseif (genotypeC == 'b') then | ||
genotype = "Mutated Human" | genotype = "Mutated Human" | ||
classcalled = "Calling | classcalled = "Calling" | ||
extname = "Mutations: " | extname = "Mutations: " | ||
subtype = decode.MutantSubtype(subtypeC) | subtype = decode.MutantSubtype(subtypeC) | ||
Line 46: | Line 58: | ||
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)[1] | |||
i = i + 1 | |||
end | |||
end | end | ||
end | end | ||
Line 56: | Line 82: | ||
attributes = p.fixattributes(bonus, attributes) | attributes = p.fixattributes(bonus, attributes) | ||
end | end | ||
output = p.MakeUpSheet(buildcode, genotype, subtype, | |||
classcalled, extname, attributes, bonus, exts, title) | |||
return output | return output | ||
end | end | ||
Line 66: | Line 93: | ||
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 119: | Line 146: | ||
end | end | ||
function p.MakeUpSheet(codeIn, genoIn, subtype, classcalledIn, extnameIn, attributes, bonus, | function p.MakeUpSheet(codeIn, genoIn, subtype, classcalledIn, extnameIn, | ||
attributes, bonus, exts, title) | |||
local frame = mw.getCurrentFrame() | |||
return frame:expandTemplate { | return frame:expandTemplate { | ||
title = 'Crypto result', | title = 'Crypto result', | ||
Line 139: | Line 163: | ||
ego = attributes[6] .. bonus[6], | ego = attributes[6] .. bonus[6], | ||
extname = extnameIn, | extname = extnameIn, | ||
exts = | exts = utilTable.concat(exts, "</br>"), | ||
skills = subtype[8], | skills = subtype[8], | ||
notes = subtype[14] | notes = subtype[14], | ||
buildname = title, | |||
author = "Legacy Build Code" | |||
} | } | ||
} | } | ||
end | end | ||
function p.test() | |||
return p.Main({["args"]={"BGMMMKMKBABJBPD1", ["beta"]=1}}) | |||
end | |||
return p | return p |