Module:Available

--[=[ -- LUA script to get Items Availability Info -- --]=]

local p = {}

---[==[ local availableData = mw.loadData( 'Module:Available/data' ) --[===[]==] local availableData = { ["Hocus Pocus Event 2022"] = { ["Winifred Sanderson"] = {"2022/10/29", 6, " 18:00:00 UTC", true, A="Event Shop"}, },	["Striking Gold Mini Event"] = {true, ["Hocus Pocus Gold Trophy"] = {"2022/11/01", 3, A="Striking Gold #125", R="L1"}, },	["Chests"] = { ["Legendary Chests"] = { ["The Incredibles"] = {"2022/08/18", 15, " 18:00:00 UTC"}, },		["Red Ribbon Chests"] = { ["Christmas 2022"] = {"2022/12/25", 1, nil, true}, },	} } --]===]

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

local function strDate(sDate) local theDate = date(sDate)

return string.gsub(theDate:fmt("%d"), "^0", "") .. theDate:fmt(" %B %Y") end

local function lastCharacter(count) local limit = count local tIndex = {} if not limit or limit == 0 then limit = 3 end

for sName, data in pairs(availableData) do		if sName ~= "Legendary" then for k, v in pairs(data) do				if type(v) == "table" and v[4] and v[1] and today >= v[1] then table.insert(tIndex, {k, v[1]}) end end end end

table.sort(tIndex, function(a,b) return a[2] > b[2] end) local outText = ""

local retText = "" for i, v in ipairs(tIndex) do       local linkText = v[1] and "" or "Work In Progress"

local space = ""

for cName in mw.text.gsplit(v[1], "%s*%$%s*") do           linkText = linkText .. space .. "" .. cName .. "" space = ", " end

retText = retText .. "* "               .. linkText .. " "               .. strDate(v[2]) .. " \n"

if i>= limit then break end end return retText end

function p.latest local lastLTE = require ("Module:LTEvent").getLastLTE local lastUpdate = require("Module:UpdateNumber").getLastVer

local headerlast = '{| class="article-table" width="100%"\n! style="font-weight: normal;"|\n' local headerupcoming = '{| class="article-table" width="100%" style="border: 3px solid yellowgreen;"\n! style="font-weight: normal;"|\n' local foot1 = ' For '

local foot2 = '|here]] \n|}\n'

local outText = '==Upcoming Mini Events ==\n' .. headerupcoming .. ME.getUpcomingME({"5"}) .. foot1 .. "a complete timeline of the events in Disney Magic Kingdoms, click [[Event Timeline"                   .. foot2

outText = outText .. '{| class="" style="background-color:transparent;'                   .. ' color:inherit; width:100%;"\n' .. '|style="width:50%;"|\n' outText = outText .. "==Latest Events==\n" .. headerlast .. lastLTE({"5"}) .. foot1 .. "more events, click [[:Category:Events"                   .. foot2

outText = outText .. "==Latest Mini Events==\n" .. headerlast .. ME.getLastME({"5"}) .. foot1 .. "more mini events, click [[:Category:Mini Events"                   .. foot2

outText = outText .. '| style="width:50%;"|\n'

outText = outText .. "==Latest Updates==\n" .. headerlast .. lastUpdate({"5"}) .. foot1 .. "more updates, click [[Content Updates"                   .. foot2

outText = outText .. "==Latest Characters==\n" .. headerlast .. lastCharacter(5) .. foot1 .. "more characters, click [[:Category:Characters"                   .. foot2

outText = outText .. "|}\n"

return outText end

local function dispTime(t) local d = math.floor(t / 86400) local h = math.floor((t % 86400) / 3600) local m = math.floor((t % 3600) / 60) if d == 0 and h == 0 then return string.format("%dm", m)	elseif d == 0 then return string.format("%dh %02d", h, m)	else return string.format("%dd %dh %02d", d, h, m)	end end

local function getCost(costData) local tOut = {}

for costItem in mw.text.gsplit(costData, "%s*$%s*") do		local costName, costNumb = mw.ustring.match(costItem, "^(.-)%s*^%s*(.-)$") if not costName then costName = costItem end

if costName:match("^EC-") then local curName, curNumb = mw.ustring.match(costName, "^([^,]-)%s*#%s*(.-)$") if not curName then curName = costName end if not curNumb then curNumb = "1" end

local cNumb, sNumb = mw.ustring.match(curNumb, "^([^,]-)%s*-%s*(.-)$") if not cNumb then cNumb = count end

if sNumb then cNumb = tonumber((string.gsub(cNumb or "", "[,]", ""))) sNumb = tonumber((string.gsub(sNumb or "", "[,]", "")))

table.insert(tOut, EC({(curName .. " #" .. util.th_comma(sNumb)), nil, nil, nil, 30})) table.insert(tOut, ' ') table.insert(tOut, util.th_comma(cNumb)) table.insert(tOut, '  -') table.insert(tOut, (100-(string.format("%.2f", (sNumb/cNumb))*100))) table.insert(tOut, '% ') else table.insert(tOut, EC({costName, nil, nil, nil, 30})) end else table.insert(tOut, costName) end table.insert(tOut, (costNumb and (" (" .. costNumb .. ") ") or "")) end

return table.concat(tOut) end

function p.availabilitySale(frame) local tArgs = util.getArgs(frame) if not tArgs["P"] then tArgs["P"] = mw.title.getCurrentTitle.text end local LockDate = ""

for k, data in pairs(availableData["Sales"]) do LockDate = date(data[1]):adddays(data[2]):fmt("%Y/%m/%d") .. (data[3] or util.dayStart) if today <= LockDate then for cName in mw.text.gsplit(k, "%s*%$%s*") do				if tArgs["P"] == cName then if tArgs[1] == "I" then return getCost("EC-Gems #" .. tArgs[3] .. "-" .. tArgs[2]) else return tArgs[3] end break end end end end

return tArgs[2] or "" end

local function oneSource(srcName, anchName, dispName, costVal, rewType) local tOut = {"", "", ""} local fileName = "home-limited_time" local linkName = srcName .. (anchName and ("#" .. anchName) or "") .. "|" .. dispName

if srcName:match(" Chests") then fileName = "ec-" .. srcName:gsub(" ", "_"):gsub("_Chests", ""):lower if anchName then tOut[3] = "" .. linkName .. "" end elseif srcName:match(" Mini Event$") and anchName then local meName = srcName:match("^(.+) Mini Event$") local meNumb = anchName:match("^meName %#") tOut[1] = ME.getME({meName, meNumb, "I", 25}) if rewType then local mile, pos = string.match(rewType, "^([LM])(.*)") tOut[3] = "" .. linkName .. ": " .. util.ordinal(pos) .. (rewType:match("^M") and " Milestone Reward" or " Leaderboard Reward") end elseif srcName:match("^The Tower Challenge ") then fileName = "update-20-event_shop" elseif dispName == "Challenging the Tower" then fileName = "update-20-event_challenge" elseif srcName:match("^Season ") then fileName = "season_pass" if anchName then tOut[3] = "" .. linkName .. ": " .. anchName end elseif srcName:match(" Calendar$") then fileName = "home-calendar" if anchName then tOut[3] = "" .. linkName .. ": " .. anchName end elseif anchName and anchName:match("^Chain Offer") then fileName = "home-chain_offer" linkName = srcName .. (anchName and ("#" .. anchName) or "") .. "|" .. (anchName or dispName) elseif srcName == "Bundles Shop" then fileName = "home-shop" elseif srcName == "Discovery Rewards" then fileName = "discovery" if anchName then tOut[3] = "" .. linkName .. ": " .. anchName end elseif srcName:match(" Sales$") then fileName = "home-sale" end

if costVal then tOut[3] = "" .. linkName .. ": " .. getCost(costVal) end

if tOut[1]=="" then tOut[1] = " " end if tOut[2]=="" then tOut[2] = "" .. linkName .. ":  " end

return tOut end

function p.availability(frame) local cData = mw.loadData('Module:ItemCollection/data' ) local bData = mw.loadData('Module:Bundle/data' ) local meData = mw.loadData( 'Module:MiniEvent/data')

local VL = mw.ext.VariablesLua local tArgs = util.getArgs(frame) local pagename = tArgs[1] or mw.title.getCurrentTitle.text

local onlybundle = nil local tItem = require("Module:ECR").getDATA(pagename) local space = "" local space2 = "" local tAv = {} local tOb = {}

for sName, data in pairs(availableData) do		if sName ~= "Legendary" then for k, v in pairs(data) do				if type(v) == "table" then for cName in mw.text.gsplit(k, "%s*%$%s*") do						if pagename == cName then table.insert(tItem, {cName, v[1], v[2], (v[3] or util.dayStart), {(v["L"] or sName), v["A"], (v["D"] or v["A"] or v["L"] or sName), v["C"], v["R"]}, (sName=="Shop")}) end end end end end end

for sName, data in pairs(bData) do		for _, cName in pairs(data["C"]) do			if pagename == cName then table.insert(tItem, {cName, data["D"][1], data["D"][2], (data["D"][3] or util.dayStart), {"Bundles Shop", sName, (data["N"] or sName), data["G"]}}) end end end

for sName, data in pairs(meData) do		if sName:match("^ttc ") then for k, tab in pairs(data) do				if tab["C"] then for _, cName in pairs(mw.text.split(tab["C"], "%s*%$%s*")) do						if pagename == cName then table.insert(tItem, {cName, tab[1], tab[2], util.dayStart, {data["Name"], "Characters Required", "Challenging the Tower"}}) end end end end end end

table.sort(tItem, function(a,b) return (date(a[2]):adddays(a[3]):fmt("%Y/%m/%d")) < (date(b[2]):adddays(b[3]):fmt("%Y/%m/%d")) end)

for _, v in pairs(tItem) do		local itemData = oneSource(v[5][1], v[5][2], v[5][3], v[5][4], v[5][5])

local UnlockDate = v[2] .. util.dayStart local LockDate = date(v[2]):adddays(v[3]):fmt("%Y/%m/%d") .. v[4]

if today <= UnlockDate then if v[6] then onlybundle = true end table.insert(tAv, space) table.insert(tAv, itemData[1]) table.insert(tAv, itemData[2]) table.insert(tAv, ": ") table.insert(tAv, util.countdown(UnlockDate, " in ", " on ")) space = " " elseif v[3] == 0 then if v[6] then onlybundle = true end table.insert(tAv, space) table.insert(tAv, itemData[1]) table.insert(tAv, itemData[2]) table.insert(tAv, ": Currently Available ") space = " " if itemData[3]~="" then table.insert(tOb, space2) table.insert(tOb, itemData[3]) space2 = " " end elseif today <= LockDate then if v[6] then onlybundle = true end table.insert(tAv, space) table.insert(tAv, itemData[1]) table.insert(tAv, itemData[2]) table.insert(tAv, ": ") table.insert(tAv, util.countdown(LockDate, " for ", " until ")) space = " " if itemData[3]~="" then table.insert(tOb, space2) table.insert(tOb, itemData[3]) space2 = " " end end end

if tArgs[2] and cData["Items"][pagename] and not cData["Items"][pagename][4] and not onlybundle then table.insert(tAv, space) table.insert(tAv, "Shop:  : Currently Available") space = " " end

if space == " " then VL.vardefine("availability", table.concat(tAv)) VL.vardefine("obtainable", table.concat(tOb)) else VL.vardefine("availability", "Shop:  : Not Currently Available") VL.vardefine("obtainable", "") end

return "" end

return p