Module:Skill calc/Archaeology

From the RuneScape Wiki, the wiki for all things RuneScape
Jump to: navigation, search
Module documentation
This documentation is transcluded from Module:Skill calc/Archaeology/doc. [edit] [purge]
Module:Skill calc/Archaeology's function main is invoked by Calculator:Archaeology/template.
Module:Skill calc/Archaeology loads data from Module:Skill calc/Archaeology/data.

The functionality for the Calculator:Archaeology calculator.


-- <nowiki>
local p = {}
local data = mw.loadData('Module:Skill calc/Archaeology/data')
local gemw = require('Module:Exchange')._price
local remainingExp = require('Module:Experience').remainingExp
local coins = require('Module:Currency')._amount
local curimg = require('Module:Currency Image')
local commas = require('Module:Addcommas')._add
local sortedPairs = require('Module:Iterator').sortedPairs

local cnoteprice = gemw('Chronotes')

function p.main(frame)
	local args = frame:getParent().args
	local arch_level = tonumber(args.arch_level) or 1			-- Archaeology level
	local arch_xp = tonumber(args.arch_xp) or 1				-- Archaeology xp
	local target_level = tonumber(args.target_level) or 120		-- Target Archaeology level
	local target_xp = tonumber(args.target_xp) or 0		-- Target Archaeology xp
	local poutfit = tonumber(args.outfit) or 0					-- Number of outfit pieces
	local customtmp = tonumber(args.custom) or 0
	local custom = customtmp / 100								-- Custom XP boost
	local filt_type = args.filter or 'None'						-- Filtering method
	local site = args.digsite or 'Kharid-et'					-- Dig site filter
	local god = args.god or 'Agnostic'							-- Alignment filter
	local colarg = args.col or 'Armadylean I'					-- Collection filter
	local coltmp = data.collections[colarg]
	local col = {}
	if coltmp and coltmp.arts then
		col = coltmp.arts
	end
	local filter_min = tonumber(args.minlvl) or 1							-- Minimum level for filter
	local filter_max = tonumber(args.maxlvl) or 120						-- Minimum level for filter
	
	-- Levels and targets
	local raw_remaining = 0
	arch_level, arch_xp, target_level, target_xp, raw_remaining = remainingExp(arch_level, arch_xp, target_level, target_xp)
	-- XP Boosts
	local xpboost = 1 + custom
	if poutfit == 5 then
		xpboost = xpboost + 0.06
	else
		xpboost = xpboost + (0.01 * poutfit)
	end
	
	local remaining = raw_remaining / xpboost
	
	local t = mw.html.create('table')
	t:addClass('wikitable sortable sticky-header')
	:tag('tr')
		:tag('th'):attr('rowspan','2'):wikitext('Artefact'):done()
		:tag('th'):attr('rowspan','2'):wikitext('Level'):done()
		:tag('th'):attr('rowspan','2'):wikitext('Number required'):done()
		:tag('th'):attr('colspan','2'):wikitext('Materials'):done()
		:tag('th'):attr('rowspan','2'):wikitext('Total cost'):done()
		:tag('th'):attr('rowspan','2'):wikitext('Cost/XP'):done()
		:tag('th'):attr('rowspan','2'):wikitext('Chronotes'):done()
		:tag('th'):attr('rowspan','2'):wikitext('Profit/Loss'):done()
		:tag('th'):attr('rowspan','2'):wikitext('Profit/XP'):done()
	:done()
	:tag('tr')
		:tag('th'):wikitext('Number'):addClass('unsortable'):done()
		:tag('th'):wikitext('Cost'):addClass('unsortable'):done()
	:done()
	
	for _,_,a in sortedPairs(data.artefacts, function(lhs, rhs) return lhs.level < rhs.level end) do
		local disp = false
		if filt_type == 'None' then
			disp = true
		elseif filt_type == 'Level' then
			if a.level < target_level and a.level > (arch_level - 20) then
				disp = true
			end
		elseif filt_type == 'Manual level' then
			if a.level >= filter_min and a.level <= filter_max then
				disp = true
			end
		elseif filt_type == 'Alignment' then
			if a.alignment == god then
				disp = true
			elseif god == 'Agnostic' and a.alignment == '' then
				disp = true
			end
		elseif filt_type == 'Collection' then
			for _,item in ipairs(col) do
				if item == a.name then
					disp = true
					break
				end
			end
		elseif filt_type == 'Dig site' then
			if a.digsite == site then
				disp = true
			end
		end
		
		if disp then
			local num = math.ceil( remaining / a.xp )
			
			local mats = {}
			local costs = {}
			local totcost = 0
			for i,v in pairs(a.mats) do
				local found, price = pcall(gemw, i)
				if not found then
					price = 0
				end
				price = price * v * num
				totcost = totcost + price
				table.insert(mats, string.format('%s [[File:%s.png|link=%s]] [[%s]]', commas(v*num),i,i,i) )
				if price > 0 then
					table.insert(costs, coins(price,'coins'))
				else
					table.insert(costs, '-')
				end
			end
			local costxp = totcost / remaining
			costxp = math.ceil(costxp * 100) / 100
			local sortname = mw.ustring.gsub(a.name, '[^%a%d ]', '')
			local cnotes = a.chronotes and a.chronotes * num or 0
			local cnoteval = cnotes * cnoteprice
			local profit = cnoteval - totcost
			local profxp = profit / remaining
			profxp = math.ceil( profxp*100 ) / 100
			
			local row = t:tag('tr')
			row	:tag('td'):attr('data-sort-value', sortname):wikitext( string.format('[[File:%s.png|link=%s]] [[%s]]', a.name,a.name,a.name) ):done()
				:tag('td'):wikitext(a.level):done()
				:tag('td'):attr('data-sort-value', num):wikitext( commas(num) ):done()
				:tag('td'):wikitext( table.concat(mats, '<br>') ):done()
				:tag('td'):wikitext( table.concat(costs, '<br>') ):done()
			if totcost > 0 then
				row	:tag('td'):attr('data-sort-value', totcost):wikitext( coins(totcost,'coins') ):done()
					:tag('td'):attr('data-sort-value', costxp):wikitext( coins(costxp,'coins') ):done()
			else
				row	:tag('td'):attr('data-sort-value', '0'):wikitext( 'N/A' ):done()
					:tag('td'):attr('data-sort-value', '0'):wikitext( 'N/A' ):done()
			end
			row	:tag('td'):attr('data-sort-value', cnotes):wikitext( '[[File:'..curimg('chronotes', cnotes)..'|link=]] '..commas(cnotes)..'<br>'..coins(cnoteval,'coins') ):done()
				:tag('td'):attr('data-sort-value', profit):wikitext( coins(profit,'coins') ):done()
				:tag('td'):attr('data-sort-value', profxp):wikitext( coins(profxp,'coins') ):done()
			:done()
		end
	end
	
	local msg = mw.html.create('div')
	-- Add message of xp needed to reach target
	local msgtxt = 'To train archaeology from '..commas(arch_xp)..' experience (level '..arch_level..') to '..commas(target_xp)..' experience (level '..target_level..'), '..commas(raw_remaining)..' experience is required.'
	msg:tag('p'):css({['font-size'] = "1.1em", ['font-weight'] = "bold"}):wikitext(msgtxt):done()
	
	return tostring(msg) .. tostring(t)
end

return p
-- </nowiki>