Module:Reward/RokkrSieges

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

local ROUNDS = 3 local ROUND_DURATION = 44 * 60 * 60 local BREAK_DURATION = 4 * 60 * 60

local total = function (args, frame) local t0 = frame:callParserFunction('#time', 'U', args.time or '') return RewardTables.score(args, function (reward, damage)		for i = 0, ROUNDS - 1 do			Reward.define(reward, 'RokkrSieges', { source = 'total', damage = damage, from = Datetime.to_iso8601(t0 + i * (ROUND_DURATION + BREAK_DURATION)), to = Datetime.to_iso8601(t0 + i * (ROUND_DURATION + BREAK_DURATION) + ROUND_DURATION - 1), }, frame)		end	end, ' Damage', frame) end

local rank = function (args, frame) local t0 = frame:callParserFunction('#time', 'U', args.time or '') return RewardTables.rank(args, function (reward)		for i = 0, ROUNDS - 1 do			Reward.define(reward, 'RokkrSieges', { source = 'rank', from = Datetime.to_iso8601(t0 + i * (ROUND_DURATION + BREAK_DURATION) + ROUND_DURATION), to = Datetime.MAX_TIME, }, frame)		end	end, nil, frame) end

local world = function (args, frame) args.reverse = true local t0 = frame:callParserFunction('#time', 'U', args.time or '') return RewardTables.rank(args, function (reward)		for i = 0, ROUNDS - 1 do			Reward.define(reward, 'RokkrSieges', { source = 'world', from = Datetime.to_iso8601(t0 + i * (ROUND_DURATION + BREAK_DURATION) + ROUND_DURATION), to = Datetime.MAX_TIME, }, frame)		end	end, ' World damage', frame) end

local damageToRokkr = function (args, frame) local bosses = {} local bossRewards = {} for i = 1, math.huge do		if not args[i] then break end local def, err = parseArgs(args[i]) if err then return require 'Module:Error'.error(err) elseif type(def) ~= 'table' then return require 'Module:Error'.error('Definition object for a Røkkr boss must be a table.') elseif not def.boss then return require 'Module:Error'.error('Missing "boss" parameter.') end

bossRewards[i] = {} bosses[i] = def

for k, v in pairs(def) do			local damage = tonumber(k) if damage then def[k], err = Reward.normalize(v) if err then return require 'Module:Error'.error(err) end local t0 = frame:callParserFunction('#time', 'U', def.since or '') table.insert(bossRewards[i], {damage, def[k]}) Reward.define(def[k], 'RokkrSieges', {					source = 'max', damage = damage, rokkr = def.boss,					from = Datetime.to_iso8601(t0),					to = Datetime.to_iso8601(t0 + ROUND_DURATION - 1),				}, frame) end end

table.sort(bossRewards[i], function (x, y) return x[1] < y[1] end) end

local tbl = mw.html.create('table'):addClass('wikitable'):addClass('default'):addClass('reward-table'):css('text-align', 'center') local row = tbl:tag('tr') for i, boss in ipairs(bosses) do		if i > 1 then row:tag('th'):attr('rowspan', 0):css('width', '.5em'):css('padding', '0') end row:tag('th'):attr('colspan', 2):attr('scope', 'colgroup'):css('padding-top', '.5em') :wikitext(Util.getHeroIcon(boss.boss, '40px'), ' ', boss.boss) end row = tbl:tag('tr') for _ in ipairs(bosses) do		row:tag('th'):attr('scope', 'col'):wikitext(' Top Damage'):done :tag('th'):attr('scope', 'col'):addClass('reward-table-header'):wikitext('Reward') end

local lang = mw.language.getContentLanguage local rowCount = select(2, List.max(List.map(bossRewards, function (v) return #v end))) for y = 1, rowCount do		row = tbl:tag('tr') for x = 1, #bosses do			local scoreCell = row:tag('td') local rewardCell = row:tag('td') local r = bossRewards[x][y] if r then scoreCell:wikitext(lang:formatNum(r[1])) rewardCell:wikitext(RewardText._main({r[2], size = args.iconsize, iconfirst = 1}, frame)) end end end

return tbl end

return require 'Module:MakeMWModule'.makeMWModule { total = total, rank = rank, world = world, max = damageToRokkr, }