Module:Sandbox/User:Choppe/Sandbox/Sieve

From Old School RuneScape Wiki
Jump to navigation Jump to search
Module documentation
This documentation is transcluded from Template:Module sandbox/doc. [edit] [history] [purge]
Module:Sandbox/User:Choppe/Sandbox/Sieve requires Module:Addcommas.
Module:Sandbox/User:Choppe/Sandbox/Sieve requires Module:Experience.
Module:Sandbox/User:Choppe/Sandbox/Sieve requires Module:Paramtest.
Module:Sandbox/User:Choppe/Sandbox/Sieve requires Module:SCP.
Module:Sandbox/User:Choppe/Sandbox/Sieve requires Module:ScaledExperience.

This module is a sandbox for Choppe. It can be used to test changes to existing modules, prototype new modules, or just experimenting with lua features.

Invocations of this sandbox should be kept in userspace; if the module is intended for use in other namespaces, it should be moved out of the sandbox into a normal module and template.

This default documentation can be overridden by creating the /doc subpage of this module, as normal.

local experience = require('Module:Experience')
local paramTest = require('Module:Paramtest')
local scaledExperience = require('Module:ScaledExperience')
local scp = require('Module:SCP')._main
local addCommas = require('Module:Addcommas')

local p = {}
--Module:Lamp calculator
function p.itemTable(item)
	local ret = mw.html.create('tr')
		:tag('td'):wikitext('Results'):attr('colspan', 5):done()
		
	return ret
end

function p.buildReturn(startingExp, skill, itemCount)
	local ret = mw.html.create('table'):addClass('wikitable align-center-1')
		:tag('tr'):tag('th'):wikitext('Results'):attr('colspan', 5):done()
		
	for _,v in (itemCount) do
		ret:node(itemTable(v))
	end
	
	return tostring(ret)
end

function p.main(args)
	local startingExp = paramTest.default_to(tonumber(args.startingExp), 0)
	local skill, targetType, targetLevel, targetExp = paramTest.defaults{
		{args.skill, 'Attack'},
		{args.targetType, 'Level'},
		{tonumber(args.targetLevel), 1},
		{tonumber(args.targetExp), 0},
	}
	
	if(targetType == 'Level') then
		targetExp = experience.xp_at_level_unr({args = {targetLevel}})
	end

	-- Lamp multiplier: 10, Book multiplier: 15
	local lampCount = scaledExperience.xp_to_xp_actions(startingExp, targetExp, 10)
	local bookCount = scaledExperience.xp_to_xp_actions(startingExp, targetExp, 15)
	
	itemCounts = {
		{
			['name'] = 'Lamps',
			['link'] = 'Lamp',
			['file'] = 'Lamp.png',
			['count'] = lampCount,
		},
		{
			['name'] = 'Books',
			['link'] = 'Book_of_knowledge',
			['file'] = 'Book_of_knowledge.png',
			['count'] = bookCount,
		}
	}
	
	return buildReturn(startingExp, skill, itemCounts)
end

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

return p