Difference between revisions of "Module:Glolfer"

From Glolf Wiki
Jump to navigation Jump to search
(Created page with "local pyrandom = require "Module:Pyrandom" function titlecase(str) local buf = {} local inWord = false for i = 1, #str do local c = string.sub(str, i, i) if inWord the...")
 
Line 195: Line 195:
 
end
 
end
  
return frame:expandTemplate{ title = "Glolfer", args = template_args}
+
return frame:expandTemplate{ title = "GlolferInfo", args = template_args}
 
end
 
end
  
 
return glolfer
 
return glolfer

Revision as of 22:49, 3 June 2021

Documentation for this module may be created at Module:Glolfer/doc

local pyrandom = require "Module:Pyrandom"

function titlecase(str)
	local buf = {}
	local inWord = false
	for i = 1, #str do
		local c = string.sub(str, i, i)
		if inWord then
			table.insert(buf, string.lower(c))
			if string.find(c, '%s') then
				inWord = false
			end
		else
			table.insert(buf, string.upper(c))
			inWord = true
		end
	end
	return table.concat(buf)
end

function random_player_emoji(name)
	local humanoid = {
		"👶","👧","🧒","👦","👩","🧑","👨","👩‍🦱","🧑‍🦱","👨‍🦱","👩‍🦰","🧑‍🦰","👨‍🦰","👱‍♀️",
		"👱","👱‍♂️","👩‍🦳","🧑‍🦳","👨‍🦳","👩‍🦲","🧑‍🦲","👨‍🦲","🧔","👵","🧓","👴","👲","👳‍♀️",
		"👳","👳‍♂️","🧕","👮‍♀️","👮","👮‍♂️","👷‍♀️","👷","👷‍♂️","💂‍♀️","💂","💂‍♂️","🕵️‍♀️","🕵️",
		"🕵️‍♂️","👩‍⚕️","🧑‍⚕️","👨‍⚕️","👩‍🌾","🧑‍🌾","👨‍🌾","👩‍🍳","🧑‍🍳","👨‍🍳","👩‍🎓","🧑‍🎓","👨‍🎓","👩‍🎤",
		"🧑‍🎤","👨‍🎤","👩‍🏫","🧑‍🏫","👨‍🏫","👩‍🏭","🧑‍🏭","👨‍🏭","👩‍💻","🧑‍💻","👨‍💻","👩‍💼","🧑‍💼","👨‍💼",
		"👩‍🔧","🧑‍🔧","👨‍🔧","👩‍🔬","🧑‍🔬","👨‍🔬","👩‍🎨","🧑‍🎨","👨‍🎨","👩‍🚒","🧑‍🚒","👨‍🚒","👩‍✈️","🧑‍✈️",
		"👨‍✈️","👩‍🚀","🧑‍🚀","👨‍🚀","👩‍⚖️","🧑‍⚖️","👨‍⚖️","👰","🏋️","🤵","🤸","👸","🤴","🦸‍♀️","🦸",
		"🦸‍♂️","🦹‍♀️","🦹","🦹‍♂️","🤶","🚴","🎅","🧙‍♀️","🧙","🧙‍♂️","🧝‍♀️","🧝","🧝‍♂️","🧛‍♀️","🧛",
		"🧛‍♂️","🧟‍♀️","🧟","🧟‍♂️","🧞‍♀️","🧞","🧞‍♂️","🧜‍♀️","🧜","🧜‍♂️","🧚‍♀️","🧚","🧚‍♂️","👼","🤰",
		"🤱","🙇‍♀️","🙇","🙇‍♂️","💁‍♀️","💁","💁‍♂️","🙅‍♀️","🙅","🙅‍♂️","🙆‍♀️","🙆","🙆‍♂️","🙋‍♀️","🙋",
		"🙋‍♂️","🧏‍♀️","🧏","🧏‍♂️","🤦‍♀️","🤦","🤦‍♂️","🤷‍♀️","🤷","🤷‍♂️","🙎‍♀️","🙎","🙎‍♂️","🙍‍♀️","🙍",
		"🙍‍♂️","💇‍♀️","💇","💇‍♂️","💆‍♀️","💆","💆‍♂️","🧖‍♀️","🧖","🧖‍♂️","💅","🤳","💃","🕺","🕴","👩‍🦽",
		"🧑‍🦽","👨‍🦽","👩‍🦼","🧑‍🦼","👨‍🦼","🚶‍♀️","🚶","🚶‍♂️","👩‍🦯","🧑‍🦯","👨‍🦯","🧎‍♀️","🧎","🧎‍♂️","🏃‍♀️","🏃",
		"🏃‍♂️","🧍‍♀️","🧍","🧍‍♂️","👭","🧑‍🤝‍🧑","👬","👫","👩‍❤️‍👩","💑","👨‍❤️‍👨","👩‍❤️‍👨","👩‍❤️‍💋‍👩","💏","👨‍❤️‍💋‍👨","👩‍❤️‍💋‍👨",
		"👪","👨‍👩‍👦","👨‍👩‍👧","👨‍👩‍👧‍👦","👨‍👩‍👦‍👦","👨‍👩‍👧‍👧","👨‍👨‍👦","👨‍👨‍👧","👨‍👨‍👧‍👦","👨‍👨‍👦‍👦","👨‍👨‍👧‍👧","👩‍👩‍👦","👩‍👩‍👧","👩‍👩‍👧‍👦","👩‍👩‍👦‍👦","👩‍👩‍👧‍👧",
		"👨‍👦","👨‍👦‍👦","👨‍👧","👨‍👧‍👦","👨‍👧‍👧","👩‍👦","👩‍👦‍👦","👩‍👧","👩‍👧‍👦","👩‍👧‍👧","🗣","👤","👥"
	}

	local nonhumanoid={
		"🐶","🐱","🐭","🐹","🐰","🦊","🐻","🐼","🐨","🐯","🦁","🐮","🐷","🐽","🐸","🐵",
		"🙈","🙉","🙊","🐒","🐔","🐧","🐦","🐤","🐣","🐥","🦆","🦅","🦉","🦇","🐺","🐗","🐴","🦄",
		"🐝","🐛","🦋","🐌","🐞","🐜","🦟","🦗","🕷️","🦂","🐢","🐍","🦎","🦖","🦕","🐙","🦑","🦐",
		"🦞","🦀","🐡","🐠","🐟","🐬","🐳","🐋","🦈","🐊","🐅","🐆","🦓","🦍","🦧","🐘","🦛","🦏",
		"🐪","🐫","🦒","🦘","🐃","🐂","🐄","🐎","🐖","🐏","🐑","🦙","🐐","🦌","🐕","🐩","🦮","🐕‍🦺",
		"🐈","🐓","🦃","🦚","🦜","🦢","🦩","🕊️","🐇","🦝","🦨","🦡","🦦","🦥","🐁","🐀","🐿","🦔",
		"🐉","🐲","🪐","💫","🌪","🌈","📠","📺"
	}

	local rand = pyrandom.new(titlecase(name))
	if rand:random() > 0.5 then
		return rand:choice(humanoid)
	else
		return rand:choice(nonhumanoid)
	end
end

function generate_random_stlats_from_name(name)
	local rand = pyrandom.new(titlecase(name))
	return {
		nyoomability = math.max(rand:gauss(0,0.3),1.4),
		tofu = rand:random(),
		wiggle = rand:random(),
		ritualism = rand:random(),
		musclitude = rand:random(),
		finesse = rand:random(),
		needlethreadableness = rand:random(), 
		left_handedness = rand:gauss(0,0.3),
		stance = rand:choice({"Tricky","Flashy","Aggro","Tanky","Twitchy","Powerful",
		"Wibble","Wobble","Reverse","Feint","Electric","Spicy","Pomegranate",
		"Explosive","Cottagecore","Corecore","Hardcore","Softcore",
		"Hand to Hand","Lefty","Pop-Punk","DPS","Repose"}),
		fav_tea = rand:choice({"Iced","Boba","White","Green","Oolong",
		"Pu'erh","Chai","Milk","Neon","Sweet","Void","Tea?","Caramel",
		"Lightspeed","Time-traveling","Bloody","Black","Miso","Concrete",
		"Hard-boiled egg","Hot Chocolate","Bubble"}),
		estimation = rand:random(),

		earliness = rand:random(),
		twirliness = rand:random(),
		churliness = rand:random(),
		aceness = rand:random(),
		marbles = rand:randrange(2,4),

		unworthiness = rand:random(),
		splortsmanship = rand:random(),
		tankitude = rand:random(),
		pettiness = rand:random(),
		owlishness = rand:random(),
		disco = rand:random(),
		pettability = rand:random(),
		softness = rand:random(),
		improv = rand:random(),
		tentacles = rand:randrange(0,10),
		capitalism = -rand:random(),
		polkadottedness = 0,
	}
end

function generate_random_player_from_name(name)
	local player = generate_random_stlats_from_name(name)
	player.name = name
	player.emoji = random_player_emoji(name)
	return player
end

function search_array(a, v)
	for i = 1, #a do
		if a[i] == v then
			return true
		end
	end
	return false
end

function sum(a)
	local r = 0
	for i = 1, #a do
		r = r + a[i]
	end
	return r
end

function unpredictability(p)
	local weights = {p.churliness,p.earliness,p.twirliness}
	if search_array({"Aggro","Powerful","Hand to Hand","DPS","Explosive","Hardcore", "Wibble","Electric"}, p.stance) then
		weights[1] = weights[1] + 0.5
	elseif search_array({"Tanky","Twitchy","Repose","Reverse","Softcore",  "Cottagecore","Pomegranate"}, p.stance) then
		weights[2] = weights[2] + 0.5
	elseif search_array("Feint","Tricky","Pop-Punk","Flashy","Spicy",       "Corecore","Wobble","Lefty", p.stance) then
		weights[3] = weights[3] + 0.5
	end

	local chanceOfBiggest = math.max(unpack(weights))/sum(weights)

	local minChance = 1/#weights

	return 1-(chanceOfBiggest-minChance)/(1-minChance)
end

function driving_rating(p)
	return (p.musclitude + p.tofu)*5/2
end

function precision_rating(p)
	return (p.needlethreadableness*0.5 + p.finesse + p.estimation*0.2) * 5/(1+0.2+0.5) - math.abs(p.left_handedness)
end

function aerodynamics_rating(p)
	return (p.ritualism + p.owlishness + p.softness) * 5/3
end

function self_awareness_rating(p)
	return (p.wiggle*0.5 + (p.marbles-2)/2 + unpredictability(p)*0.8) * 5/(0.5+1+0.8) + p.polkadottedness * 5
end

local glolfer = {}

function glolfer.emoji(frame)
	local args
	if frame.args.name then
		args = frame.args
	else
		args = frame:getParent().args
	end
	local name = args.name
	return random_player_emoji(name)
end

function glolfer.infobox(frame)
	local args
	if frame.args.name then
		args = frame.args
	else
		args = frame:getParent().args
	end
	local name = args.name
	local p = generate_random_player_from_name(name)
	local template_args = {}
	for k, v in pairs(args) do
		template_args[k] = v
	end
	for k, v in pairs({
		name = p.name,
		signature = p.emoji,
		stance = p.stance,
		tea = p.fav_tea,
		driving = driving_rating(p),
		grip = precision_rating(p),
		aerodynamics = aerodynamics_rating(p),
		["self-awareness"] = self_awareness_rating(p),
	}) do
		template_args[k] = v
	end

	return frame:expandTemplate{ title = "GlolferInfo", args = template_args}
end

return glolfer