FANDOM


--<pre>
--Implements [[Template:Tier category]]
local p = {}
 
local tier, f_tank, f_pow, f_hyb, lp_bod, lp_shield
 
--data for the tables
--doesn't really need to be a separate page, since every single thing here is used (so basically no saving from mw.loadData)
local data = {
	head = {
			name = 'Head',  --name of slot to go into th
			armour = 0.2,   --armour multiplier
			lifepoints = 20,	--lifepoints multiplier
			damagebonus = 0.25, --damage bonus multiplier (not weapon damage)
		},
	body = {
			name = 'Body',
			armour = 0.23,
			lifepoints = 40,
			damagebonus = 0.375,
		},
	legs = {
			name = 'Legs',
			armour = 0.22,
			lifepoints = 30,
			damagebonus = 0.3125,
		},
	hands = {
			name = 'Hands',
			armour = 0.05,
			lifepoints = 0, --0 shows a 0 in the column; missing/nil shows NA
			damagebonus = 0.15625,
		},
	feet = {
			name = 'Feet',
			armour = 0.05,
			lifepoints = 0,
			damagebonus = 0.15625,
		},
	--total = {
	--        name = 'Total',
	--		armour = 0.75, -- total armor (head + body + legs + hands + feet)
	--		damagebonus = 1.25, -- same as above
	--		lifepoints = 90, -- same as above
	--   },
	shield = {
			name = 'Shield',
			armour = 0.2,
			lifepoints = 35,
			damagebonus = -1, -- damagebonus = -1 => N/A in 2 columns (power armour)
		},
	cape = {
			name = 'Cape',
			armour = 0.03,
			damagebonus = -1,
		},
	ring = {
			name = 'Ring',
			armour = 0.02,
			damagebonus = -1,
		},
	shieldbow = {
			name = 'Shieldbow',
			armour = 0.2,
			lifepoints = 35,
			damagebonus = -1,
			average = 5.3,
			ability = 9.6, --ability damage
			nohybrid = true,	--no hybrid variants available, put NA
		},
	defender = {	--all for the reworked defenders
			name = 'Defender',
			armour = 0.2/2,
			lifepoints = 35/2,
			damagebonus = -1,
			fastest = 2.4,
			nohybrid = true,
		},
	mainhand = {
			name = 'Main-hand',
			fastest = 9.6,  --damage multipliers at each speed
			fast = 12.25,   --if missing, defaults to NA
			average = 14.9,
		},
	offhand = {
			name = 'Off-hand',
			fastest = 4.8,
			fast = 6.125,
			average = 7.45,
		},
	twohand = {
			name = 'Two-handed',
			fastest = 14.4,
			fast = 18.375,
			average = 22.35,
		},
	dualwield = {
			name = 'Dual-wielding',
			note = 'Wielding a main and off-hand of the same tier and matching speeds (excluding ability damage).', --hover note
			ital = true, --make it italic
			fastest = 14.4,
			fast = 18.375,
			average = 22.35,
		},
	armour_order = {
		'head', 'body', 'legs', 'hands', 'feet', 'cape', 'ring', 'shield', 'shieldbow', 'defender', 
		},
	weapon_order = {
		'mainhand', 'offhand', 'dualwield', 'twohand', 'shieldbow', 'defender',
		},
}
 
-- add a vertical separator
local function sep(tr, rows)
	tr:tag('th')
		:css('width', '3px')
		:attr('rowspan', rows)
		:wikitext(' ')
		:done()
end
 
--adds hover text
local function hover(td, txt, hovertxt)
	td  :attr('title', hovertxt)
		:css('cursor', 'help')
		:tag('span')
			:css('border-bottom', '1px black dotted')
			:wikitext(txt)
		:done()
	:done()
end
 
--formats the cell into a N/A cell
local function na(td, cols)
	td  :addClass('table-na')
		:wikitext('N/A')
	if cols and cols > 1 then
		td:attr('colspan', cols)
	end
	td:done()
end
 
--the armour value function (also applies to accuracy)
local function armourfunc(t)
	local r = 2.5 * (t^3/1250 + 4*t + 40)
	if r > 0 then
		return r
	else
		return 0
	end
end
 
--create a row in the armour table
local function make_armour_row(table, name)
	local v = data[name]
	local tr = table:tag('tr')
	local namestr = v.name
 
	--name
	if v.ital then
		namestr = "''" .. namestr .. "''"
	end
 
	if v.note then
		hover(tr:tag('th'), namestr, v.note)
	else
		tr  :tag('th')
				:wikitext(namestr)
			:done()
	end
 
	--tank armour
	tr  :tag('td')
			:wikitext(math.floor(v.armour * f_tank))
		:done()
 
	--tank LP
	if v.lifepoints == nil then
		na(tr:tag('td'))
	elseif name == 'shield' then
		tr  :tag('td')
				:wikitext(v.lifepoints * lp_shield)
			:done()
	else
		tr  :tag('td')
				:wikitext(v.lifepoints * lp_bod)
			:done()
	end
 
	-- power armour
	if v.damagebonus == -1 then
		na(tr:tag('td'), 2) --N/A both cells if -1
	else
		--power armour value
		tr  :tag('td')
				:wikitext(math.floor(v.armour * f_pow))
			:done()
			--power damage bonus
			:tag('td')
				:wikitext(math.floor(v.damagebonus * tier))
			:done()
	end
 
	--hybrid
	if v.nohybrid then
		na(tr:tag('td'))
	else
		tr  :tag('td')
				:wikitext(math.floor(v.armour * f_hyb))
			:done()
	end	 
end
 
--create a row in the weapon table
local function make_weapon_row(table, name, acc)
	local v = data[name]
	local tr = table:tag('tr')
	local namestr = v.name
 
	--name
	if v.ital then
		namestr = "''" .. namestr .. "''"
	end
 
	if v.note then
		hover(tr:tag('th'), namestr, v.note)
	else
		tr  :tag('th')
				:wikitext(namestr)
			:done()
	end
 
	--accuracy, only if acc is true
	if acc then
		tr  :tag('td')
				:attr('rowspan', 6)
				:wikitext(math.floor(armourfunc(tier)))
			:done()
	end
 
	--fastest damage
	if v.fastest then
		tr  :tag('td')
				:wikitext(math.floor(v.fastest * tier))
			:done()
	else
		na(tr:tag('td'))
	end
 
	--fast damage
	if v.fast then
		tr  :tag('td')
				:wikitext(math.floor(v.fast * tier))
			:done()
	else
		na(tr:tag('td'))
	end
 
	--average damage
	if v.average then
		tr  :tag('td')
				:wikitext(math.floor(v.average * tier))
			:done()
	else
		na(tr:tag('td'))
	end
 
	--ability damage
	if v.ability then
		tr  :tag('td')
				:wikitext(math.floor(v.ability * tier))
			:done()
	else
		tr  :tag('td')
				:wikitext(math.floor(v.fastest * tier))
			:done()
	end
 
 
end
 
--make the tables
local function make_tables()
	local armour = mw.html.create('table')
	local _tr
	--calculate the basic armour value, before slot multipliers, for each type
	f_tank, f_pow, f_hyb = armourfunc(tier), armourfunc(tier-5), armourfunc(tier-15)
 
	--life point values
	lp_bod, lp_shield = (tier >= 80 and tier - 69) or 0, (tier >= 70 and tier - 69) or 0
 
	--create table and caption
	armour:addClass('wikitable')
			:css('text-align', 'center')
			:tag('caption')
				:wikitext('Tier ' .. tier .. ' armour stats')
			:done()
 
	_tr = armour:tag('tr')
				:tag('th')
					:attr('rowspan', 2)
					:wikitext('Slot')
				:done()
				:tag('th')
					:attr('colspan', 2)
					:wikitext('Tank')
				:done()
 
	sep(_tr, 12)
 
	_tr :tag('th')
			:attr('colspan', 2)
			:wikitext('Power')
		:done()
 
	sep(_tr, 12)
 
	_tr :tag('th')
			:wikitext('Hybrid/All')
		:done()
		:done()
 
	armour  :tag('tr')
				:tag('th')
					:wikitext('Armour')
				:done()
				:tag('th')
					:wikitext('Life points')
				:done()
				:tag('th')
					:wikitext('Armour')
				:done()
				:tag('th')
					:wikitext('Damage')
				:done()
				:tag('th')
					:wikitext('Armour')
				:done()
			:done()
		:done()
 
	--add all the slots in order
	for _, i in ipairs(data.armour_order) do
		make_armour_row(armour,i)
	end
	armour:done()
 
 
	--move on to weapons
	local weapons = mw.html.create('table')
	weapons:addClass('wikitable')
			:css('text-align', 'center')
			:tag('caption')
				:wikitext('Tier ' .. tier .. ' weapon stats')
			:done()
	weapons:tag('tr')
				:tag('th')
					:attr('rowspan', 2)
					:wikitext('Type')
				:done()
				:tag('th')
					:attr('rowspan', 2)
					:wikitext('Accuracy')
				:done()
				:tag('th')
					:attr('colspan', 5)
					:wikitext('Damage')
				:done()
	_tr = weapons   :tag('tr')
						:tag('th')
							:wikitext('Fastest')
						:done()
						:tag('th')
							:wikitext('Fast')
						:done()
						:tag('th')
							:wikitext('Average')
						:done()
 
	sep(_tr, 7)
 
	hover(_tr:tag('th'), 'Ability', 'Ability damage is the damage value used by abilities, scaled by speed such that all weapons of the same tier and handedness have the same ability damage.')
	_tr:done()
 
	--add all the weapon types in order
	for n, i in ipairs(data.weapon_order) do
		make_weapon_row(weapons, i, n==1)
	end
	weapons:done()
 
	--footer with notes
	local footer = mw.html.create('span'):css('font-size', 'smaller')
								:wikitext("Values may differ by ±1 due to rounding errors, either here or in-game. For a full list of stats at every tier, see [[Calculator:Combat stats]].")
							:done()
 
	return tostring(armour) .. '\n' .. tostring(weapons) .. '\n' .. tostring(footer)
 
end
 
--accessor for just the table
function p.table(frame)
	local args = frame:getParent().args
	_, _, tier = string.find(mw.title.getCurrentTitle().text, 'Tier (%d+) equipment')
	tier = args.tier or args[1] or tier or 1
	tier = tonumber(tier)
 
	return make_tables()
end
 
--main accessor for the preamble and category generation
function p.main(frame)
	local t = p.table(frame)
	local c = ''
	local tierstr
	local intro = "This category contains all '''tier " .. tier .. " equipment'''. Tier is based on the stats a piece of equipment has, and is usually (but not necessarily always) the requirement to use it. The tier-based stats of the items in this category are given by the following tables; however, the items may have additional bonuses which are unrelated to tier. ''For more details on tier, see [[equipment tier]].''"
 
	if mw.title.getCurrentTitle().namespace == 14 then
		if tier < 10 then
			tierstr = '00' .. tostring(tier)
		elseif tier < 100 then
			tierstr = '0' .. tostring(tier)
		else
			tierstr = tostring(tier)
		end
		c = '[[Category:Equipment by tier|Tier ' .. tierstr .. ' equipment]]' --SORTKEY SUPER IMPORTANT DO NOT FORGET
	end
 
	return intro .. '\n' .. t .. c
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.