Module:Charge drain
Jump to navigation
Jump to search
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,
[4] = 0.76,
e1 = 0.91,
e2 = 0.82,
e3 = 0.73,
e4 = 0.64
}
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(' ')
:done()
:tag('th')
:attr('colspan', 4)
:wikitext('Efficient 1')
:done()
:tag('th')
:attr('rowspan', 14)
:wikitext(' ')
:done()
:tag('th')
:attr('colspan', 4)
:wikitext('Enhanced Efficient 1')
:done()
:tag('th')
:attr('rowspan', 14)
:wikitext(' ')
:done()
:tag('th')
:attr('colspan', 4)
:wikitext('Efficient 2')
:done()
:tag('th')
:attr('rowspan', 14)
:wikitext(' ')
:done()
:tag('th')
:attr('colspan', 4)
:wikitext('Eff 3/Enh Eff 2')
:done()
:tag('th')
:attr('rowspan', 14)
:wikitext(' ')
: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(' ')
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()
:tag('td')
:wikitext(floor_s(adj * eff[4]))
:done()
:tag('td')
:wikitext(floor_s(adj * eff['e4']))
: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', 9)
:wikitext(str)
:done()
:done()
:tag('tr')
:tag('th')
:wikitext('Base')
:done()
:tag('th')
:attr('rowspan', 13)
:wikitext(' ')
: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()
:tag('th')
:wikitext('Eff 4')
:done()
:tag('th')
:wikitext('EnhEff 4')
: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