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) lu1  = lu2  = lu3  = --]]

local p = {}

local util = require("Module:Utility") 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 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 function luItems(inStr) local tIn = mw.text.split(inStr, "%s*%$%s*") local tOut = {} for idx = 1, #tIn do		table.insert(tOut, tIn[idx]) end return tOut end

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

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

if nCount == 0 then tItem[3] = " ?" end

if item:match("^EC") then if not colspan then tItem[1] = '| style="width: 15%;"|' end tItem[2] = EC({item}) if withName then tItem[5] = EC({item, "L", S=(nCount == 1)}) end else if not colspan then tItem[1] = '| style="width: 13%;"|' end tItem[2] = TOK({item, "C"}) if withName then tItem[5] = TOK({item, "L"}) if nCount > 1 then tItem[6] = "s" end end end

return table.concat(tItem) end

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

local token = {} local lu   = {}

local pagename = tArgs["name"] or mw.title.getCurrentTitle.text local collection = COLL({pagename, "S"}) local lu   = {}

token = {("IP-" .. collection), (pagename .. ",2"), (pagename .. ",3"), "EC-Magic"}

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 == "lu" then lu[num] = luItems(value) end end end

local colspan = false local chest = ""

if not lu[1] or lu[1] == "" then if not tArgs["event"] then chest = CHEST({"L"}) end local cost = "" cost = tArgs["cost"] or "" lu[1] = {cost} colspan = true end

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

local event = {"", ""}

if tArgs["event"] then local eName, eType = mw.ustring.match(tArgs["event"], "^(.-)%s*$%s*(.-)$") event = {(eName or tArgs["event"]), (eType or "N")} tOut[2] = '! colspan="7" style="text-align: center;"|' .. LTE({event[1], event[2]}) .. '\n|-\n' elseif tArgs["title"] then tOut[2] = '! colspan="7" style="text-align: center;"|' .. tArgs["title"] .. '\n|-\n' end

local prevToken = {}

for luNo, luData in ipairs(lu) do		table.insert(tOut, "|-\n| nowrap|") if luNo == 1 then table.insert(tOut, "Welcome") else table.insert(tOut, table.concat{"Level ", luNo}) end table.insert(tOut, "\n")

if colspan == true and luNo == 1 then table.insert(tOut, '| colspan="4"|') table.insert(tOut, chest) local iName, iCount = string.match(luData[1], "^([^#]-)%s*#*%s*([%d%,]*)$") if not iCount or iCount == "" then table.insert(tOut, luData[1]) else table.insert(tOut, oneItem(iName, iCount, true, colspan)) end table.insert(tOut, '\n|Instant\n| nowrap|\n') else for idx = 1, 7 do				if idx == 5 then table.insert(tOut, "| ") if luNo == 2 and event[1] ~= "" and event[2] == "N" then table.insert(tOut, (luData[idx] or "6s")) else table.insert(tOut, (luData[idx] or time[luNo])) end table.insert(tOut, "\n") elseif idx == 6 then table.insert(tOut, "| nowrap|") if luNo ~= 1 then table.insert(tOut, EC({"Gems"})) table.insert(tOut, (luData[idx] or gems[luNo])) else table.insert(tOut, "") end elseif idx == 7 then if luNo ~= 1 then table.insert(tOut, ", ") table.insert(tOut, EC({"XP"})) table.insert(tOut, (luData[idx] or xp[luNo])) end table.insert(tOut, "\n") elseif luData[idx] then 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 if iCount == "" then table.insert(tOut, oneItem(iName, iCount, iName ~= prevToken[idx])) else table.insert(tOut, oneItem(iName, iCount, iName ~= prevToken[idx])) token[idx]    = iName prevToken[idx] = iName end table.insert(tOut, "\n") end end end end

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

return p