Module:WeaponUpgradeBox

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

local STAT_NAMES = {'HP', 'Atk', 'Spd', 'Def', 'Res'}

local main = function (args) local frame = mw.getCurrentFrame local pagename = args[1] local refinePath = args[2] or 'Skill1'

local skillQuery = cargo.query('Skills,WeaponUpgrades,Skills__CanUseWeapon,WeaponTypes',		'Skills.Name=Name,Icon,Might,UseRange,WeaponUpgrades.StatModifiers=Stats,BaseDesc,AddedDesc,SP,CostStones,CostDews,CostMedals,WeaponTypes.Type=Type', {			where = ("Skills._pageName='%s' AND RefinePath='%s'"):format(escq(pagename), escq(refinePath)),			join = 'Skills.WikiName=WeaponUpgrades.UpgradesInto,Skills._ID=Skills__CanUseWeapon._rowID,Skills__CanUseWeapon._value=WeaponTypes.WikiName',			groupBy = 'Skills.WikiName',		})[1] if not skillQuery then return '' end local heroesQuery = cargo.query('UnitSkills,Skills', 'UnitSkills._pageName=hero,unlockRarity=rarity', {		join = 'UnitSkills.skill=Skills.WikiName',		where = ("Scategory='weapon' AND Skills._pageName='%s'"):format(escq(pagename)),		groupBy = 'UnitSkills._pageName',	})

local tbl = mw.html.create('table') :css('display', 'inline-table') :css('border', '1px solid #a2a9b1') :css('border-collapse', 'collapse') :css('width', '24em') :css('margin', '0.5em 0') :css('background-color', '#f8f9fa')

local row = tbl:tag('tr') row:tag('th'):css('background-color', '#408bca'):attr('colspan', 2):wikitext(table.concat(List.map_self(heroesQuery, function (row)		return frame:expandTemplate {title = 'Iconframe', args = row}	end)))

row = tbl:tag('tr'):css('vertical-align', 'middle') row:tag('td'):css('padding', '0.6em 0 0 1em') :tag('span'):css('font-size', '160%'):wikitext((' '):format(skillQuery.Icon, pagename)) :tag('b'):wikitext(('%s'):format(pagename, skillQuery.Name)) row:tag('td'):css('text-align', 'right'):css('padding', '0.6em 1em 0 0'):wikitext((''):format(skillQuery.Type))

local statModifiers = List.map_self(mw.text.split(skillQuery.Stats, ','), function (x) return tonumber(x) end) local statTxt = {("Might: %d, Range: %d"):format(tonumber(skillQuery.Might), tonumber(skillQuery.UseRange))} for i, v in ipairs(statModifiers) do		if v ~= 0 then statTxt[#statTxt + 1] = ("%s %+d"):format(STAT_NAMES[i], v)		end end row = tbl:tag('tr') row:tag('td'):css('padding', '0 1em'):attr('colspan', 2):wikitext(table.concat(statTxt, ', ')) if skillQuery.BaseDesc ~= '' then row = tbl:tag('tr') row:tag('td'):css('padding', '0 1em'):attr('colspan', 2):wikitext(' ' .. skillQuery.BaseDesc) end if skillQuery.AddedDesc ~= '' then row = tbl:tag('tr') row:tag('td'):css('padding', '0 1em 0.6em 1em'):attr('colspan', 2) :tag('span'):css('color', '#528C34'):wikitext(skillQuery.AddedDesc) end local itemTxt = {} if skillQuery.SP ~= '' and tonumber(skillQuery.SP) ~= 0 then itemTxt[#itemTxt + 1] = ("%d SP"):format(tonumber(skillQuery.SP)) end if skillQuery.CostStones ~= '' and tonumber(skillQuery.CostStones) ~= 0 then itemTxt[#itemTxt + 1] = ("%d %s"):format(tonumber(skillQuery.CostStones),			'') --			mw.getCurrentFrame:expandTemplate {title = 'ItemIcon', args = {'Refining Stone'}})	end	if skillQuery.CostDews ~= '' and tonumber(skillQuery.CostDews) ~= 0 then		itemTxt[#itemTxt + 1] = ("%d %s"):format(tonumber(skillQuery.CostDews), '') --			mw.getCurrentFrame:expandTemplate {title = 'ItemIcon', args = {'Divine Dew'}}) end if skillQuery.CostMedals ~= '' and tonumber(skillQuery.CostMedals) ~= 0 then itemTxt[#itemTxt + 1] = ("%d %s"):format(tonumber(skillQuery.CostMedals),			'') --			mw.getCurrentFrame:expandTemplate {title = 'ItemIcon', args = {'Arena Medal'}})	end	row = tbl:tag('tr')	row:tag('td'):css('padding', '0 1em 0.6em 1em'):css('text-align', 'right'):attr('colspan', 2):wikitext(table.concat(itemTxt, ', '))

return tostring(tbl) end

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