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 meData = mw.loadData("Module:MiniEvent/data") local util = require("Module:Utility") local EC = require("Module:EC").getEC local CHEST = require("Module:EnchantedChest").getChest local TOK = require("Module:CharacterToken").getToken local ICON = require("Module:CharacterAvatar").getAvatar local NPC = require("Module:NPC")

local tArgs = {}

-- LB Prizes local prize = {} local lb   = {} local lbA  = {} local lbV  = {} -- alternate LB ranking table. (uses the same prizes/counts) local alb  = {} local ms   = {} local msA  = {} local msV  = {} local ch   = {}

local meName = "" local altStr = "

If already unlocked: "

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 albItems(inStr) local tIn = mw.text.split(inStr, "%s*%$%s*") local tOut = {} for i, v in ipairs(tIn) do		tOut[i] = tonumber((string.gsub(tIn[i], "[%,]", ""))) or 0 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 do		local tt = mw.text.split(tIn[idx], "%s*#%s*") if not tt[2] or tt[2] == "" then tt[2] = 1 end table.insert(tOut, tt) 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)

meName = tArgs.mename or mw.title.getCurrentTitle.baseText meName = mw.text.decode(meName, false) :gsub("^%s*(.-)%s*$", "%1") :lower :gsub("%s*mini event$", "")

-- 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		-- Prize / Reward Counts 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) elseif cat == "alb" then -- alternate LB rankings alb[num] = albItems(value) end end -- Alternate Prize/Reward cat, n = tostring(arg):match('^(%a+)([1-9]%d*)A$') num = tonumber(n) if num then if cat == "lb" then lbA[num] = lbItems(value) elseif cat == "ms" then msA[num] = msItems(value) end end -- Valued At ?? cat, n = tostring(arg):match('^(%a+)([1-9]%d*)V$') num = tonumber(n) if num then if cat == "lb" then lbV[num] = lbItems(value) elseif cat == "ms" then msV[num] = msItems(value) end end end end

local function oneItem(item, count, withName) local nCount = tonumber((string.gsub(count or "", "[,]", ""))) or 0 --skip item if count = 0 if nCount == 0 then return "" end

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

local tItem = {"", " " .. util.th_comma(nCount), (withName and " " or ""), "", "",			(withName and " " or ""), }

local iData = cData.Items[item]

if item:match(" Chests") then tItem[1] = CHEST({item, 30}) if withName then tItem[4] = CHEST({item, "L"}) if nCount > 1 then tItem[5] = "s" end end elseif iData and iData[2] then local fname = item:lower:gsub("[':%,%.]", ""):gsub(" ", "_") if iData[2] == "pf" then fname = fname:gsub("_float$", "") else fname = fname:gsub("^([^%(]-)_*%(([^%(]-)%)$", "%1-%2") end

tItem[1] = table.concat({""					})

if withName then tItem[4] = "" .. item.. "" end tItem[2] = "" elseif item:match("^EC") then tItem[1] = EC({item, nil, nil, nil, 30}) if withName then tItem[4] = EC({item, "L", S=(nCount == 1)}) end else tItem[1] = TOK({item, 35}) if withName then tItem[4] = TOK({item, "L"}) if nCount > 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 = "" local aftCount = ""

if meName:match("tower challenge") then maxMS = 5 aftCount = " Points" else if meData[meName] and meData[meName].NPC then befCount = NPC.getNPC({meData[meName].NPC, "", "", 30, tArgs.npcver}) end end

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

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			if msA[i] then				table.insert(tRew, altStr)				for rNo, rData in ipairs(msA[i]) do					if rNo > 1 then table.insert(tRew, "

") end					table.insert(tRew, oneItem(rData[1], rData[2], true))				end			elseif msV[i] then				table.insert(tRew, " (Valued at ")				local vData = msV[i][1]				local iSize = 30 * 0.6				table.insert(tRew, EC({vData[1], nil, nil, nil, iSize}))				table.insert(tRew, util.th_comma(vData[2]))				table.insert(tRew, ") ")			end		end		table.insert(tOut, "\n")		table.insert(tRew, "\n")	end	return table.concat(tOut) .. table.concat(tRew) .. "|}\n" end

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

local useAlt = nil if type(altRank) == "number" and alb[altRank] then useAlt = alb[altRank] tOut[2] = " (Alternate"		tOut[5] = ")" if #alb > 1 then tOut[3] = " " tOut[4] = tostring(altRank) end end

local prevRange = 0 local prevPrize = {}

for lbNo, lbData in ipairs(lb) do		table.insert(tOut, "|-\n| nowrap|") table.insert(tOut, util.th_comma(prevRange + 1)) table.insert(tOut, "-") if type(useAlt) == "table" then prevRange = useAlt[lbNo] else prevRange = lbData.range end table.insert(tOut, util.th_comma(prevRange)) table.insert(tOut, "\n") for idx= 1, 4 do			table.insert(tOut, "|") if lbData[idx] then local iName = prize[idx] local iCount = string.match(lbData[idx], "^[%d%,]*$") if not iCount then iName, iCount = string.match(lbData[idx], "^([^#]-)%s*#*%s*([%d%,]*)$") if iCount == "" then iCount = "1" end end if iCount == "" then iCount = "0" end if iName then table.insert(tOut, oneItem(iName, iCount, iName ~= prevPrize[idx])) end prize[idx]    = iName prevPrize[idx] = iName end if lbA[lbNo] and lbA[lbNo][idx] then local lbAData = lbA[lbNo] local iName, iCount = string.match(lbAData[idx], "^([^#]-)%s*#*%s*([%d%,]*)$") if iCount == "" then iCount = "1" end if iName and iName ~= "" then table.insert(tOut, altStr) table.insert(tOut, oneItem(iName, iCount, true)) end elseif lbV[lbNo] and lbV[lbNo][idx] then local lbVData = lbV[lbNo] local iName, iCount = string.match(lbVData[idx], "^([^#]-)%s*#*%s*([%d%,]*)$") if iCount == "" then iCount = "1" end if iName and iName ~= "" then table.insert(tOut, " (Valued at ")					local iSize = 30 * 0.6					table.insert(tOut, EC({iName, nil, nil, nil, iSize}))					table.insert(tOut, util.th_comma(iCount))					table.insert(tOut, ") ") end end table.insert(tOut, "\n") end end

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

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

for chNo, chData in ipairs(ch) do table.insert(tHead, "! style=\"width: 10%; text-align: center;\"|Character\n! style=\"text-align: center;\"|Time\n") table.insert(tRow, "| style=\"text-align: center;\"|") table.insert(tRow, ICON({chData[1]})) table.insert(tRow, " ")		table.insert(tRow, chData[1])		table.insert(tRow, " \n| style=\"text-align: center; border-right: 1px solid #cbcbcb;\"|") table.insert(tRow, chData[2]) table.insert(tRow, "\n") end

local npcName if meData[meName] then npcName = meData[meName].NPC end

if npcName and tArgs.TOK then local tokens = tArgs.TOK local t1Count, t2Count = tokens:match("^%s*([%d%?]+)%s*%$%s*([%d%?]+)%s*$") if t1Count then tokens = npcName .. ",1," .. t1Count .. "$" .. npcName .. ",2," .. t2Count end

table.insert(tHead, "! width=\"20%\"|Requirements\n") table.insert(tRow, "|") table.insert(tRow, TOK({tokens, "C"})) table.insert(tRow, "\n") end

return table.concat(tHead) .. table.concat(tRow) .. "|}\n" end

function p.getTables(frame) processArgs(frame)

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

for idx, data in ipairs(alb) do		table.insert(allTables, lbTable(idx)) end

return table.concat(allTables) end

return p