Module:CryptogullJrOld
Documentation for this module may be created at Module:CryptogullJrOld/doc
local p = {}
local decode = require'Module:CryptogullJr/Codes'
function p.Main(frame)
local buildcode = string.lower(frame.args[1])
local genotype
local subtype
local classcalled
local extname
local attributes = {}
local bonus = {}
local exts = {}
local beta = frame.args['beta'] or '1'
if (string.len(buildcode) >= 8) then
--[Check Genotype Code, and then subtype code]
local genotypeC = string.match(buildcode, '%w')
local subtypeC = string.sub(buildcode, 2, 2)
if (genotypeC == 'a') then
genotype = "True Kin"
classcalled = "Caste: "
extname = "Implants: "
subtype = decode.TrueKinSubtype(subtypeC)
elseif (genotypeC == 'b') then
genotype = "Mutated Human"
classcalled = "Calling: "
extname = "Mutations: "
subtype = decode.MutantSubtype(subtypeC)
else
error("The genotype code " .. genotypeC .. " does not exist!", 0)
end
--[Check if subtype worked]
if (subtype == nil) then
error("Couldn't find subtype " .. subtypeC, 0)
else
--[get attributes and put it in a table]
local attributesC = string.sub(buildcode, 3, 8)
local i = 1
for char in string.gmatch(attributesC, "%w") do
attributes[i] = tonumber(string.byte(char)) - 91
i = i + 1
end
--[Mutations/Implants hooray]
--if >8 chars, and have an even set of chars
if (buildcode:len() >= 10 and buildcode:len() % 2 == 0) then
local i = 1
local extstring = buildcode:sub(9)
for chars in string.gmatch(extstring, "%w%w") do
exts[i] = decode.getexts(chars, subtypeC)
i = i + 1
end
end
--calculate bonus
bonus = p.getbonus(subtype, exts)
if beta ~= '1' then
attributes = p.fixattributes(bonus, attributes)
end
output = p.MakeUpSheet(buildcode, genotype, subtype, classcalled, extname, attributes, bonus, exts, frame)
return output
end
else
error("This build code is too short(<8 chars)!", 0)
end
end
function p.getbonus(subtype, exts)
--STR, AGI, TOUGH,INT, WILL, EGO
local extbonuses = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
for x, y in ipairs(exts) do
extbonuses[1] = extbonuses[1] + y[2]
extbonuses[2] = extbonuses[2] + y[3]
extbonuses[3] = extbonuses[3] + y[4]
extbonuses[4] = extbonuses[4] + y[5]
extbonuses[5] = extbonuses[5] + y[6]
extbonuses[6] = extbonuses[6] + y[7]
extbonuses[7] = extbonuses[7] + y[8]
extbonuses[8] = extbonuses[8] + y[9]
extbonuses[9] = extbonuses[9] + y[10]
extbonuses[10] = extbonuses[10] + y[11]
end
local bonusints = {}
bonusints[1] = subtype[2] + extbonuses[1]
bonusints[2] = subtype[3] + extbonuses[2]
bonusints[3] = subtype[4] + extbonuses[3]
bonusints[4] = subtype[5] + extbonuses[4]
bonusints[5] = subtype[6] + extbonuses[5]
bonusints[6] = subtype[7] + extbonuses[6]
local i = 0
local bonusT = {}
for x, y in ipairs(bonusints) do
local symbol = " "
if y < 0 then
symbol = ""
elseif y > 0 then
symbol = "+"
end
if symbol ~= nil and symbol ~= " " then
bonusT[x] = symbol .. y
else
bonusT[x] = " "
end
end
return bonusT
end
function p.fixattributes(bonus, attr)
local newattr = {}
for x, y in ipairs(bonus) do
if y ~= " " then
newattr[x] = tonumber(attr[x]) - tonumber(y)
else
newattr[x] = tonumber(attr[x])
end
end
return newattr
end
function p.MakeUpSheet(codeIn, genoIn, subtype, classcalledIn, extnameIn, attributes, bonus, extsIn, frame)
local mutstring = ""
for _, ext in ipairs(extsIn) do
mutstring = mutstring .. ", " .. ext[1]
end
return frame:expandTemplate {
title = 'Crypto result',
args = {
code = codeIn:upper(),
genotype = genoIn,
classcalled = classcalledIn,
class = subtype[1],
strength = tostring(attributes[1]) .. bonus[1],
agility = tostring(attributes[2]) .. bonus[2],
toughness = attributes[3] .. bonus[3],
intelligence = attributes[4] .. bonus[4],
willpower = attributes[5] .. bonus[5],
ego = attributes[6] .. bonus[6],
extname = extnameIn,
exts = mutstring:sub(3),
skills = subtype[8],
notes = subtype[14]
}
}
end
return p