Module:Lamp calculator

From Old School RuneScape Wiki
Jump to navigation Jump to search
Module documentation
This documentation is transcluded from Template:No documentation/doc. [edit] [history] [purge]
This module does not have any documentation. Please consider adding documentation at Module:Lamp calculator/doc. [edit]
Module:Lamp calculator requires Module:Addcommas.
Module:Lamp calculator requires Module:Experience.
Module:Lamp calculator requires Module:Paramtest.
Module:Lamp calculator requires Module:ScaledExperience.

local Paramtest = require( 'Module:Paramtest' )
local Experience = require( 'Module:Experience' )
local ScaledExperience = require( 'Module:ScaledExperience' )
local Addcommas = require( 'Module:Addcommas' )

local p = {}

function p.invoke_main( frame )
	local result = p.main( frame:getParent().args )
	
	return p.render_combined_tables( result )
end

function p.main( args )	
	-- Need to know the following information
	-- Skill, Exp in Skill, Target Level or Target Exp
	local skillTable = {
		Attack = "startingAttackExp", Agility = "startingAgilityExp", Construction = "startingConstructionExp",
		Cooking = "startingCookingExp", Crafting = "startingCraftingExp", Defence = "startingDefenceExp",
		Farming = "startingFarmingExp", Firemaking = "startingFiremakingExp", Fishing = "startingFishingExp",
		Fletching = "startingFletchingExp", Herblore = "startingHerbloreExp", Hitpoints = "startingHitpointsExp",
		Hunter = "startingHunterExp", Magic = "startingMagicExp", Mining = "startingMiningExp", Prayer = "startingPrayerExp",
		Ranged = "startingRangedExp", Runecraft = "startingRunecraftExp", Slayer = "startingSlayerExp", Smithing = "startingSmithingExp",
		Strength = "startingStrengthExp", Thieving = "startingThievingExp", Woodcutting = "startingWoodcuttingExp"
	}
	local skill, targetType, targetLevel, targetExp = Paramtest.defaults{
		{ args.skill, 'Attack' },
		{ args.targetType, 'Level' },
		{ args.targetLevel, 1 },
		{ args.targetExp, 0 }
	}

	local startingExp = Paramtest.defaults{
		{ tonumber(args[skillTable[skill]]), 0 }
	}
	if startingExp < 0 then
		startingExp = 0
	end
	if targetType == 'Level' then
		targetExp = Experience.xp_at_level_unr( { args = { targetLevel } } )
	else
		targetExp = tonumber(targetExp)
	end



	local lampMultiplier = 10
	local lampResults = ScaledExperience.xp_to_xp_actions(startingExp, targetExp, lampMultiplier)

	local bookMultiplier = 15
	local bookResults = ScaledExperience.xp_to_xp_actions(startingExp, targetExp, bookMultiplier)


	lampResults['wikiText'] = '[[File:Lamp.png|link=Lamp]]'
	lampResults['name'] = 'Lamps'

	bookResults['wikiText'] = '[[File:Book_of_knowledge.png|link=Book_of_knowledge]]'
	bookResults['name'] = 'Books'

	local results = {
		lampResults = lampResults,
		bookResults = bookResults
	}
	return results
end

function p.render_combined_tables(results)
	local resultsDiv = mw.html.create( 'div' )
	local resultsTable = mw.html.create( 'table' )
	resultsTable:addClass( 'wikitable' )
		:addClass( 'align-center-1' )
		:tag( 'tr' )
			:tag( 'th' )
				:wikitext( 'Results' )
				:attr( 'colspan', 5 )
			:done()
		:done()
	:done()

	p.render_result_table(resultsTable, results['lampResults'])
	p.render_result_table(resultsTable, results['bookResults'])

	resultsDiv:node(tostring(resultsTable))
	return resultsDiv
end

function p.render_result_table(resultsTable, results)
	
	resultsTable:tag( 'tr' )
		:tag( 'td' )
			:wikitext( results['wikiText'] )
		:done()
		:tag( 'td' )
			:wikitext( results['name'] .. ' needed' )
			:attr( 'colspan', 3 )
		:done()
		:tag( 'td' )
			:wikitext( Addcommas._add( results['endActions'] ) )
		:done()
	:done()

	resultsTable:tag('tr')
		:tag( 'th' )
			:wikitext( '&nbsp;' )
			:attr( 'colspan', 2 )
		:done()
		:tag( 'th' )
			:wikitext( 'Start' )
		:done()
		:tag( 'th' )
			:wikitext( 'End' )
		:done()
		:tag( 'th' )
			:wikitext( 'Earned' )
		:done()
	:done()

	resultsTable:tag('tr')
		:tag( 'td' )
			:wikitext( '[[File:Stats_icon.png|link=Experience]]' )
		:done()
		:tag( 'td' )
			:wikitext( 'Experience' )
		:done()
		:tag( 'td' )
			:wikitext( Addcommas._add( results['startingExp'] ) )
		:done()
		:tag( 'td' )
			:wikitext( Addcommas._add( results['endExp'] ) )
		:done()
		:tag( 'td' )
			:wikitext(Addcommas._add( results['endExp'] - results['startingExp'] ) )
		:done()
	:done()
	resultsTable:tag('tr')
		:tag( 'td' )
			:wikitext( '[[File:Stats_icon.png|link=Experience]]' )
		:done()
		:tag( 'td' )
			:wikitext( 'Level' )
		:done()
		:tag( 'td' )
			:wikitext( results['startingLevel'] )
		:done()
		:tag('td')
			:wikitext( results['endLevel'] )
		:done()
		:tag('td')
			:wikitext( results['endLevel'] - results['startingLevel'] )
		:done()
	:done()
	resultsTable:tag('tr')
		:tag( 'th' )
			:wikitext( '&nbsp;' )
			:attr( 'colspan', 5 )
		:done()
	:done()
end

return p