Module:LU

--[[ Lua script to get Character Level Ups Tables

getLU: get Character Level Ups Table based on input parameters Parameters: event = Event Name / IP Short Name (optional) cost = Building Cost (Legendary Chests by default) (optional) --]]

local p = {}

local util = require("Module:Utility") local ACT = require("Module:Activity").main local COLL = require("Module:ItemCollection").getCollection local LTE = require("Module:LTEvent").getLTE local EC = require("Module:EC").getEC local TOK = require("Module:CharacterToken").getToken local CHEST = require("Module:ECR").getITEM

local lu   = {} local pagename = ""

local function oneItem(item, count, withName, colspan) local nCount = tonumber((string.gsub(count or "", "[,]", ""))) if not nCount then return (colspan and "" or '| style="width: 15%;"|') end

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

if nCount == 0 then tItem[3] = " ?" end if not colspan then tItem[1] = '| style="width: 15%;"|' end

if item:match(" Chests") then return require("Module:EnchantedChest").getChest({item, "O"}) elseif item:match("^EC") then tItem[2] = EC({item}) if withName then tItem[5] = EC({item, "L", S=(nCount == 1)}) end else tItem[2] = TOK({item}) if withName then tItem[5] = TOK({item, "L"}) if nCount ~= 1 then tItem[6] = "s" end end end

return table.concat(tItem) end

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

return tOut end

local function luTable(tableData, tableNo) local time = {"Instant", "36s", "6m", "35m", "60m", "2h", "4h", "8h", "16h", "24h"} local gems = {"", "1", "1", "1", "2", "2", "3", "3", "3", "5"} local xp  = {"", "10", "12", "14", "17", "20", "23", "26", "29", "30"} local title = "" local tabName = "" local eName = "" local eType = ""

local prevToken = {} local collection = COLL({pagename, "S"}) local token = {("IP-" .. collection:upper), (pagename .. ",2"), (pagename .. ",3"), "EC-Magic"}

if tableNo and lu[tableNo]["name"] then eName = lu[tableNo]["name"][1] eType = lu[tableNo]["name"][2] or "N" if LTE({eName, eType}) == "Unknown Event 0001" then title = '! colspan="7" style="text-align: center;"|' .. eName .. '\n|-\n' tabName = " (" .. eName .. ")" else title = '! colspan="7" style="text-align: center;"|' .. LTE({eName, eType}) .. '\n|-\n' if eType == "T" then token[4] = "EC-TTC" else token[4] = "EC-" .. eName end tabName = LTE({eName:lower, eType, "K"}) tabName = " (" .. tabName .. " Event)" end end

local tOut = { --			'\n|-| Level Ups', tabName, '=\n', '{| class="article-table" style="width: 100%; text-align: center; line-height: 1.0;"\n', title, '! style="width: 10%; text-align: center;"|Level\n', '! style="text-align: center;" colspan="4"|Requirements\n', '! style="width: 5%; text-align: center;"|Time\n', '! style="width: 10%; text-align: center;"|Rewards\n' }

for luNo, luData in ipairs(tableData) do local tRow = {'|-\n', '| nowrap|', ("Level " .. luNo), '\n', "", "", "", "", '|', (luData[5] or time[luNo]), '\n', '| nowrap|', EC({"Gems"}), (luData[6] or gems[luNo]), ', ', EC({"XP"}), (luData[7] or xp[luNo]), '\n', }

if luNo == 1 then tRow[3] = "Welcome" tRow[13] = "" tRow[14] = "" tRow[15] = "" tRow[16] = "" tRow[17] = "" end

if luNo == 2 and eName ~= "" and eType == "N" then tRow[10] = "6s" end

for idx = 1, 4 do			if luNo == 1 and not luData[idx + 1] then local iName, iCount = string.match((luData[1] or ""), "^([^#]-)%s*#*%s*([%d%,]*)$") tRow[5] = '| colspan="4"|' if eName == "" then tRow[6] = CHEST({"L"}) end if iCount == "" and iName ~= "" then tRow[7] = luData[1] else tRow[7] = oneItem(iName, iCount, true, true) end tRow[8] = '\n' else local iName = token[idx] local iCount = string.match(luData[idx], "^[%d%,]*$") if not iCount then iName, iCount = string.match(luData[idx], "^([^#]-)%s*#*%s*([%d%,]*)$") if iCount == "" then iCount = "1" end end tRow[4 + idx] = oneItem(iName, iCount, iName ~= prevToken[idx]) .. '\n' if iCount ~= "" then token[idx]    = iName prevToken[idx] = iName end end end

table.insert(tOut, table.concat(tRow)) end

table.insert(tOut, '|}\n')

return table.concat(tOut) end

function p.getLU(frame) local tArgs = util.getArgs(frame)

pagename = tArgs["name"] or mw.title.getCurrentTitle.text

if tArgs["cost"] then tArgs["lu1"] = tArgs["cost"] end if tArgs["event"] or tArgs["title"] then tArgs["luN1"] = (tArgs["event"] or tArgs["title"]) end

local onetable = {}

lu[1] =

for arg, value in pairs(tArgs) do		local cat, t, n = tostring(arg):match('^(%a+)([1-9]-)_?([1-9]%d*)$') local num = tonumber(n) local tNo = tonumber(t) or 1 if num then if cat == "lu" then if not lu[tNo] then lu[tNo] = {} end lu[tNo][num] = luItems(value, pagename) elseif cat == "luN" then if not lu[num] then lu[num] = {} end lu[num]["name"] = mw.text.split(value, "%s*%$%s*") elseif cat == "luA" then onetable = {num, tonumber(value)} end end end

if table.concat(onetable) ~= "" then lu[onetable[2]] = lu[onetable[1]] lu[onetable[1]] = nil end

local allTables = {}

if lu[1] then for tNo, tData in ipairs(lu) do			table.insert(allTables, luTable(tData, tNo)) end --		table.insert(allTables, 2, ('\n|-| Activities=\n' .. ACT({pagename, display="character"}))) --		table.insert(allTables, 3, ('\n|-| Event Activities=\n' .. ACT({pagename, display="characterEvent"}))) end

return table.concat(allTables) end

return p