FANDOM


-- <nowiki>
local pt = require('Module:Paramtest')
local hc = pt.has_content
local dt = pt.default_to
local dplscroll = require('Module:DPL scroll')._main
 
local p = {}
 
 
function get_num(v1, v2)
	return tonumber(dt(v1, v2 or 0)) or 0
end
 
function is_offhand(v)
	v = string.lower(v)
	return v == 'off-hand weapon' or v == 'ohw' or v == 'off-hand' or v == 'shield'
end
 
 
--[[ 
    ARMOUR
--]]
p.armourrow = function(frame)
	local a = frame:getParent().args
	local ret = ''
	local i = 1
	local tmin, tmax
 
	-- if version1 has a value, we (probably) have a switchfo
	if hc(a.version1) then
		while hc(a['version' .. i]) do
			ret = ret .. make_armour_row({
				name = a['%TITLE%'],
				version = a['version' .. i],
				class = dt(a['class' .. i], a.class),
				tier = dt(a['tier' .. i], a.tier),
				armour = dt(a['armour' .. i], a.armour),
				life = dt(a['life' .. i], a.life),
				prayer = dt(a['prayer' .. i], a.prayer),
				magic = dt(a['magic' .. i], a.magic),
				ranged = dt(a['ranged' .. i], a.ranged),
				strength = dt(a['strength' .. i], a.strength),
			})
			i = i + 1
		end
 
	else
		ret = make_armour_row({
			name = a['%TITLE%'],
			class = a.class,
			tier = a.tier,
			armour = a.armour,
			life = a.life,
			prayer = a.prayer,
			magic = a.magic,
			ranged = a.ranged,
			strength = a.strength,
		})
	end
 
	return ret
end
 
function make_armour_row(bon)
	local l = mw.getContentLanguage()
	local ret = ''
	local tcalc
 
	local tier = string.lower(bon.tier)
	if tier == 'no' or tier == 'n/a' or tier == 'none' or tier == '0' or tier == 0 then
		tier = 'data-sort-value="0" {{na}}'
		tcalc = 0
	else
		tier = tonumber(bon.tier) or '?'
		tcalc = tonumber(bon.tier) or 0
	end
 
	ret = '\n|- data-tier="' .. tcalc .. '" \n| [[' .. bon.name .. ']]'
	if bon.version then
		ret = ret .. ' <small>' .. bon.version .. '</small>'
	end
 
	ret = ret .. string.format('\n| %s\n| %s\n| %s\n| %s\n| %s\n| %s\n| %s\n| %s',
			l:ucfirst(dt(bon.class, '?')),
			tier,
			get_num(bon.armour),
			get_num(bon.life),
			get_num(bon.prayer),
			get_num(bon.strength),
			get_num(bon.ranged),
			get_num(bon.magic))
	return ret
end
 
 
--[[ 
    WEAPONS
--]]
p.weaponrow = function(frame)
	local a = frame:getParent().args
	local ret = ''
	local i = 1
	local acc, dam, def_ma, def_md, def_oa, def_od
 
	-- if version1 has a value, we (probably) have a switchfo
	if hc(a.version1) then
		def_ma = get_num(a.accuracy, a.mainAccuracy)
		def_md = get_num(a.damage, a.mainDamage)
		def_oa = get_num(a.accuracy, a.offAccuracy)
		def_od = get_num(a.damage, a.offDamage)
		while hc(a['version' .. i]) do
			if is_offhand(dt(a['slot'..i], a.slot)) then
				acc = get_num(a['offAccuracy' .. i], def_oa)
				dam = get_num(a['offDamage' .. i], def_od)
			else
				acc = get_num(a['mainAccuracy' .. i], def_ma)
				dam = get_num(a['mainDamage' .. i], def_md)
			end
 
			ret = ret .. make_weapon_row({
				name = a['%TITLE%'],
				version = a['version' .. i],
				class = dt(a['class' .. i], a.class),
				style = string.gsub(string.gsub(string.gsub(dt(a['style' .. i], dt(a.style, '')), '-?casting', ''), 'ing', ''), 'bb', 'b'),
				tier = dt(a['tier' .. i], a.tier),
				armour = dt(a['armour' .. i], a.armour),
				life = dt(a['life' .. i], a.life),
				prayer = dt(a['prayer' .. i], a.prayer),
				damage = dam,
				accuracy = acc,
				tierstart = frame:preprocess('{{#dplvar:tierstart}}'),
				tierstart = frame:preprocess('{{#dplvar:tierend}}'),
			})
			i = i + 1
		end
 
	else
		if is_offhand(a.slot) then
			acc = get_num(a.accuracy, a.offAccuracy)
			dam = get_num(a.damage, a.offDamage)
		else
			acc = get_num(a.accuracy, a.mainAccuracy)
			dam = get_num(a.damage, a.mainDamage)
		end
 
		ret = make_weapon_row({
			name = a['%TITLE%'],
			class = a.class,
			style = string.gsub(string.gsub(string.gsub(dt(a.style, ''), '-?casting', ''), 'ing', ''), 'bb', 'b'),
			tier = a.tier,
			armour = a.armour,
			life = a.life,
			prayer = a.prayer,
			damage = dam,
			accuracy = acc,
		})
	end
 
	return ret
end
 
function make_weapon_row(bon)
	local l = mw.getContentLanguage()
	local ret = ''
	local tcalc
 
	local tier = string.lower(bon.tier)
	if tier == 'no' or tier == 'n/a' or tier == 'none' or tier == '0' or tier == 0 then
		tier = 'data-sort-value="0" {{na}}'
		tcalc = 0
	else
		tier = tonumber(bon.tier) or '?'
		tcalc = tonumber(bon.tier) or 0
	end
 
	if tcalc < (tonumber(bon.tierstart) or 0) or tcalc > (tonumber(bon.tierend) or 120) then
		return ''
	end
 
 
	ret = '\n|-" \n| [[' .. bon.name .. ']]'
	if bon.version then
		ret = ret .. ' <small>' .. bon.version .. '</small>'
	end
 
	ret = ret .. string.format('\n| %s\n| %s\n| %s\n| %s\n| %s\n| %s\n| %s\n| %s',
			l:ucfirst(dt(bon.class, '?')),
			l:ucfirst(dt(bon.style, '?')),
			tier,
			get_num(bon.accuracy),
			get_num(bon.damage),
			get_num(bon.armour),
			get_num(bon.life),
			get_num(bon.prayer))
	return ret
end
 
-- creates navigation links at the top of the table
-- combat classes, members/free to play, restriction, augmentation, tierless, tier range search
-- page navigation
-- changing filter resets to first page
-- changing page preserves filters
p.classes = function(frame)
	local a = frame:getParent().args
	local title = mw.title.getCurrentTitle()
	local table = mw.html.create('table')
	local query = { action = 'purge', DPL_offset = 0 }
	local thcss = {} -- {['border-top'] = '1px dashed black'}
	local css = { ['background-color'] = '#e5e5e5', padding = '0.1em 0.7em 0.2em 0.7em' } --, ['border-top'] = '1px dashed black' }
	local td, query_working
	local boldmem, boldtrade, boldtier, boldloc, boldaug = '0', '0', '0', '0', '0'
	local boldclass = 'all'
	local showaug = false
	local sep = ' • '
 
	local weps = false
	local ctype = 'armour'
	if dt(a.weapons, 'n') == 'y' then
		weps = true
		ctype = 'weapons'
	end
	if dt(a.showaug, 'n') == 'y' then
		showaug = true
	end
 
	local tmin = 0
	local tmax = 120
 
	local function make_link(td, link, query_new, bold)
		td:css(css)
 
		if bold then
			td:wikitext("'''" .. link .. "'''")
		else
			td:wikitext(string.format('[%s %s]', title:fullUrl(query_new), link))
		end
	end
 
 
	-- setup base query
	if hc(a.mems) then
		query.members = a.mems
		boldmem = a.mems
	end
 
	if hc(a.class) then
		query.class = a.class
		boldclass = string.lower(a.class)
	end
 
	if hc(a.trade) then
		query.trade = a.trade
		boldtrade = a.trade
	end
 
	if hc(a.tierless) then
		query.tierless = a.tierless
		boldtier = a.tierless
	end
 
	if hc(a.loc) then
		query.loc = a.loc
		boldloc = a.loc
	end
 
	if hc(a.useskin) then
		query.useskin = a.useskin
	end
 
	if showaug and hc(a.aug) then
		query.aug = a.aug
		boldaug = a.aug
	end
 
	if hc(a.tiermin) then
		query.tiermin = a.tiermin
		tmin = tonumber(a.tiermin) or 0
	end
	if hc(a.tiermax) then
		query.tiermax = a.tiermax
		tmax = tonumber(a.tiermax) or 120
	end
 
 
	table:addClass('dplequipmenttable')
		:css('text-align', 'left')
 
	-- total reset
	td = table:tag('tr'):tag('th')
			:wikitext('Reset filters')
		:done()
		:tag('td')
	query_working = {action = 'purge'}
	if hc(a.useskin) then
		query_working.useskin = a.useskin
	end
	make_link(td, 'Reset', query_working, false)
 
 
	-- membership status links
	td = table:tag('tr'):tag('th'):css(thcss)
			:wikitext('Membership')
		:done()
		:tag('td')
 
	query_working = get_copy(query)
	query_working.members = '0'
	make_link(td, 'All', query_working, boldmem == '0')
	td:wikitext(sep)
	query_working.members = '1'
	make_link(td, 'Members only', query_working, boldmem == '1')
	td:wikitext(sep)
	query_working.members = '2'
	make_link(td, 'Free-to-play only', query_working, boldmem == '2')
 
 
	-- tradeability links
	td = table:tag('tr'):tag('th'):css(thcss)
			:wikitext('Tradeable')
		:done()
		:tag('td')
 
	query_working = get_copy(query)
	query_working.trade = '0'
	make_link(td, 'All', query_working, boldtrade == '0')
	td:wikitext(sep)
	query_working.trade = '1'
	make_link(td, 'Tradeable only', query_working, boldtrade == '1')
	td:wikitext(sep)
	query_working.trade = '2'
	make_link(td, 'Untradeable only', query_working, boldtrade == '2')
 
 
	-- class links
	td = table:tag('tr'):tag('th'):css(thcss)
			:wikitext('Class')
		:done()
		:tag('td')
 
	query_working = get_copy(query)
	query_working.class = 'all'
	make_link(td, 'All', query_working, boldclass == 'all')
	td:wikitext(sep)
	query_working.class = 'melee'
	make_link(td, 'Melee', query_working, boldclass == 'melee')
	td:wikitext(sep)
	query_working.class = 'ranged'
	make_link(td, 'Ranged', query_working, boldclass == 'ranged')
	td:wikitext(sep)
	query_working.class = 'magic'
	make_link(td, 'Magic', query_working, boldclass == 'magic')
	if not weps then
		td:wikitext(sep)
		query_working.class = 'hybrid'
		make_link(td, 'Hybrid', query_working, boldclass == 'hybrid')
		td:wikitext(sep)
		query_working.class = 'typeless'
		make_link(td, 'Typeless', query_working, boldclass == 'typeless')
	end
 
 
	td = table:tag('tr'):tag('th'):css(thcss)
			:wikitext('Restriction')
		:done()
		:tag('td')
 
	query_working = get_copy(query)
	query_working.loc = '0'
	make_link(td, 'All', query_working, boldloc == '0')
	td:wikitext(sep)
	query_working.loc = '1'
	make_link(td, 'Surface only', query_working, boldloc == '1')
	td:wikitext(sep)
	query_working.loc = '2'
	make_link(td, 'Daemonheim only', query_working, boldloc == '2')
	td:wikitext(sep)
	query_working.loc = '3'
	make_link(td, 'No restricted', query_working, boldloc == '3')
 
 
	-- augmentation links
	if showaug then
		td = table:tag('tr'):tag('th'):css(thcss)
				:wikitext('Augmentation')
			:done()
			:tag('td')
 
		query_working = get_copy(query)
		query_working.aug = '0'
		make_link(td, 'All', query_working, boldaug == '0')
		td:wikitext(sep)
		query_working.aug = '1'
		make_link(td, 'Augmentable', query_working, boldaug == '1')
		td:wikitext(sep)
		query_working.aug = '2'
		make_link(td, 'Augmented', query_working, boldaug == '2')
		td:wikitext(sep)
		query_working.aug = '3'
		make_link(td, 'No augmented', query_working, boldaug == '3')
	end
 
	-- tier links
	td = table:tag('tr'):tag('th'):css(thcss)
			:attr('rowspan', '3')
			:wikitext('Tiers')
		:done()
		:tag('td')
 
	query_working = get_copy(query)
	query_working.tierless = '0'
	make_link(td, 'All', query_working, boldtier == '0')
	td:wikitext(sep)
	query_working.tierless = '1'
	make_link(td, 'No tierless', query_working, boldtier == '1')
	td:wikitext(sep)
	query_working.tierless = '2'
	make_link(td, 'Only tierless', query_working, boldtier == '2')
 
	table:tag('tr'):tag('td')
		:css(css)
		:wikitext("Current tier range: '''" .. tmin .. '&ndash;' .. tmax .. "''' inclusive")
 
	query_working = get_copy(query)
	query_working.useskin = 'wikia'
 
	td = table:tag('tr'):tag('td')
	td:css(css)
		:wikitext('<span class="jshide">Tier range selector requires javascript and ['.. title:fullUrl(query_working) .. ' the desktop site].<br /></span>')
 
 
	query_working = get_copy(query)
	query_working.tierless = '3'
	if query_working.tiermax then
		query_working.tiermax = nil
	end
	if query_working.tiermin then
		query_working.tiermin = nil
	end
 
	td:tag('span')
		:addClass('jsunhide hidden')
		:css('display', 'none')
		:wikitext('Min:&nbsp;')
		:tag('span')
			:addClass('jcInput')
			:wikitext('name=tlow|type=int|range=0,120|value='..tmin..'|size=5|sublist=tierlink')
		:done()
		:wikitext(' &bull; Max:&nbsp;')
		:tag('span')
			:addClass('jcInput')
			:wikitext('name=thigh|type=int|range=0,120|value='..tmax..'|size=5|sublist=tierlink')
		:done()
		:wikitext('<br />')
		:tag('span')
			:addClass('jcInput')
			:wikitext('name=tout|type=output')
		:done()
		:tag('div')
			:addClass('jcSub hidden')
			:wikitext('tierlink|')
			:wikitext('let(tl, tlow)')
			:wikitext('let(th, thigh)')
			:wikitext('if(tl>th){')
			:wikitext('let(c,th)')
			:wikitext('let(th,tl)')
			:wikitext('let(tl,c)')
			:wikitext('}')
			:wikitext('let( link, "{"+"{fullurl:'..title.prefixedText..'|'..mw.uri.buildQueryString(query_working)..'&tiermin=" + tl + "&tiermax=" + th + "}}" )')
			:wikitext('parse(tout, "[" + link + " Click to filter to tiers " + tl + " to " + th + " inclusive]" )]=])')
		:done()
	:done():done()
 
 
 
	-- pagination
 
	--separate from filters by a bit
	table:tag('tr'):tag('td'):attr('colspan','2'):wikitext('&nbsp;'):done():done()
 
 
 
 
	local pages_b, pages = dplscroll({
		total = a.total,
		count = a.count,
		offset = a.offset,
		query = query
	})
 
	table:tag('tr'):tag('td'):attr('colspan','2'):wikitext(string.format("'''Total results: %s'''", a.total)):done():done()
 
	-- only show pagination if there are pages to show
	if pages_b then
		table:tag('tr')
				:tag('th')
					:wikitext('Pages')
				:done()
				:tag('td')
					:css(css)
					:node(pages)
				:done()
			:done()
	end
 
	return tostring(table)
end
 
-- shallow copy of a table, only for use on a basic primitive=primitive table, like url query
-- use mw.clone() for deep copy
function get_copy(t)
	local r = {}
	for i,v in pairs(t) do
		r[i] = v
	end
	return r
end
 
 
 
 
return p

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.