Module:SeasonTables

-- Lua script to get Seasons Tables --

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

local tArgs = {}

-- Tables local sp   = {} local spA  = {} local dt   = {} local wt   = {} local et   = {} local en   = {}

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 Tower Event Points", },	["lte"] = { ["cur"] = "Collect %1 pieces of ", ["char"] = "Welcome %1 Characters from the ", ["qst"] = "Complete %1 quests from the ", ["npc"] = "Clear %1 Tappers", ["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 = {'', util.th_comma(spVal), ' (',						util.th_comma(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][2])			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, type) 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 item = "CHEST-" .. item 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") fname = mw.ustring.gsub(fname, "^([^%(]-) *%(([^%(]-)%)$", "%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) .. ""

item = "ZITM-" .. 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

item = "TOK-" .. item end

if not sp["totalreward"][item] then sp["totalreward"][item] = {I = (tItem[1] .. tItem[3] .. tItem[4] .. tItem[5])} end if not sp["totalreward"][item][type] then sp["totalreward"][item][type] = nCount else sp["totalreward"][item][type] = (sp["totalreward"][item][type] + nCount) 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: 25%; border: 5px solid #afc3de; border-style: solid solid dotted;"|Free Pass \n', '! style="width: 20%;"|Happiness Required\n', '! style="width: 25%; border: 5px solid #ffd10d; border-style: solid solid dotted;"|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

for idx=2, 3 do			if idx == 3 then 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]) table.insert(tOut, '\n| style="border: 5px solid #ffd10d; border-style: dotted solid;"|') else table.insert(tOut, '\n| style="border: 5px solid #afc3de; border-style: dotted solid;"|') 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 if idx == 3 then table.insert(tOut, oneItem(iName, iCount, "K")) else table.insert(tOut, oneItem(iName, iCount, "F")) end 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, "

If already unlocked: ")					table.insert(tOut, oneItem(iName, iCount, "I"))				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 spRewardTable local tOut = {'|-|Total Season Pass Rewards=\n', '{| class="article-table dmk-seasons sortable" style="width: 100%; line-height: 1.0;"\n', '! style="width: 20%;"|Item Name\n', '! style="width: 27%; border: 5px solid #afc3de; border-style: solid solid dotted; border-right: 5px dotted #3dd30c;"|Total Free Pass \n', '! style="width: 30%; border: 5px solid #ffd10d; border-style: solid solid dotted; border-left: none;"|Total Kingdom Pass \n', '! style="width: 23%;"|Total Season Pass\n', }

for k, spData in pairs(sp["totalreward"]) do		table.insert(tOut, '|-\n| data-sort-value="')		table.insert(tOut, k)		table.insert(tOut, '"|') table.insert(tOut, spData["I"]) table.insert(tOut, '\n| style="border: 5px solid #afc3de; border-style: dotted solid; border-right: 5px dotted #3dd30c;"|') table.insert(tOut, util.th_comma(spData["F"] or 0)) table.insert(tOut, '\n| style="border: 5px solid #ffd10d; border-style: dotted solid; border-left: none;"|') table.insert(tOut, util.th_comma(spData["K"] or 0)) table.insert(tOut, '\n!') table.insert(tOut, util.th_comma((spData["K"] or 0) + (spData["F"] or 0))) 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 name ~= "Event" and taskData.task and taskData.task ~= "" then table.insert(tOut, taskImages[taskData.task] or "") 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)) if not data.totalreward then data.totalreward = taskData.reward else data.totalreward = (data.totalreward + taskData.reward) end table.insert(tOut, '\n') end end

if name ~= "Weekly" then table.insert(tOut, '|-\n! colspan="2" style="text-align: right;"|Total Rewards:\n!') table.insert(tOut, kpHappiness(data.totalreward)) table.insert(tOut, '\n') end

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

return table.concat(tOut) end

function p.getTables(frame) processArgs(frame)

local allTables = {}

if sp[1] then sp["totalreward"] = {} table.insert(allTables, spTable) table.insert(allTables, spRewardTable) 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