Difference between revisions of "Module:Rank"

From Pandorabox
Jump to navigation Jump to search
m (debugz)
m (debugz)
Line 115: Line 115:
 
local module = {}
 
local module = {}
 
function module.toRank(frame)
 
function module.toRank(frame)
xp = (frame or {})[1] or 0 -- edge case hell
+
xp = (frame or {})[1] or 1000000 -- edge case hell
 
local r = #rnames
 
local r = #rnames
 
for i,rxp in pairs(rnumbers) do
 
for i,rxp in pairs(rnumbers) do
Line 125: Line 125:
 
 
 
local x = rnames[r]
 
local x = rnames[r]
return table.concat(rnumbers) --prefixes[x[1]].icon.." "..prefixes[x[1]].name.." "..suffixes[x[2]].name
+
return prefixes[x[1]].icon.." "..prefixes[x[1]].name.." "..suffixes[x[2]].name
 
end
 
end
  
 
return module
 
return module

Revision as of 18:26, 8 April 2024

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: Xp gold block.png Gold God -> 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: Xp gold block.png Gold God -> rank with 314159 xp, and no icon (options are n, but effectively is nyy)

Example: Xp gold block.png Gold God -> rank with 123456 xp, but only icon (options are ynn)

Example: Xp gold block.png Gold God -> 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 1000000 -- 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 prefixes[x[1]].icon.." "..prefixes[x[1]].name.." "..suffixes[x[2]].name
end

return module