Module:LTEvent

--[=[ Lua script to get Limited Time Event information

getLTE: get Limited Time Event based on input parameters Parameters: 1 = short name : Event / IP short name for multiple set to "MULTIyyyy" where yyyy (optional) is the year will list all events for type for year in order specified by sequence no in data 2 = type      : event type N = normal limited time event (default) T = Tower Challenge C = Cascading Creatures S = Season 3 = output    : output type N = Full Event Name (default) S = Short Name Only D = Event Name with start date R = Only Event start and end date C = Collection Name (=S if no Collection Name) A = Alternate Text (parameter 4) P = Event Name with Event Period (start-end dates) K = Event Key (abbreviated Event Name) U = Single Event Number entry on the LTE Page 4 = alt text  : alternate text

Unknown Event is returned if Event is not in data.

getNavi: get Previous and Next event from current Event Page Parameter: none

getLastLTE: get Last X Events (formatted for main page) Parameter: 1 = Count  : return Last Count Events (default 5) --]=]

local p = {}

local COLL = require("Module:ItemCollection").getCollection local EC  = require("Module:EC").getEC local NPC = require("Module:NPC") local date = require('Dev:Date') local today = os.date("%Y/%m/%d %H:%M:%S") local util = require("Module:Utility")

-- Get Event Start Time from util module local dayStart = util.dayStart

---[==[ local lteData = mw.loadData( 'Module:LTEvent/data' ) --[===[]==] local lteData = { ["N"] = { ["nbc"]       = {2, "This Is Halloween", "2016/10/13",   	                    "Nightmare Before Christmas", 21, nil, "NBC"}, },   ["C"] = { ["nbc2"]      = {34, "Welcome Shock", "2020/10/23",   	                    "Nightmare Before Christmas", 9, 2, "NBC"}, },   ["T"] = { ["nbc"]       = {16, "Nightmare Before Christmas", "2018/10/18", nil, 15, 3}, } } --]===]

local function lteHeader(sName, eType) local eData = {0, "Unknown", "0001/01/01", "Unknown", 0, nil, "?"}

if lteData[eType] and lteData[eType][sName] then eData = lteData[eType][sName] end

local tRetText = {}

local pagename = mw.title.getCurrentTitle.text local eventname = "" if eType == "T" then eventname = "The Tower Challenge (" .. eData[2] .. ")" else eventname = eData["L"] or eData[4] or eData[2] end eventname = eventname .. " Event "

local storyline = nil if pagename ~= (eventname .. string.sub(eData[3], 1, 4)) then storyline = true end if eType == "S" and pagename == eData[2] then storyline = nil eventname = eData[2] end

if eType == "N" then table.insert(tRetText, '\n') end

table.insert(tRetText, ' ') if eType == "T" then table.insert(tRetText, "The Tower Challenge") else table.insert(tRetText, (eData["L"] or eData[2])) if eType ~= "S" then table.insert(tRetText, " Event") end end table.insert(tRetText, '  ') if eType == "S" then table.insert(tRetText, 'season_pass.png') elseif eType == "T" then table.insert(tRetText, 'update-20-event_shop.png') else local file = "cc-" .. mw.ustring.gsub((eData[4] or eData[2]), "[\,\.']", "") .. "-l.png" table.insert(tRetText, mw.ustring.lower(mw.ustring.gsub(file, " ", "_"))) end table.insert(tRetText, ' ')

local enddate = date(eData[3]):adddays(eData[5]):fmt("%Y/%m/%d") if eType == "S" then enddate = enddate .. util.dayStart else enddate = enddate .. util.dayEnd end if today <= enddate then table.insert(tRetText, ' ') end

table.insert(tRetText, ' ')

table.insert(tRetText, ' ')

if eType ~= "S" and not storyline then if not eData[8] then table.insert(tRetText, ' ') end if eType ~= "C" and eType ~= "S" then table.insert(tRetText, ' ') end table.insert(tRetText, ' ")	end

if eType ~= "S" then local curDate = eData[3] local prevData = "0001/01/01" local nextData = "9001/01/01" local prevEvent = "" local nextEvent = ""

local tEvent = {"", "?", ""}

if storyline then tEvent[3] = " Event Storyline " end

for k, t in pairs(lteData) do			if k ~= "S" then for _, v in pairs(t) do					if (storyline and not v[8]) or not storyline then if k == "T" then tEvent[2] = "The Tower Challenge (" .. v[2] .. ")" tEvent[6] = "Tower Challenge (" .. v[2] .. ")" else tEvent[2] = (v["L"] or v[4]) tEvent[6] = v[2] .. " Event" end tEvent[4] = string.sub(v[3],1,4) if curDate < v[3] and v[3] < nextData then nextData = v[3] nextEvent = table.concat(tEvent) elseif curDate > v[3] and v[3] > prevData then prevData = v[3] prevEvent = table.concat(tEvent) end end end end end

table.insert(tRetText, ' Events timeline  ') end table.insert(tRetText, " ")

if not storyline then table.insert(tRetText, "\n")		if eType == "T" then			table.insert(tRetText, eventname)		else			table.insert(tRetText, (eData["L"] or eData[2]))			if eType ~= "S" then table.insert(tRetText, " Event") end		end		table.insert(tRetText, " is the ") if eType ~= "S" then table.insert(tRetText, util.wordinal(eData[1])) table.insert(tRetText, " event of Disney Magic Kingdoms, and the ") end table.insert(tRetText, util.wordinal(eData[6])) if eType == "T" then table.insert(tRetText, " Tower Challenge Event") table.insert(tRetText, "") elseif eType == "C" then table.insert(tRetText, " Cascading Critters Event") table.insert(tRetText, "") elseif eData["S"] and eType == "N" then table.insert(tRetText, " Short (aka Mini) Event") table.insert(tRetText, "") elseif eType == "N" then table.insert(tRetText, " Mega Event") table.insert(tRetText, "") elseif eType == "S" then table.insert(tRetText, " Season of Disney Magic Kingdoms") table.insert(tRetText, "") end table.insert(tRetText, "") table.insert(tRetText, ". It") table.insert(tRetText, util.strDate(eData[3], eData[5], nil, nil, true)) table.insert(tRetText, ".") end

return table.concat(tRetText) end

local function singleEvent(sName, eType, outType, altText, tier) local eData = {0, "Unknown", "0001/01/01", "Unknown", 0, nil, "?"}

if eType == "N" then if lteData["N"] and lteData["N"][sName] then eData = lteData["N"][sName] elseif lteData["C"] and lteData["C"][sName] then eType = "C" eData = lteData["C"][sName] end else if lteData[eType] and lteData[eType][sName] then eData = lteData[eType][sName] end end

local tRetText = {}

if outType == "X" then table.insert(tRetText, util.strDate(eData[3], eData[5])) elseif outType == "SD" then table.insert(tRetText, eData[3] .. util.dayStart) elseif outType == "ED" then table.insert(tRetText, date(eData[3]):adddays(eData[5]):fmt("%Y/%m/%d") .. util.dayEnd) elseif outType == "I" then local lteImage = {""} if eType == "S" then lteImage[2] = "season_pass.png" lteImage[6] = eData[2] elseif eType == "T" then lteImage[2] = "Update-20-event shop" lteImage[6] = "The Tower Challenge (" .. eData[2] .. ")" else local file = mw.ustring.gsub((eData[4] or eData[2]), "[\,\.']", "") lteImage[2] = "Cc-" .. mw.ustring.lower(mw.ustring.gsub(file, " ", "_")) .. "-l" end table.insert(tRetText, table.concat(lteImage)) elseif outType == "K" then if sName == "after" then table.insert(tRetText, "After") else table.insert(tRetText, sName:upper) end if eType == "T" then table.insert(tRetText, " TC") elseif eType == "C" then table.insert(tRetText, " CC") end elseif outType == "R" then local pass, pos = string.match(tier, "^([FK])(.*)")

local lteImage = {""} table.insert(tRetText, table.concat(lteImage))

local pagename = mw.title.getCurrentTitle.subpageText if string.match(pagename, "s$") then pagename = pagename:gsub("s$", "") end if altText ~= "" and tonumber(altText) then pagename = altText .. " " .. pagename .. "s" elseif altText ~= "" then pagename = altText .. " " .. pagename end table.insert(tRetText, pagename)

if eData[3] > today then table.insert(tRetText, " will be") elseif string.match(pagename, "s$") then table.insert(tRetText, " were") else table.insert(tRetText, " was") end

if pos then local sep = "" local tOut = ""

local TierTable = mw.text.split(pos, "%s*%-%s*") for idx = #TierTable, 1, -1 do tOut = " " .. util.ordinal(TierTable[idx]) .. sep .. tOut if sep == "" then sep = " and" else sep = "," end end table.insert(tRetText, " the") table.insert(tRetText, tOut) else table.insert(tRetText, " a") end

table.insert(tRetText, " tier prize to win in the ") if pass == "K" then table.insert(tRetText, "Kingdom") else table.insert(tRetText, "Free") end table.insert(tRetText, " Pass of Season ")		table.insert(tRetText, eData[6])		table.insert(tRetText, "") table.insert(tRetText, util.durDate(eData[3], eData[5])) table.insert(tRetText, ".") else tRetText = {"", "", eData[2],				"", " Event", " ", string.sub(eData[3], 1, 4), "", "", "",				}

if eType == "T" then tRetText[2] = "The Tower Challenge ("			tRetText[3]  = eData[2]			tRetText[4]  = ")"

tRetText[9] = "The Tower Challenge ("			tRetText[10]  = eData[4] or eData[2]			tRetText[11] = ")" elseif eType == "S" then tRetText[3] = eData[2] tRetText[5] = "" tRetText[6] = "" tRetText[7] = "" tRetText[12] = "" tRetText[13] = "" tRetText[14] = "" end

if outType == "S" then if eType == "T" then tRetText[9] = "Tower Challenge ("				tRetText[12] = ""			end			tRetText[13] = ""			tRetText[14] = ""		elseif outType == "W" then			tRetText[5] = " Event Storyline"			tRetText[12] = " Event Storyline"			if altText ~= "" then				tRetText[9]  = altText				tRetText[10] = ""				tRetText[11] = ""				tRetText[12] = ""				tRetText[13] = ""				tRetText[14] = ""			end		elseif outType == "D" then			if altText ~= "" then				tRetText[9]  = altText				tRetText[10] = ""				tRetText[11] = ""				tRetText[12] = ""			end			tRetText[13] = ""			tRetText[14] = ""			tRetText[16] = " on "			tRetText[17] = util.strDate(eData[3], 0)		elseif outType == "A" then			tRetText[8]  = (tier ~= "" and ("#" .. tier .. "|") or "|")			tRetText[9]  = (altText ~= "" and altText or "")			tRetText[10] = ""			tRetText[11] = ""			tRetText[12] = ""			tRetText[13] = ""			tRetText[14] = ""		elseif outType == "C" then			tRetText[9]  = eData[4] or eData[2] tRetText[10] = eData[7] or "" tRetText[11] = "" tRetText[12] = "" tRetText[13] = "" tRetText[14] = "" elseif outType == "CW" then tRetText[5] = " Event Storyline" tRetText[9] = eData[4] or eData[2] tRetText[10] = eData[7] or "" tRetText[11] = "" tRetText[12] = "" tRetText[13] = "" tRetText[14] = "" elseif outType == "P" then if eType == "T" then tRetText[12] = "" elseif eType == "C" then tRetText[11] = " Cascading Critters" elseif eType == "N" then tRetText[10] = eData[4] tRetText[11] = (eData["S"] and " Short" or " Mega") end tRetText[14] = eData[7] or "" tRetText[16] = " " tRetText[17] = util.strDate(eData[3], eData[5]) end end

return table.concat(tRetText) end

local function multiEvent(eType, outType) local navbox = require('Module:Navbox').main local allEvents = {} local small = false

if eType == "M" then eType = "N" small = true end

if lteData[eType] then for k, v in pairs(lteData[eType]) do			local year = string.sub(v[3], 1, 4) if not allEvents[year] then allEvents[year] = {} end if small == true and v["S"] then table.insert(allEvents[year], {k, eType, v[3], v[8]}) elseif small ~= true and not v["S"] then table.insert(allEvents[year], {k, eType, v[3], v[8]}) end end end

local paramTable = {"child"} local group = 1 local currColl = nil local list = {}

table.sort(allEvents, function(a,b) return a[1] < b[1] end)

for key, values in pairs(allEvents) do		if key ~= currColl then if currColl then paramTable["group" .. key] = key paramTable["list" .. key] = table.concat(list, " · ") group = group + 1 list = {} end currColl = key end

table.sort(values, function(a,b) return a[3] < b[3] end)

for i, tData in pairs(values) do			if outType=="W" and not tData[4] then table.insert(list, singleEvent(tData[1], tData[2], "CW")) elseif outType~="W" then table.insert(list, singleEvent(tData[1], tData[2], "C")) end end

paramTable["group" .. key] = key paramTable["list" .. key] = table.concat(list, " · ") end

return navbox(paramTable) end

-- function get Limited Time Event function p.getLTE(frame) local tArgs = util.getArgs(frame)

local sName   = tArgs[1] or "" local eType   = tArgs[2] or "" local outType = tArgs[3] or "" local altText = tArgs[4] or "" local tier    = tArgs[5] or ""

sName = sName:lower:gsub("^%s*(.-)%s*$", "%1") or '' local tempName, tempType = sName:match("^(.+)%%([nNtTcC])$")

if tempName then sName = tempName eType = tempType end if eType == "" then eType = "N" end if outType == "" then outType = "N" end eType = eType:upper outType = outType:upper

if sName == "multi" then return multiEvent(eType, outType) elseif outType == "U" then return frame:preprocess(lteHeader(sName, eType)) else return singleEvent(sName, eType, outType, altText, tier) end end

-- function get Last X events function p.getLastLTE(frame) local tArgs = util.getArgs(frame)

local count = tArgs[1] count = tonumber(count) or 5 local allEvents = {}

for k, t in pairs(lteData) do		if k ~= "S" then for _, v in pairs(t) do if (today > (v[3] .. dayStart)) then table.insert(allEvents, {k, t, v[3]}) end end end end

table.sort(allEvents, function(a,b) return a[3] > b[3] end)

local outText = ""

for i, v in ipairs(allEvents) do outText = outText .. singleEvent(v[2], v[3], "S") .. " " .. util.strDate(v[3], nil, nil, true) .. " \n" if i >= count then break end end return outText end

function p.getAllEC local allEvents = {}

for k, t in pairs(lteData["N"]) do       table.insert(allEvents, {t[1], k, t[3]}) end

table.sort(allEvents, function(a,b) return a[1] > b[1] end)

local outText = ""

for i, v in ipairs(allEvents) do       outText = outText .. "* "                         .. singleEvent(v[2], "N", "S") .. "\n** " .. EC({v[2]}) .. " '''"                         .. EC({v[2], "T"}) .. "''' could be collected during the event in " .. string.sub(v[3], 1, 4) .. ". They are obtained by collecting from quests and character activities, which are then used to buy event exclusive items. ''" .. EC({v[2], "L", "Read More..."}) .. "''\n" end

return outText end

function p.getECNavbox local navbox = require('Module:Navbox').main local allEvents = {}

for k, t in pairs(lteData["N"]) do		local year = EC({k, "T"}) if not allEvents[year] then allEvents[year] = {} end if not allEvents[year]["N"] or t[1] < allEvents[year]["N"][1] then allEvents[year]["N"] = {t[1]} end table.insert(allEvents[year], {t[1], t[4], t[3]}) end

table.sort(allEvents, function(a,b) return a[1] > b[1] end)

local paramTable = {"child", group1="Disney Magic Kingdoms", list1="Elixirs · Gems · Magic", group2="The Tower Challenge Events", list2="Maleficent Coins"} local group = 1 local currColl = nil local key = nil local list = {}

for name, values in pairs(allEvents) do		key = values["N"][1] + 2 if key ~= currColl then if currColl then paramTable["group" .. key] = table.concat(list, " ") paramTable["list" .. key] = "" .. name .. "" group = group + 1 list = {} end currColl = key end

table.sort(values, function(a,b) return a[1] < b[1] end)

for i, tData in pairs(values) do			if tData[2] then local tItem = {"", tData[2], " Event (", string.sub(tData[3], 1, 4), ")"} table.insert(list, table.concat(tItem)) end end

paramTable["group" .. key] = table.concat(list, " ") paramTable["list" .. key] = "" .. name .. "" end

return navbox(paramTable) end

function p.eventType(frame) local tArgs = util.getArgs(frame) local pagename = tArgs[1] if not tArgs[1] or tArgs[1] == "" then pagename = mw.title.getCurrentTitle.prefixedText end

if pagename:match(" Mini Event$") then return "Mini Events" end

for eType, data in pairs(lteData) do		for _, v in pairs(data) do			local eventname = "" if eType == "T" then eventname = "The Tower Challenge (" .. v[2] .. ")" else eventname = v["L"] or v[4] or v[2] end eventname = eventname .. " Event " if tArgs[2] then eventname = eventname .. "Storyline " end eventname = eventname .. string.sub(v[3], 1, 4) if eType == "S" then eventname = v[2] end if pagename == eventname then if eType == "T" then return "The Tower Challenge Events" elseif eType == "C" then return "Cascading Critters Events" elseif v["S"] and eType == "N" then return "Short Events" elseif eType == "N" then return "Mega Events" elseif eType == "S" then return "Seasons" end end end end

if tArgs[2] then return "Main" else return "Promotions" end end

return p