Module:CryptogullJr: Difference between revisions

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


Line 23: Line 24:
function p.decode(code, title, author)
function p.decode(code, title, author)
local frame = mw.getCurrentFrame()
local frame = mw.getCurrentFrame()
local decoded = mw.text.jsonDecode(zlib.gzdecode(zlib.base64_decode(code)))
local gzdecode = zlib.gzdecode(zlib.base64_decode(code))
if gzdecode == false or gzdecode == nil then -- error handling
error("This code isn't in base64. Please double check your input!")
end
local decoded = mw.text.jsonDecode(gzdecode)
local version = decoded["gameversion"]
local version = decoded["gameversion"]
Line 40: Line 45:
local bonusInt = {}
local bonusInt = {}
local exts = {}
local exts = {}
local bonus = {
local bonus = {
["Strength"] = "",
["Strength"] = "",
["Intelligence"] = "",
["Intelligence"] = "",
Line 63: Line 68:
extNoun='Mutation'
extNoun='Mutation'
end
end
stats = decoded["modules"][statPos]["data"]["PointsPurchased"]
stats = decoded["modules"][statPos]["data"]["PointsPurchased"]
-- No cybernetics means extra toughness
-- No cybernetics means extra toughness
if extPos == 4 and #decoded["modules"][4]["data"]["selections"] == 1 then
if extPos == 4 and #decoded["modules"][4]["data"]["selections"] == 0 then
exts[1] = "No Cybernetic"
exts[1] = "No Cybernetic"
else  
else  
for i, v in ipairs(decoded["modules"][extPos]["data"]["selections"]) do
for i, v in ipairs(decoded["modules"][extPos]["data"]["selections"]) do
exts[i] = v[extNoun]
if extPos == 4 then
exts[1] = getCyberneticName(v[extNoun])
else
exts[i] = v[extNoun]
end
if v["variantName"] ~= "" and v["variantName"] ~= nil then
if v["variantName"] ~= "" and v["variantName"] ~= nil then
exts[i] = exts[i] .. " (" .. v["variantName"] .. ")"
exts[i] = exts[i] .. " (" .. v["variantName"] .. ")"
Line 89: Line 96:
end
end


--[[Add stat bonuses from subtype and mutations/cybernetics.
--[Add stat bonuses from subtype and mutations/cybernetics.
disabled as cryptogull/data already sums these up
 
local bonusInt= data.getTotalStatBonuses(subtype, exts)
local bonusInt= data.getTotalStatBonuses(subtype, exts)
for name, num in pairs(bonusInt) do
for name, num in pairs(bonusInt) do
if num > 0 then
stats[name] = stats[name] + num
bonus[name] = "+" .. num
end
elseif num < 0 then
bonus[name] = "-" .. num
end
end]]
local skills = data.getSkills(subtype)
local skills = data.getSkills(subtype)
local extra = data.getExtra(subtype)
local extra = data.getExtra(subtype)
Line 115: Line 118:
             classcalled = classcalledIn,
             classcalled = classcalledIn,
             class = subtype,
             class = subtype,
             strength = tostring(attributes["Strength"]) .. bonus["Strength"],
             strength = tostring(attributes["Strength"]),
             agility = tostring(attributes["Agility"]) .. bonus["Agility"],
             agility = tostring(attributes["Agility"]),
             toughness = attributes["Toughness"] .. bonus["Toughness"],
             toughness = attributes["Toughness"],
             intelligence = attributes["Intelligence"] .. bonus["Intelligence"],
             intelligence = attributes["Intelligence"],
             willpower = attributes["Willpower"] .. bonus["Willpower"],
             willpower = attributes["Willpower"],
             ego = attributes["Ego"] .. bonus["Ego"],
             ego = attributes["Ego"],
             extname = extnameIn,
             extname = extnameIn,
             skills= skills,
             skills= skills,
Line 129: Line 132:
         }
         }
     }
     }
end
function getCyberneticName(id)
local result = cargo.query("Cybernetics", "CyberneticID, Name",
{where='CyberneticID ="'.. id..'"'})
if not next(result) then
error(id .."is not a valid cybernetic id.")
else
return result[1]["Name"]
end
end
end


return p
return p

Latest revision as of 14:58, 7 August 2023


local zlib = mw.ext.zlib
local utilTable = require('Module:Table Utility')
local data = require('Module:CryptogullJr/Data')
local cargo = mw.ext.cargo
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.decode(mw.text.trim(frame:preprocess(frame.args["code"])), title, author)
		else
    		error "There was no code in your input!"
		end
	end
	
end

function p.decode(code, title, author)
	local frame = mw.getCurrentFrame()
	local gzdecode = zlib.gzdecode(zlib.base64_decode(code))
	if gzdecode == false or gzdecode == nil then -- error handling
		error("This code isn't in base64. Please double check your input!")
	end
	local decoded = mw.text.jsonDecode(gzdecode)
	
	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"] == 0 then
			exts[1] = "No Cybernetic"
	else 
		for i, v in ipairs(decoded["modules"][extPos]["data"]["selections"]) do
			if extPos == 4 then
				exts[1] = getCyberneticName(v[extNoun])
			else
				exts[i] = v[extNoun]
			end
			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.

	local bonusInt= data.getTotalStatBonuses(subtype, exts)
	for name, num in pairs(bonusInt) do
		stats[name] = stats[name] + num
	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 = 'Crypto result',
        args = {
            code = codeIn,
            genotype = genoIn,
            classcalled = classcalledIn,
            class = subtype,
            strength = tostring(attributes["Strength"]),
            agility = tostring(attributes["Agility"]),
            toughness = attributes["Toughness"],
            intelligence = attributes["Intelligence"],
            willpower = attributes["Willpower"],
            ego = attributes["Ego"],
            extname = extnameIn,
            skills= skills,
            exts = utilTable.concat(exts, "</br>"),
            extra=extra,
            buildname=title,
            author=author
        }
    }
end

function getCyberneticName(id)
	local result = cargo.query("Cybernetics", "CyberneticID, Name",
									{where='CyberneticID ="'.. id..'"'})	
	if not next(result) then
		error(id .."is not a valid cybernetic id.")
	else 
		return result[1]["Name"]	
	end
end

return p