Module:Reward/PawnsOfLoki

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

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

local points = function (args, frame) args.columns = args.columns or 2 return RewardTables.score(args, function (reward, score)		Reward.define(reward, 'PawnsOfLoki', {score = score}, frame)	end, ' Cumulative Points', frame) end

local tier = function (args, frame) local query = mw.ext.cargo.query('PawnsOfLoki', 'StartTime,EndTime', {			where = ("_pageName='%s'"):format(mw.title.getCurrentTitle.text),			limit = 1,		})[1] local startTime = args['start'] and Datetime.from_iso8601(args['start']) or Datetime.from_cargo(query["StartTime"]) local endTime = args['end'] and Datetime.from_iso8601(args['end']) or Datetime.from_cargo(query["EndTime"]) local rounds = (endTime + 1 - startTime + BREAK_DURATION) / (ROUND_DURATION + BREAK_DURATION) local rewards = {} local rewardobjs = {} for k, v in pairs(args) do		if tonumber(k) then local reward, err = Reward.parse(v) if err then return require 'Module:Error'.error(err) end rewards[#rewards + 1] = { 'Tier ' .. k, RewardText({reward, size = args.iconsize, iconfirst = '1'}, frame) } rewardobjs[tonumber(k)] = reward end end table.sort(rewards, function (x, y) return tonumber(mw.ustring.match(x[1], "%d+") or 0) > tonumber(mw.ustring.match(y[1], "%d+") or 0) end)

local maxTier = {} mw.ustring.gsub(args.maxTier or "", "%d+", function (tier) maxTier[#maxTier + 1] = tonumber(tier) end) if not (args['no cargo'] or mw.title.getCurrentTitle.namespace ~= 0) then for i = 1, rounds do			local reward = rewardobjs[#maxTier >= i and maxTier[i] or #rewardobjs] if not reward then return require 'Module:Error'.error("Unknow best reward Tier Reward") else Reward.define(reward, 'PawnsOfLoki', {					from = Datetime.to_iso8601(startTime + ROUND_DURATION * i + BREAK_DURATION * (i - 1)),					to = Datetime.MAX_TIME,				}, frame) end end end

return RewardTables.createTable(rewards, ' Tier', args.columns or 1) end

return require 'Module:MakeMWModule'.makeMWModule { points = points, tier = tier }