FANDOM


-- <pre>
local p = {}
 
local pdata = mw.loadData('Module:Perks/data')
local mdata = mw.loadData('Module:Perks/materials')
 
function p.maxRank(frame)
	local arg = frame:getParent().args[1]
	return p._maxRank(arg)
end
 
function p._maxRank(arg)
	arg = string.lower(arg or '')
 
	arg = pdata[arg]
 
	if not arg then
		return string.format('No such perk as: %s', arg)
	end
 
	-- why is #table bad?
	local i = 0
	for _, _ in ipairs(arg.weight) do
		i = i + 1
	end
 
	return i
end
 
function p.perkWeights()
	local ret = mw.html.create('table')
			:addClass('wikitable')
			:css('text-align','right')
			:tag('tr')
				:tag('th')
					:attr('rowspan','2')
					:wikitext('Material')
				:done()
				:tag('th')
					:attr('rowspan','2')
					:wikitext('Perk')
				:done()
				:tag('th')
					:attr('rowspan','4000')
				:done()
				:tag('th')
					:attr('colspan','3')
					:wikitext('1')
				:done()
				:tag('th')
					:attr('rowspan','4000')
				:done()
				:tag('th')
					:attr('colspan','3')
					:wikitext('2')
				:done()
				:tag('th')
					:attr('rowspan','4000')
				:done()
				:tag('th')
					:attr('colspan','3')
					:wikitext('3')
				:done()
				:tag('th')
					:attr('rowspan','4000')
				:done()
				:tag('th')
					:attr('colspan','3')
					:wikitext('4')
				:done()
				:tag('th')
					:attr('rowspan','4000')
				:done()
				:tag('th')
					:attr('colspan','3')
					:wikitext('5')
				:done()
				:tag('th')
					:attr('rowspan','4000')
				:done()
				:tag('th')
					:attr('colspan','3')
					:wikitext('Overall')
				:done()
			:done()
			:tag('tr')
				:tag('th')
					:wikitext('Display')
				:done()
				:tag('th')
					:wikitext('Min')
				:done()
				:tag('th')
					:wikitext('Max')
				:done()
				:tag('th')
					:wikitext('Display')
				:done()
				:tag('th')
					:wikitext('Min')
				:done()
				:tag('th')
					:wikitext('Max')
				:done()
				:tag('th')
					:wikitext('Display')
				:done()
				:tag('th')
					:wikitext('Min')
				:done()
				:tag('th')
					:wikitext('Max')
				:done()
				:tag('th')
					:wikitext('Display')
				:done()
				:tag('th')
					:wikitext('Min')
				:done()
				:tag('th')
					:wikitext('Max')
				:done()
				:tag('th')
					:wikitext('Display')
				:done()
				:tag('th')
					:wikitext('Min')
				:done()
				:tag('th')
					:wikitext('Max')
				:done()
				:tag('th')
					:wikitext('Min')
				:done()
				:tag('th')
					:wikitext('Max')
				:done()
				:tag('th')
					:wikitext('🗇')
				:done()
			:done()
	for w, v in pairs(mdata) do
		for x, y in pairs(v.perks) do
			local _data = pdata[x]
			if _data then
				_data = _data.weight
			end
			local minweights = {}
			local maxweights = {}
			local displays = {}
			for i, c in ipairs(y) do
				local minrank = c[1]
				local maxrank = c[2]
				-- calculate min perk weight
				-- find required weight of perk
				local _w
				_w = _data[minrank]
				if _w then
					_w = _w[1]
				else
					_w = 0
				end
				table.insert(minweights,math.floor(_w/i))
 
				-- calculate max weight, requires looking at next rank
				local maxp1 = _data[maxrank+1]
 
				if maxp1 then
					_w = maxp1[1] - 1
					table.insert(maxweights,math.floor(_w/i))
				else
					table.insert(maxweights,1000)
				end
 
				-- add display
				if minrank == 0 then
					table.insert(displays,'-')
				elseif minrank == maxrank then
					table.insert(displays,minrank)
				else
					table.insert(displays,string.format('%s–%s',minrank,maxrank))
				end
			end
 
			-- overall
			table.insert(minweights,math.max(unpack(minweights)))
			table.insert(maxweights,math.min(unpack(maxweights)))
			local problem = minweights[6] > maxweights[6]
			local problemcss
 
			if problem then
				table.insert(displays,'⚠')
				problemcss = 'sg-red'
			elseif idealmin == idealmax then
				table.insert(displays,'👌')
				problemcss = 'sg-green'
			end
 
			ret:tag('tr')
				:tag('td'):wikitext(w):done()
				:tag('td'):wikitext(x):done()
				:tag('td'):wikitext(displays[1]):done()
				:tag('td'):wikitext(minweights[1]):done()
				:tag('td'):wikitext(maxweights[1]):done()
				:tag('td'):wikitext(displays[2]):done()
				:tag('td'):wikitext(minweights[2]):done()
				:tag('td'):wikitext(maxweights[2]):done()
				:tag('td'):wikitext(displays[3]):done()
				:tag('td'):wikitext(minweights[3]):done()
				:tag('td'):wikitext(maxweights[3]):done()
				:tag('td'):wikitext(displays[4]):done()
				:tag('td'):wikitext(minweights[4]):done()
				:tag('td'):wikitext(maxweights[4]):done()
				:tag('td'):wikitext(displays[5]):done()
				:tag('td'):wikitext(minweights[5]):done()
				:tag('td'):wikitext(maxweights[5]):done()
				:tag('td'):wikitext(minweights[6]):done()
				:tag('td'):wikitext(maxweights[6]):done()
				:tag('td'):addClass(problemcss):css('text-align','center'):wikitext(displays[6]):done()
			:done()
			:tag('tr')
				:tag('th')
					:attr('colspan','26')
				:done()
			:done()
		end
	end
	return ret
end
 
-- useful for creating redirects
function p.allperkranks()
	local ret = {}
	for w, v in pairs(pdata) do
		local perk = w
		-- capitalise each word
		perk = mw.text.split(perk,' ')
		local _perk = {}
		for _, x in ipairs(perk) do
			local _word = mw.text.split(x,'')
			_word[1] = string.upper(_word[1])
			_word = table.concat(_word)
			table.insert(_perk,_word)
		end
		perk = table.concat(_perk,' ')
 
		-- dont add "1" to rankless perks
		if v.weight[2] then
			for i, _ in ipairs(v.weight) do
				table.insert(ret,string.format('* [[%s %s]]',perk,i))
			end
		else
			table.insert(ret,string.format('* [[%s]]',perk))
		end
	end
 
	ret = table.concat(ret,'\n')
	return ret
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.