Module:LimitedHeroBattleTable

local cargo = mw.ext.cargo local List = require 'Module:ListUtil' local Hash = require 'Module:HashUtil' local Datetime = require 'Module:DatetimeUtil' local RewardText = require 'Module:RewardText'._main local DifficultyTexts = require 'Module:DifficultyTexts'._main

local main = function (_, frame) local maps = cargo.query('LimitedMaps=LM,LimitedMaps__Entry=LME',		"_pageName=page,StartTime=t0,EndTime=t1,GROUP_CONCAT(LME._value SEPARATOR ',')=entry,AllowedRefresher=refresher", {			join = 'LM._ID=LME._rowID',			groupBy = 'LM._ID',			orderBy = 'Map',			limit = 1000,	}) local mapRewards = List.group_by(cargo.query( 'MapRewards', _pageName=page,TabName=difficulty,		IF (Kind = 'item', Item, Kind)=kind, Amount=count,		Unit=hero, Rarity=rarity, FBRank=fbrank,		SacredSeal=seal, Accessory=accessory, { where = "Map LIKE 'I%'", orderBy = 'Map', limit = 1000, }), function (v) return v.page end)

List.map_self(maps, function (map)		map.entry = List.map(mw.text.split(map.entry, ','), function (v) return tonumber(v) end)		map.deployements = table.concat(List.map(map.entry, function (entry)			return 'Heroes from ' .. tostring(frame:expandTemplate{title='EntryText', args={entry}}) .. ''		end), '')		if tonumber(map.refresher) > 0 then			map.deployements = map.deployements .. 'Max Sing/Dance users: ' .. map.refresher .. ''		else			map.deployements = map.deployements .. 'Do not Sing or Dance'		end		map.reward = DifficultyTexts(Hash.from_pairs(			List.group_by(List.map(mapRewards[map.page] or {}, function(mapR)					mapR.count = tonumber(mapR.count)					return mapR 				end), function (v) return v.difficulty end),			function (v, k) return k, RewardText({v, iconfirst=1}, frame) end))		return map	end)

local tbl = mw.html.create('table'):addClass('wikitable'):addClass('default'):addClass('sortable'):css('text-align', 'center') local row = tbl:tag('tr') row:tag('th'):css('width', '23%'):wikitext('Map') row:tag('th'):css('width', '10%'):wikitext('Rewards') row:tag('th'):css('width', '30%'):wikitext('Deployment limits') row:tag('th'):css('width', '20%'):wikitext('Availability')

for _, v in ipairs(maps) do		row = tbl:tag('tr') row:tag('td'):wikitext(frame:expandTemplate {title = 'Banner HB', args = {link = v.page, limited = table.concat(v.entry, ',')}}) row:tag('td'):wikitext(v.reward) row:tag('td'):wikitext('' .. v.deployements .. '') row:tag('td'):wikitext(Datetime.ht_range(v.t0, v.t1)) end

return tbl end

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