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) for v in mw.text.gsplit(characters, "%s*%$%$%s*") do		if not tChar[eName] then tChar[eName] = {} end table.insert(tChar[eName], 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 = {"1", "1", "1"} local tOut = {"", "", ""} local tChap = {}

for k, v in pairs(meData) do		if k:match("^ttc ") and pagename == v["Name"] then local i = 1 repeat if v[i] and v[i]["C"] then getCharChapter(v[i]["C"], ("Chapter " .. i)) end if v[i] and v[i]["F"] then tRefresh[i] = v[i]["F"] end i = i + 1 until i == 4 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}), tRefresh[chapter], ") \n", }

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

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

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

for i, cName in ipairs(mw.text.split(v, "%s*%$%s*")) do tCh[i] = tCh[i] .. ICON({cName}) .. ' ' .. cName .. ' ' end

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

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

if tArgs[chapter] then table.insert(tChap, (": Note: ''" .. 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 charCell(charData) local iDisp = (charData[1] or "?"):gsub("^([^%(]-)%/([^%(]-)$", "%2") iDisp = mw.ustring.gsub(iDisp, "^([^%(]-) *%(([^%(]-)%)", "%1")

return table.concat({'| colspan="2" style="width: 18%;"|',		ICON({(charData[1] or "?")}),		' ',		iDisp,		' "',		(charData[5] or "?"),		'" \n'}) end

local rTotal = 0

local function timeCell(timeData) rTotal = rTotal + (timeData[4] or "0") return table.concat({'|', 		(timeData[3] or "?h"), 		'\n|', 		TOK({"Refresh", 25}),		(timeData[4] or "?"), 		'\n'}) end

local function expTable(tData, tNo, note) local tRefresh = { [1] = {"8", "6"},			[2] = {"10", "8"},			[3] = {"12", "10"},			}

rTotal = tRefresh[tNo][1]*4 + tRefresh[tNo][2]*5

local l = -1 + (2 * tNo)

local tOut = {'|-|Chapter ', tNo, '=\n', '{| class="article-table dmk-explorations" style="width: 100%"\n', '! colspan="11"|Explorations (All Characters Level ', l, ') \n', '|-\n', charCell(tData[1]), charCell(tData[2]), charCell(tData[3]), charCell(tData[4]), charCell(tData[5]), '! rowspan="2"|', TOK({"Refresh", 40}), tRefresh[tNo][1], '\n|-\n', timeCell(tData[1]), timeCell(tData[2]), timeCell(tData[3]), timeCell(tData[4]), timeCell(tData[5]), '|-\n', charCell(tData[6]), charCell(tData[7]), charCell(tData[8]), charCell(tData[9]), charCell(tData[10]), '! rowspan="2"|', TOK({"Refresh", 40}), tRefresh[tNo][1], '\n|-\n', timeCell(tData[6]), timeCell(tData[7]), timeCell(tData[8]), timeCell(tData[9]), timeCell(tData[10]), '|-\n', charCell(tData[11]), charCell(tData[12]), charCell(tData[13]), charCell(tData[14]), charCell(tData[15]), '! rowspan="2"|', TOK({"Refresh", 40}), tRefresh[tNo][1], '\n|-\n', timeCell(tData[11]), timeCell(tData[12]), timeCell(tData[13]), timeCell(tData[14]), timeCell(tData[15]), '|-\n', charCell(tData[16]), charCell(tData[17]), charCell(tData[18]), charCell(tData[19]), charCell(tData[20]), '! rowspan="2"|', TOK({"Refresh", 40}), tRefresh[tNo][1], '\n|-\n', timeCell(tData[16]), timeCell(tData[17]), timeCell(tData[18]), timeCell(tData[19]), timeCell(tData[20]), '|-\n', '! colspan="2"|', TOK({"Refresh", 40}), tRefresh[tNo][2], '\n', '! colspan="2"|', TOK({"Refresh", 40}), tRefresh[tNo][2], '\n', '! colspan="2"|', TOK({"Refresh", 40}), tRefresh[tNo][2], '\n', '! colspan="2"|', TOK({"Refresh", 40}), tRefresh[tNo][2], '\n', '! colspan="2"|', TOK({"Refresh", 40}), tRefresh[tNo][2], '\n', '! colspan="2"| Total: ', TOK({"Refresh", 35}), rTotal }

return table.concat(tOut) .. "\n|}\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