Module:METables

--[[ Lua script to get Mini Event Tables

getMilestones: get Milestones Table based on input parameters Parameters: 1 =        2 =         3 = --]]

local p = {}

local cData = mw.loadData("Module:ItemCollection/data") local util = require("Module:Utility") local ME = require("Module:MiniEvent").getME local EC = require("Module:EC").getEC local TOK = require("Module:CharacterToken").getToken local ICON = require("Module:CharacterAvatar").getAvatar

local tArgs = {}

local prize = {} local lb = {} local ms = {} local ch = {}

local iconSize = "30"

local function lbItems(inStr) local tIn = mw.text.split(inStr, "%s*%$%s*") local tOut = {} tOut.range = tonumber((string.gsub(tIn[1], "%,", ""))) or 0 for idx = 2, #tIn do		table.insert(tOut, tIn[idx]) end return tOut end

local function msItems(inStr) local tIn = mw.text.split(inStr, "%s*%$%s*") local tOut = {} tOut.count = tIn[1] for idx = 2, #tIn, 2 do		table.insert(tOut, {tIn[idx], tIn[idx+1]}) end return tOut end

local function chItems(inStr) local tIn = mw.text.split(inStr, "%s*%$%s*") local tOut = {tIn[1], tIn[2]} return tOut end

local function processArgs(frame) tArgs = util.getArgs(frame)

-- Leaderboard Prizes if tArgs.prize then prize = mw.text.split(tArgs.prize, "%s*%$%s*") end

-- Loop over all the args to get tier/ms prize counts for arg, value in pairs(tArgs) do		local cat, n = tostring(arg):match('^(%a+)([1-9]%d*)$') local num = tonumber(n)

if num then if cat == "lb" then lb[num] = lbItems(value) elseif cat == "ms" then ms[num] = msItems(value) elseif cat == "ch" then ch[num] = chItems(value) end end end end

local function getCollection(coll) local collName = "" for _, data in pairs(cData.Collections) do		if (data[3] and data[3] == coll) or coll == data[1] then collName = data[1] end end return collName end

local function oneItem(item, count, withName) --skip item if count = 0 if not count or count == "0" then return "" end

local conv = { ["ch"] = "cp", ["cos"] = "cp", }

local tItem = {"", " " .. count, (withName and " " or ""), "", "",			(withName and " " or ""), }

local coll = nil local iName = item local iData = cData.Items[iName] if not iData then coll = item:match("^Legendary Chests%s*%-%s*(.-)$") if coll then iName = "Legendary Chests" iData = cData.Items[iName] end end

if iData and iData[2] then local fname = iData.I or iName:lower:gsub("[':%,%.]", ""):gsub(" ", "_") if iData[2] == "ec" then fname = fname:gsub("_chests$", "") elseif iData[2] == "pf" then fname = fname:gsub("_float$", "") else fname = fname:gsub("^([^%(]-)_*%(([^%d]+%d*)%)$", "%1-%2")			mw.log(fname)		end

tItem[1] = table.concat({								""							}) if count == "1" then tItem[2] = "" end

if withName then local tLink = { "", iName,				"", "", "", "", "",				"", }			local sp = nil local spText = iName if count == "1" and iData.S then sp = true spText = iName:gsub("[Ss]$", "") elseif iData.P then sp = true spText = string.gsub(iData.P, "%%N", function return iName end) end if coll or sp then tLink[3] = "|" tLink[4] = coll and getCollection(coll) or "" tLink[5] = coll and " " or "" tLink[6] = spText end tItem[4] = table.concat(tLink) end elseif item:match("^EC") then tItem[1] = EC({item, nil, nil, nil, iconSize}) if withName then tItem[4] = EC({item, "L", S=(count == "1")}) end else tItem[1] = TOK({item, iconSize}) if withName then tItem[4] = TOK({item, "L"}) if count > "1" then tItem[5] = "s" end end end

return table.concat(tItem) end

local function msTable local tOut = {'|-|Milestones=\n{| class="article-table dmk-milestone" style="width: 100%;"\n', '|-\n!Milestone\n'} local tRew = {'|-\n!Rewards\n'}

local maxMS = 4 local befCount = ME({tArgs.mename or "", "", "N"}) local aftCount = ""

if mw.title.getCurrentTitle.text:match("Tower Challenge") then maxMS = 5 befCount = "" aftCount = " Points" end

for i = 1, maxMS do		table.insert(tOut, "!") table.insert(tRew, "|") if ms[i] then table.insert(tOut, befCount) table.insert(tOut, "'''") table.insert(tOut, ms[i].count) table.insert(tOut, aftCount) table.insert(tOut, "'''")

for rNo, rData in ipairs(ms[i]) do				if rNo > 1 then table.insert(tRew, " ") end table.insert(tRew, oneItem(rData[1], rData[2], true)) end end table.insert(tOut, "\n") table.insert(tRew, "\n") end return table.concat(tOut) .. table.concat(tRew) .. "|}" end

local function lbTable local tOut = {'|-|Leaderboards=\n', '{| class="article-table dmk-leaderboard" style="width: 100%;"\n', '! style="width: 1%"|Rank\n! colspan="4"|Rewards\n', }

local prevRange = 0

for lbNo, lbData in ipairs(lb) do		table.insert(tOut, "|-\n| nowrap|") table.insert(tOut, util.th_comma(prevRange + 1)) table.insert(tOut, "-") prevRange = lbData.range table.insert(tOut, util.th_comma(prevRange)) table.insert(tOut, "\n") for idx= 1, 4 do			table.insert(tOut, "|") mw.log(idx, lbData[idx]) if lbData[idx] then if string.match(lbData[idx], "^[%d%,]+$") then if prize[idx] then table.insert(tOut, oneItem(prize[idx], lbData[idx], lbNo == 1)) end else table.insert(tOut, oneItem(lbData[idx], "1", true)) end end table.insert(tOut, "\n") end end

return table.concat(tOut) .. "|}" end

local function chTable local tHead = {'|-|Character Tasks=\n', '{| class="article-table" style="width: 100%;"\n', }	local tRow = {"|-\n"}

for chNo, chData in ipairs(ch) do table.insert(tHead, "! width=\"10%\"|Character\n!Time\n") table.insert(tRow, "| align=\"center\"|") mw.log(chData[1]) table.insert(tRow, ICON({chData[1]})) table.insert(tRow, "\n|") table.insert(tRow, chData[2]) table.insert(tRow, "\n") end

if tArgs.TOK then table.insert(tHead, "! width=\"20%\"|Requirements\n") table.insert(tRow, "|") table.insert(tRow, TOK({tArgs.TOK})) table.insert(tRow, "\n") end return table.concat(tHead) .. table.concat(tRow) .. "|}" end

function p.getTables(frame) processArgs(frame)

iconSize = tArgs.iconsize or "30" local allTables = {}

if ch[1] then table.insert(allTables, chTable) end

if ms[1] then table.insert(allTables, msTable) end

if lb[1] then table.insert(allTables, lbTable) end

return table.concat(allTables) end

return p