Module:Clue nest chance calculator

This is the current revision of this page, as edited by Alex (talk | contribs) at 00:00, 17 October 2024 (Created page with "local p = {} local lang = mw.language.getContentLanguage() local baseChanceArray = { {tree = 'Magic trees', chance = 72321}, {tree = 'Redwood trees', chance = 72321}, {tree = 'Yew trees', chance = 145013}, {tree = 'Arctic pine trees', chance = 145758}, {tree = 'Hollow trees', chance = 214367}, {tree = 'Mahogany trees', chance = 220623}, {tree = 'Maple trees', chance = 221918}, {tree = 'Teak trees', chance = 264336}, {tree = 'Willow trees', chance = 289286}, {..."). The present address (URL) is a permanent link to this version.

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:Clue nest chance calculator/doc

local p = {}

local lang = mw.language.getContentLanguage()

local baseChanceArray = {
	{tree = 'Magic trees', chance = 72321},
	{tree = 'Redwood trees', chance = 72321},
	{tree = 'Yew trees', chance = 145013},
	{tree = 'Arctic pine trees', chance = 145758},
	{tree = 'Hollow trees', chance = 214367},
	{tree = 'Mahogany trees', chance = 220623},
	{tree = 'Maple trees', chance = 221918},
	{tree = 'Teak trees', chance = 264336},
	{tree = 'Willow trees', chance = 289286},
	{tree = 'Achey trees', chance = 317647},
	{tree = 'Normal trees', chance = 317647},
	{tree = 'Sulliusceps', chance = 343000},
	{tree = 'Juniper trees', chance = 360000},
	{tree = 'Oak trees', chance = 361146}
}

local clueTierArray = {
    {tier = 'Beginner', modifier = 0.2},
    {tier = 'Easy', modifier = 1.7},
    {tier = 'Medium', modifier = 2},
    {tier = 'Hard', modifier = 3.3},
    {tier = 'Elite', modifier = 10}
}

local caTierArray = {
	['None'] = 0,
	['Easy'] = 1,
	['Medium'] = 2,
	['Hard'] = 3,
	['Elite+'] = 4
}

function p.buildTable(denomArray)
	local ret = mw.html.create('table'):addClass('wikitable sortable align-center-1'):done()
		ret:tag('tr'):tag('th'):wikitext('Tree type'):done()
			:tag('th'):wikitext('Beginner'):done()
			:tag('th'):wikitext('Easy'):done()
			:tag('th'):wikitext('Medium'):done()
			:tag('th'):wikitext('Hard'):done()
			:tag('th'):wikitext('Elite'):done()
	
	for i, denoms in ipairs(denomArray) do
		local row = mw.html.create('tr'):tag('th'):wikitext(denoms[1]):done()
				:tag('td'):wikitext('1/' .. lang:formatNum(denoms[2])):done()
				:tag('td'):wikitext('1/' .. lang:formatNum(denoms[3])):done()
				:tag('td'):wikitext('1/' .. lang:formatNum(denoms[4])):done()
				:tag('td'):wikitext('1/' .. lang:formatNum(denoms[5])):done()
				:tag('td'):wikitext('1/' .. lang:formatNum(denoms[6])):done()
		ret:node(row)
	end
	
	return ret
end

function p.getDenom(woodcuttingLevel, clueTier, clueMod, caTier, baseChance)
	local caModifier = 1
	if clueTier == 0 then
		caModifier = 1
	elseif caTier >= clueTier then 
		caModifier = 0.95
	end
		
	local firstNum = math.floor(baseChance * caModifier)
	local ret = math.floor((firstNum / (100 + woodcuttingLevel)) * clueMod)
	return ret
end

function p._main(args)
	local bigTable = {}
	for _, treeArray in ipairs(baseChanceArray) do
		local smallTable = {treeArray.tree}
		for i, clueArray in ipairs(clueTierArray) do
			table.insert(smallTable, p.getDenom(args.woodcuttingLevel, i-1, clueArray.modifier, caTierArray[args.caTier], treeArray.chance))
		end
		table.insert(bigTable, smallTable)
	end
	return p.buildTable(bigTable)
end

function p.main(frame)
	local args = frame:getParent().args
	return p._main(args)
end

return p