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 date = require('Dev:Date') 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 Functions -- function get previous, next navigation links local function getNavi local curName = mw.title.getCurrentTitle.text local storyline = nil local eType = "N" local eName = "" local eYear = ""

if curName:match("^The Tower Challenge %(.+%) Event %d%d%d%d$") then eName, eYear = curName:match("^The Tower Challenge %((.+)%) Event (%d+)$") eType = "T" elseif curName:match("^.+ Event %d%d%d%d$") then eName, eYear = curName:match("^(.+) Event (%d+)$") eType = "N" elseif curName:match("^The Tower Challenge %(.+%) Event Storyline %d%d%d%d$") then eName, eYear = curName:match("^The Tower Challenge %((.+)%) Event Storyline (%d+)$") eType = "T" storyline = true elseif curName:match("^.+ Event Storyline %d%d%d%d$") then eName, eYear = curName:match("^(.+) Event Storyline (%d+)$") eType = "N" storyline = true end

local curDate = ""

if eType == "N" then if lteData["N"] then for k, v in pairs(lteData["N"]) do	           if eYear == string.sub(v[3],1,4) and eName == (v["L"] or v[4]) then curDate = v[3] break end end end if curDate == "" and not storyline then if lteData["C"] then for k, v in pairs(lteData["C"]) do		           if eYear == string.sub(v[3],1,4) and eName == (v["L"] or v[4]) then curDate = v[3] eType = "C" break end end end end else if lteData[eType] then for k, v in pairs(lteData[eType]) do	           if eYear == string.sub(v[3],1,4) and eName == v[2] then curDate = v[3] break end end end end

local prevDate = nil local prevEvent = "" local prevType = "" local nextDate = nil local nextEvent = "" local nextType = ""

if curDate ~= "" then for _, pnType in ipairs({"N", "C", "T"}) do	   if (storyline and pnType ~= "C") or not storyline then for k, v in pairs(lteData[pnType]) do	           if (storyline and not v[8]) or not storyline then if v[3] < curDate and v[3] > (prevDate or "") then prevDate = v[3] prevEvent = v	               prevType = pnType end if v[3] > curDate and v[3] < (nextDate or "9") then nextDate = v[3] nextEvent = v	               nextType = pnType end end end end end end

local prevName = "Main Storyline Walkthrough" local nextName = ""

if prevDate then if prevType == "T" then prevName = "The Tower Challenge ("                       .. prevEvent[2]                        .. (storyline and ") Event Storyline " or ") Event ")                        .. string.sub(prevEvent[3],1,4)                        .. "|Tower Challenge (" .. prevEvent[2] .. ")"                       .. (prevEvent[7] or "")        else            prevName = (prevEvent["L"] or prevEvent[4])                        .. (storyline and " Event Storyline " or " Event ")                        .. string.sub(prevEvent[3],1,4)                        .. "|"                        .. prevEvent[2]                        .. " Event"        end        prevName = "" .. prevName .. ""    end    if nextDate then        if nextType == "T" then            nextName = "The Tower Challenge (" .. nextEvent[2] .. (storyline and ") Event Storyline " or ") Event ") .. string.sub(nextEvent[3],1,4) .. "|Tower Challenge ("                       .. nextEvent[2]                        .. ")" .. (nextEvent[7] or "") else nextName = (nextEvent["L"] or nextEvent[4]) .. (storyline and " Event Storyline " or " Event ") .. string.sub(nextEvent[3],1,4) .. "|"                       .. nextEvent[2] .. " Event" end nextName = "" .. nextName .. "" end return ' Events timeline  ' 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.dayEnd) elseif outType == "ED" then local date = require('Dev:Date') table.insert(tRetText, date(eData[3]):adddays(eData[5]):fmt("%Y/%m/%d") .. util.dayEnd) elseif outType == "I" then if eType == "T" then table.insert(tRetText, "") else table.insert(tRetText, '[[File:Cc-')			local file = mw.ustring.gsub((eData[4] or eData[2]), "[\,\.']", "")			file = mw.ustring.gsub(file, " ", "_")			table.insert(tRetText, mw.ustring.lower(file))			table.insert(tRetText, '-l.png|50px|')			table.insert(tRetText, eData[2])			table.insert(tRetText, " Event")			table.insert(tRetText, eData[7] or "")			table.insert(tRetText, "|link=")			table.insert(tRetText, (eData["L"] or eData[4]))			table.insert(tRetText, " Event ")			table.insert(tRetText, string.sub(eData[3], 1, 4))			table.insert(tRetText, "]]") end elseif outType == "K" then local name, numb = tostring(sName):match('^(%a+)([1-9]%d*)$') if not name then name = sName end if eType == "S" then table.insert(tRetText, eData[2]) elseif name:upper == (eData["L"] or eData[4] or eData[2]):upper then table.insert(tRetText, string.sub(name, 1, 1):upper..string.sub(name, 2)) elseif name == "after" then table.insert(tRetText, "After") else table.insert(tRetText, name:upper) end if eType == "T" then table.insert(tRetText, " TC ") elseif eType == "C" then table.insert(tRetText, " CC ") end if numb then table.insert(tRetText, (" " .. numb)) end elseif outType == "R" then local pass, pos = string.match(tier, "^([FK])(.*)")

table.insert(tRetText, "[[File:Season pass-")		if pass == "K" then table.insert(tRetText, "gold") else table.insert(tRetText, "silver") end		table.insert(tRetText, ".png|25x25px|link=Season ")		table.insert(tRetText, (eData[6] or 1))		table.insert(tRetText, "|")		if pass == "K" then table.insert(tRetText, "Kingdom") else table.insert(tRetText, "Free") end		table.insert(tRetText, " Pass]] ") 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)

local today = os.date("%Y/%m/%d") 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, "")

if eData[3] and eData[5] then table.insert(tRetText, " from the ") table.insert(tRetText, util.strDate(eData[3], 0)) table.insert(tRetText, " to the ") table.insert(tRetText, util.strDate(date(eData[3]):adddays(eData[5]):fmt("%Y/%m/%d"), 0)) end

table.insert(tRetText, ".") elseif outType == "U" then local pagename = mw.title.getCurrentTitle.text local eventname = "" if eType == "T" then eventname = eventname .. "The Tower Challenge (" end		eventname = eventname .. (eData["L"] or eData[4] or eData[2])		if eType == "T" then eventname = eventname .. ")" end eventname = eventname .. " Event " if eType == "S" then eventname = eData[2] end

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

local today = os.date("%Y/%m/%d %H:%M:%S") 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, ' ')

if pagename == (eventname .. string.sub(eData[3], 1, 4)) then if not eData[8] then table.insert(tRetText, ' ') end if eType ~= "C" then table.insert(tRetText, ' ') end table.insert(tRetText, ' ")		end		table.insert(tRetText, getNavi)		table.insert(tRetText, " \n")

table.insert(tRetText, "")		table.insert(tRetText, eData[2])		if eType == "T" then table.insert(tRetText, " Tower Challenge") end		if eType ~= "S" then table.insert(tRetText, " Event") end		table.insert(tRetText, "") if eType == "T" then table.insert(tRetText, eData[7] or "") end table.insert(tRetText, " is the ") if eType ~= "S" then table.insert(tRetText, util.wordinal(eData[1])) end if eType ~= "S" then 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") eventname = eventname .. string.sub(eData[3], 1, 4) elseif eType == "C" then table.insert(tRetText, " Cascading Critters Event") eventname = eventname .. string.sub(eData[3], 1, 4) elseif eData["S"] and eType == "N" then table.insert(tRetText, " Short (aka Mini) Event") eventname = eventname .. string.sub(eData[3], 1, 4) elseif eType == "N" then table.insert(tRetText, " Mega Event") eventname = eventname .. string.sub(eData[3], 1, 4) elseif eType == "S" then table.insert(tRetText, " Season of Disney Magic Kingdoms") end table.insert(tRetText, ". It") table.insert(tRetText, util.strDate(eData[3], eData[5], nil, nil, true)) table.insert(tRetText, ".") if pagename == eventname then table.insert(tRetText, "") if eType == "T" then table.insert(tRetText, "") elseif eType == "C" then table.insert(tRetText, "") elseif eData["S"] and eType == "N" then table.insert(tRetText, "") elseif eType == "N" then table.insert(tRetText, "") elseif eType == "S" then table.insert(tRetText, "") end end else tRetText = {"", "", (eData["L"] or eData[4]), "", " Event", "", "", "", "", "",					"", "", "", "", "",					"", "",					}

if eType == "T" then tRetText[1] = ""			tRetText[9]  = "The Tower Challenge ("			tRetText[10] = eData[2]			tRetText[11] = ")"			tRetText[12] = " Event"			tRetText[13] = " "			tRetText[14] = string.sub(eData[3], 1, 4)			tRetText[15] = "" elseif eType == "S" then tRetText[1] = ""			tRetText[9]  = eData[2]			tRetText[15] = "" else tRetText[1] = ""			tRetText[9]  = eData[2]			tRetText[10] = " Event"			tRetText[11] = " "			tRetText[12] = string.sub(eData[3], 1, 4)			tRetText[15] = "" end

if outType == "S" then if eType == "T" then tRetText[9] = eData[2] tRetText[10] = "'" if not eData[2]:match("s$") then tRetText[11] = "s" else tRetText[11] = "" end tRetText[12] = " Tower Challenge" tRetText[13] = eData[7] or "" else tRetText[11] = "" tRetText[12] = "" tRetText[13] = "" end tRetText[14] = "" elseif outType == "D" then if altText ~= "" then tRetText[9] = altText tRetText[10] = "" tRetText[11] = "" tRetText[12] = "" tRetText[13] = "" tRetText[14] = "" else if eType == "T" then tRetText[13] = eData[7] or "" tRetText[14] = "" else tRetText[11] = "" tRetText[12] = "" end end tRetText[16] = " on " tRetText[17] = util.strDate(eData[3], 0) elseif outType == "A" then tRetText[9] = (altText ~= "") and altText tRetText[10] = "" tRetText[11] = "" tRetText[12] = "" tRetText[13] = "" tRetText[14] = "" elseif outType == "C" then tRetText[9] = eData["L"] or eData[4] or eData[2] tRetText[10] = "" tRetText[11] = "" tRetText[12] = "" tRetText[13] = "" tRetText[14] = "" elseif outType == "P" then tRetText[9] = eData["L"] or eData[4] or eData[2] if eType == "T" then tRetText[10] = " Tower Challenge" elseif eType == "C" then tRetText[10] = " Cascading Critters Event" elseif eData["S"] then tRetText[10] = " Short Event" else tRetText[10] = " Mega Event" end tRetText[11] = "" tRetText[12] = "" tRetText[13] = eData[7] or "" tRetText[14] = "]]" tRetText[15] = " " tRetText[16] = 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 _, 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], v)			elseif small ~= true and not v["S"] then table.insert(allEvents[year], v)			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			local tItem = {"", (tData["L"] or tData[4] or tData[2]), (tData[7] or ""), ""} if eType == "T" then tItem[2] = "The Tower Challenge ("				tItem[4] = ")" elseif eType == "S" then tItem = {"", tData[2], ""} end

if outType == "W" then tItem[5] = " Event Storyline " if not tData[8] then table.insert(list, table.concat(tItem)) end else table.insert(list, table.concat(tItem)) 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(singleEvent(sName, eType, outType, altText, tier)) 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 = {} local today = date:fmt("%Y/%m/%d %H:%M:%S")

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, v[2], v[3], (v["L"] or v[4])}) 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       local linkText  = "" local dateText = util.strDate(v[3], nil, nil, true)

if v[1] == "T" then linkText = "* "                       .. mw.text.truncate(v[2] .. "'s Tower Challenge", 43 - mw.ustring.len(dateText), nil, true)                        .. " " .. dateText .. " \n" elseif v[1] ~= "S" then linkText = "* "                       .. v[2]                        .. " " .. dateText .. " \n" end

outText = outText .. linkText 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[2], t[3], t[4]}) end

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

local outText = ""

for i, v in ipairs(allEvents) do       outText = outText .. "* "                         .. v[3]                          .. " Event\n** " .. EC({v[2]}) .. " '''"                         .. EC({v[2], "T"}) .. "''' could be collected during the event in " .. string.sub(v[4], 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 = eventname .. "The Tower Challenge (" end			eventname = eventname .. (v["L"] or v[4] or v[2])			if eType == "T" then eventname = eventname .. ")" 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 "Season" end end end end

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

return p