Module:UpgradableWeaponTable

local cargo = mw.ext.cargo local escq = require 'Module:EscQ'.main1 local List = require 'Module:ListUtil' local Hash = require 'Module:HashUtil'

local getRowSpan = function (list, i, field) local v1 = list[i] and list[i][field] if list[i - 1] and v1 == list[i - 1][field] then return 0 end return (List.find_if(list, function (t) return t[field] ~= v1 end, i) or (#list + 1)) - i end

local byType = function (args) local weapons = List.group_by(cargo.query( 'WeaponUpgrades,Skills=b,Skills=a,Skills__CanUseWeapon,WeaponTypes,RefinePathSortValues', BaseWeapon=base,UpgradesInto=upgrade,a.RefinePath=refine,		 b.Name=name,b._pageName=page,b.Might=mt,b.UseRange=rng,a.Icon=icon,WeaponUpgrades.StatModifiers=stats,		  b.Description=basedesc,WeaponUpgrades.BaseDesc=newdesc,WeaponUpgrades.AddedDesc=adddesc,		  CostMedals=medals,CostStones=stones,CostDews=dews,a.SP=spcost, { join = 'WeaponUpgrades.BaseWeapon=b.WikiName,WeaponUpgrades.UpgradesInto=a.WikiName,b._ID=Skills__CanUseWeapon._rowID,Skills__CanUseWeapon._value=WeaponTypes.WikiName,a.RefinePath=RefinePathSortValues.Path', where = ("WeaponUpgrades._pageName IS NOT NULL AND a._pageName IS NOT NULL AND WeaponTypes.Type='%s'"):format(escq(args[1])), groupBy = 'BaseWeapon,UpgradesInto', orderBy = 'b.Name,b.WikiName,RefinePathSortValues.Sort', limit = 5000, }), function (v) return v.base end)

local tbl = mw.html.create('table'):addClass('wikitable'):addClass('unsortable') :css('text-align', 'center'):css('width', '1200px') local row = tbl:tag('tr') row:tag('th'):css('width', '11%'):wikitext('Weapon') row:tag('th'):css('width', '3%'):wikitext('Icon') row:tag('th'):css('width', '5%'):wikitext('Mt') row:tag('th'):css('width', '5%'):wikitext('HP') row:tag('th'):css('width', '5%'):wikitext('Spd') row:tag('th'):css('width', '5%'):wikitext('Def') row:tag('th'):css('width', '5%'):wikitext('Res') row:tag('th'):css('width', '28%'):wikitext('Original effect') row:tag('th'):css('width', '28%'):wikitext('Upgraded effect') row:tag('th'):css('width', '5%'):css('min-width', '65px'):wikitext('Cost')

for base, upgrades in Hash.sorted_pairs(weapons) do		for _, skill in ipairs(upgrades) do			skill.stats = List.map_self(mw.text.split(skill.stats, ','), function (v) return tonumber(v) or 0 end) skill.namefield = ('%s%s Mt %s&emsp;Rng %s'):format(skill.page, skill.page == skill.name and '' or ('|' .. skill.name), skill.mt, skill.rng) skill.origfield = skill.basedesc == '' and '—' or skill.basedesc skill.upgradedfield = skill.newdesc == skill.basedesc and skill.adddesc ==  and '(Unchanged)' or				skill.adddesc ==  and skill.newdesc or				('%s%s %s '):format(skill.newdesc, skill.newdesc ~=  and ' ' or , mw.text.encode(skill.adddesc)) local costs = List.select({				{tonumber(skill.spcost) or 0, 'SP'},				{tonumber(skill.medals) or 0, },				{tonumber(skill.stones) or 0, },				{tonumber(skill.dews) or 0, ''},			}, function (v) return v[1] ~= 0 end) skill.costfield = table.concat(List.map_self(costs, function (v) return ('%d %s'):format(v[1], v[2]) end), ' ') end

for i, skill in ipairs(upgrades) do			local addMergedField = function (field) local rowspan = getRowSpan(upgrades, i, field) if rowspan > 0 then row:tag('td'):attr('rowspan', rowspan):wikitext(skill[field]) end end

row = tbl:tag('tr') addMergedField('namefield') row:tag('td'):wikitext((''):format(skill.icon or 'Passive No Image.png')) row:tag('td'):wikitext(skill.stats[2] == 0 and '—' or ('%d Mt'):format(skill.mt + skill.stats[2])) row:tag('td'):wikitext(skill.stats[1] == 0 and '—' or ('HP%+d'):format(skill.stats[1])) row:tag('td'):wikitext(skill.stats[3] == 0 and '—' or ('Spd%+d'):format(skill.stats[3])) row:tag('td'):wikitext(skill.stats[4] == 0 and '—' or ('Def%+d'):format(skill.stats[4])) row:tag('td'):wikitext(skill.stats[5] == 0 and '—' or ('Res%+d'):format(skill.stats[5])) addMergedField('origfield') addMergedField('upgradedfield') addMergedField('costfield') end end

return ('%s%s'):format(args.indent or 3, args[1], args.indent or 3, tostring(tbl)) end

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