Module:WeaponsTable

local p = {} local cargo = mw.ext.cargo local Util = require 'Module:Util' local List = require 'Module:ListUtil' local escq = require 'Module:EscQ'.main1

local MAX_WEAPONS = 5

local weaponsList = function (args, frame) local RARITY_TXT = Util.getRarityTexts

local weapons = List.select(List.generate(MAX_WEAPONS, function (i) return Util.isNilOrEmpty(args[i * 3 - 2]) and {} or { skill = args[i * 3 - 2], default = tonumber(args[i * 3 - 1]), unlock = tonumber(args[i * 3]), }	end), function (x) return not Util.isNilOrEmpty(x.skill) end) if #weapons == 0 then return ' This unit owns no Weapon skills. '	end local weaponsQueryResult = List.map(weapons, function (w)		local queryResult = cargo.query('Skills', '_pageName=page,Name=name,WikiName=wikiname,Might=mt,UseRange=rng,Description=desc,SP', { where = ("Scategory='weapon' AND _pageName='%s'"):format(escq(w.skill)), groupBy = '_pageName', limit = 1, })[1]		if not queryResult then			return {page = w.skill, name = w.skill, evolve = {}, refine = {}}		end

queryResult.evolve = List.map_self(cargo.query('WeaponEvolutions,Skills', 'Name', { join = 'WeaponEvolutions.EvolvesInto=Skills.WikiName', where = ("BaseWeapon='%s'"):format(escq(queryResult.wikiname)), groupBy = 'WikiName', limit = 10, }), function (v) return v.Name end) queryResult.refine = cargo.query('WeaponUpgrades,Skills', 'Icon,AddedDesc,Description=FullDesc,RefinePath', {			join = 'WeaponUpgrades.UpgradesInto=Skills.WikiName',			where = ("BaseWeapon='%s'"):format(escq(queryResult.wikiname)),		}) return queryResult end)

-- Initialize the table local tbl = mw.html.create('table') :addClass('wikitable default unsortable skills-table') :css('text-align','center')

-- Table Headers tbl:tag('th'):wikitext('Name') tbl:tag('th'):wikitext('Might') tbl:tag('th'):wikitext('Range') tbl:tag('th'):wikitext('Description') tbl:tag('th'):wikitext('SP') tbl:tag('th'):wikitext(frame:expandTemplate {title = 'Hover', args = {'Default',		'Skills are listed at the lowest rarity they are automatically learned at, regardless of whether or not the Hero can be obtained at that rarity.'}}) tbl:tag('th'):wikitext(frame:expandTemplate {title = 'Hover', args = {'Unlock',		'Skills are listed at the lowest rarity they can be learned at, regardless of whether or not the Hero can be obtained at that rarity.'}})

local extraTexts = {}

-- Go through all the weapons in the query result for i, q in ipairs(weaponsQueryResult) do		local wep = weapons[i] local tr = tbl:tag('tr')

tr:tag('td'):wikitext( .. q.name .. ) tr:tag('td'):wikitext(tonumber(q.mt) or '') tr:tag('td'):wikitext(tonumber(q.rng) or '') tr:tag('td'):wikitext(q.desc == '' and '—' or q.desc) local cost = tonumber(q.SP) or '' tr:tag('td'):wikitext(cost or '—') tr:tag('td'):wikitext(RARITY_TXT[wep.default] or '—') tr:tag('td'):wikitext(RARITY_TXT[wep.unlock] or '—')

List.concat_self(extraTexts, List.map(q.evolve, function (v) return ("%s can be evolved into %s."):format(				q.name, frame:expandTemplate {title = 'SkillText', args = {v}}) end))

if #q.refine > 0 then extraTexts[#extraTexts + 1] = ('%s can be upgraded in the Weapon Refinery.'):format(q.name) List.concat_self(extraTexts, List.uniq(List.map(List.select(q.refine, function (v) return v.FullDesc ~= q.desc and not v.RefinePath:find('^skill') end), function (v)				return ('When upgraded, the description of %s becomes "%s".'):format(q.name, v.FullDesc)			end))) List.concat_self(extraTexts, List.map(List.select(q.refine, function (v)				return v.AddedDesc ~= ''			end), function (v) return ('%s can be upgraded with the additional effect "%s".'):format(q.name, v.Icon, v.AddedDesc) end)) end end

local ret = tostring(tbl) if #extraTexts > 0 then ret = ('%s%s'):format(ret, table.concat(extraTexts, ' ')) end return ret end

return require 'Module:MakeMWModule'.makeMWModule {weaponsList = weaponsList}