From the RuneScape Wiki, the wiki for all things RuneScape
Jump to navigation Jump to search
Module documentation
This documentation is transcluded from Template:Module sandbox/doc. [edit] [history] [purge]
Module:Sandbox/User:Suity/SmeltingCalc requires Module:ExchangeLite.
Module:Sandbox/User:Suity/SmeltingCalc loads data from Module:Sandbox/User:Suity/msdata.

This module is a sandbox for Suity. 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 data = mw.loadData('Module:Sandbox/User:Suity/msdata')
local gemw = require('Module:ExchangeLite')

local lang = mw.getContentLanguage() -- Number format helper function.
function fnum(x)
    if type(x) == 'number' then return lang:formatNum(x) end
return x end

function p.main(frame)
    local args = frame:getParent().args
    local smith_level = tonumber(args.smith_level) or 1		-- Smithing level
    local avatar = data.avatar[args.avatar]					-- Avatar bonus
    local urns = data.urns[args.urns]						-- Urns
    local superheat = tonumber(args.superheat)				-- Superheat Form
    local bxp = tonumber(args.bxp)							-- Bonus XP
    local dxp = tonumber(args.dxp)							-- Double XP Weekend
    local outfit = data.outfit_s[args.outfit]				-- Blacksmith's Outfit
    local addon = tonumber(args.addon)						-- Modified Blacksmith's Helmet
    local aura = data.auras[args.aura]						-- Aura
    local wise = data.wise[args.wise]						-- Wise 
    local raf = tonumber(args.raf)							-- Refer a friend bonus
    local varrock = data.varrock[args.varrock]				-- Varrock armour
    local newvar = tonumber(args.newvar)					-- New varrock tasks
    if dxp == 1 then raf = raf * 2 end						-- Refer a friend bonus gets doubled on Double XP Weekend
local t = mw.html.create('table')
:tag('th')	:wikitext('Level')					:attr('rowspan', 2)	:done()
:tag('th')	:wikitext('Metal')					:attr('rowspan', 2)	:done()
:tag('th')	:wikitext('Bars Smelted Per Hour')	:attr('colspan', 3)	:done()
:tag('th')	:wikitext('XP Per Hour')			:attr('rowspan', 2)	:done()
:tag('th')	:wikitext('Base')	:done()
:tag('th')	:wikitext('Free')	:done()
:tag('th')	:wikitext('Total')	:done()

for index,i in ipairs(data.metals) do
	if smith_level >= i.level then

-- Smelting rate
local smelt_rate = data.smelt_rate_base
if		smith_level >= i.smelt_rate_level[2] then smelt_rate = data.smelt_rate[2]
elseif	smith_level >= i.smelt_rate_level[1] then smelt_rate = data.smelt_rate[1] end
local base_bars = 6000/(smelt_rate - superheat) -- Base bars smelted

-- Extra smelting chance (free bars smelted)
local double_chance = 0
if smith_level >= i.double_smelt then double_chance = data.double_bars + addon end -- Levelling benefit and modified helmet
-- Varrock armour smelting chance
if > 0 then -- Skips if no varrock armour is selected
	if i.varrock[] == 1 then -- Checks if the armour selected applies to the bar
		double_chance = double_chance + (data.varrock[i.varrock_no]['effect'] * newvar) -- If new varrock tasks then double the effect
local effective_chance = double_chance + (2*(double_chance)^2) + (4*(double_chance)^3) + (8*(double_chance)^4) + (16*(double_chance)^5) 
-- Since the double_chance can proc itself with a finite endpoint, effective_chance is the real % of extra free bars smelted
local free_bars = base_bars * effective_chance	-- Amount of free bars smelted
local total_bars = base_bars + free_bars		-- Total bars smelted

-- Experience per hour
local xp_boost = 1 + avatar + urns + bxp + dxp + outfit + aura.xp + wise + raf
local xp_per_hour = total_bars * i.smelt * xp_boost

-- Populating the remaining cells in the table
:tag('td')	:wikitext(i.level)				:css('text-align', 'center')	:done()
:tag('td')	:wikitext(i.img..' '									:done()
:tag('td')	:wikitext(fnum(math.floor(base_bars)))		:css('text-align', 'center')	:done()
:tag('td')	:wikitext(fnum(math.floor(free_bars)))		:css('text-align', 'center')	:done()
:tag('td')	:wikitext(fnum(math.floor(total_bars)))		:css('text-align', 'center')	:done()
:tag('td')	:wikitext(fnum(math.floor(xp_per_hour)))	:css('text-align', 'center')	:done()
return t
return p