Module:CryptogullJrOld: Difference between revisions

From Caves of Qud Wiki
Jump to navigation Jump to search
(wikid)
mNo edit summary
 
(23 intermediate revisions by 2 users not shown)
Line 1: Line 1:
local p = {}
local p = {}
local decode = require'Module:CryptogullJr/Codes'
local utilTable = require('Module:Table Utility')


function p.Main(frame)
function p.Main(frame)
  local buildcode=string.lower(frame.args[1])
local buildcode = frame.args['code']
  local genotype
    local beta = frame.args['beta'] or '1'
  local subtype
     local title = frame.args['title']
  local classcalled
     return p.decode(buildcode, beta, title)
  local extname
end
  local attributes = {}
  local bonus = {}
  local exts = {}
  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 = p.TrueKinSubtype(subtypeC)
     elseif (genotypeC == 'b') then
      genotype="Mutated Human"
      classcalled = "Calling: "
      extname = "Mutations: "
      subtype = p.MutantSubtype(subtypeC)
    else
      error ("The genotype code " .. genotypeC .. " does not exist!",0)
    end


     --[Check if subtype worked]
function p.decode(buildcode, beta, title)
     if (subtype == nil) then
     local genotype
      error("Couldn't find subtype " ..subtypeC, 0)
    local subtype
     else
     local classcalled
    --[get attributes and put it in a table]
    local extname
      local attributesC = string.sub(buildcode,3,8)
    local attributes = {}
      local i = 1
    local bonus = {}
      for char in string.gmatch(attributesC, "%w") do
    local exts = {}
         attributes[i] = tonumber(string.byte(char))-91
    local beta = beta or '1'
        i = i+1
   
      end
if buildcode == nil then
      --[Mutations/Implants hooray]
error("A build code must be provided!")
      --if >8 chars, and have an even set of chars
end
      if (buildcode:len() >=10 and buildcode:len()%2 ==0) then
    buildcode = string.lower(buildcode)
      local i = 1
     if (string.len(buildcode) >= 8) then
      local extstring = buildcode:sub(9)
        --[Check Genotype Code, and then subtype code]
        for chars in string.gmatch(extstring,"%w%w") do
        local genotypeC = string.match(buildcode, '%w')
             exts[i] = p.getexts(chars, subtypeC)
        local subtypeC = string.sub(buildcode, 2, 2)
             i=i+1
         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
         end
      end
      --calculate bonus
      bonus=p.getbonus(subtype, exts)
      --recalculate attributes after stat bonuses
      attributes=p.fixattributes(bonus, attributes)
      --make the dang sheet
      p.MakeUpSheet(buildcode, genotype, subtype, classcalled, extname, attributes,bonus,exts)
    end
  else
    error("This build code is too short(<8 chars)!",0)
  end
end


function p.TrueKinSubtype(code)
        --[Check if subtype worked]
--[1 NAME, stats (2 STR, 3 AGI, 4 TUF, 5 INT, 6 WIL, 7 EGO),]--
        if (subtype == nil) then
--[8 Skills, Resist(9 ACID, 10 ELEC, 11 COLD, 12 HEAT, 13 BLEED), 14 bonusstart]--
            error("Couldn't find subtype " .. subtypeC, 0)
local caste= {
        else
  --[The Toxic Arboreta of Ekuemekiyye, the Holy City]
        --[get attributes and put it in a table]
  ['a'] = {"Horticulturist", 0,0,0,3,0,0,"Harvestry, Axe Proficiency, Steady Hands, Draw a Bead, Wilderness Lore: Jungles",0,0,0,0,2, "Start with a bio-scanning bracelet"},
            local attributesC = string.sub(buildcode, 3, 8)
  ['b'] = {"Priest of All Suns", 0,0,0,0,0,3,"Cudgel Proficiency, Heal, Snake Oiler, Intimidate, Wilderness Lore: Jungles",0,0,0,0,2,"Start with a smiling sun mask"},
            local i = 1
  ['c'] = {"Priest of All Moons", 0,0,2,0,2,0,"Axe Proficiency, Butchery, Lionheart, Poison Tolerance, Wilderness Lore: Jungles",0,0,0,0,2, "Start with a frowning moon mask"},
            for char in string.gmatch(attributesC, "%w") do
  ['d'] = {"Syzygyrior", 0,3,0,0,0,0,"Offhand Strikes, Ambidexterity, Wayfaring: Jungle",0,0,0,0,0, "Start with a bio-scanning bracelet"},
                attributes[i] = tonumber(string.byte(char)) - 91
  --[he Ice-Sheathed Arcology of Ibul]
                i = i + 1
  ['e'] = {"Artifex", 0,0,0,3,0,0,"Repair, Disassemble,Deploy Turret, Tinker I, Tinker II",0,0,15,0,0,""},
            end
  ['f'] = {"Consul", 0,0,0,0,0,3,"Inspiring Presence, Proselytize",0,0,15,0,0, ""},
            --[Mutations/Implants hooray]
  ['g'] = {"Praetorian", 2,0,1,0,1,0,"Long Blade Proficiency, Shield Slam, Steady Hands, Draw a Bead", 0,0,15,0,0,""},
            --if >8 chars, and have an even set of chars
  ['h'] = {"Eunuch", 0,2,0,2,0,0,"Hobble, Weak Spotter, Spry, Hurdle",0,0,15,0,0,""},
            if (buildcode:len() >= 10 and buildcode:len() % 2 == 0) then
  --[The Crustal Mortars of Yawningmoon]
                local i = 1
  ['i'] = {"Child of the Hearth", 3,0,0,0,0,0,"Slam, Calloused, Strapping Shoulders",0,0,0,15,0, ""},
                local extstring = buildcode:sub(9)
  ['j'] = {"Child of the Wheel", 1,2,0,0,0,1,"Short Blades Proficiency, Cleave, Offhand Strikes, Iron Mind",0,0,0,15,0,""},
            previouscode = nil
  ['k'] = {"Child of the Deep", 0,0,3,0,0,0,"Tank, Strapping Shoulders, Shake It Off, Wilderness Lore: Mountains, Wilderness Long: Canyons",0,0,0,15,0, ""},
                for chars in string.gmatch(extstring, "[%w#]%w") do
  ['l'] = {"Fuming God-Child", 0,0,0,0,4,0,"Fasting Way, Lionheart, Poison Tolerance, Intimidate",0,0,0,15,0, ""}
                varnum = tonumber(chars:match("#(%d)"))
}
                if varnum ~= nil then
return caste[code]
                if previouscode == nil or (exts[i-1][2] == "") then
end
                error("Unexpected variant code")
 
                end
function p.MutantSubtype(code)
                -- add 1 to the index because lua is silly
--[NAME, stats (STR, AGI, TUF, INT, WIL, EGO),]--
                variant = exts[i-1][2][varnum + 1]
--[Skills, Resist(ACID, ELEC, COLD, HEAT, BLEED), bonusstart]--
                -- get the previous extension and append variant to it
local calling = {
                exts[i - 1][1] = exts[i - 1][1] .. " (" .. variant .. ")"
  ['a'] = {"Apostle", 0,0,0,0,0,2,"Intimidate, Proselytize, Tactful",0,0,0,0,0, ""},
                previouscode = nil
  ['b'] = {"Arconaut", 0,2,0,0,0,0,"Short Blades Proficiency, Scavenger, Spry",0,0,0,0,0,"Start with random junk and artifacts"},
                else
  ['c'] = {"Greybeard", -1,0,0,0,3,0,"Cudgel Proficiency, Berate, Calloused",0,0,0,0,0, "Start with +100 bear reputation"},
                previouscode = chars
  ['d'] = {"Gunslinger", 0,2,0,0,0,0,"Weak Spotter",0,0,0,0,0, "Start with +200 reputation with mysterious strangers"},
                    exts[i] = decode.getexts(chars, subtypeC)[1]
  ['e'] = {"Marauder", 2,0,0,0,0,0,"Dismember, Charge, Butchery",0,0,0,0,0,""},
                    i = i + 1
  ['f'] = {"Pilgrim", 0,0,0,0,2,0,"Meditate, Fasting Way, Iron Mind, Mind's Compass",0,0,0,0,0, ""},
                    end
  ['g'] = {"Nomad", 0,0,2,0,0,0,"Mind's Compass, Wilderness Lore: Salt Pans, Harvestry,Weathered", 0,0,15,15,0,"Starts with +200 Issachari reputation"},
                end
  ['h'] = {"Scholar", 0,0,0,2,0,0,"Gadget Inspector, Heal, Harvestry, Hurdle, Tactful",0,0,0,0,0,""},
            end
  ['i'] = {"Tinker", 0,0,0,2,0,0,"Gadget Inspector, Lay Mine, Disassemble, Repair, Tinker I",0,0,0,0,0, "Begins with a number of random artifacts and scrap and +100 Barathrumites reputation"},
            --calculate bonus
  ['j'] = {"Warden", 2,0,0,0,0,0,"Long Blades Proficiency, Shield Slam, Steady Hands, Draw a Bead, Pistol Proficiency",0,0,0,0,0,"Starts with +300 Warden reputation"},
            bonus = p.getbonus(subtype, exts)
  ['k'] = {"Water Merchant", 0,0,0,0,0,2,"Menacing Stare, Snake Oiler",0,0,0,0,0, "Starts with trade goods and a merchant's token"},
            if beta ~= '1' then
  ['l'] = {"Watervine Farmer", 0,0,2,0,0,0,"Cooking and Gathering, Harvestry, Axe Proficiency, Wilderness Lore: Salt Marshes",0,0,0,0,0, "Starts with +100 reputation with the villagers of Joppa and a farmer's token"}
              attributes = p.fixattributes(bonus, attributes)
}
            end
return calling[code]
output = p.MakeUpSheet(buildcode, genotype, subtype,
end
            classcalled, extname, attributes, bonus, exts, title)
 
            return output
function p.getexts(code,subtypeC)
        end
  local muts = {
     else
    ['aa'] = {"Chimera", 0,0,0,0,0,0,0,0,0,0},
        error("This build code is too short(<8 chars)!", 0)
    ['ab'] = {"Esper", 0,0,0,0,0,0,0,0,0,0},
    ['uu'] = {"Unstable Genome",0,0,0,0,0,0,0,0,0,0},
    ['u2'] = {"Unstable Genome(2)",0,0,0,0,0,0,0,0,0,0},
    ['u3'] = {"Unstable Genome(3)",0,0,0,0,0,0,0,0,0,0},
    ['u4'] = {"Unstable Genome(4)",0,0,0,0,0,0,0,0,0,0},
    ['u5'] = {"Unstable Genome(5)",0,0,0,0,0,0,0,0,0,0},
    ['u6'] = {"Unstable Genome(6)",0,0,0,0,0,0,0,0,0,0},
    ['u7'] = {"Unstable Genome(7)",0,0,0,0,0,0,0,0,0,0},
    ['u8'] = {"Unstable Genome(8)",0,0,0,0,0,0,0,0,0,0},
    ['u9'] = {"Unstable Genome(9)",0,0,0,0,0,0,0,0,0,0},
    ['ba'] = {"Adrenal Control", 0,0,0,0,0,0,0,0,0,0},
    ['bb'] = {"Burrowing Claws", 0,0,0,0,0,0,0,0,0,0},
    ['bc'] = {"Carapace", 0,0,0,0,0,0,0,0,0,0},
    ['b6'] = {"Carnivorous",0,0,0,0,0,0,0,0,0,0},
    ['bd'] = {"Corrosive Gas Generation", 0,0,0,0,0,0,0,0,0,0},
    ['be'] = {"Double-muscled", 2,0,0,0,0,0,0,0,0,0},
    ['bf'] = {"Electrical Generation", 0,0,0,0,0,0,0,0,0,0},
    ['bg'] = {"Electromagnetic Pulse",0,0,0,0,0,0,0,0,0,0},
    ['bh'] = {"Flaming Hands", 0,0,0,0,0,0,0,0,0,0},
    ['bi'] = {"Freezing Hands", 0,0,0,0,0,0,0,0,0,0},
    ['bj'] = {"Heightened Hearing", 0,0,0,0,0,0,0,0,0,0},
    ['bk'] = {"Heightened Quickness",0,0,-1,0,0,0,0,0,0,0},
    ['bl'] = {"Horns", 0,0,0,0,0,0,0,0,0,0},
    ['bm'] = {"Metamorphosis", 0,0,0,0,0,0,0,0,0,0},
    ['bn'] = {"Multiple Arms", 0,0,0,0,0,0,0,0,0,0},
    ['bo'] = {"Multiple Legs",0,0,0,0,0,0,0,0,0,0},
    ['bp'] = {"Night Vision", 0,0,0,0,0,0,0,0,0,0},
    ['bq'] = {"Phasing", 0,0,0,0,0,0,0,0,0,0},
    ['br'] = {"Photosynthetic Skin", 0,0,0,0,0,0,0,0,0,0},
    ['bs'] = {"Quills",0,0,0,0,0,0,0,0,0,0},
    ['bt'] = {"Regeneration", 0,0,0,0,0,0,0,0,0,0},
    ['bu'] = {"Sleep Gas Generation", 0,0,0,0,0,0,0,0,0,0},
    ['bv'] = {"Slime Glands", 0,0,0,0,0,0,0,0,0,0},
    ['bw'] = {"Spinnerets",0,0,0,0,0,0,0,0,0,0},
    ['bx'] = {"Stinger (Confusing Venom)", 0,0,0,0,0,0,0,0,0,0},
    ['by'] = {"Stinger (Paralyzing Venom)", 0,0,0,0,0,0,0,0,0,0},
    ['bz'] = {"Stinger (Poisoning Venom)", 0,0,0,0,0,0,0,0,0,0},
    ['b1'] = {"Thick Fur",0,0,0,0,0,0,0,0,4,4},
    ['b2'] = {"Triple-jointed", -1,2,0,0,0,0,0,0,0,0},
    ['b3'] = {"Two-headed",0,0,0,0,0,0,0,0,0,0},
    ['b4'] = {"Two-hearted", 0,0,2,0,0,0,0,0,0,0},
    ['b5'] = {"Wings", 0,0,0,0,0,0,0,0,0,0},
    --[phys defects]
    ['ca'] = {"Albino", 0,0,0,0,0,0,0,0,0,0},
    ['cb'] = {"Amphibious",0,0,0,0,0,0,0,0,0,0},
    ['cc'] = {"Analgesia", 0,0,0,0,0,0,0,0,0,0},
    ['cd'] = {"Beak", 0,0,0,0,0,-1,0,0,0,0},
    ['ce'] = {"Cold-Blooded", 0,0,0,0,0,0,0,0,0,0},
    ['cf'] = {"Brittle Bones",0,0,0,0,0,0,0,0,0,0},
    ['cg'] = {"Electromagnetic Impulse", 0,0,0,0,0,0,0,0,0,0},
    ['ch'] = {"Hemophilia", 0,0,0,0,0,0,0,0,0,0},
    ['ci'] = {"Hooks for Feet", 0,0,0,0,0,0,0,0,0,0},
    ['cj'] = {"Myopia",0,0,0,0,0,0,0,0,0,0},
    ['ck'] = {"Spontaneous Combustion", 0,0,0,0,0,0,0,0,0,0},
    --[mental muts]
    ['da'] = {"Beguiling", 0,0,0,0,0,0,0,0,0,0,0},
    ['db'] = {"Burgeoning",0,0,0,0,0,0,0,0,0,0,0},
    ['dc'] = {"Clairvoyance", 0,0,0,0,0,0,0,0,0,0,0},
    ['dd'] = {"Confusion", 0,0,0,0,0,0,0,0,0,0,0},
    ['de'] = {"Cryokinesis",0,0,0,0,0,0,0,0,0,0,0},
    ['df'] = {"Domination", 0,0,0,0,0,0,0,0,0,0,0},
    ['dg'] = {"Disintegration", 0,0,0,0,0,0,0,0,0,0,0},
    ['dh'] = {"Ego Projection", 0,0,0,0,0,0,0,0,0,0,0},
    ['di'] = {"Force Bubble",0,0,0,0,0,0,0,0,0,0,0},
    ['dj'] = {"Force Wall", 0,0,0,0,0,0,0,0,0,0,0},
    ['dk'] = {"Kindle", 0,0,0,0,0,0,0,0,0,0,0},
    ['dl'] = {"Light Manipulation", 0,0,0,0,0,0,0,0,0,0,0},
    ['dm'] = {"Mass Mind",0,0,0,0,0,0,0,0,0,0,0},
    ['dn'] = {"Mental Mirror", 0,0,0,0,0,0,0,0,0,0,0},
    ['do'] = {"Precognition", 0,0,0,0,0,0,0,0,0,0,0},
    ['dp'] = {"Psychometry",0,0,0,0,0,0,0,0,0,0},
    ['dq'] = {"Pyrokinesis", 0,0,0,0,0,0,0,0,0,0},
    ['dr'] = {"Sense Psychic", 0,0,0,0,0,0,0,0,0,0},
    ['ds'] = {"Space-Time Vortex",0,0,0,0,0,0,0,0,0,0},
    ['dt'] = {"Stunning Force", 0,0,0,0,0,0,0,0,0,0},
    ['du'] = {"Sunder Mind", 0,0,0,0,0,0,0,0,0,0},
    ['dv'] = {"Syphon Vim", 0,0,0,0,0,0,0,0,0,0},
    ['dw'] = {"Telepathy",0,0,0,0,0,0,0,0,0,0},
    ['dx'] = {"Teleportation", 0,0,0,0,0,0,0,0,0,0},
    ['dy'] = {"Teleport Other", 0,0,0,0,0,0,0,0,0,0},
    ['dz'] = {"Time Dilation", 0,0,0,0,0,0,0,0,0,0},
    ['d1'] = {"Temporal Fugue",0,0,0,0,0,0,0,0,0,0},
    --[mental defects]
    ['ea'] = {"Amnesia", 0,0,0,0,0,0,0,0,0,0},
    ['eb'] = {"Blinking Tic", 0,0,0,0,0,0,0,0,0,0},
    ['ec'] = {"Evil Twin",0,0,0,0,0,0,0,0,0,0},
    ['ed'] = {"Narcolepsy", 0,0,0,0,0,0,0,0,0,0},
    ['ee'] = {"Pack Rat", 0,0,0,0,0,0,0,0,0,0},
    ['ef'] = {"Socially Repugnant",0,0,0,0,0,0,0,0,0,0},
    ['eg'] = {"Unwelcome Germination", 0,0,0,0,0,0,0,0,0,0},
    --[cybernetics (to be added)]
    ['00'] = {"", 0,0,1,0,0,0,0,0,0,0},
    ['01'] = {"dermal insulation",0,0,0,0,0,0,6,6,6,6},
    ['04'] = {'optical bioscanner',0,0,0,0,0,0,0,0,0,0},
    ['05'] = {'optical technoscanner', 0,0,0,0,0,0,0,0,0,0},
    ['06'] = {'night vision', 0,0,0,0,0,0,0,0,0,0},
    ['07'] = {'hyper-elastic ankle tendons', 0,0,0,0,0,0,0,0,0,0},
    ['08'] = {'parabolic muscular subroutine', 0,0,0,0,0,0,0,0,0,0},
    ['09'] = {'translucent skin', 0,0,0,0,0,0,0,0,0,0},
    ['11'] = {'stabilizer arm locks', 0,0,0,0,0,0,0,0,0,0},
    ['12'] = {'rapid release finger flexors', 0,0,0,0,0,0,0,0,0,0},
    ['13'] = {'carbide hand bones', 0,0,0,0,0,0,0,0,0,0},
    ['14'] = {'pentaceps', 0,0,0,0,0,0,0,0,0,0},
    ['15'] = {'inflatable axons', 0,0,0,0,0,0,0,0,0,0},
    -- subtypes A-D, E-H, I-L
     ['16'] = { 'nocturnal apex', 'cherubic visage', 'air current microsensor', 0,0,0,0,0,0,0,0,0,0}
  }
 
  if code ~= nil and code == '16' then
    if subtypeC < 'e' then
      return { 'nocturnal apex', 0,0,0,0,0,0,0,0,0,0}
    elseif subtypeC < 'i' then
      return { 'cherubic visage', 0,0,0,0,0,0,0,0,0,0}
    else
      return { 'air current microsensor', 0,0,0,0,0,0,0,0,0,0}
     end
     end
  else
    return muts[code]
  end
end
function p.getImplants(code,subtypeC)
end
end


function p.getbonus(subtype, exts)
function p.getbonus(subtype, exts)
--STR, AGI, TOUGH,INT, WILL, EGO
    --STR, AGI, TOUGH,INT, WILL, EGO
local extbonuses = {0,0,0,0,0,0,0,0,0,0,0}
    local extbonuses = { 0, 0, 0, 0, 0, 0 }
for x,y in ipairs(exts) do
    for x, y in pairs(exts) do
  extbonuses[1] = extbonuses[1] + y[2]
    mw.logObject(y[1])
  extbonuses[2] = extbonuses[2] + y[3]
    if decode.getStatBonus(y[1]) then
  extbonuses[3] = extbonuses[3] + y[4]
    statbonus = decode.getStatBonus(y[1])
  extbonuses[4] = extbonuses[4] + y[5]
    extbonuses[1] = extbonuses[1] + statbonus[1]
  extbonuses[5] = extbonuses[5] + y[6]
    extbonuses[2] = extbonuses[2] + statbonus[2]
  extbonuses[6] = extbonuses[6] + y[7]
        extbonuses[3] = extbonuses[3] + statbonus[3]
  extbonuses[7] = extbonuses[7] + y[8]
        extbonuses[4] = extbonuses[4] + statbonus[4]
  extbonuses[8] = extbonuses[8] + y[9]
        extbonuses[5] = extbonuses[5] + statbonus[5]
  extbonuses[9] = extbonuses[9] + y[10]
        extbonuses[6] = extbonuses[6] + statbonus[6]
  extbonuses[10] = extbonuses[10] + y[11]
    end
end
    end


local bonusints = {}
    local bonusints = {}
bonusints[1] = subtype[2] + extbonuses[1]
    bonusints[1] = subtype[2] + extbonuses[1]
bonusints[2] = subtype[3] + extbonuses[2]
    bonusints[2] = subtype[3] + extbonuses[2]
bonusints[3] = subtype[4] + extbonuses[3]
    bonusints[3] = subtype[4] + extbonuses[3]
bonusints[4] = subtype[5] + extbonuses[4]
    bonusints[4] = subtype[5] + extbonuses[4]
bonusints[5] = subtype[6] + extbonuses[5]
    bonusints[5] = subtype[6] + extbonuses[5]
bonusints[6] = subtype[7] + extbonuses[6]
    bonusints[6] = subtype[7] + extbonuses[6]


local i = 0
    local i = 0
local bonusT = {}
    local bonusT = {}
for x,y in ipairs(bonusints) do
    for x, y in ipairs(bonusints) do
  local symbol = " "
        local symbol = " "
  if y < 0 then
        if y < 0 then
  symbol = ""
            symbol = ""
  elseif y > 0 then
        elseif y > 0 then
  symbol = "+"
            symbol = "+"
  end
        end


  if symbol ~= nil and symbol ~= " " then
        if symbol ~= nil and symbol ~= " " then
    bonusT[x] = symbol .. y
            bonusT[x] = symbol .. y
  else  
        else
    bonusT[x] = " "
            bonusT[x] = " "
end
        end
end
    end
return bonusT
    return bonusT
end
end


function p.fixattributes(bonus, attr)
function p.fixattributes(bonus, attr)
local newattr = {}
    local newattr = {}
for x,y in ipairs(bonus) do
    for x, y in ipairs(bonus) do
  if y ~= " " then
        if y ~= " " then
    newattr[x] = tonumber(attr[x]) - tonumber(y)
            newattr[x] = tonumber(attr[x]) - tonumber(y)
  else
        else
    newattr[x] = tonumber(attr[x])
            newattr[x] = tonumber(attr[x])
  end
        end
    end
    return newattr
end
end
return newattr
 
function p.MakeUpSheet(codeIn, genoIn, subtype, classcalledIn, extnameIn,
attributes, bonus, exts, title)
local frame = mw.getCurrentFrame()
    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 = utilTable.concat(exts, "</br>"),
            skills = subtype[8],
            notes = subtype[14],
            buildname = title,
            author = "Legacy Build Code"
        }
    }
end
end
 
function p.test()
function p.MakeUpSheet(codeIn, genoIn, subtype, classcalledIn, extnameIn,attributes, bonus,extsIn)
return p.Main({["args"]={"BGMMMKMKBABJBPD1", ["beta"]=1}})
 
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=mw.text.listToText(extsIn, ', ', ', '),
skills=subtype[8],
notes=subtype[14]} }
 
end
end
return p
return p

Latest revision as of 01:14, 7 August 2023

Documentation for this module may be created at Module:CryptogullJrOld/doc

local p = {}
local decode = require'Module:CryptogullJr/Codes'
local utilTable = require('Module:Table Utility')

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 subtype
    local classcalled
    local extname
    local attributes = {}
    local bonus = {}
    local exts = {}
    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
        --[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)
            	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
            --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, title)
            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 }
    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

    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, exts, title)
	local frame = mw.getCurrentFrame()
    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 = utilTable.concat(exts, "</br>"),
            skills = subtype[8],
            notes = subtype[14],
            buildname = title,
            author = "Legacy Build Code"
        }
    }
end
function p.test()
	return p.Main({["args"]={"BGMMMKMKBABJBPD1", ["beta"]=1}})	
end
return p