Module:Sandbox/User:Teamtoto/LuaModule: Difference between revisions
Jump to navigation
Jump to search
(Created page with "local zlib = mw.ext.zlib local p = {} function p.a(code) local decoded = mw.text.jsonDecode(zlib.gzdecode(zlib.base64_decode(code))) local version = decoded["gameversion"] local genotype = decoded["modules"][1]["data"]["Genotype"] local class = decoded["modules"][2]["data"]["Subtype"] local base_stat = 10 local exts = {} for i=1, #decoded["modules"][3]["data"]["selections"] do exts[i] = decoded["modules"][3]["data"]["selections"][i]["Mutation"] end local stats = dec...") |
mNo edit summary |
||
Line 4: | Line 4: | ||
function p.a(code) | function p.a(code) | ||
local decoded = mw.text.jsonDecode(zlib.gzdecode(zlib.base64_decode(code))) | local frame = mw.getCurrentFrame() | ||
local version = decoded["gameversion"] | local decoded = mw.text.jsonDecode(zlib.gzdecode(zlib.base64_decode(code))) | ||
local genotype = decoded["modules"][1]["data"]["Genotype"] | local version = decoded["gameversion"] | ||
local | local genotype = decoded["modules"][1]["data"]["Genotype"] | ||
local base_stat = 10 | local class_called = "Calling: " | ||
local ext_called = "Mutations: " | |||
local subtype = decoded["modules"][2]["data"]["Subtype"] | |||
local base_stat = 10 | |||
local stats = nil | |||
local exts = {} | |||
if genotype == "True Kin" then | |||
-- if true kin, stats are [3] and cybernetics are [4] | |||
class_called= "Caste: " | |||
ext_called = "Cybernetics: " | |||
stats = decoded["modules"][4]["data"]["PointsPurchased"] | |||
-- No cybernetics means extra toughness | |||
if #decoded["modules"][4]["data"]["selections"] > 1 then | |||
stats["Toughness"] = stats["Toughness"] + 2 | |||
else | |||
exts[1] = decoded["modules"][4]["data"]["selections"]["Cybernetic"] | |||
end | |||
else | |||
-- if mutant, stats are [4] and mutations are [3] :crungled: | |||
for i=1, #decoded["modules"][3]["data"]["selections"] do | |||
exts[i] = decoded["modules"][3]["data"]["selections"][i]["Mutation"] | |||
end | |||
stats = decoded["modules"][4]["data"]["PointsPurchased"] | |||
local | end | ||
for stat_name, stat_value in ipairs(stats) do | |||
stats[stat_name] = stat_value + base_stat | |||
end | |||
local bonus = { | |||
["Strength"] = "", | |||
["Intelligence"] = "", | |||
["Toughness"] = "", | |||
["Willpower"] = "", | |||
["Ego"] = "", | |||
["Agility"] = "" | |||
} | |||
return p.MakeUpSheet("", genotype, subtype, class_called, ext_called, attributes, bonus, exts, frame) | |||
end | end | ||
local | 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["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, | |||
exts = exts | |||
} | |||
} | |||
end | end | ||
function p.test() | function p.test() | ||
str = "H4sIAAAAAAAACs1UXUvDMBR9F/wPYfhYy6aCH7CHOUXUCXMbKogPaXtpg1lSkhuljP53k3WzX+BUUDYYXe85995zT+6y2N0hpBPTObyB0kyKzhnpHPhd/6B75J8ed7wlHhjGowqhZwndFTaXkeGgbfjZvROyKB6f0CxLwSU9TUb+MKGKhgjq3FXU/r2J3PcKhERLu1smeGSgNcwDnu0PpzYh9chD0btfKvPI0HA0CvoCDCrKPTI2AWfhLWQz+QqiLwznhcalmIgitTI+1dnQHv5U2oUt0pJXNrE113xXdqYMkFsmaoSWjWssL37k3q9tnJpgS12sKdts4oruio4VBZSK0X9zcYCoWGAQ9BYa2RS32cuxZAL12KgwoRqiek/nNSoQMSYW6Ho1ZBAzzjBrAzNp4kSA1m3oWiBwzmIQIbTRR8Z5Kt9BtaHLWLpgGcurQ9B0moLARpoNT2BOmWAittDhSRUL7LSDtBX+w8UZZgEoAcjCbdyclrrNq8Odffu9akgDhxDtBJULv/jUtsoyy36W6UbwmgRplifaawIP1P3dcZVWBfPy5eW/DjWRUsMUqUK7ZSMZUjf9Np7vF0K/ceM28lyzG5mm9Ge3rnu87O7kH3N16ShXCAAA" | |||
return p.a(str) | |||
end | end | ||
return p | return p |
Revision as of 22:44, 30 July 2023
Documentation for this module may be created at Module:Sandbox/User:Teamtoto/LuaModule/doc
local zlib = mw.ext.zlib
local p = {}
function p.a(code)
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 class_called = "Calling: "
local ext_called = "Mutations: "
local subtype = decoded["modules"][2]["data"]["Subtype"]
local base_stat = 10
local stats = nil
local exts = {}
if genotype == "True Kin" then
-- if true kin, stats are [3] and cybernetics are [4]
class_called= "Caste: "
ext_called = "Cybernetics: "
stats = decoded["modules"][4]["data"]["PointsPurchased"]
-- No cybernetics means extra toughness
if #decoded["modules"][4]["data"]["selections"] > 1 then
stats["Toughness"] = stats["Toughness"] + 2
else
exts[1] = decoded["modules"][4]["data"]["selections"]["Cybernetic"]
end
else
-- if mutant, stats are [4] and mutations are [3] :crungled:
for i=1, #decoded["modules"][3]["data"]["selections"] do
exts[i] = decoded["modules"][3]["data"]["selections"][i]["Mutation"]
end
stats = decoded["modules"][4]["data"]["PointsPurchased"]
end
for stat_name, stat_value in ipairs(stats) do
stats[stat_name] = stat_value + base_stat
end
local bonus = {
["Strength"] = "",
["Intelligence"] = "",
["Toughness"] = "",
["Willpower"] = "",
["Ego"] = "",
["Agility"] = ""
}
return p.MakeUpSheet("", genotype, subtype, class_called, ext_called, attributes, bonus, exts, frame)
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["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,
exts = exts
}
}
end
function p.test()
str = "H4sIAAAAAAAACs1UXUvDMBR9F/wPYfhYy6aCH7CHOUXUCXMbKogPaXtpg1lSkhuljP53k3WzX+BUUDYYXe85995zT+6y2N0hpBPTObyB0kyKzhnpHPhd/6B75J8ed7wlHhjGowqhZwndFTaXkeGgbfjZvROyKB6f0CxLwSU9TUb+MKGKhgjq3FXU/r2J3PcKhERLu1smeGSgNcwDnu0PpzYh9chD0btfKvPI0HA0CvoCDCrKPTI2AWfhLWQz+QqiLwznhcalmIgitTI+1dnQHv5U2oUt0pJXNrE113xXdqYMkFsmaoSWjWssL37k3q9tnJpgS12sKdts4oruio4VBZSK0X9zcYCoWGAQ9BYa2RS32cuxZAL12KgwoRqiek/nNSoQMSYW6Ho1ZBAzzjBrAzNp4kSA1m3oWiBwzmIQIbTRR8Z5Kt9BtaHLWLpgGcurQ9B0moLARpoNT2BOmWAittDhSRUL7LSDtBX+w8UZZgEoAcjCbdyclrrNq8Odffu9akgDhxDtBJULv/jUtsoyy36W6UbwmgRplifaawIP1P3dcZVWBfPy5eW/DjWRUsMUqUK7ZSMZUjf9Np7vF0K/ceM28lyzG5mm9Ge3rnu87O7kH3N16ShXCAAA"
return p.a(str)
end
return p