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 ME = require("Module:MiniEvent").getME 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", nil, nil, nil, 20}),			'10 = ',			EC({"Gems", nil, nil, nil, 20}),			'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 sortable" style="width: 100%; text-align: center; line-height: 1.5;"\n', '! style="text-align: center; width: 1%;"|\n', '! class="unsortable" style="text-align: center;"|', name, ' Tasks', '', '\n', '! style="text-align: center; width: 17%;"|Rewards  (+10% Kingdom Pass) \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 taskData[1] = taskData[1]:lower if taskData[1]:match("^.+ #.+$") then local MEName, MENumb = taskData[1]:match("^(.+) #(.+)$") if not MEName then MEName = taskData[1] MENumb = "1" end table.insert(tOut, ME({MEName, MENumb, "I"})) elseif taskData[1]:match("^ttc .+$") then taskData[1] = taskData[1]:match("^ttc (.+)$") table.insert(tOut, LTE({taskData[1], "T", "I"})) else table.insert(tOut, LTE({taskData[1], "N", "I"})) end elseif taskData[1] and taskData[1] ~= "" then table.insert(tOut, taskImages[taskData[1]] or "") end table.insert(tOut, ' \n| style="text-align: left;"|') table.insert(tOut, taskData[2] or "?") table.insert(tOut, '\n|') table.insert(tOut, EC({"Happiness"})) if tonumber(taskData[3]) then table.insert(tOut, taskData[3]) table.insert(tOut, ' (+10%: ')			table.insert(tOut, EC({"Happiness", nil, nil, nil, 20}))			table.insert(tOut, math.ceil(taskData[3] * 1.1))			table.insert(tOut, ') ') else table.insert(tOut, "?") end 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