Module:Sandbox/User:Teamtoto/LuaModule: Difference between revisions

From Caves of Qud Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
 
(24 intermediate revisions by the same user not shown)
Line 1: Line 1:
local zlib = mw.ext.zlib
local zlib = mw.ext.zlib
local utilTable = require('Module:Table Utility')
local data = require('Module:CryptogullJr/Data')
local p = {}


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)
function p.a(code, title, author)
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"]
local class_called = "Calling: "
local classCalled = "Calling"
local ext_called = "Mutations: "
local extCalled = "Mutations"
local subtype = decoded["modules"][2]["data"]["Subtype"]
local subtype = decoded["modules"][2]["data"]["Subtype"]
local base_stat = 10
local baseStat = 10
local stats = nil
local stats = {
["Strength"] = 0,
["Intelligence"] = 0,
["Toughness"] = 0,
["Willpower"] = 0,
["Ego"] = 0,
["Agility"] = 0}
local bonusInt = {}
local exts = {}
local exts = {}
local bonus = {
["Strength"] = "",
["Intelligence"] = "",
["Toughness"] = "",
["Willpower"] = "",
["Ego"] = "",
["Agility"] = ""
}
if genotype == "True Kin" then
if genotype == "True Kin" then
-- if true kin, stats are [3] and cybernetics are [4]
-- if true kin, stats are [3] and cybernetics are [4]
class_called= "Caste: "
classCalled= "Caste"
ext_called = "Cybernetics: "
extCalled = "Cybernetics"
stats = decoded["modules"][3]["data"]["PointsPurchased"]
statPos = 3
-- No cybernetics means extra toughness
extPos = 4
if #decoded["modules"][4]["data"]["selections"] > 1 then
extNoun = 'Cybernetic'
stats["Toughness"] = stats["Toughness"] + 2
baseStat = 12
else
exts[1] = decoded["modules"][4]["data"]["selections"]["Cybernetic"]
end
else
else
-- if mutant, stats are [4] and mutations are [3] :crungled:
-- if mutant, stats are [4] and mutations are [3] :crungled:
for i=1, #decoded["modules"][3]["data"]["selections"] do
statPos=4
exts[i] = decoded["modules"][3]["data"]["selections"][i]["Mutation"]
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"][extPos]["data"]["selections"]) do
exts[i] = v[extNoun]
if v["variantName"] ~= "" and v["variantName"] ~= nil then
exts[i] = exts[i] .. " (" .. v["variantName"] .. ")"
end
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
stats = decoded["modules"][4]["data"]["PointsPurchased"]
end
end
for stat_name, stat_value in ipairs(stats) do  
stats[stat_name] = stat_value + base_stat
-- add 10 (or 12) to stats chosen...
for statName, statValue in pairs(stats) do
stats[statName] = stats[statName] + baseStat
end
end
local bonus = {
 
["Strength"] = "",
--[[Add stat bonuses from subtype and mutations/cybernetics.
["Intelligence"] = "",
disabled as cryptogull/data already sums these up
["Toughness"] = "",
["Willpower"] = "",
local bonusInt= data.getTotalStatBonuses(subtype, exts)
["Ego"] = "",
for name, num in pairs(bonusInt) do
["Agility"] = ""
if num > 0 then
}
bonus[name] = "+" .. num
return p.MakeUpSheet("", genotype, subtype, class_called, ext_called, stats, bonus, exts, frame)
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)
end
end


function p.MakeUpSheet(codeIn, genoIn, subtype, classcalledIn, extnameIn, attributes, bonus, extsIn, frame)
function p.MakeUpSheet(codeIn, genoIn, subtype, classcalledIn, extnameIn,
    local mutstring = ""
attributes, bonus, exts, skills, extra, title, author, frame)
    for _, ext in ipairs(extsIn) do
        mutstring = mutstring .. ", " .. ext[1]
    end
 
     return frame:expandTemplate {
     return frame:expandTemplate {
         title = 'Crypto result',
         title = 'CryptoResultTest',
         args = {
         args = {
             code = "",
             code = codeIn,
             genotype = genoIn,
             genotype = genoIn,
             classcalled = classcalledIn,
             classcalled = classcalledIn,
Line 68: Line 122:
             ego = attributes["Ego"] .. bonus["Ego"],
             ego = attributes["Ego"] .. bonus["Ego"],
             extname = extnameIn,
             extname = extnameIn,
             exts = exts
            skills= skills,
             exts = utilTable.concat(exts, "</br>"),
            extra=extra,
            buildname=title,
            author=author
         }
         }
     }
     }
Line 74: Line 132:


function p.test()
function p.test()
str = "H4sIAAAAAAAACs1UXUvDMBR9F/wPYfhYy6aCH7CHOUXUCXMbKogPaXtpg1lSkhuljP53k3WzX+BUUDYYXe85995zT+6y2N0hpBPTObyB0kyKzhnpHPhd/6B75J8ed7wlHhjGowqhZwndFTaXkeGgbfjZvROyKB6f0CxLwSU9TUb+MKGKhgjq3FXU/r2J3PcKhERLu1smeGSgNcwDnu0PpzYh9chD0btfKvPI0HA0CvoCDCrKPTI2AWfhLWQz+QqiLwznhcalmIgitTI+1dnQHv5U2oUt0pJXNrE113xXdqYMkFsmaoSWjWssL37k3q9tnJpgS12sKdts4oruio4VBZSK0X9zcYCoWGAQ9BYa2RS32cuxZAL12KgwoRqiek/nNSoQMSYW6Ho1ZBAzzjBrAzNp4kSA1m3oWiBwzmIQIbTRR8Z5Kt9BtaHLWLpgGcurQ9B0moLARpoNT2BOmWAittDhSRUL7LSDtBX+w8UZZgEoAcjCbdyclrrNq8Odffu9akgDhxDtBJULv/jUtsoyy36W6UbwmgRplifaawIP1P3dcZVWBfPy5eW/DjWRUsMUqUK7ZSMZUjf9Np7vF0K/ceM28lyzG5mm9Ge3rnu87O7kH3N16ShXCAAA"
str = "H4sIAAAAAAAACs1VW2vbMBR+L/Q/CLNH16RZNtZCHtJs7NaOLE67weiDbB9sUVky0lFHGvLfJ9lp4kuztIOFBIKj853Ll3O+Iy+OjwjxUprDPSjNpPDOidcPekG/NwjO3nl+iUeG8aTmcGodeissl4nhoK35lzsTsqgea2g2L8AF/ZxeBuOMKhojqAuXUQffTeK+H0FItG5XZYBPRlpDHvH5yTi0AYVPbqraww0zn4wNR6NgKMCgotwnExNxFn+F+UzegRgKw3nFsSSTUKSWxpqdNb3Cl1J7b5N06G2K2JyP/i7tlUGKkJBPJqei4dXp5SO2rH4s/X/uZWiiA21lg9nuTq7cXdIwziSnal8tLOdmc+sDbGKL2+425oXN+KZu0cAhLnNslrb6LOoHshLwqsnXQiONOBCn8BzqNUrfsTQCrWO/DdxQxWgJ9drQfQV9s9ePK+HV4aX/XGYXQO+20jndTqfDtEVnKjUqkzdZbQ63e1LjCFGxyCAcohzb5HbrcSKZQD0xKs6ohqRZ0609KhApZhZ42xiQN0oZZzi3wOsmMJMmzQRo3dGY91kgcM5SEDF00R+M80L+BtWFPqTSGTe2uh49WoQFlCI6OWvap5BTJphIHc3G2kX2747cMg4Ge1LO2GiUOXuANX6ACtpGcreSRLWnjkbdXAA+YbUKSMo5d9yVFPauCJ+M+p/DyaTUECJVaNVyKePyPjvEAf2F6DPe4q04V+yLLAr6spe5e9weHy3/ADv8xUOwCgAA"
return p.a(str)
return p.a(str, "DijTItle", "Dij")
end
end
return p
return p

Latest revision as of 21:36, 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"][extPos]["data"]["selections"]) do
			exts[i] = v[extNoun]
			if v["variantName"] ~= "" and v["variantName"] ~= nil then
				exts[i] = exts[i] .. " (" .. v["variantName"] .. ")"
			end
			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)
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 = "H4sIAAAAAAAACs1VW2vbMBR+L/Q/CLNH16RZNtZCHtJs7NaOLE67weiDbB9sUVky0lFHGvLfJ9lp4kuztIOFBIKj853Ll3O+Iy+OjwjxUprDPSjNpPDOidcPekG/NwjO3nl+iUeG8aTmcGodeissl4nhoK35lzsTsqgea2g2L8AF/ZxeBuOMKhojqAuXUQffTeK+H0FItG5XZYBPRlpDHvH5yTi0AYVPbqraww0zn4wNR6NgKMCgotwnExNxFn+F+UzegRgKw3nFsSSTUKSWxpqdNb3Cl1J7b5N06G2K2JyP/i7tlUGKkJBPJqei4dXp5SO2rH4s/X/uZWiiA21lg9nuTq7cXdIwziSnal8tLOdmc+sDbGKL2+425oXN+KZu0cAhLnNslrb6LOoHshLwqsnXQiONOBCn8BzqNUrfsTQCrWO/DdxQxWgJ9drQfQV9s9ePK+HV4aX/XGYXQO+20jndTqfDtEVnKjUqkzdZbQ63e1LjCFGxyCAcohzb5HbrcSKZQD0xKs6ohqRZ0609KhApZhZ42xiQN0oZZzi3wOsmMJMmzQRo3dGY91kgcM5SEDF00R+M80L+BtWFPqTSGTe2uh49WoQFlCI6OWvap5BTJphIHc3G2kX2747cMg4Ge1LO2GiUOXuANX6ACtpGcreSRLWnjkbdXAA+YbUKSMo5d9yVFPauCJ+M+p/DyaTUECJVaNVyKePyPjvEAf2F6DPe4q04V+yLLAr6spe5e9weHy3/ADv8xUOwCgAA"
	return p.a(str, "DijTItle", "Dij")
end

return p