Module:SeasonTables

--[[ Lua script to get Mini Event Tables

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

local p = {}

local cData = mw.loadData("Module:ItemCollection/data") local util = require("Module:Utility") local EC = require("Module:EC").getEC local CHEST = require("Module:EnchantedChest").getChest local LTE = require("Module:LTEvent").getLTE local TOK = require("Module:CharacterToken").getToken

local tArgs = {}

-- LB Prizes local prize = {} local sp   = {} local spA  = {} local dt   = {} local wt   = {} local et   = {}

local meName = "" local altStr = "

If already unlocked: "

local function getItems(inStr) local tIn = mw.text.split(inStr, "%s*%$%s*") local tOut = {tIn[1], tIn[2], tIn[3]} return tOut end

local function processArgs(frame) tArgs = util.getArgs(frame)

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 == "sp" then sp[num] = getItems(value) elseif cat == "dt" then dt[num] = getItems(value) elseif cat == "wt" then wt[num] = getItems(value) elseif cat == "et" then et[num] = getItems(value) end end -- Alternate Prize/Reward cat, n = tostring(arg):match('^(%a+)([1-9]%d*)A$') num = tonumber(n) if num then if cat == "sp" then spA[num] = getItems(value) end end end end

local function oneItem(item, count) local nCount = tonumber((string.gsub(count or "", "[,]", ""))) or 0 --skip item if count = 0 if nCount == 0 then return "" end

local conv = { ["ch"] = "cp", ["cos"] = "cp", }

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

local iData = cData.Items[item]

if item:match(" Chests") then tItem[1] = CHEST({item, 40}) tItem[4] = CHEST({item, "L"}) if nCount > 1 then tItem[5] = "s" end elseif iData and iData[2] then local iDisp = item:gsub("^([^%(]-)%/([^%(]-)$", "%2") local fname = item:lower:gsub("[':%,%.]", ""):gsub(" ", "_") if iData[2] == "pf" then fname = fname:gsub("_float$", "") else fname = fname:gsub("^([^%(]-)%/([^%(]-)$", "%1-%2") end tItem[1] = table.concat({""					}) if cData["Items"][item]["C"] and cData["Categories"][cData["Items"][item]["C"]] then local category = cData["Items"][item]["C"] tItem[1] = ' ' .. tItem[1] .. '  '			tItem[3] = ' ' end

tItem[2] = "" tItem[4] = "" .. (iDisp or item) .. "" elseif item:match("^EC") then tItem[1] = EC({item, nil, nil, "E", 40}) tItem[4] = EC({item, "L", S=(nCount == 1)}) else tItem[1] = TOK({item, 40}) tItem[4] = TOK({item, "L"}) if nCount > 1 then tItem[5] = "s" end end

return table.concat(tItem) end

local function spTable local tOut = {'|-|Season Pass=\n', '{| class="article-table" style="width: 100%; text-align: center; line-height: 1.0;"\n', '! style="text-align: center;"|Tier\n', '! style="text-align: center; width: 20%;"|Happiness Required\n', '! style="text-align: center; width: 25%; background-color: #afc3de;"|Free Pass \n', '! style="text-align: center; width: 25%; background-color: #ffd10d;"|Kingdom Pass \n', '! style="text-align: center; width: 20%;"|Skip Cost (',			EC({"Happiness"}),			'10 = ',			EC({"Gems"}),			'1)\n', }

for spNo, spData in ipairs(sp) do		table.insert(tOut, '|-\n| nowrap|') if not sp[spNo + 1] then table.insert(tOut, '  ∞   ') else table.insert(tOut, (spNo - 1)) end table.insert(tOut, '\n| nowrap|') if not sp[spNo + 1] then table.insert(tOut, 'Every ') end table.insert(tOut, EC({"Happiness"})) table.insert(tOut, spData[1])

for idx=2, 3 do			if idx == 3 then table.insert(tOut, '\n| style="background-color: #ffd10d7a;"|') else table.insert(tOut, '\n| style="background-color: #afc3de87;"|') end if spData[idx] then local iName, iCount = string.match(spData[idx], "^([^#]-)%s*#*%s*([%d%,]*)$") if iCount == "" then iCount = "1" end if iName and iName ~= "" then table.insert(tOut, oneItem(iName, iCount)) end end if spA[spNo] and spA[spNo][idx] then local spAData = spA[spNo] local iName, iCount = string.match(spAData[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)) end end end table.insert(tOut, '\n|') if spNo ~= 1 and sp[spNo + 1] then table.insert(tOut, ' nowrap|± ') table.insert(tOut, EC({"Gems"})) table.insert(tOut, math.ceil(spData[1] * 0.1)) end table.insert(tOut, "\n") end

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

local function taskTable(name, data) local tOut = {'|-|', name, ' Tasks=\n', '{| class="article-table act sortable" style="width: 100%;"\n', '! style="text-align: center; width: 10%"|\n', '! class="unsortable" style="text-align: center;"|', name, ' Tasks', '', '\n', '! style="text-align: center; width: 10%;"|Rewards\n', }

if name == "Daily" then tOut[9] = " " elseif name == "Weekly" then tOut[9] = " " else tOut[9] = " " end

local taskImages = { ["act"] = "", ["pf"] = "", ["ec"] = "", ["magic"] = "", ["mc"] = "", ["wish"] = "", ["dt"] = "", }

for taskNo, taskData in ipairs(data) do		table.insert(tOut, '|-\n| ') if name == "Event" then local eType = "N" if taskData[1]:match("^TTC .+$") then taskData[1] = taskData[1]:match("^TTC (.+)$") eType = "T" end table.insert(tOut, LTE({taskData[1], eType, "I"})) elseif taskData[1] and taskData[1] ~= "" then table.insert(tOut, taskImages[taskData[1]] or "") end table.insert(tOut, " \n|") table.insert(tOut, taskData[2] or "?") table.insert(tOut, "\n|") table.insert(tOut, EC({"Happiness"})) table.insert(tOut, taskData[3] or "?") table.insert(tOut, "\n") end

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

function p.getTables(frame) processArgs(frame)

local allTables = {}

if sp[1] then table.insert(allTables, spTable) end

if dt[1] then table.insert(allTables, taskTable("Daily", dt)) end

if wt[1] then table.insert(allTables, taskTable("Weekly", wt)) end

if et[1] then table.insert(allTables, taskTable("Event", et)) end

return table.concat(allTables) end

return p