Module:Rank

From Pandorabox
Revision as of 18:25, 8 April 2024 by Birdlover32767 (talk | contribs) (debugz)
Jump to navigation Jump to search

This is a module to make getting ranks out of XP values easier.

toRank

You can do
{{#invoke:Rank|toRank|<xp value>|[<options>]}}
to generate a rank. The options are not required, but they allow some customization.

Example: 0100200300500700100020002200240026003000340040005000550060006500750085001000020000260003200038000500006200080000100000110000120000130000150000170000200000300000350000400000450000550000650000800000100000010800001160000124000014000001560000180000020000002200000240000026000003000000340000040000005000000530000056000005900000650000071000008000000900000093000009600000990000010500000111000001200000013000000134000001380000014200000150000001580000017000000180000001840000018800000192000002000000020800000220000002300000023500000240000002450000025500000265000002800000029000000296000003020000030800000320000003320000035000000 -> rank with 1234 xp

Options

The options are a string of 1 to 3 width, consisting entirely out of "y" (denoting yes) and "n" (denoting no) characters. The first character controls whether the icon appears, the second controls whether the major rank appears, and the last character controls whether the minor rank appears. For any ommited or invalid characters, the default of "yyy" is used.


Example: 0100200300500700100020002200240026003000340040005000550060006500750085001000020000260003200038000500006200080000100000110000120000130000150000170000200000300000350000400000450000550000650000800000100000010800001160000124000014000001560000180000020000002200000240000026000003000000340000040000005000000530000056000005900000650000071000008000000900000093000009600000990000010500000111000001200000013000000134000001380000014200000150000001580000017000000180000001840000018800000192000002000000020800000220000002300000023500000240000002450000025500000265000002800000029000000296000003020000030800000320000003320000035000000 -> rank with 314159 xp, and no icon (options are n, but effectively is nyy)

Example: 0100200300500700100020002200240026003000340040005000550060006500750085001000020000260003200038000500006200080000100000110000120000130000150000170000200000300000350000400000450000550000650000800000100000010800001160000124000014000001560000180000020000002200000240000026000003000000340000040000005000000530000056000005900000650000071000008000000900000093000009600000990000010500000111000001200000013000000134000001380000014200000150000001580000017000000180000001840000018800000192000002000000020800000220000002300000023500000240000002450000025500000265000002800000029000000296000003020000030800000320000003320000035000000 -> rank with 123456 xp, but only icon (options are ynn)

Example: 0100200300500700100020002200240026003000340040005000550060006500750085001000020000260003200038000500006200080000100000110000120000130000150000170000200000300000350000400000450000550000650000800000100000010800001160000124000014000001560000180000020000002200000240000026000003000000340000040000005000000530000056000005900000650000071000008000000900000093000009600000990000010500000111000001200000013000000134000001380000014200000150000001580000017000000180000001840000018800000192000002000000020800000220000002300000023500000240000002450000025500000265000002800000029000000296000003020000030800000320000003320000035000000 -> rank with 44444 xp, but no major rank (options are yn, but effectively is yny)

toMajorRank

You can do
{{#invoke:Rank|toMajorRank|<xp value>}}
to generate a rank without a minor rank. This is only used as an alias to
{{#invoke:Rank|toRank|<xp value>|yyn}}

Example: Script error: The function "toMajorRank" does not exist. -> rank with 17363925 xp, icon and major only


-- bird's number -> rank converter
-- use this wherever you want, i guess?


--- THIS IS DIRECTLY COPIED FROM xp_redo_ranks_ores/ranks.lua
local prefixes = {
	{
		name="Cobble",
		icon="[[File:Xp_cobble.png]]",
		base_xp=0,
		xp_modifier=100
	}, -- 0 - 1k
	{
		name="Stone",
		icon="[[File:Xp_stone_block.png]]",
		base_xp=2000,
		xp_modifier=200
	}, -- 2k - 4k
	{
		name="Coal",
		icon="[[File:Xp_coal_block.png]]",
		base_xp=5000,
		xp_modifier=500
	}, -- 5k - 10k
	{
		name="Iron",
		icon="[[File:Xp_iron_block.png]]",
		base_xp=20*1000,
		xp_modifier=6000
	}, -- 20k - 80k
	{
		name="Copper",
		icon="[[File:Xp_copper_block.png]]",
		base_xp=100*1000,
		xp_modifier=10*1000
	}, -- 100k - 200k
	{
		name="Gold",
		icon="[[File:Xp_gold_block.png]]",
		base_xp=300*1000,
		xp_modifier=50*1000
	}, -- 300k - 800k
	{
		name="Diamond",
		icon="[[File:Xp_diamond_block.png]]",
		base_xp=1*1000*1000,
		xp_modifier=80*1000
	}, -- 1M - 1.8M
	{
		name="Mese",
		icon="[[File:Xp_mese_block.png]]",
		base_xp=2*1000*1000,
		xp_modifier=200*1000
	}, -- 2M - 4M
	{
		name="Lava",
		icon="[[File:Xp_lava.png]]",
		base_xp=5*1000*1000,
		xp_modifier=300*1000
	}, -- 5M - 8M
	{
		name="Sulfur",
		icon="[[File:Xp_sulfur.png]]",
		base_xp=9*1000*1000,
		xp_modifier=300*1000
	}, -- 9M - 12M
		{
		name="Uranium",
		icon="[[File:Xp_uranium.png]]",
		base_xp=13*1000*1000,
		xp_modifier=400*1000
	}, -- 13M - 17M
	{
		name="Chernobylite",
		icon="[[File:Xp_chernobylite.png]]",
		base_xp=18*1000*1000,
		xp_modifier=400*1000
	}, -- 18M - 22M
	{
		name="Corium",
		icon="[[File:Xp_corium.png]]",
		base_xp=23*1000*1000,
		xp_modifier=500*1000
	}, -- 23M - 28M
	{
		name="Mithril",
		icon="[[File:Xp_mithril.png]]",
		base_xp=29*1000*1000,
		xp_modifier=600*1000
	}, -- 29M - 35M
}

local suffixes = {
	-- 7 suffixes
	{name="Peasant", xp_modifier=0},
	{name="Merchant", xp_modifier=1},
	{name="Knight", xp_modifier=2},
	{name="Lord", xp_modifier=3},
	{name="Mayor", xp_modifier=5},
	{name="Master", xp_modifier=7},
	{name="God", xp_modifier=10}
}

local rnumbers = {}
local rnames = {}
-- #suffixes x #prefixes
for i,prefix in pairs(prefixes) do
	for j,suffix in pairs(suffixes) do
		table.insert(rnumbers,prefix.base_xp + (prefix.xp_modifier * suffix.xp_modifier))
		table.insert(rnames, {i,j})

	end
end

local module = {}
function module.toRank(frame)
	xp = (frame or {})[1] or 0 -- edge case hell
	local r = #rnames
	for i,rxp in pairs(rnumbers) do
		if xp >= (rxp or 0) and xp <= (rnumbers[i+1] or math.huge) then
			r = i
			break
		end
	end
	
	local x = rnames[r]
	return table.concat(rnumbers) --prefixes[x[1]].icon.." "..prefixes[x[1]].name.." "..suffixes[x[2]].name
end

return module