Module:ListArmors

local p = {} local cargo = mw.ext.cargo

local armorSlots = { headarmour = "head", headwear = "head", chestarmour = "chest", chestwear = "chest", legsarmour = "legs", legswear = "legs" }

-- Print the list of all armor sets in the game. (based on Special:CargoTables/item) -- Usage: function p.ListAllSets( frame ) -- Perform a SQL query to the Cargo database. local tables = 'item' local fields = 'name,description,category,tier,rarity,price,wikiPage,id' local queryOpt = { -- TODO: this is minimal testing query, should also add headwear,chestwear,legswear later. where = 'category IN ("headarmour","chestarmour","legsarmour")', limit = 50, orderBy = 'id' -- Makes debugging with low limit= values more convenient }	local rows = cargo.query( tables, fields, queryOpt ) if not rows then -- Nothing found. return '' end

local sets = {} for _, row in ipairs( rows ) do		local setId = row.id:gsub( 'head$',  ):gsub( 'chest$',  ):gsub( 'legs$', '' ) local set = sets[setId] if not set then -- Discovered a new set. set = {}

set.tier = row.tier set.rarity = row.rarity set.bonus = row.description:gsub( '^.*Set Bonuses:', '' ) set.powerMultiplier = 0 set.protection = 0 set.maxEnergy = 0 set.maxHealth = 0 set.price = 0 end

-- Add this item to the set. set[armorSlots[row.category]] = row sets[setId] = set end

-- Show a table of all sets. local ret = '{| class="wikitable sortable"\n' .. '|-\n! Tier !! Rarity !! Head !! Chest !! Legs !! Power multiplier !! Protection !! Max energy !! Max health !! Set bonus !! Total price\n'

for _, set in pairs( sets ) do ret = ret .. '|-\n|' .. set.tier .. '||' .. set.rarity .. '||' .. ( set.head and set.head.name or '-' ) .. '||' .. ( set.chest and set.chest.name or '-' ) .. '||' .. ( set.legs and set.legs.name or '-' ) .. '||' .. set.powerMultiplier .. '||' .. set.protection .. '||' .. set.maxEnergy .. '||' .. set.maxHealth .. '||' .. set.bonus .. '\n|' .. set.price .. '\n' end

ret = ret .. '\n|}' return ret end

return p