Module:TTCTables

-- Lua script to get The Tower Challenges Tables --

local p = {}

local util = require("Module:Utility") local COLL = require('Module:ItemCollection').getCollection local ICON = require("Module:CharacterAvatar").getAvatar local TOK = require("Module:CharacterToken").getToken

local tChar = {}

local function getCharChapter(characters, eName, type) for v in mw.text.gsplit(characters, "%s*%$%$%s*") do		if not tChar[eName] then tChar[eName] = {} end if not tChar[eName][type] then tChar[eName][type] = {} end table.insert(tChar[eName][type], v)	end end

function p.getCharacters(frame) local meData = mw.loadData('Module:MiniEvent/data') local tArgs = util.getArgs(frame)

local pagename = tArgs["P"] or mw.title.getCurrentTitle.baseText local tRefresh = {"3", "?", "?"} local tOut = {"", "", ""} local tChap = {}

for k, v in pairs(meData) do		if k:match("^ttc ") and pagename == v["Name"] then if v[1] and v[1]["C"] then getCharChapter(v[1]["C"], "Chapter 1", "C") end if v[2] and v[2]["C"] then getCharChapter(v[2]["C"], "Chapter 2", "C") end if v[3] and v[3]["C"] then getCharChapter(v[3]["C"], "Chapter 3", "C") end

if v[1] and v[1]["F"] then getCharChapter(v[1]["F"], "Chapter 1", "F") end if v[2] and v[2]["F"] then getCharChapter(v[2]["F"], "Chapter 2", "F") end if v[3] and v[3]["F"] then getCharChapter(v[3]["F"], "Chapter 3", "F") end end end

for chapter, data in pairs(tChar) do		chapter = chapter:gsub("Chapter ", "") chapter = tonumber(chapter)

tChap = {'|-|Chapter ', chapter, '=\n', '{| class="article-table" style="width: 100%; text-align: center; line-height: 1.0;"\n', '! style="text-align: center; width: 20%;"|Collections\n', '! colspan="6"|Characters', " (Refresh Cost: ", TOK({"Refresh", 25}) .. (data["F"] and tRefresh[chapter] or "1"), ") \n", '!', (data["F"] and ' style="text-align: center; width: 1%;"|Favorite Collection\n' or '\n') }

for k, v in pairs(data["C"]) do table.insert(tChap, '|-\n! style="text-align: center;"|')

if k == 5 then table.insert(tChap, "Featured Character\n") else table.insert(tChap, COLL({v, 45}) .. '\n') end

local tCh = {'| style="width: 12%;"|\n', '| style="width: 12%;"|\n', '| style="width: 12%;"|\n', '| style="width: 12%;"|\n', '| style="width: 12%;"|\n', '| style="width: 12%;"|\n', '| style="width: 12%;"|\n'}

for i, cName in ipairs(mw.text.split(v, "%s*%$%s*")) do tCh[i] = '| style="width: 12%;"|' .. ICON({cName}) .. ' ' .. cName .. ' \n' end

if data["F"] and data["F"][k] then local tt = mw.text.split(data["F"][k], "%s*#%s*") if not tt[2] or tt[2] == "" then tt[2] = 1 end tCh[7] = '! style="text-align: center;"|' .. COLL({tt[1]:lower}) .. ' x' .. tt[2] .. '\n' end

table.insert(tChap, table.concat(tCh)) end

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

if tArgs[chapter] then table.insert(tChap, (tArgs[chapter] .. '\n')) end

tOut[chapter] = table.concat(tChap) end

return table.concat(tOut) end

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

local tOut = {	'{| class="article-table" style="width: 100%; text-align: center; line-height: 1.0;"\n', '! style="text-align: center; width: 14%;"|\n', '! style="text-align: center; width: 20%;"|Collections\n', '! colspan="6"|Attractions\n', '! style="text-align: center; width: 1%;"|Time' }

for k, v in pairs(tArgs) do		if tonumber(k) then

local tRow = {	'\n|-', '\n! style="text-align: center;"|', ' ', "Whole Event", ' ', '\n! style="text-align: center;"|', COLL({v, 45}), '\n| style="width: 10%;"|', '\n| style="width: 10%;"|', '\n| style="width: 10%;"|', '\n| style="width: 10%;"|', '\n| style="width: 10%;"|', '\n| style="width: 10%;"|', '\n! style="text-align: center;"|', "1h30", ,			,			,			,			,						}

if k == 3 or k == 4 then tRow[4] = 'Chapter ' .. (k - 1) elseif k == 5 then tRow[4] = 'Kingdom Pass ' end

local twoline = false

if not tArgs["A"] then for i, aName in ipairs(mw.text.split(v, "%s*%$%s*")) do					local aDisp = aName:gsub("^([^%(]-)%/([^%(]-)$", "%2") iDisp = mw.ustring.gsub(aDisp, "^([^%(]-) *%(([^%(]-)%)", "%1") local fname = aName:lower:gsub("[':%,%.]", ""):gsub(" ", "_") fname = mw.ustring.gsub(fname, "^([^%(]-)%/([^%(]-)$", "%1-%2") fname = mw.ustring.gsub(fname, "^([^%(]-) *%(([^%(]-)%)$", "%1_%2") fname = ""

if i > 6 then twoline = true tRow[16] = '\n|-\n| style="width: 10%;"|' tRow[17] = '\n| style="width: 10%;"|' tRow[18] = '\n| style="width: 10%;"|' tRow[19] = '\n| style="width: 10%;"|' tRow[20] = '\n| style="width: 10%;"|' tRow[21] = '\n| style="width: 10%;"|' tRow[i + 9] = tRow[i + 9] .. fname .. ' " .. aDisp .. ' ' else tRow[i + 7] = tRow[i + 7] .. fname .. ' " .. aDisp .. ' ' end end end

if twoline == true then tRow[2] = '\n! rowspan="2" style="text-align: center;"|' tRow[6] = '\n! rowspan="2" style="text-align: center;"|' tRow[14] = '\n! rowspan="2" style="text-align: center;"|' end

if k == 3 then tRow[15] = '60m' elseif k == 4 then tRow[15] = '45m' end

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

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

local exp = {}

local function expTable(tData, tNo, note) local tRefresh = { [1] = {"8", "6"},			[2] = {"10", "8"},			[3] = {"12", "10"},			}	local l = -1 + (2 * tNo) local tOut = {'|-|Chapter ', tNo, '=\n', '{| class="article-table" style="width: 100%; text-align: center; line-height: 1.0;"\n', '! style="text-align: center;" colspan="6"|Explorations (All Characters Level ', l, ') \n', }	local i = 1

for expNo, expData in pairs(tData) do		local iDisp = (expData[1] or "?"):gsub("^([^%(]-)%/([^%(]-)$", "%2") iDisp = mw.ustring.gsub(iDisp, "^([^%(]-) *%(([^%(]-)%)", "%1")

local tRow = {'', '| style="width: 18%;"|', ICON({(expData[1] or "?")}), " ',			iDisp,			" \"",			(expData[5] or "?"),			"\" '''", (expData[3] or "?h"), "''' ",			TOK({"Refresh", 25}), (expData[4] or "?"), "\n", }

if i == 1 then tRow[1] = '|-\n' elseif i == 5 then table.insert(tRow, '! style="text-align: center;"|' .. TOK({"Refresh", 40}) .. tRefresh[tNo][1] .. "\n") i = 0 end

i = i + 1

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

table.insert(tOut, '|-') table.insert(tOut, '\n! style="text-align: center;"|') table.insert(tOut, TOK({"Refresh", 40})) table.insert(tOut, tRefresh[tNo][2]) table.insert(tOut, '\n! style="text-align: center;"|') table.insert(tOut, TOK({"Refresh", 40})) table.insert(tOut, tRefresh[tNo][2]) table.insert(tOut, '\n! style="text-align: center;"|') table.insert(tOut, TOK({"Refresh", 40})) table.insert(tOut, tRefresh[tNo][2]) table.insert(tOut, '\n! style="text-align: center;"|') table.insert(tOut, TOK({"Refresh", 40})) table.insert(tOut, tRefresh[tNo][2]) table.insert(tOut, '\n! style="text-align: center;"|') table.insert(tOut, TOK({"Refresh", 40})) table.insert(tOut, tRefresh[tNo][2]) table.insert(tOut, '\n! style="text-align: center; width: 10%;"| Bonus Column/Row Completed \n')

return table.concat(tOut) .. "|}\n: Note: ''" .. note .. "''\n" end

function p.getExplorations(frame) local tArgs = util.getArgs(frame) local npc = {}

for arg, value in pairs(tArgs) do		local cat, c, n = tostring(arg):match('^(%a+)([1-9]-)_?([1-9]%d*)$') local num = tonumber(n) local cNo = tonumber(c) --Chapter Number within the Event if not cNo then cNo = 1 end if num and cat == "exp" then if not exp[cNo] then exp[cNo] = {} end exp[cNo][num] = mw.text.split(value, "%s*%$%s*") elseif arg ~= "1" then npc[2] = true npc[arg] = value end end

local allTables = {}

if exp[1] then for tNo, tData in ipairs(exp) do			table.insert(allTables, expTable(tData, tNo, (tArgs[1] or "?"))) end end

if npc[2] then local NPCTable = require("Module:METables").getTables table.insert(allTables, NPCTable(npc)) end

return table.concat(allTables) end

return p