Module:Glolfer

From Glolf Wiki
Jump to navigation Jump to search

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))
		else
			table.insert(buf, string.upper(c))
		end
		inWord = (string.find(c, '%a') ~= nil)
	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 known_players = {
	["Polkadot Patterson"] = {
		name="Polkadot Patterson",
		stance="Squiddish",
		fav_tea= "Iced",
		nyoomability = 1.5,
		musclitude=1,
		finesse=1,
		needlethreadableness=1,
		polkadottedness=1,  
		left_handedness= 0,
		estimation=1,
		twirliness=0.3,
		churliness=0.3,
		earliness=0.3,
		aceness=0.3,
		marbles=4,

		tofu=1,
		wiggle=1,
		ritualism=1,
		owlishness=1,
		disco=0.0,
		pettability=0.0,
		softness=1,
		improv=0.0,
		unworthiness=0,
		splortsmanship=1,
		tankitude=1.0,
		pettiness=0.0,
		tentacles=4,
		capitalism=-0.5,
		emoji="๐Ÿ˜…",
	},
}

function get_player_from_name(name)
	name = titlecase(name)
	return known_players[name] or generate_random_player_from_name(name)
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 = get_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 = 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