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
Line 79: Line 79:
function p.MakeUpSheet(codeIn, genoIn, subtype, classcalledIn, extnameIn, attributes, bonus, exts, skills, extra, frame)
function p.MakeUpSheet(codeIn, genoIn, subtype, classcalledIn, extnameIn, attributes, bonus, exts, skills, extra, frame)
     return frame:expandTemplate {
     return frame:expandTemplate {
         title = 'Crypto result',
         title = 'CryptoResultTest',
         args = {
         args = {
             code = codeIn,
             code = codeIn,

Revision as of 18:35, 31 July 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
		if frame.args["code"]~= nil and frame.args["code"] ~= '' then
			return p.a(mw.text.trim(frame:preprocess(frame.args["code"])))
		else
    		error "There was no code in your input!"
		end
	end
	
end

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 classCalled = "Calling: "
	local extCalled = "Mutations: "
	local subtype = decoded["modules"][2]["data"]["Subtype"]
	local baseStat = 10
	local stats = nil
	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: "
		stats = decoded["modules"][3]["data"]["PointsPurchased"]
		-- No cybernetics means extra toughness
		if #decoded["modules"][4]["data"]["selections"] == 1 then
			exts[1] = "No Cybernetic"
		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
	-- add 10 to stats chosen...
	for statName, statValue in pairs(stats) do
		stats[statName] = stats[statName] + baseStat
	end

	-- Add stat bonuses from subtype and mutations/cybernetics...
	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, class_called, ext_called, stats, bonus, exts, skills, extra, frame)
end

function p.MakeUpSheet(codeIn, genoIn, subtype, classcalledIn, extnameIn, attributes, bonus, exts, skills, extra, 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, ", "),
            extra=extra
        }
    }
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