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 NPC = require("Module:NPC").getNPC local TOK = require("Module:CharacterToken").getToken

local tArgs = {}

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

local meName = "" local altStr = "

If already unlocked: " local taskImages = {	["act"] = "",	["pf"] = "",	["ec"] = "",	["magic"] = "",	["mc"] = "",	["wish"] = "",	["dt"] = "", } local taskTypes = {	["act"] = {		["any"] = "Complete %1 Character Activities",		["time"] = "Complete %1 Activities of %2 or more.",		["char"] = "Complete %1 Activities with %2",		["coll"] = "Complete %1 Activities with Characters from %2",	},	["pf"] =  {		["any"]  = "Launch %1 Parades",		["coll"] = "Launch %1 Parades with Floats from %2",	},	["ec"] = {		["any"]  = "Open %1 Chests",		["hid"]  = "Find %1 Hidden Chests in the Park",		["type"] = "Open %1 %2 Chests",	},	["magic"] = {		["any"]  = "Gather  from Attractions %1 times",		["amount"] = "Gather %1  from %2",		["count"] = "Gather  %1 times from %2",	},	["mc"] = {		["any"]  = "Convert %1 items into  using Merlin's Cauldron", },	["wish"] = { ["any"] = "Collect %1 Wishes ", ["type"] = "Collect %1 %2 Wishes", },	["dt"] = { ["any"] = "Complete %1 Dailies", },	["ttc"] = { ["points"] = "Collect %1 ", },	["lte"] = { ["cur"] = "Collect %1 pieces of ", ["char"] = "Welcome %1 Characters from the ", ["qst"] = "Complete %1 quests from the ", },	["npc"] = { ["any"] = "Clear %1 %2", ["gt"] = "Collect %1 Gold Trophies", }, } local taskDefaults = { ["act"] = { ["char"] = "(3 Random Characters)", ["coll"] = "(3 Random Collections)", },	["pf"] = { ["coll"] = "(3 Random Collections)", },	["ec"] = { ["type"] = "Silver", },	["magic"] = { ["amount"] = "(3 Random Attractions)", ["count"] = "(3 Random Attractions)", },	["wish"] = { ["type"] = "Collect %1 %2 Wishes", }, }

local function kpHappiness(val) local kpVal = "?" local spVal = tonumber(val) if spVal then kpVal = math.floor((spVal * 1.1) + 0.5) else spVal = "?" end

local tHappy = {'', spVal, ' (',						kpVal,						') ' }	return table.concat(tHappy) end

local function split2text(inStr, subtype) local tList = mw.text.split(inStr, "%s*#%s*") local tOut = {} local joiner = "" for idx, val in ipairs(tList) do		table.insert(tOut, joiner) table.insert(tOut, "")				table.insert(tOut, cData["Collections"][cID][1])			end		else			table.insert(tOut, val)		end		table.insert(tOut, "") if joiner == "" then joiner = ", " else joiner = " or " end end return table.concat(tOut) end

local function getTaskText(task, subtype, p1, p2) local taskText = "" if not p1 or p1 == "" then p1 = "(##)" end if subtype ~= "any" then if p2 and p2 ~= "" then if (task == "act" and subtype ~= "time") or task == "pf" or task == "magic" then p2 = split2text(p2, subtype) end else if taskDefaults[task] and taskDefaults[task][subtype] then p2 = taskDefaults[task][subtype] end end end

if taskTypes[task] then if not subtype or not taskTypes[task][subtype] then subtype = "any" end taskText = taskTypes[task][subtype] end if taskText and taskText ~= "" then taskText = string.gsub(taskText, "%%1", p1) if p2 and p2 ~= "" then taskText = string.gsub(taskText, "%%2", p2) end end return taskText end

local function getItems(inStr) local tIn = mw.text.split(inStr, "%s*%$%s*") local tOut = { ["task"]  = string.lower(tIn[1]), ["type1"] = tIn[2], ["type2"] = tIn[3], ["reward"] = tIn[4], ["count"] = {unpack(tIn, 5)} }

if string.match(tOut.task, "^ttc%s") or			string.match(tOut.task, "^lte%s") then tOut.task, tOut.event = string.match(tOut.task, "^(.-)%s+(.+)$") end return tOut end

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

for arg, value in pairs(tArgs) do		-- Prize / Reward Counts local cat, e, n = tostring(arg):match('^(%a+)([1-9]-)_?([1-9]%d*)$') local num = tonumber(n) local eNo = tonumber(e) --Event Number within Season if not eNo then eNo = 1 end if num then if cat == "sp" then sp[num] = mw.text.split(value, "%s*%$%s*") elseif cat == "dt" then dt[num] = getItems(value) elseif cat == "wt" then wt[num] = getItems(value) elseif cat == "en" then en[num] = mw.text.split(value, "%s*%$%s*") elseif cat == "et" then if not et[eNo] then et[eNo] = {} end et[eNo][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 dmk-seasons" style="width: 100%; line-height: 1.0;"\n', '!Tier\n', '! style="width: 20%;"|Happiness Required\n', '! style="width: 25%; background-color: #afc3de;"|Free Pass \n', '! style="width: 25%; background-color: #ffd10d;"|Kingdom Pass \n', '! style="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!') 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, eventNo) local tOut = {} if name == "Weekly" then tOut = {'|-|Weekly Tasks=\n', '{| class="article-table dmk-seasons" style="width: 100%; line-height: 1.5;"\n', '! rowspan="3" style="width: 1%;"|\n', '! rowspan="3"|Weekly Tasks

(Each week 2 Tasks for each Reward Amount are randomly selected, for a total of 10 Tasks.)\n', '! colspan="5"|Rewards (+10% Kingdom Pass Bonus) \n', '|-\n', '! style="width: 1%;"|', kpHappiness(150), '\n', '! style="width: 1%;"|', kpHappiness(175), '\n', '! style="width: 1%;"|', kpHappiness(200), '\n', '! style="width: 1%;"|', kpHappiness(225), '\n', '! style=" width: 1%;"|', kpHappiness(250), '\n', '|-\n| colspan="5" |Value of \'\'\'##\'\'\'\n' }	else local tabName = name if name == "Event" and eventNo then if en[eventNo] then tabName = en[eventNo][1] end end tOut = {'|-|', tabName, ' Tasks=\n', '{| class="article-table dmk-seasons" style="width: 100%; line-height: 1.5;"\n', '! style="width: 1%;"|\n', '!', name, ' Tasks', '', '\n', '! style="width: 17%;"|Rewards (+10% Kingdom Pass Bonus) \n', }		if name == "Daily" then tOut[9] = " " else tOut[9] = " " end end

for taskNo, taskData in ipairs(data) do table.insert(tOut, '|-\n! ') if taskData.task and taskData.task ~= "" then if taskData.task == "ttc" then table.insert(tOut, LTE({taskData.event, "T", "I"})) elseif taskData.task == "lte" then table.insert(tOut, LTE({taskData.event, "N", "I"})) elseif taskData.task == "npc" and taskData.type1 == "gt" then table.insert(tOut, NPC({"Gold Trophies", nil, nil, 50, (taskData.type2 or "")})) elseif taskData.task == "npc" then table.insert(tOut, NPC({taskData.type2, nil, nil, 50})) else table.insert(tOut, taskImages[taskData.task] or "") end end table.insert(tOut, ' \n') table.insert(tOut, '| style="text-align: left;"|') if name == "Weekly" then table.insert(tOut, getTaskText(taskData.task, taskData.type1, nil, taskData.type2) or "?") table.insert(tOut, '\n') for i = 1, 5, 1 do				table.insert(tOut, '|') if taskData.count[i] then table.insert(tOut, util.th_comma(taskData.count[i])) end table.insert(tOut, '\n'); end else local count = "?" if taskData.count[1] then count = util.th_comma(taskData.count[1]) end table.insert(tOut, getTaskText(taskData.task, taskData.type1, count, taskData.type2) or "?") table.insert(tOut, '\n|') table.insert(tOut, kpHappiness(taskData.reward)) table.insert(tOut, '\n') end end table.insert(tOut, '|}\n') return table.concat(tOut) 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 for eNo, etE in ipairs(et) do			table.insert(allTables, taskTable("Event", etE, eNo)) end end

return table.concat(allTables) end

return p