Module:Reward/Coliseum

local List = require 'Module:ListUtil' local Hash = require 'Module:HashUtil' local Datetime = require 'Module:DatetimeUtil' local Reward = require 'Module:Reward' local RewardText = require 'Module:RewardText' local RewardTables = require 'Module:Reward/Tables' local parseArgs = require 'Module:ObjectArg'.parse

local REWARD_SOURCES = {'offense', 'defense', 'rank', 'tier', 'streak', 'interval'} local MAX_TIME = Datetime.MAX_TIME local FIRST_COLISEUM_SEASON = 117 local FIRST_RB_SEASON = 177 local ALLEGIANCE_BATTLES_START = Datetime.make_iso8601(2019, 4, 27, 7, 0, 0) local RESONANT_BATTLES_START = Datetime.make_iso8601(2020, 6, 18, 7, 0, 0)

local offenseTable = function (rewards) for k, r in pairs(rewards) do		local r2, err = Reward.normalize(r) end end

local normalizeAll = function (modeRewards) for _, src in ipairs(REWARD_SOURCES) do		if modeRewards[src] then Hash.map_self(modeRewards[src], function (r)				local r2, err = Reward.normalize(r)				return err or r2			end) end end end

local arenaSection = function (args, frame) local bonusHeroesTable = mw.html.create('table'):addClass('wikitable') :css('text-align', 'center'):css('margin-left', 'auto'):css('margin-right', 'auto') :tag('tr'):tag('td'):tag('div') :css('display', 'flex'):css('justify-content', 'space-evenly'):css('flex-wrap', 'wrap'):css('width', '850px') for v in mw.text.gsplit(args.arenaBonusHeroes, '%s*;%s*') do		bonusHeroesTable:tag('span'):css('display', 'inline-block'):css('width', '150px'):css('margin', '10px'):wikitext(			frame:expandTemplate {title = 'UnitText with Type', args = {name = v}}) end

local rows = { ' Arena ', ' Bonus Heroes ', args.arenaNotification and ('Notification'):format(args.arenaNotification) or nil, tostring(bonusHeroesTable:allDone), }

local rewards, err = parseArgs(args.arenaRewards) if err then rows[#rows + 1] = require 'Module:Error'.error(err) return rows end normalizeAll(rewards)

if rewards.streak then local tbl = mw.html.create('table'):addClass('wikitable'):addClass('default'):addClass('reward-table'):css('text-align', 'center') local row = tbl:tag('tr') row:tag('th'):wikitext('Streak') row:tag('th'):addClass('reward-table-header'):wikitext('Reward')

for i, r in ipairs(rewards.streak) do			row = tbl:tag('tr') row:tag('td'):wikitext(('%d/%d'):format(i, #rewards.streak)) row:tag('td'):wikitext(RewardText._main({r, iconfirst = '1'}, frame)) Reward.define(r, 'Coliseum', {mode = 'arena', source = 'streak'}, frame) end

rows[#rows + 1] = ' Win streak rewards ' rows[#rows + 1] = tostring(tbl) end if rewards.offense then rewards.offense.columns = 2 rewards.offense.reverse = true rows[#rows + 1] = ' Offense score rewards ' rows[#rows + 1] = tostring(RewardTables.rank(rewards.offense, function (reward) Reward.define(reward, 'Coliseum', {mode = 'arena', source = 'offense', from = args.t0, to = MAX_TIME}, frame) end, ' Score', frame)) end if rewards.tier then local tableArgs = Hash.from_ipairs(rewards.tier, function (v, i)			return tostring(i), v		end) tableArgs.columns = 3 tableArgs.reverse = true tableArgs['arena tiers'] = true rows[#rows + 1] = ' Tier rewards ' rows[#rows + 1] = frame:expandTemplate {title = 'Hatnote', args = {'See Arena for a description of movement across Tiers at the end of each season.'}} rows[#rows + 1] = tostring(RewardTables.rank(tableArgs, function (reward) Reward.define(reward, 'Coliseum', {mode = 'arena', source = 'tier', from = args.t0, to = MAX_TIME}, frame) end, ' Tier', frame)) end if rewards.defense then rewards.defense.reverse = true rows[#rows + 1] = ' Defense score rewards ' rows[#rows + 1] = tostring(RewardTables.rank(rewards.defense, function (reward) Reward.define(reward, 'Coliseum', {mode = 'arena', source = 'defense', from = args.t0, to = MAX_TIME}, frame) end, ' Score', frame)) end if rewards.rank then rows[#rows + 1] = ' Rank rewards ' rows[#rows + 1] = tostring(RewardTables.rank(rewards.rank, function (reward) Reward.define(reward, 'Coliseum', {mode = 'arena', source = 'rank', from = args.t0, to = MAX_TIME}, frame) end, nil, frame)) end

return rows end

local arenaAssaultSection = function (args, frame) local rows = { ' Arena Assault ', }

local rewards, err = parseArgs(args.arenaAssaultRewards) if err then rows[#rows + 1] = require 'Module:Error'.error(err) return rows end normalizeAll(rewards)

if rewards.rank then rows[#rows + 1] = ' Rank rewards ' rows[#rows + 1] = tostring(RewardTables.rank(rewards.rank, function (reward) Reward.define(reward, 'Coliseum', {mode = 'arena_assault', source = 'rank', from = args.t0, to = MAX_TIME}, frame) end, nil, frame)) end

return rows end

local allegianceBattlesSection = function (args, frame) local rows = { ' Allegiance Battles ', args.allegianceBattlesInfobox, }

local rewards, err = parseArgs(args.allegianceBattlesRewards) if err then rows[#rows + 1] = require 'Module:Error'.error(err) rows[#rows + 1] = ' ' return rows end normalizeAll(rewards)

if rewards.offense then rewards.offense.reverse = true rewards.offense.columns = 2 rows[#rows + 1] = ' Score rewards ' rows[#rows + 1] = tostring(RewardTables.rank(rewards.offense, function (reward) Reward.define(reward, 'Coliseum', {mode = 'allegiance_battles', source = 'offense', from = args.t0, to = MAX_TIME}, frame) end, ' Score', frame)) end if rewards.rank then rows[#rows + 1] = ' Rank rewards ' rows[#rows + 1] = tostring(RewardTables.rank(rewards.rank, function (reward) Reward.define(reward, 'Coliseum', {mode = 'allegiance_battles', source = 'rank', from = args.t0, to = MAX_TIME}, frame) end, nil, frame)) end

rows[#rows + 1] = ' ' return rows end

local resonantBattlesSection = function (args, frame) local rows = { ' Resonant Battles ', args.resonantBattlesInfobox, }

local rewards, err = parseArgs(args.resonantBattlesRewards) if err then rows[#rows + 1] = require 'Module:Error'.error(err) rows[#rows + 1] = ' ' return rows end normalizeAll(rewards)

if rewards.interval then local tableArgs = Hash.from_ipairs(rewards.interval, function (v, i)			return tostring(i), v		end) tableArgs.columns = 3 tableArgs.reverse = true tableArgs.intervals = true rows[#rows + 1] = ' Interval rewards ' rows[#rows + 1] = frame:expandTemplate {title = 'Hatnote', args = {'See Resonant Battles for a description of movement across Intervals at the end of each season.'}} rows[#rows + 1] = tostring(RewardTables.rank(tableArgs, function (reward) Reward.define(reward, 'Coliseum', {mode = 'resonant_battles', source = 'interval', from = args.t0, to = MAX_TIME}, frame) end, ' Interval', frame)) end

rows[#rows + 1] = ' ' return rows end

local seasonPage = function (args, frame) local seasonNo = tonumber(args.number) args.t0 = Datetime.to_iso8601(Datetime.from_iso8601(args.endTime) + 1)

if mw.title.getCurrentTitle.namespace == 0 then frame:expandTemplate {title = 'ColiseumSeasonDefinition', args = { number = seasonNo, startTime = args.startTime, endTime = args.endTime, heroes = args.arenaBonusHeroes, }}	end

local content = { ' Availability ', ('This %s season was made available:'):format(seasonNo and seasonNo < FIRST_COLISEUM_SEASON and 'Arena' or 'Coliseum'), ('* %s'):format(Datetime.ht_range(args.startTime, args.endTime)), }	if seasonNo == FIRST_COLISEUM_SEASON then content[#content + 1] = 'The Allegiance Battles map was made available:' content[#content + 1] = ('* %s'):format(Datetime.ht_range(ALLEGIANCE_BATTLES_START, args.endTime)) elseif seasonNo == FIRST_RB_SEASON then content[#content + 1] = 'The Resonant Battles map was made available:' content[#content + 1] = ('* %s'):format(Datetime.ht_range(RESONANT_BATTLES_START, args.endTime)) end

if args.resonantBattlesRewards then List.concat_self(content, resonantBattlesSection(args, frame)) end if args.allegianceBattlesRewards then List.concat_self(content, allegianceBattlesSection(args, frame)) end if args.arenaRewards then List.concat_self(content, arenaSection(args, frame)) end if args.arenaAssaultRewards then List.concat_self(content, arenaAssaultSection(args, frame)) end

return table.concat(content, '\n') end

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