Module:Sandbox/User:Choppe/Sandbox/Sandcastle

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/Sandcastle requires Module:Addcommas.
Module:Sandbox/User:Choppe/Sandbox/Sandcastle requires Module:Coins.
Module:Sandbox/User:Choppe/Sandbox/Sandcastle requires Module:Paramtest.
Module:Sandbox/User:Choppe/Sandbox/Sandcastle requires Module:SCP.
Module:Sandbox/User:Choppe/Sandbox/Sandcastle requires Module:Yesno.

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 p = {}

local coins = require('Module:Coins')._amount
local commas = require('Module:Addcommas')._add
local skillPic = require('Module:SCP')._main
local paramTest = require('Module:Paramtest')
local yesNo = require('Module:Yesno')

local lang = mw.language.getContentLanguage()


function p.membersIcon(memberBool)
	return (memberBool and yesNo(memberBool, true)) and '[[File:Member icon.png|center|link=Members]]' or '[[File:Free-to-play icon.png|center|link=Free-to-play]]'
end

function p.makeRowNoMaterial(data, skillType, displayHA, displayOnlyF2P)
	local picture = data.pic or data.name
	local resourcePic = action.resourcePic or action.resource
	
	--plinkt logs
	-- Scaled tree image
	--plink tree
	--level
	--xp
	--gep
	--gp/xp
	--HA val
	--HA profit
	--member
	actionExperience = (helpers.jagexFloor(action.xp * options.setValue, 1) + action.xp) * options.leagueMultiplier
	local outputQuantity = action.outputQuantity and action.outputQuantity or 1
	local members = p.membersIcon(data.members)
	local getOutputPrice = getOutput(action.name, action.outputItem, outputQuantity, numberOfActionsNeeded, reducedNumberOfActions)
	local gpXp = (getOutputPrice / actionExperience)
	
	return mw.html.create('tr')
		:tag('td'):wikitext('[[File:' .. picture .. '.png|link=' .. data.name .. ']]'):done()
		:tag('td'):wikitext(data.title and '[[' .. data.name .. '|' .. data.title .. ']]' or '[[' .. data.name .. ']]'):done()
		:tag('td'):wikitext(data.level or 1):done()
		:tag('td'):wikitext(commas(actionExperience)):done()
		:tag('td'):wikitext(commas(numberOfActionsNeeded)):done()
		:tag('td'):wikitext(coins(commas(getOutputPrice))):done()
		:tag('td'):wikitext(coins(commas(gpXp))):done()
		:tag('td'):wikitext(p.membersIcon(data.members)):done()
		
end



function p.createHeaders(skill, displayHA)
	local ret
	if((skill == 'Woodcutting') or (skill == 'Mining')) then
		ret = mw.html.create('table'):addClass('wikitable sortable sticky-header align-center-1 align-center-3 align-center-5 align-center-6 align-center-9')
		ret:tag('tr')
			:tag('th'):attr('colspan', 2):wikitext((skill == 'Woodcutting') and 'Logs' or 'Ore')
			:tag('th'):attr('colspan', 2):wikitext((skill == 'Woodcutting') and 'Tree Source' or 'Rock Source')
			:tag('th'):wikitext('Level')
			:tag('th'):wikitext('Experience')
			:tag('th'):wikitext('GE Price')
			:tag('th'):wikitext('GP/XP')
		if(displayHA) then
		ret:tag('th'):wikitext('HA Value')
			:tag('th'):wikitext('HA Profit')
		end
		ret:tag('th'):wikitext('Members')
	elseif((skill == 'Agility') or (skill == 'Thieving')) then
		ret = mw.html.create('table'):addClass('wikitable sortable sticky-header align-center-1 align-center-3 align-center-4 align-center-5')
		ret:tag('tr')
			:tag('th'):attr('colspan', 2):wikitext('Action')
			:tag('th'):wikitext('Level')
			:tag('th'):wikitext('XP')
			:tag('th'):wikitext('# Needed')
	elseif((skill == 'Firemaking') or (skill == 'Prayer') or (skill == 'Construction')) then
		ret = mw.html.create('table'):addClass('wikitable sortable sticky-header align-center-1 align-center-3 align-center-4 align-center-5 align-right-7 align-right-8')
		ret:tag('tr')
			:tag('th'):attr('colspan', 2):wikitext('Action')
			:tag('th'):wikitext('Level')
			:tag('th'):wikitext('XP')
			:tag('th'):wikitext('# Needed')
			:tag('th'):wikitext('Materials')
			:tag('th'):wikitext('Input Cost')
			:tag('th'):wikitext('GP/XP')
			:tag('th'):wikitext('Members')
	else
		ret = mw.html.create('table'):addClass('wikitable sortable sticky-header align-center-1 align-center-3 align-center-4 align-center-5 align-right-7 align-right-8 align-right-9 align-right-10')
		ret:tag('tr')
			:tag('th'):attr('colspan', 2):wikitext('Action')
			:tag('th'):wikitext('Level')
			:tag('th'):wikitext('XP')
			:tag('th'):wikitext('# Needed')
			:tag('th'):wikitext('Materials')
			:tag('th'):wikitext('Input Cost')
			:tag('th'):wikitext('Output Price')
			:tag('th'):wikitext('Profit/Loss')
			:tag('th'):wikitext('GP/XP')
			:tag('th'):wikitext('Members')
	end
	return ret
end

function p._main(args)
	local skill, skillType, displayHA, displayOnlyF2P = paramTest.defaults{ {paramTest.ucflc(args.skill), nil}, {paramTest.ucflc(args.skillType), nil}, {yesNo(args.displayHA), false}, {yesNo(args.displayOnlyF2P), false} }
	
	local ret = ''
	local noErr, skillData = pcall(mw.loadData, 'Module:Skill calc/' .. skill)
	
	if(noErr) then
		local validType = false
		for _, v in ipairs(skillData) do
			if((string.lower(v.type) == string.lower(skillType)) or (string.lower(skillType) == 'all')) then
				validType = true
				break
			end
		end
		
		if(validType) then
			ret = p.createHeaders(skill, displayHA)
			for _, v in ipairs(skillData) do
				if((skill == 'Woodcutting') or (skill == 'Mining')) then
					ret:node(p.makeRowNoMaterial(v, skillType, displayHA, displayOnlyF2P))
				elseif((skill == 'Agility') or (skill == 'Thieving')) then
					ret:node(p.makeRowBareBone(v, tskillType, displayHA, displayOnlyF2P))
				elseif((skill == 'Firemaking') or (skill == 'Prayer') or (skill == 'Construction')) then
					ret:node(p.makeRowNoProfit(v, skillType, displayHA, displayOnlyF2P))
				else
					ret:node(p.makeRowFull(v, skillType, displayHA, displayOnlyF2P))
				end
			end
		else
			ret = skillType .. '\'\'\' does not exist in this dataset.\'\'\''
		end
	else
		ret = skill .. '\'\'\' data does not exist.\'\'\''
	end
	return ret
end

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

return p