Documentation for this module may be created at Module:Charge drain/doc
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
}
local lv = {
[false] = 1,
[true] = 0.9,
}
local cape = {
[false] = 1,
[true] = 0.98,
}
local function floor(n)
return math.floor(n*100)/100
end
local function floor_s(n)
return string.format('%.2f', floor(n))
end
p.table = function (frame)
local args = frame:getParent().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 base = (tier - 60) / 8
local t = mw.html.create('table')
local function make_4(tr, i, mult)
local adj = base * reduction[i][2] * mult
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[2] * cape[addcape])
make_4(tr, i, lv[lvl] * eff[3] * 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 then
str = 'Item level 5+'
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', 19)
:wikitext(str)
:done()
:done()
:tag('tr')
:tag('th')
:attr('colspan', 4)
:wikitext('Base')
:done()
:tag('th')
:attr('rowspan', 12)
:wikitext(' ')
:done()
:tag('th')
:attr('colspan', 4)
:wikitext('Efficient 1')
:done()
:tag('th')
:attr('rowspan', 12)
:wikitext(' ')
:done()
:tag('th')
:attr('colspan', 4)
:wikitext('Efficient 2')
:done()
:tag('th')
:attr('rowspan', 12)
:wikitext(' ')
:done()
:tag('th')
:attr('colspan', 4)
:wikitext('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()
:done()
:done()
end
t :tag('tr')
:tag('th')
:attr('colspan', 21)
:wikitext('Tier ' .. atier)
:done()
:done()
make_header(false)
for i = 0, 9, 1 do
make_row(i, false)
end
make_header(true)
for i = 0, 9, 1 do
make_row(i, true)
end
return t
end
p.oneslot = function(tier, s)
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')
local function make_row(i, l, addcape)
addcape = addcape or false
local adj = base * lv[l] * reduction[i][2] * cape[addcape]
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[2]))
:done()
:tag('td')
:wikitext(floor_s(adj * eff[3]))
:done()
:done()
if i >= 8 and not addcape then
make_row(i,l,true)
end
end
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', 4)
:wikitext('Item level 1–4')
:done()
:done()
:tag('tr')
:tag('th')
:wikitext('Base')
:done()
:tag('th')
:wikitext('Efficient 1')
:done()
:tag('th')
:wikitext('Efficient 2')
:done()
:tag('th')
:wikitext('Efficient 3')
:done()
:done()
for i = 0,9,1 do
make_row(i, false)
end
t :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', 4)
:wikitext('Item level 5+')
:done()
:done()
:tag('tr')
:tag('th')
:wikitext('Base')
:done()
:tag('th')
:wikitext('Efficient 1')
:done()
:tag('th')
:wikitext('Efficient 2')
:done()
:tag('th')
:wikitext('Efficient 3')
:done()
:done()
for i = 0,9,1 do
make_row(i, true)
end
return t
end
return p