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 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" 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[4] then curDate = v[3] break end end end if curDate == "" then if lteData["C"] then for k, v in pairs(lteData["C"]) do		           if eYear == string.sub(v[3],1,4) and eName == 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	       for k, v in pairs(lteData[pnType]) do	            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

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

if prevDate then if prevType == "T" then prevName = "The Tower Challenge ("                       .. prevEvent[2]                        .. ") Event " .. string.sub(prevEvent[3],1,4) .. "|Tower Challenge ("                       .. prevEvent[2]                        .. ")" .. (prevEvent[7] or "") else prevName = prevEvent[4] .. " 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]                        .. ") Event " .. string.sub(nextEvent[3],1,4) .. "|Tower Challenge ("                       .. nextEvent[2]                        .. ")" .. (nextEvent[7] or "") else nextName = nextEvent[4] .. " 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) local eData = {0, "Unknown", "", "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 == "R" then table.insert(tRetText, util.strDate(eData[3], eData[5])) 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[4])			table.insert(tRetText, " Event ")			table.insert(tRetText, string.sub(eData[3], 1, 4))			table.insert(tRetText, "]]") end elseif outType == "K" then if eType == "T" then table.insert(tRetText, "TTC ") elseif eType == "C" then table.insert(tRetText, "CC ") end 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[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 numb then table.insert(tRetText, (" " .. numb)) end 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[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, '  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 ")		else			if eType ~= "C" then				table.insert(tRetText, '  ')				table.insert(tRetText, '   ") table.insert(tRetText, getNavi) end

table.insert(tRetText, " \n")		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[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[4] or eData[2] tRetText[10] = "" tRetText[11] = "" tRetText[12] = "" tRetText[13] = "" tRetText[14] = "" elseif outType == "P" then if eType == "T" then tRetText[9] = eData[4] or eData[2] tRetText[10] = "'" if not eData[2]:match("s$") then tRetText[11] = "s" else tRetText[11] = "" end tRetText[12] = " Tower Challenge" elseif eType ~= "S" then tRetText[9] = eData[4] or eData[2] tRetText[10] = "" tRetText[11] = "" tRetText[12] = "" end 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 = nil

if eType == "SH" 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 then if v["S"] then table.insert(allEvents[year], v)				end else 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[1] < b[1] end)

for i, tData in pairs(values) do			local tItem = {"", (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 " end

table.insert(list, table.concat(tItem)) 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 ""

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)) else return singleEvent(sName, eType, outType, altText) 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       for _, v in pairs(t) do            if (today > (v[3] .. dayStart)) then table.insert(allEvents, {k, v[2], v[3], v[4]}) 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.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[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