Module:Salvage info

From the RuneScape Wiki, the wiki for all things RuneScape
Jump to: navigation, search
Module documentation
This documentation is transcluded from Module:Salvage info/doc. [edit] [purge]
Module:Salvage info is invoked by Template:Salvage info.
Module:Salvage info requires Module:ExchangeLite.

local p = {}
local l = mw.getContentLanguage()
local e = require('Module:ExchangeLite').price

local metals = {
	bronze = { l=1, v=20 },
	iron = { l=10, v=65 },
	steel = { l=20, v=240, t=true },
	mithril = { l=30, v=600, t=true },
	adamant = { l=40, v=2000, t=true },
	rune = { l=50, v=8000, t=true },
	orikalkum = { l=60, v=25000 },
}
local sizes = {
	tiny = 1,
	small = 2,
	medium = 3,
	large = 4,
	huge = 5,
}
local types = {
	bladed = true,
	blunt = true,
	plated = true,
	spiky = true,
}

local replacements = {
	tiny = { bladed = {'hatchet'}, blunt={'mace'}, plated={'med helm', 'gauntlets', 'armoured boots'}, spiky = {'dagger', 'claws', 'sword'} },
	small = { bladed = {'scimitar', 'longsword'}, blunt = {}, plated = {'square shield', 'full helm'}, spiky = {'pickaxe'} },
	medium = { bladed = {'battleaxe', '2h sword'}, blunt = {'warhammer'}, plated = {'plateskirt', 'platelegs', 'kiteshield'}, spiky = {'spear'} },
	large = { bladed = {}, blunt = {}, plated = {}, spiky = {} },
	huge = { bladed = {'halberd'}, blunt = {}, plated = {'platebody'}, spiky = {} },
}
local replacements_rune = {
	tiny = { bladed = {'hatchet'}, blunt={'mace'}, plated={'med helm', 'gauntlets', 'armoured boots'}, spiky = {'dagger', 'claws', 'sword', '2h crossbow'} },
	small = { bladed = {}, blunt = {}, plated = {}, spiky = {} },
	medium = { bladed = {'scimitar', 'longsword'}, blunt = {'warhammer'}, plated = {'full helm', 'square shield'}, spiky = {'spear', 'pickaxe'} },
	large = { bladed = {'battleaxe', '2h sword'}, blunt = {}, plated = {'chainbody', 'plateskirt', 'platelegs','kiteshield'}, spiky = {} },
	huge = { bladed = {'halberd'}, blunt = {}, plated = {'platebody'}, spiky = {} },
}

function append(t, t2)
	for i,v in ipairs(t2) do
		table.insert(t, v)
	end
end

function _nocoins(n)
	if type(n) == 'string' then
		n = tonumber(n:gsub(',',''))
	end
	local r = mw.html.create('span')
	r	:addClass('coins')
		:wikitext(l:formatNum(n))
		:wikitext(' coins')
	if n > 0 then
		r:addClass('coins-pos')
	elseif n < 0 then
		r:addClass('coins-neg')
	end
	return tostring(r)
end
function nocoins(n)
	return '{{NoCoins|'..n..'|c}}'
end

function p.main(frame)
	return frame:preprocess(p._main(frame:getParent().args[1]))
end
function p._main(name)
	if not name then
		name = mw.title.getCurrentTitle().text
	end
	local lc = l:lc(name)
	local size, stype, metal = unpack(mw.text.split(lc, ' '))
	
	if not (sizes[size] and types[stype] and metals[metal]) then
		return 'Invalid salvage name "'..name..'"; expects <tiny|small|medium|large|huge> <bladed|blunt|plated|spiky> <bronze|iron|steel|adamant|rune|orikalkum> salvage'
	end
	local minf = metals[metal]
	local lcuc = l:ucfirst(lc)
	local ret = {
		"'''", lcuc, "''' is a [[salvage]] item introduced with the [[Mining and Smithing rework]]. Salvage has no use other than [[disassemble|disassembly]], [[High Level Alchemy|alchemy]], or trading.",
		'\n\n',
		lcuc, ' is worth ',nocoins(sizes[size] * minf.v), ' in high level alchemy.'
	}
	if metal == 'orikalkum' then
		ret = {
			"'''", lcuc, "''' was a [[salvage]] item introduced with the second [[Mining and Smithing beta]]. Salvage has no use other than [[disassemble|disassembly]], [[High Level Alchemy|alchemy]], or trading.",
			'\n\n',
			lcuc, ' would have been worth ',nocoins(sizes[size] * minf.v), ' in high level alchemy.'
		}
		append(ret, {'\n\nAlthough orikalkum salvage was not obtainable by any means, the items were listed in the game cache during the beta as a placeholder in the event that drops of this value were to be released. Orikalkum salvage was not included in the final release of the [[Mining and Smithing rework]].'})
	else
		append(ret, {
			' When dropped by a monster, it can automatically be alchemised by a [[spring cleaner 2000]] or higher at the cost of a [[spring]] (',
			nocoins(sizes[size] * minf.v - e('Spring')), ' profit); alternatively it can be automatically disassembled for free by a [[spring cleaner 3000]] or higher. Because it does not use a spring, automatic disassembly does not advance the spring cleaner towards its next upgrade. Dismantle mode does not work on salvage items.'
		})
	end
	local repl
	if metal == 'rune' then
		repl = replacements_rune
	else
		repl = replacements
	end
	repl = repl[size][stype]
	if metal ~= 'orikalkum' and #repl > 0 then
		local repl2 = {}
		table.sort(repl)
		for i,v in ipairs(repl) do
			local x = ''
			if v == 'halberd' then
				x = ' (2 salvage per halberd)'
			end
			table.insert(repl2, string.format('\n* [[%s %s]]%s', l:ucfirst(metal), v, x))
		end
		append(ret, {
			'\n\nWhen the rework was launched, the following items on monster drop tables were replaced with ', lc, ':', table.concat(repl2, '')
		})
	end
	
	if minf.t then
		append(ret, {
			'\n\n', lcuc, ' can also be bought from [[Elof]] for ', sizes[size] * 10, ' [[', metal, ' item token]]s.'
		})
	end
	if metal ~= 'orikalkum' then
		append(ret, {
			'\n\n==Drop sources==',
			'\n{{Dropping monsters list|', lcuc, '}}',
--[=[		'\n\n==Disassembly==',
			'\n{{Disassembly',
			'\n|level=',minf.l,
			'\n|category=',size,' ',stype,' salvage',
			'\n}}'
--]=]
		})
	end
	mw.logObject(ret)
	return table.concat(ret, '')
end

return p