Module:METables

--[[ Lua script to get Mini Event Tables

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

local p = {}

local meData = mw.loadData("Module:MiniEvent/data") local util = require("Module:Utility") local oneItem = require("Module:MultiItems").getOneItem local ME = require("Module:MiniEvent").getME local EC = require("Module:EC").getEC local NPC = require("Module:NPC").getNPC

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 gt   = {} local gc   = {} local ac   = {}

local eName = nil local eNumb = nil 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)

local mename = tArgs.mename if not mename then mename = "Unknown #1" end

eName, eNumb = mw.ustring.match(mename, "^([^,]-)%s*#%s*([%/%,%d%?%-]*)$") if not eName then eName = tArgs.mename end if not eNumb then eNumb = "1" end eName = eName:lower

-- 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[arg] = value ch[1] = true elseif cat == "tok" then ch[arg] = value elseif cat == "gt" then gt[num] = value elseif cat == "gc" then gc[num] = value elseif cat == "ac" then local conv = {"Common", "Uncommon", "Rare", "Epic", "Legendary"} if num <= 5 then if not ac["R"] then ac["R"] = {} end ac["R"][conv[num]] = value elseif num == 10 then if not ac["S"] then ac["S"] = {} end ac["S"][1] = value elseif num > 10 and num <= 15 then if not ac["S"] then ac["S"] = {} end ac["S"][conv[num-10]] = value end 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 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 eName:match("ttc ") then maxMS = 5 aftCount = " Points" else if meData[eName] and meData[eName].NPC then befCount = NPC({meData[eName].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], nil, 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], nil, 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, nil, 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, nil, 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

function p.getTables(frame) processArgs(frame)

local allTables = {}

if ch[1] then local NPCTable = require("Module:NPCTables").getTables local npcName if meData[eName] then npcName = meData[eName].NPC end ch["npcname"] = npcName table.insert(allTables, NPCTable(ch)) end

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

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

if gt[1] or gc[1] then local BUILD = require("Module:Building").building local actGold = {'|-|Gold ', (gc[1] and "Coins" or "Trophies"), '=\n', '{| style="width:100%;"\n', '| style="width:50%; vertical-align: top;"|\n', '==Character Activities==\n', '{| class="article-table act" style="width: 100%;"\n', '! width="1"|Character\n', '! width="100%"|Activity\n', '! style="text-align: center;" width="1" nowrap|+\n', '! width="5%"|Time\n', (gt[1] or gc[1] or ""), '\n|}\n| style="width:50%; vertical-align: top;"|\n', '==Attraction Activities==\n', '{| class="article-table act" style="width: 100%;"\n', '! width="1"|Attraction\n', '! width="100%"|Activity\n', '! style="text-align: center;" width="1" nowrap|\n', '! width="5%"|Time\n', BUILD({(gt[2] or gc[2] or ""), "0", (meData[eName][tonumber(eNumb)][3] or nil), "ME"}), '\n|}\n|}\n'} table.insert(allTables, table.concat(actGold)) end

if ac["R"] then local ECR = require("Module:ECR").getPrizeTable table.insert(allTables, '|-|Ad Chest Prizes=\n') table.insert(allTables, ECR(ac)) end

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

return table.concat(allTables) end

return p