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 CHEST = require("Module:EnchantedChest").getChest local EC = require("Module:EC").getEC local TOK = require("Module:CharacterToken").getToken

local tArgs = {}

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

local function lbItems(inStr) local tIn = mw.text.split(inStr, "%s*%$%s*") local tOut = {} tOut.range = tIn[1] 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 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) end end end end

local function itemType(item) local iType = "Unknown Item" if cData.Items[item] and cData.Items[item][2] then iType = cData.Items[item][2] end return iType end

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

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

if iType == "Unknown Item" then if item:match("^EC") then table.insert(tItem, EC({item, nil, nil, nil, "30"})) else table.insert(tItem, TOK({item, "30"})) end elseif iType == "ec" then table.insert(tItem, CHEST({item, "30"})) else table.insert(tItem, table.concat({ "[[File:",					iType:gsub(".+", conv),					"-",					item:gsub("^([^%(]+)%s%(([^%d]+%d*)%)$", "%1-%2")						:lower:gsub("[':%,%.]", ""):gsub(" ", "_"),					".png|x30px|link=",					item,					(iType == "pf" and " Float" or ""),					"]]"				}			))  	end

if count > "1" then table.insert(tItem, " '''") table.insert(tItem, count) table.insert(tItem, "'''") end

if withName then table.insert(tItem, " ") local name = "" if iType == "Unknown Item" then if item:match("^EC") then name = EC({item, "L"}) else name = TOK({item, "L"}) end elseif iType == "ec" then name = CHEST({item, "L"}) else name = "" .. item:gsub("s$", "")  			end   			name = name .. "" end table.insert(tItem, name) if count > "1" and not name:match("[sS]%]%]$") then table.insert(tItem, "s") end table.insert(tItem, " ") 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', '|-\n! Rank\n! colspan="4"|Rewards\n', }

for lbNo, lbData in ipairs(lb) do		table.insert(tOut, "|-\n|") table.insert(tOut, lbData.range) 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

function p.getTables(frame) processArgs(frame)

local allTables = {}

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