RuneScape Wiki
m (t)
Tag: sourceedit
m (-)
 
(13 intermediate revisions by 5 users not shown)
Line 1: Line 1:
  +
-- <nowiki>
  +
local yesno = require('Module:Yesno')
 
local p = {}
 
local p = {}
   
Line 39: Line 41:
   
 
local lv = {
 
local lv = {
[false] = 1,
+
[0] = 1,
[true] = 0.9,
+
[1] = 0.9,
  +
[2] = 0.875,
  +
[3] = 0.85,
 
}
 
}
   
Line 62: Line 66:
   
   
p.table = function (frame)
+
function main_table(args)
local args = frame:getParent().args
 
 
local atier = tonumber(args.tier) or 70
 
local atier = tonumber(args.tier) or 70
 
local tier = atier
 
local tier = atier
Line 70: Line 73:
 
end
 
end
 
local collapsed = args.collapsed or false
 
local collapsed = args.collapsed or false
  +
local coinsver = yesno(args.coins, args.coins)
 
 
 
local base = (tier - 60) / 8
 
local base = (tier - 60) / 8
Line 75: Line 79:
 
 
 
local function make_4(tr, i, mult)
 
local function make_4(tr, i, mult)
local adj = base * reduction[i][2] * mult
+
local adj = base * reduction[i][2] * mult * coins[coinsver]
 
tr :tag('td')
 
tr :tag('td')
 
:wikitext(floor_s(adj * slot['2h']))
 
:wikitext(floor_s(adj * slot['2h']))
Line 117: Line 121:
 
local function make_header(lv)
 
local function make_header(lv)
 
local str = 'Item level 1-4'
 
local str = 'Item level 1-4'
if lv then
+
if (lv == 1) then
str = 'Item level 5+'
+
str = 'Item level 5-13'
  +
end
  +
if (lv == 2) then
  +
str = 'Item level 14-17'
  +
end
  +
if (lv == 3) then
  +
str = 'Item level 18+'
 
end
 
end
 
local class = 'wikitable mw-collapsible'
 
local class = 'wikitable mw-collapsible'
Line 271: Line 281:
 
:done()
 
:done()
 
 
make_header(false)
+
make_header(0)
 
for i = 0, 9, 1 do
 
for i = 0, 9, 1 do
make_row(i, false)
+
make_row(i, 0)
 
end
 
end
make_header(true)
+
make_header(1)
 
for i = 0, 9, 1 do
 
for i = 0, 9, 1 do
make_row(i, true)
+
make_row(i, 1)
 
end
 
end
  +
make_header(2)
 
  +
for i = 0, 9, 1 do
return t
 
  +
make_row(i, 2)
  +
end
  +
make_header(3)
  +
for i = 0, 9, 1 do
  +
make_row(i, 3)
  +
end
  +
  +
return tostring(t)
 
end
 
end
  +
  +
function p.table(frame)
 
local args = frame:getParent().args
  +
  +
local ret = ''
  +
if args.coins == nil then
  +
args.coins = false
  +
ret = {'{{Switch infobox', '|text1=Charges per second', '|text2=Equivalent coins per second', '|item1=', main_table(args), '|item2=' }
  +
  +
args.coins = true
  +
table.insert(ret, main_table(args))
  +
table.insert(ret, '}}')
  +
ret = mw.getCurrentFrame():preprocess(table.concat(ret, '\n'))
  +
  +
else
  +
-- coins specified, only do one
  +
ret = tostring(main_table(args))
  +
end
 
return ret
  +
end
  +
   
 
 
Line 291: Line 330:
 
local base = (tier - 60) / 8 * slot[s]
 
local base = (tier - 60) / 8 * slot[s]
 
local t = mw.html.create('table')
 
local t = mw.html.create('table')
  +
t:tag('caption'):wikitext('&nbsp;')
 
 
 
local function make_row(i, l, addcape, coinver)
 
local function make_row(i, l, addcape, coinver)
Line 377: Line 417:
 
make_header('Item level 1-4')
 
make_header('Item level 1-4')
 
for i = 0,9,1 do
 
for i = 0,9,1 do
make_row(i, false, false, coinstable)
+
make_row(i, 0, false, coinstable)
 
end
 
end
 
 
make_header('Item level 5+')
+
make_header('Item level 5-13')
  +
for i = 0,9,1 do
  +
make_row(i, 1, false, coinstable)
  +
end
  +
  +
make_header('Item level 14-18')
  +
for i = 0,9,1 do
  +
make_row(i, 2, false, coinstable)
  +
end
  +
  +
make_header('Item level 18+')
 
for i = 0,9,1 do
 
for i = 0,9,1 do
make_row(i, true, false, coinstable)
+
make_row(i, 3, false, coinstable)
 
end
 
end
 
 
return t
+
return tostring(t)
 
end
 
end
   

Latest revision as of 15:59, 19 January 2018

Documentation for this module may be created at Module:Charge drain/doc

-- <nowiki>
local yesno = require('Module:Yesno')
local p = {}

local reduction = {
	[0] = {1, 1},
	[1] = {34, 0.99},
	[2] = {49, 0.97},
	[3] = {64, 0.95},
	[4] = {69, 0.93},
	[5] = {78, 0.91},
	[6] = {83, 0.88},
	[7] = {91, 0.86},
	[8] = {95, 0.83},
	[9] = {105, 0.8},
}

local slot = {
	['2h'] = 1.5,
	mh = 1,
	['1h'] = 1,
	armour = 1,
	a = 1,
	body = 1,
	legs = 1,
	shield = 0.5,
	oh = 0.5,
	t = 0.25,
	tool = 0.25,
}

local eff = {
	[0] = 1,
	[1] = 0.94,
	[2] = 0.88,
	[3] = 0.82,
	e1 = 0.91,
	e2 = 0.82,
	e3 = 0.73
}

local lv = {
	[0] = 1,
	[1] = 0.9,
	[2] = 0.875,
	[3] = 0.85,
}

local cape = {
	[false] = 1,
	[true] = 0.98,
}

local coins = {
	[true] = require('Module:ExchangeLite').price('Divine charge') / 3000,
	[false] = 1,
}

local function floor(n)
	return math.floor(n*100)/100
end

local function floor_s(n)
	return string.format('%.2f', floor(n))
end


function main_table(args)
	local atier = tonumber(args.tier) or 70
	local tier = atier
	if tier < 67 then
		tier = 67
	end
	local collapsed = args.collapsed or false
	local coinsver = yesno(args.coins, args.coins)
	
	local base = (tier - 60) / 8
	local t = mw.html.create('table')
	
	local function make_4(tr, i, mult)
		local adj = base * reduction[i][2] * mult * coins[coinsver]
		tr	:tag('td')
				:wikitext(floor_s(adj * slot['2h']))
			:done()
			:tag('td')
				:wikitext(floor_s(adj * slot['1h']))
			:done()
			:tag('td')
				:wikitext(floor_s(adj * slot['oh']))
			:done()
			:tag('td')
				:wikitext(floor_s(adj * slot['t']))
			:done()
	end
	
	local function make_row(i, lvl, addcape)
		local tr = t:tag('tr')
		addcape = addcape or false
		local str = i
		if addcape then
			str = i .. '<br/>+Cape'
		end
		
		tr	:tag('th')
				:wikitext(str)
			:done()
			:tag('th')
				:wikitext(reduction[i][1])
			:done()
		make_4(tr, i, lv[lvl] * eff[0] * cape[addcape])
		make_4(tr, i, lv[lvl] * eff[1] * cape[addcape])
		make_4(tr, i, lv[lvl] * eff['e1'] * cape[addcape])
		make_4(tr, i, lv[lvl] * eff[2] * cape[addcape])
		make_4(tr, i, lv[lvl] * eff[3] * cape[addcape])
		make_4(tr, i, lv[lvl] * eff['e3'] * cape[addcape])
		if i >= 8 and not addcape then
			make_row(i, lvl, true)
		end
	end
	
	local function make_header(lv)
		local str = 'Item level 1-4'
		if (lv == 1) then
			str = 'Item level 5-13'
		end
		if (lv == 2) then
			str = 'Item level 14-17'
		end
		if (lv == 3) then
			str = 'Item level 18+'
		end
		local class = 'wikitable mw-collapsible'
		if collapsed then
			class = 'wikitable mw-collapsible mw-collapsed'
		end
		
		t	:addClass(class)
			:css('text-align', 'right')
			:tag('tr')
				:tag('th')
					:attr('rowspan', 3)
					:wikitext('Reduction')
				:done()
				:tag('th')
					:attr('rowspan', 3)
					:wikitext('[[File:Invention-icon.png|21x21px|link=Invention]]')
				:done()
				:tag('th')
					:attr('colspan', 29)
					:wikitext(str)
				:done()
			:done()
			:tag('tr')
				:tag('th')
					:attr('colspan', 4)
					:wikitext('Base')
				:done()
				:tag('th')
					:attr('rowspan', 14)
					:wikitext('&nbsp;')
				:done()
				:tag('th')
					:attr('colspan', 4)
					:wikitext('Efficient 1')
				:done()
				:tag('th')
					:attr('rowspan', 14)
					:wikitext('&nbsp;')
				:done()
				:tag('th')
					:attr('colspan', 4)
					:wikitext('Enhanced Efficient 1')
				:done()
				:tag('th')
					:attr('rowspan', 14)
					:wikitext('&nbsp;')
				:done()
				:tag('th')
					:attr('colspan', 4)
					:wikitext('Efficient 2')
				:done()
				:tag('th')
					:attr('rowspan', 14)
					:wikitext('&nbsp;')
				:done()
				:tag('th')
					:attr('colspan', 4)
					:wikitext('Eff 3/Enh Eff 2')
				:done()
				:tag('th')
					:attr('rowspan', 14)
					:wikitext('&nbsp;')
				:done()
				:tag('th')
					:attr('colspan', 4)
					:wikitext('Enhanced Efficient 3')
				:done()
			:done()
			:tag('tr')
				:tag('th')
					:wikitext('2H')
				:done()
				:tag('th')
					:wikitext('MH/A')
				:done()
				:tag('th')
					:wikitext('OH')
				:done()
				:tag('th')
					:wikitext('T')
				:done()
				:tag('th')
					:wikitext('2H')
				:done()
				:tag('th')
					:wikitext('MH/A')
				:done()
				:tag('th')
					:wikitext('OH')
				:done()
				:tag('th')
					:wikitext('T')
				:done()
				:tag('th')
					:wikitext('2H')
				:done()
				:tag('th')
					:wikitext('MH/A')
				:done()
				:tag('th')
					:wikitext('OH')
				:done()
				:tag('th')
					:wikitext('T')
				:done()
				:tag('th')
					:wikitext('2H')
				:done()
				:tag('th')
					:wikitext('MH/A')
				:done()
				:tag('th')
					:wikitext('OH')
				:done()
				:tag('th')
					:wikitext('T')
				:done()
				:tag('th')
					:wikitext('2H')
				:done()
				:tag('th')
					:wikitext('MH/A')
				:done()
				:tag('th')
					:wikitext('OH')
				:done()
				:tag('th')
					:wikitext('T')
				:done()
				:tag('th')
					:wikitext('2H')
				:done()
				:tag('th')
					:wikitext('MH/A')
				:done()
				:tag('th')
					:wikitext('OH')
				:done()
				:tag('th')
					:wikitext('T')
				:done()
			:done()
		:done()
	end
	
	t	:tag('tr')
			:tag('th')
				:attr('colspan', 31)
				:wikitext('Tier ' .. atier)
			:done()
		:done()
	
	make_header(0)
	for i = 0, 9, 1 do
		make_row(i, 0)
	end
	make_header(1)
	for i = 0, 9, 1 do
		make_row(i, 1)
	end
	make_header(2)
	for i = 0, 9, 1 do
		make_row(i, 2)
	end
	make_header(3)
	for i = 0, 9, 1 do
		make_row(i, 3)
	end

	return tostring(t)
end

function p.table(frame)
	local args = frame:getParent().args

	local ret = ''
	if args.coins == nil then
		args.coins = false
		ret = {'{{Switch infobox', '|text1=Charges per second', '|text2=Equivalent coins per second', '|item1=', main_table(args), '|item2=' }
		
		args.coins = true
		table.insert(ret, main_table(args))
		table.insert(ret, '}}')
		ret = mw.getCurrentFrame():preprocess(table.concat(ret, '\n'))
		
	else
		-- coins specified, only do one
		ret = tostring(main_table(args))
	end
	return ret
end


	
function oneslot_table(tier, s, coinstable)
	tier = tonumber(tier) or 70
	if tier < 67 then
		tier = 67
	end
	local base = (tier - 60) / 8 * slot[s]
	local t = mw.html.create('table')
	t:tag('caption'):wikitext('&nbsp;')
	
	local function make_row(i, l, addcape, coinver)
		local adj = base * lv[l] * reduction[i][2] * cape[addcape] * coins[coinver]
		local str = i
		if addcape then
			str = i .. '<br />+Cape'
		end
		t	:tag('tr')
				:tag('th')
					:wikitext(str)
				:done()
				:tag('th')
					:wikitext(reduction[i][1])
				:done()
				:tag('td')
					:wikitext(floor_s(adj * eff[0]))
				:done()
				:tag('td')
					:wikitext(floor_s(adj * eff[1]))
				:done()
				:tag('td')
					:wikitext(floor_s(adj * eff['e1']))
				:done()
				:tag('td')
					:wikitext(floor_s(adj * eff[2]))
				:done()
				:tag('td')
					:wikitext(floor_s(adj * eff[3]))
				:done()
				:tag('td')
					:wikitext(floor_s(adj * eff['e3']))
				:done()
			:done()
		if i >= 8 and not addcape then
			make_row(i,l,true,coinver)
		end
	end
	
	local function make_header(str)
		t	:addClass('wikitable')
			:css({
				['text-align'] = 'right',
				margin = '1em auto',
				})
			:tag('tr')
				:tag('th')
					:attr('rowspan', 2)
					:wikitext('Reduction')
				:done()
				:tag('th')
					:attr('rowspan', 2)
					:wikitext('[[File:Invention-icon.png|21x21px|link=Invention]]')
				:done()
				:tag('th')
					:attr('colspan', 7)
					:wikitext(str)
				:done()
			:done()
			:tag('tr')
				:tag('th')
					:wikitext('Base')
				:done()
				:tag('th')
					:attr('rowspan', 13)
					:wikitext('&nbsp;')
				:done()
				:tag('th')
					:wikitext('Eff 1')
				:done()
				:tag('th')
					:wikitext('EnhEff 1')
				:done()
				:tag('th')
					:wikitext('Eff 2')
				:done()
				:tag('th')
					:wikitext('Eff 3<br />EnhEff 2')
				:done()
				:tag('th')
					:wikitext('EnhEff 3')
				:done()
			:done()
	end
	
	make_header('Item level 1-4')
	for i = 0,9,1 do
		make_row(i, 0, false, coinstable)
	end
	
	make_header('Item level 5-13')
	for i = 0,9,1 do
		make_row(i, 1, false, coinstable)
	end

	make_header('Item level 14-18')
	for i = 0,9,1 do
		make_row(i, 2, false, coinstable)
	end

	make_header('Item level 18+')
	for i = 0,9,1 do
		make_row(i, 3, false, coinstable)
	end
	
	return tostring(t)
end


p.oneslot = function(tier, s)
	ret = {'{{Switch infobox', '|text1=Charges per second', '|text2=Equivalent coins per second', '|item1=', oneslot_table(tier,s,false), '|item2=', oneslot_table(tier,s,true), '}}'}
	
	return mw.getCurrentFrame():preprocess(table.concat(ret, '\n'))
end


return p