Module:Sandbox/User:Teamtoto/LuaModule: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
mNo edit summary |
||
Line 24: | Line 24: | ||
local frame = mw.getCurrentFrame() | local frame = mw.getCurrentFrame() | ||
local decoded = mw.text.jsonDecode(zlib.gzdecode(zlib.base64_decode(code))) | local decoded = mw.text.jsonDecode(zlib.gzdecode(zlib.base64_decode(code))) | ||
local version = decoded["gameversion"] | local version = decoded["gameversion"] | ||
local genotype = decoded["modules"][1]["data"]["Genotype"] | local genotype = decoded["modules"][1]["data"]["Genotype"] | ||
Line 70: | Line 71: | ||
else | else | ||
for i, v in ipairs(decoded["modules"][3]["data"]["selections"]) do | for i, v in ipairs(decoded["modules"][3]["data"]["selections"]) do | ||
exts[i] = v[" | exts[i] = v[extNoun] | ||
if data.isDefect(v[extNoun]) then | |||
exts[i] = exts[i] .. "(<span style=\"color:#a64a2e\">D</span>)" | |||
end | |||
if v["Count"] > 1 then | if v["Count"] > 1 then | ||
exts[i] = exts[i] .. " <small>x</small>" .. v["Count"] | exts[i] = exts[i] .. " <small>x</small>" .. v["Count"] | ||
Line 95: | Line 99: | ||
local skills = data.getSkills(subtype) | local skills = data.getSkills(subtype) | ||
local extra = data.getExtra(subtype) | local extra = data.getExtra(subtype) | ||
return p.MakeUpSheet(code, genotype, subtype, classCalled, extCalled, | --return p.MakeUpSheet(code, genotype, subtype, classCalled, extCalled, | ||
-- stats, bonus, exts, skills, extra, title, author, frame) | |||
return decoded | |||
end | end | ||
Line 125: | Line 130: | ||
function p.test() | function p.test() | ||
str = " | str = "H4sIAAAAAAAAA81WXW/aMBR9r9T/YEV7DIgiNnWVeGDpNra1EmtoO2nqg5PcJV4d2/LHKob477MNhSSsg05qBBIKvud+HO49ufL8+AihIMcl/AKpCGfBGQr63V633xt0X58GoccTQ2hWcTixDr0VVvLMUFDW/N2dEZovH2toOhPggr5dXXSjAkucapDvXEbV/Woy9/0IjGvrdukDQjRSCsqEzjpRbANEiG6WtYcbZiGKDNVGwpCB0RLTEE1MQkn6BWZTfg9syAylS46eTIY1tjTW7KzplX4utXObZIvepojN+ejv0l4ajTVkaGxKzGpeW718xBbLH4vwv3sZm+RAW1ljtruTK3eXNE4LTrFsq4V+bja3OsAmNrjtbmMpbMZe1aKAQupzbF7a5WdePaCVgFdNjgpSgsTV3N4n4oZp63DSBG6wJNhDvSqyCPetOOb8XqEfXKIPALrFwtMH3hkDziBrs6gkgkLnJydMt1r4nFudQqc0KqWtFr5mSmNbGrmdWcKTlfv7Vt4c7lraFCOtJUmMhkNcFU1yu3fFxIlPTYxMC6ysFs7q8wtGOaFEz6z9bW0mwfucW+ObuvGTFTKlJAeWOqqndTTWEliui+24KTd5wUCp7aBbQqngDyBd1Aapai7AIhbg1dEZDOrAFZSYMMLy5kpM7N8duUVZj3hB5URGaV6S37DGD1BBT5HcrSRmb5R+h2OWzVBMTV6DBbj5OJJVq1VK5kfbBITkzC6D+K9RLzmkgnMFscZSW9Fc8NTvrkMc1D+I7nHTasS5Yp+5EPh5Fy73uDs+WvwB4vrnYFQMAAA=" | ||
return p.a(str, "DijTItle", "Dij") | return p.a(str, "DijTItle", "Dij") | ||
end | end | ||
return p | return p |
Revision as of 21:31, 6 August 2023
Documentation for this module may be created at Module:Sandbox/User:Teamtoto/LuaModule/doc
local zlib = mw.ext.zlib
local utilTable = require('Module:Table Utility')
local data = require('Module:CryptogullJr/Data')
local p = {}
function p.main(frame)
local frame = mw.getCurrentFrame()
if frame.args ~= nil and frame.args ~= '' then
-- argument in template call has to be named so the equal sign doesn't
-- break input
local code = frame.args["code"]
local title = frame.args["title"]
local author = frame.args["author"]
if frame.args["code"]~= nil and frame.args["code"] ~= '' then
return p.a(mw.text.trim(frame:preprocess(frame.args["code"])), title, author)
else
error "There was no code in your input!"
end
end
end
function p.a(code, title, author)
local frame = mw.getCurrentFrame()
local decoded = mw.text.jsonDecode(zlib.gzdecode(zlib.base64_decode(code)))
local version = decoded["gameversion"]
local genotype = decoded["modules"][1]["data"]["Genotype"]
local classCalled = "Calling"
local extCalled = "Mutations"
local subtype = decoded["modules"][2]["data"]["Subtype"]
local baseStat = 10
local stats = {
["Strength"] = 0,
["Intelligence"] = 0,
["Toughness"] = 0,
["Willpower"] = 0,
["Ego"] = 0,
["Agility"] = 0}
local bonusInt = {}
local exts = {}
local bonus = {
["Strength"] = "",
["Intelligence"] = "",
["Toughness"] = "",
["Willpower"] = "",
["Ego"] = "",
["Agility"] = ""
}
if genotype == "True Kin" then
-- if true kin, stats are [3] and cybernetics are [4]
classCalled= "Caste"
extCalled = "Cybernetics"
statPos = 3
extPos = 4
extNoun = 'Cybernetic'
baseStat = 12
else
-- if mutant, stats are [4] and mutations are [3] :crungled:
statPos=4
extPos=3
extNoun='Mutation'
end
stats = decoded["modules"][statPos]["data"]["PointsPurchased"]
-- No cybernetics means extra toughness
if extPos == 4 and #decoded["modules"][4]["data"]["selections"] == 1 then
exts[1] = "No Cybernetic"
else
for i, v in ipairs(decoded["modules"][3]["data"]["selections"]) do
exts[i] = v[extNoun]
if data.isDefect(v[extNoun]) then
exts[i] = exts[i] .. "(<span style=\"color:#a64a2e\">D</span>)"
end
if v["Count"] > 1 then
exts[i] = exts[i] .. " <small>x</small>" .. v["Count"]
end
end
end
-- add 10 (or 12) to stats chosen...
for statName, statValue in pairs(stats) do
stats[statName] = stats[statName] + baseStat
end
--[[Add stat bonuses from subtype and mutations/cybernetics.
disabled as cryptogull/data already sums these up
local bonusInt= data.getTotalStatBonuses(subtype, exts)
for name, num in pairs(bonusInt) do
if num > 0 then
bonus[name] = "+" .. num
elseif num < 0 then
bonus[name] = "-" .. num
end
end]]
local skills = data.getSkills(subtype)
local extra = data.getExtra(subtype)
--return p.MakeUpSheet(code, genotype, subtype, classCalled, extCalled,
-- stats, bonus, exts, skills, extra, title, author, frame)
return decoded
end
function p.MakeUpSheet(codeIn, genoIn, subtype, classcalledIn, extnameIn,
attributes, bonus, exts, skills, extra, title, author, frame)
return frame:expandTemplate {
title = 'CryptoResultTest',
args = {
code = codeIn,
genotype = genoIn,
classcalled = classcalledIn,
class = subtype,
strength = tostring(attributes["Strength"]) .. bonus["Strength"],
agility = tostring(attributes["Agility"]) .. bonus["Agility"],
toughness = attributes["Toughness"] .. bonus["Toughness"],
intelligence = attributes["Intelligence"] .. bonus["Intelligence"],
willpower = attributes["Willpower"] .. bonus["Willpower"],
ego = attributes["Ego"] .. bonus["Ego"],
extname = extnameIn,
skills= skills,
exts = utilTable.concat(exts, "</br>"),
extra=extra,
buildname=title,
author=author
}
}
end
function p.test()
str = "H4sIAAAAAAAAA81WXW/aMBR9r9T/YEV7DIgiNnWVeGDpNra1EmtoO2nqg5PcJV4d2/LHKob477MNhSSsg05qBBIKvud+HO49ufL8+AihIMcl/AKpCGfBGQr63V633xt0X58GoccTQ2hWcTixDr0VVvLMUFDW/N2dEZovH2toOhPggr5dXXSjAkucapDvXEbV/Woy9/0IjGvrdukDQjRSCsqEzjpRbANEiG6WtYcbZiGKDNVGwpCB0RLTEE1MQkn6BWZTfg9syAylS46eTIY1tjTW7KzplX4utXObZIvepojN+ejv0l4ajTVkaGxKzGpeW718xBbLH4vwv3sZm+RAW1ljtruTK3eXNE4LTrFsq4V+bja3OsAmNrjtbmMpbMZe1aKAQupzbF7a5WdePaCVgFdNjgpSgsTV3N4n4oZp63DSBG6wJNhDvSqyCPetOOb8XqEfXKIPALrFwtMH3hkDziBrs6gkgkLnJydMt1r4nFudQqc0KqWtFr5mSmNbGrmdWcKTlfv7Vt4c7lraFCOtJUmMhkNcFU1yu3fFxIlPTYxMC6ysFs7q8wtGOaFEz6z9bW0mwfucW+ObuvGTFTKlJAeWOqqndTTWEliui+24KTd5wUCp7aBbQqngDyBd1Aapai7AIhbg1dEZDOrAFZSYMMLy5kpM7N8duUVZj3hB5URGaV6S37DGD1BBT5HcrSRmb5R+h2OWzVBMTV6DBbj5OJJVq1VK5kfbBITkzC6D+K9RLzmkgnMFscZSW9Fc8NTvrkMc1D+I7nHTasS5Yp+5EPh5Fy73uDs+WvwB4vrnYFQMAAA="
return p.a(str, "DijTItle", "Dij")
end
return p