Module:Reward/MjolnirsStrike

local Reward = require 'Module:Reward' local RewardTables = require 'Module:Reward/Tables' local RewardText = require 'Module:RewardText'.main local escq = require 'Module:EscQ'.main1

local tier = function (args, frame) local event = mw.ext.cargo.query('MjolnirsStrike',		"DATE_SUB(EndTime, INTERVAL -1 SECOND)=EndTime", {			where = ("_pageName='%s'"):format(escq(mw.title.getCurrentTitle.text)),			limit = 1,	})[1]

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) } if not tonumber(args.tierMax) or tonumber(k) <= tonumber(args.tierMax) then rewardobjs[#rewardobjs + 1] = reward end 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 best = Reward.best(rewardobjs) if best and not (args['no cargo'] or mw.title.getCurrentTitle.namespace ~= 0) then Reward.define(best, 'MjolnirsStrike', {from = event and event['EndTime'] or 0}, frame) elseif not best then return require 'Module:Error'.error('Best reward is not unique.') end

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

local askrLevel = function (args, frame) local event = mw.ext.cargo.query('MjolnirsStrike', 		"DATE_SUB(EndTime, INTERVAL -1 SECOND)=EndTime, AskrLV, CONCAT(AskrScore-StrikeScore)=score, TimesStronger", {		where = ('_pageName="%s" AND EndTime < NOW'):format(escq(mw.title.getCurrentTitle.text)),		limit = 1,	})[1]

local askrLV = 0 if event and tonumber(event['score']) then if tonumber(event['score']) > 0 then askrLV = tonumber(event['AskrLV']) + (tonumber(event['TimesStronger']) >= 10 and 2 or 1) else askrLV = tonumber(event['AskrLV']) - (tonumber(event['AskrLV']) > 1 and 1 or 0) end _, maxLevel = require 'Module:ListUtil'.max(require 'Module:HashUtil'.keys(args), 			function (x, y) return tonumber(x) < tonumber(y) end) askrLV = math.min(askrLV, maxLevel) end

local rewards = {} 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] = { 'Askr LV. ' .. k, RewardText({reward, size = args.iconsize, iconfirst = '1'}, frame) } if tonumber(k) == askrLV and not (args['no cargo'] or mw.title.getCurrentTitle.namespace ~= 0) then Reward.define(reward, 'MjolnirsStrike', {askrLV = askrLV, from = event and event['EndTime'] or 0}, frame) end 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)

return tostring(RewardTables.createTable(rewards, 'Askr LV.', args.columns or 3)) end

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