Module:ECR

--[=[ -- LUA script to get Enchanted Chests Rewards -- --]=]

local p = {}

local availableData = mw.loadData( 'Module:Available/data' ) local cData = mw.loadData( 'Module:ItemCollection/data' ) ---[==[ For testing purposes local chestData = mw.loadData( 'Module:ECR/data' ) --[===[]==] local chestData = { ["Legendary"] = { ["Pinocchio"] = { ["C"] = "EC-Gems #60$EC-Gems #120^x3", ["R"] = { ["Common"] = "EC-Magic #50-613 $ Jiminy Cricket $ Figaro $ Geppetto's Workshop", ["Uncommon"] = "EC-Magic #100-1,225 $ Geppetto $ Blue Fairy $ Pinocchio Village Haus $ Jiminy Cricket's Hat Stand", ["Rare"] = "EC-Magic #150-1,838 $ Honest John $ Stromboli's Caravan", ["Epic"] = "Stromboli $ Pinocchio's Daring Journey $ Pinocchio's Hat Stand", ["Legendary"] = "Pinocchio", },		},	}, 	["Radiant"] = {true, ["THOND Event"] = { ["N"] = "", ["D"] = {"2022/12/28", 18}, ["C"] = "EC-Gems #20$Real Money^x6", ["R"] = { ["Tokens"] = {"Phoebus$Djali$Claude Frollo$Esmeralda$Quasimodo"}, ["Common"] = "EC-THOND #200 $ EC-Magic #100-700 $ IP-THOND #5", ["Uncommon"] = "EC-Magic #200-1,400", ["Rare"] = "EC-Magic #500-3,500", },		},	}, } --]===]

local util = require('Module:Utility') local RARITY = require("Module:Rarity").rarity local EC = require("Module:EC").getEC local TOK = require("Module:CharacterToken") local CHEST = require("Module:EnchantedChest").getChest local COLL = require("Module:ItemCollection").getCollection local date = require("Dev:Date") local today = os.date("%Y/%m/%d %H:%M:%S")

local bubbles = {}

local function addItem(data) local TokenData = {} TokenData["unknown"] = data["Unknown"] or "" TokenData["common"] = data["Common"] or "" TokenData["uncommon"] = data["Uncommon"] or "" TokenData["rare"] = data["Rare"] or "" TokenData["epic"] = data["Epic"] or "" TokenData["legendary"] = data["Legendary"] or ""

local raTok = "" local rbTok = ""

if data["Tokens"] and data["Tokens"][1] then for tCh in mw.text.gsplit(data["Tokens"][1], "%s*$%s*") do raTok = TOK.getTokenDirect((tCh .. ",2"), "R", "") rbTok = TOK.getTokenDirect((tCh .. ",3"), "R", "")

TokenData[raTok] = TokenData[raTok] .. "$" .. tCh .. ",2 #" .. (data["Tokens"][raTok] or "1") TokenData[rbTok] = TokenData[rbTok] .. "$" .. tCh .. ",3 #" .. (data["Tokens"][rbTok] or "1") end end

local tRarity = {} table.insert(tRarity, {"Legendary", TokenData["legendary"]}) table.insert(tRarity, {"Epic", TokenData["epic"]}) table.insert(tRarity, {"Rare", TokenData["rare"]}) table.insert(tRarity, {"Uncommon", TokenData["uncommon"]}) table.insert(tRarity, {"Common", TokenData["common"]}) table.insert(tRarity, {"Unknown", TokenData["unknown"]})

return tRarity end

local function chItems(inStr) local tIn = mw.text.split(inStr, "%s*%$%s*") local tOut = {} for idx = 1, #tIn do		local tt = mw.text.split(tIn[idx], "%s*#%s*") if tt[1] ~= "" then if not tt[2] or tt[2] == "" then tt[2] = 1 end table.insert(tOut, tt) end end return tOut end

local function oneItem(item, count, size) nCount = count or 0 if nCount == 0 then return "" end

local conv = { ["ch"] = "cp", ["cos"] = "cp", }

local tItem = {"", (" " .. nCount), " ",			"", "",			" ",	}

local iName = item local iData = cData.Items[iName]

if iName:match("Chests") and not iName:match("Wacky Lunch Chests")then tItem[1] = CHEST({iName, (size or 35)}) tItem[4] = CHEST({item, "L"}) elseif iData and iData[2] then if size then size = size + 5 end local iDisp = iName:gsub("^([^%(]-)%/([^%(]-)$", "%2") local fname = mw.ustring.gsub(mw.ustring.lower(iName), "[':\"%,%.]", "")		fname = fname:gsub(" ", "_")		if iData[2] == "pf" then			fname = fname:gsub("_float$", "")		else			fname = fname:gsub("^([^%(]-)%/([^%(]-)$", "%1-%2")			fname = mw.ustring.gsub(fname, "^([^%(]-) *%(([^%(]-)%)$", "%1_%2")		end

local tItemData = {"", "", ""							}		if cData["Items"][item]["C"] and cData["Categories"][cData["Items"][item]["C"]] then local category = cData["Items"][item]["C"] tItemData[1] = '' tItemData[15] = ' ' tItem[3] = ' ' end tItem[1] = table.concat(tItemData) tItem[2] = "" tItem[4] = table.concat({"", (iDisp or iName), ""}) elseif item:match("^EC") then tItem[1] = EC({item, nil, nil, "E", (size or 35)}) tItem[4] = EC({item, "L", S=(nCount == "1")}) else tItem[1] = TOK.getTokenDirect(item, (size or 35)) tItem[4] = TOK.getTokenDirect(item, "L") if nCount ~= "1" then tItem[5] = "s" end end

if size then return tItem[1] else return table.concat(tItem) end end

local function colItem(iNumb, tNumb, aNumb, item) local tOut = {}

if iNumb == 1 then table.insert(tOut, '\n| colspan="2"|') table.insert(tOut, '\n| colspan="2"|') table.insert(tOut, '\n| colspan="2"|') table.insert(tOut, item) table.insert(tOut, '\n| colspan="2"|') table.insert(tOut, '\n| colspan="2"|') elseif iNumb == 2 then if aNumb == (tNumb - 1) then table.insert(tOut, '\n|\n| colspan="2"|') table.insert(tOut, '\n| colspan="2"|') table.insert(tOut, item) elseif aNumb == tNumb then table.insert(tOut, '\n| colspan="2"|') table.insert(tOut, item) table.insert(tOut, '\n| colspan="2"|\n|') end elseif iNumb == 3 then if aNumb == (tNumb - 2) then table.insert(tOut, '\n| colspan="2"|') table.insert(tOut, '\n| colspan="2"|') table.insert(tOut, item) elseif aNumb == (tNumb - 1) then table.insert(tOut, '\n| colspan="2"|') table.insert(tOut, item) elseif aNumb == tNumb then table.insert(tOut, '\n| colspan="2"|') table.insert(tOut, item) table.insert(tOut, '\n| colspan="2"|') end elseif iNumb == 4 then if aNumb == (tNumb - 3) then table.insert(tOut, '\n|\n| colspan="2"|') table.insert(tOut, item) elseif aNumb == (tNumb - 2) then table.insert(tOut, '\n| colspan="2"|') table.insert(tOut, item) elseif aNumb == (tNumb - 1) then table.insert(tOut, '\n| colspan="2"|') table.insert(tOut, item) elseif aNumb == tNumb then table.insert(tOut, '\n| colspan="2"|') table.insert(tOut, item) table.insert(tOut, '\n|') end end

return table.concat(tOut) end

local function allRarity(data, special) local tOut = {} local rData = addItem(data)

for cNumb, item in ipairs(rData) do		if item[2] ~= "" then table.insert(tOut, '\n|-\n! colspan="10" style="padding: 5px;"|') table.insert(tOut, RARITY({item[1], "ECR"}))

local tItems = {} tItems = chItems(item[2]) local tNo = #tItems local rNo = tNo%5 local iNo = math.floor(tNo/5)

local br = 1 for i, rData in ipairs(tItems) do				if i == br then table.insert(tOut, '\n|-') br = br + 5 end if i <= (iNo * 5) then table.insert(tOut, '\n| colspan="2"|') table.insert(tOut, oneItem(rData[1], rData[2])) else table.insert(tOut, colItem(rNo, tNo, i, oneItem(rData[1], rData[2]))) end

if special then if cData["Items"][rData[1]] and cData["Items"][rData[1]][2] and cData["Items"][rData[1]][2] == "ch" then table.insert(bubbles, {cNumb*0.1, 1, "specialchance", rData[1]}) elseif cData["Items"][rData[1]] and cData["Items"][rData[1]][2] and cData["Items"][rData[1]][2] == "ba" then table.insert(bubbles, {cNumb*0.1, 2, "specialchance", rData[1]}) elseif cData["Items"][rData[1]] and cData["Items"][rData[1]][2] and cData["Items"][rData[1]][2] == "bc" then table.insert(bubbles, {cNumb*0.1, 3, "specialchance", rData[1]}) elseif cData["Items"][rData[1]] and cData["Items"][rData[1]][2] and cData["Items"][rData[1]][2] == "d" then table.insert(bubbles, {cNumb*0.1, 4, "specialchance", rData[1]}) elseif rData[1]:match("^EC") then table.insert(bubbles, {cNumb*0.1, 6, "specialchance", rData[1]}) else table.insert(bubbles, {cNumb*0.1, 5, "specialchance", rData[1]}) end else if cData["Items"][rData[1]] and cData["Items"][rData[1]][2] and cData["Items"][rData[1]][2] == "ch" then table.insert(bubbles, {cNumb, 1, item[1]:lower, rData[1]}) elseif cData["Items"][rData[1]] and cData["Items"][rData[1]][2] and cData["Items"][rData[1]][2] == "ba" then table.insert(bubbles, {cNumb, 2, item[1]:lower, rData[1]}) elseif cData["Items"][rData[1]] and cData["Items"][rData[1]][2] and cData["Items"][rData[1]][2] == "bc" then table.insert(bubbles, {cNumb, 3, item[1]:lower, rData[1]}) elseif cData["Items"][rData[1]] and cData["Items"][rData[1]][2] and cData["Items"][rData[1]][2] == "d" then table.insert(bubbles, {cNumb, 4, item[1]:lower, rData[1]}) elseif rData[1]:match("^EC") then table.insert(bubbles, {cNumb, 6, item[1]:lower, rData[1]}) else table.insert(bubbles, {cNumb, 5, item[1]:lower, rData[1]}) end end end end end

return table.concat(tOut) end

function getBubbles(legendary) table.sort(bubbles, function(a,b)			if a[1] == b[1] then				return a[2] < b[2]			else				return a[1] < b[1]			end		end)

local tOut = {} local k = 1

for _, v in ipairs(bubbles) do		if legendary then if k == 1 then table.insert(tOut, (' ')) k = k + 1 elseif k == 2 and v[3] ~= "specialchance" then table.insert(tOut, (' ')) break end else if k == 1 then table.insert(tOut, (' ')) k = k + 1 elseif k == 2 and v[3] ~= "specialchance" then table.insert(tOut, (' ')) k = k + 1 elseif k == 3 and v[3] ~= "specialchance" then table.insert(tOut, (' ')) if bubbles[#bubbles-1][4] ~= v[4] then table.insert(tOut, (' ')) end if bubbles[#bubbles][4] ~= v[4] and bubbles[#bubbles][4] ~= bubbles[#bubbles-1][4] then table.insert(tOut, (' ')) end break end end end

return table.concat(tOut) end

function p.getECR(frame) local tArgs = util.getArgs(frame)

local pagename = tArgs[1] or mw.title.getCurrentTitle.baseText local cName = mw.ustring.gsub(pagename, " Chests", "") local tOut = {} local cSection = {} local allcoll = "" if chestData[cName] then for k, v in pairs(chestData[cName]) do			if v ~= true then local aData = (v["D"] or {"2016/01/01", 0}) if availableData[cName] and availableData[cName][k] then aData = availableData[cName][k] end local cNumb = date(aData[1]):adddays(aData[2]):fmt("%Y/%m/%d") .. (aData[3] or util.dayStart) local cDur = nil if (aData[1] .. util.dayStart) <= today then cDur = util.strDate(aData[1], aData[2]) end if cName == "Legendary" then cNumb = k				 	if k:match("^The .*$") then cNumb = k:match("^The (.*)$") end cDur = util.strDate(aData[1], aData[2]) elseif aData[2] == 0 then cNumb = date(aData[1]):adddays(aData[2]+1):fmt("%Y/%m/%d") .. (aData[3] or util.dayStart) cDur = nil end table.insert(cSection, {cNumb, k, v, cDur, (aData[1] .. util.dayStart), (aData["C"] or v["C"]), aData["L"]}) end end

if cName == "Legendary" then table.sort(cSection, function(a,b) return a[1] < b[1] end) else table.sort(cSection, function(a,b) return a[1] > b[1] end) end

for _, cItem in pairs(cSection) do			if chestData[cName][1] and (cItem[5] >= today) then table.insert(tOut, "") else local sName = cItem[2]:gsub(" ", "_") local ecData = cItem[3] bubbles = {}

local tTable = {'{| class="dmk-chests mw-collapsible mw-collapsed" id="mw-customcollapsible-', sName, '" style="text-align: center; line-height: 1.0; display: unset;"\n', '! id="', cItem[2], '" colspan="10" style="background: linear-gradient(#14bfe4 5%,#2866ce 100%); border-radius: 20px 20px 0 0; height: 35px; color: white; text-shadow: 1px 2px 3px #030d9d; padding: 5px;"| Possible Rewards You can receive the following rewards.\n|- style="height: 0px;"|\n||||||||||||||||||||'}

if ecData["S"] then table.insert(tTable, '\n|-\n! colspan="10"|⸺⸺⸺ Only at ') table.insert(tTable, (ecData["S"][1] or "?")) table.insert(tTable, '% Special Chance  ⸺⸺⸺ ') table.insert(tTable, allRarity(ecData["S"], true)) table.insert(tTable, '\n|-\n! colspan="10"|⸺⸺⸺⸺ ⸺⸺⸺⸺ ') end

table.insert(tTable, allRarity(ecData["R"]))

if tArgs[cItem[2]] then table.insert(tTable, '\n|-\n|colspan="10" style="line-height: 1.75; text-align: left;"|') table.insert(tTable, tArgs[cItem[2]]) end table.insert(tTable, '\n|}\n')

local tCard = {'{| class="chestcard ', "default", '"\n', '| class="Part_1"|', "", '\n', '| class="Part_2"|', "", '\n', '|-\n| colspan="2" class="Part_3"| ', CHEST({cName .. "-" .. cItem[2], 100}), getBubbles, '  \n', '|-\n| colspan="2" class="Part_4"| ', (ecData["N"] or cItem[2]), ' \n', '|-\n| colspan="2" class="Part_5"| \n', '|-\n| colspan="2" class="Part_6"|', "", '\n|}\n'}

if cName == "Special Request Wishes" then tCard[11] = '' end

if cItem[6] then local iCost = "" for costItem in mw.text.gsplit(cItem[6], "%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 "", "[,]", ""))) or 0 sNumb = tonumber((string.gsub(sNumb or "", "[,]", ""))) or 0

iCost = iCost .. " " .. EC({(curName .. " #" .. util.th_comma(sNumb)), nil, nil, nil, 30}) .. ' '.. util.th_comma(cNumb) .. ' (-' .. (100-(string.format("%.2f", (sNumb/cNumb))*100)) .. '%) ' tCard[5] = '' else curNumb = tonumber((string.gsub(curNumb or "", "[,]", ""))) or 0 iCost = iCost .. " " .. EC({(curName .. " #" .. util.th_comma(curNumb)), nil, nil, nil, 30}) .. (costNumb and (" (" .. costNumb .. ") ") or " ") end else iCost = iCost .. costName .. (costNumb and (" (" .. costNumb .. ") ") or " ") end end tCard[20] = '' .. iCost .. ' '				end

if cName == "Legendary" then tCard[2] = COLL({cItem[2], "S"}):lower tCard[8] = COLL({cItem[2], 35}) tCard[11] = "" tCard[12] = getBubbles(true) allcoll = allcoll .. "$" .. cItem[2] if cItem[7] then cItem[4] = "Limited Time Content ( Last Time in Bundle: " .. cItem[4] .. ") " else cItem[4] = "Permanent Content ( Last Time in Bundle: " .. cItem[4] .. ") " end elseif cItem[5] <= today and today <= cItem[1] then cItem[4] = util.countdown(cItem[1], " for ", " until ", true) elseif cItem[5] >= today then cItem[4] = ": " .. util.countdown(cItem[5], " in ", " on ") end

if cItem[4] then tCard[23] = ' ' end

table.insert(tOut, table.concat(tCard)) table.insert(tOut, table.concat(tTable)) end end end

if allcoll ~= "" then table.insert(tOut, 1, (COLL({allcoll, "A"}) .. " \n")) end

return frame:preprocess(table.concat(tOut)) end

function p.getPrizeTable(ecData) local tTable = {'{| class="dmk-chests" style="text-align: center;line-height: 1.0;width: 100%;background: #b3b4c112;border-radius: 20px; margin: 1em 1em 1em 0;"\n', '! colspan="10" style="background: linear-gradient(#14bfe4 5%,#2866ce 100%); border-radius: 20px 20px 0 0; height: 35px; color: white; text-shadow: 1px 2px 3px #030d9d; padding: 5px;"| Possible Rewards You can receive the following rewards.\n|- style="height: 0px;"|\n||||||||||||||||||||'}

if ecData["S"] then table.insert(tTable, '\n|-\n! colspan="10"|⸺⸺⸺ Only at ') table.insert(tTable, (ecData["S"][1] or "?")) table.insert(tTable, '% Special Chance <font style="background: -webkit-linear-gradient(right, transparent, #008600);-webkit-background-clip: text;-webkit-text-fill-color: transparent;"> ⸺⸺⸺ ') table.insert(tTable, allRarity(ecData["S"], true)) table.insert(tTable, '\n|-\n! colspan="10"|<big style="font-size: xx-large;"><font style="background: -webkit-linear-gradient(left, transparent, #008600);-webkit-background-clip: text;-webkit-text-fill-color: transparent;">⸺⸺⸺⸺ <font style="background: -webkit-linear-gradient(right, transparent, #008600);-webkit-background-clip: text;-webkit-text-fill-color: transparent;">⸺⸺⸺⸺ ') end

if ecData["R"] then table.insert(tTable, allRarity(ecData["R"])) end

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

return table.concat(tTable) end

local function getChest(iType, data, cName, pagename, special, old, section) local tRarity = addItem(data)

for _, item in pairs(tRarity) do		if item[2] ~= "" then item[2] = chItems(item[2]) for _, rData in ipairs(item[2]) do				local iName = rData[1]

if iType == "T" then if pagename == "Collection" or pagename == "Common" or pagename == "Uncommon" or pagename == "Rare" or pagename == "Epic" or pagename == "Legendary" or pagename == "Relic Common" or pagename == "Relic Uncommon" or pagename == "Relic Rare" then iName = iName elseif iName:match("^EC") then iName = EC({iName, "T"}) else iName = TOK.getTokenDirect(iName, "T") end else if iName:match("^EC") then iName = EC({iName, "T"}) end end

if rData[2] then rData[2] = "x" .. rData[2] end

if pagename == iName then return {(cName .. "-" .. (section or "")), rData[2], special, old, CHEST=true} end end end end

return tOut end

function p.getACTTOK(name) local tOut = {}

local pagename = name or mw.title.getCurrentTitle.text

for cName, chest in pairs(chestData) do		for n, v in pairs(chest) do			if v ~= true then if v["D"] then local data = v["D"] local UnlockDate = data[1] .. util.dayStart local LockDate = date(data[1]):adddays(data[2]):fmt("%Y/%m/%d") .. (data[3] or util.dayStart) if UnlockDate < today and (data[2] == 0 or today < LockDate) then if v["R"] then table.insert(tOut, getChest("T", v["R"], cName, pagename, nil, nil, n)) end if v["S"] then table.insert(tOut, getChest("T", v["S"], cName, pagename, "S", nil, n)) end

if not pagename:match("^.+ Blueprint Token$") and not pagename:match("^.+ Elixir Ingot Token$") and not pagename:match("^Time Skip Token$") then local pRarity = TOK.tokenType({pagename, "I"}) if pRarity ~= "collection" then pRarity = TOK.tokenType({pagename}) pRarity = string.upper(string.sub(pRarity, 1, 1)) .. string.sub(pRarity, 2) if pagename:match("^.+ Relic Token$") then pRarity = "Relic " .. pRarity end else pRarity = string.upper(string.sub(pRarity, 1, 1)) .. string.sub(pRarity, 2) end

if v["R"] then table.insert(tOut, getChest("T", v["R"], cName, pRarity, nil, nil, n)) end if v["S"] then table.insert(tOut, getChest("T", v["S"], cName, pRarity, "S", nil, n)) end end end end end end end

return tOut end

function p.getDATA(pagename) local tChest = {}

for cName, chest in pairs(chestData) do		for n, v in pairs(chest) do			if v ~= true then local aData = (v["D"] or {"2016/01/01", 0}) if availableData[cName] and availableData[cName][n] then aData = availableData[cName][n] end local LockDate = date(aData[1]):adddays(aData[2]):fmt("%Y/%m/%d") .. (aData[3] or util.dayStart) local Limited = aData["L"] if cName == "Legendary" and ((LockDate < today) or ((aData[1] .. util.dayStart) > today)) then aData = {"2016/01/01", 0} LockDate = aData[1] .. util.dayStart end

if (LockDate > today or aData[2] == 0) and not Limited then if v["R"] then local tRarity = addItem(v["R"]) for _, item in pairs(tRarity) do							if item[2] ~= "" then item[2] = chItems(item[2]) for _, rData in ipairs(item[2]) do									if pagename == rData[1] then table.insert(tChest, {rData[1], aData[1], aData[2], (aData[3] or util.dayStart), (cName .. " Chests"), n, (cName .. " Chests")}) end end end end end if v["S"] then local tRarity = addItem(v["S"]) for _, item in pairs(tRarity) do							if item[2] ~= "" then item[2] = chItems(item[2]) for _, rData in ipairs(item[2]) do									if pagename == rData[1] then table.insert(tChest, {rData[1], aData[1], aData[2], (aData[3] or util.dayStart), (cName .. " Chests"), n, (cName .. " Chests")}) end end end end end end end end end

return tChest end

function p.getITEM(frame) local ME = require("Module:MiniEvent").getME local tArgs = util.getArgs(frame)

local tOut = {} local tChest = {} local space = "" local pagename = tArgs["P"] or mw.title.getCurrentTitle.text

for cName, chest in pairs(chestData) do		for n, v in pairs(chest) do			if v ~= true then if v["D"] then local data = v["D"] local UnlockDate = data[1] .. util.dayStart local LockDate = date(data[1]):adddays(data[2]):fmt("%Y/%m/%d") .. (data[3] or util.dayStart) if UnlockDate < today and (data[2] == 0 or today < LockDate) and cName ~= "Legendary" then if v["R"] then table.insert(tChest, getChest("I", v["R"], cName, pagename, nil, nil, n)) end if v["S"] then table.insert(tChest, getChest("I", v["S"], cName, pagename, "S", nil, n)) end end else table.insert(tChest, getChest("I", v["R"], "Legendary", pagename, nil, nil, n)) end end end end

for sName, data in pairs(availableData) do		if availableData[sName][1] and type(data) == "table" then for name, v in pairs(data) do				if v ~= true then local UnlockDate = v[1] .. util.dayStart local LockDate = date(v[1]):adddays(v[2]):fmt("%Y/%m/%d") .. (v[3] or util.dayStart) if UnlockDate < today and (v[2] == 0 or today < LockDate) and cName ~= "Legendary" then for cName in mw.text.gsplit(name, "%s*%$%s*") do							if pagename == cName then table.insert(tChest, {(v["L"] or sName), (v["A"] or ""), (v["D"] or v["A"] or v["L"] or sName), v["R"]}) end end end end end end end

pagename = mw.title.getCurrentTitle.subpageText

for k, v in pairs(tChest) do		local tRet = {space, "", "", "", "", ""}

if tArgs[1] == "L" and v["CHEST"] then tRet[2] = CHEST({v[1], "O"}) elseif tArgs[1] == "I" and v["CHEST"] then tRet[2] = CHEST({v[1], "L", "S"}) elseif tArgs[1] == "L" then tRet[2] = "[[File:"			if v[1]:match(" Mini Event$") then				local meData = mw.loadData( 'Module:MiniEvent/data')				tRet[3] = v[1]:match("^(.+) Mini Event$"):lower				tRet[3] = meData[tRet[3]]["NPC"] tRet[3] = "Npc-" .. tRet[3]:gsub(" ", "_"):lower

local mile, pos = string.match(v[4], "^([LM])(.*)") tRet[5] = "''Unlock " .. v[3] .. ": " .. util.ordinal(pos) .. ((mile == "M") and " Milestone" or " Leaderboard") .. " to get " .. pagename .. "!''"			elseif v[1]:match("^Season") then tRet[3] = "season_pass" elseif v[1]:match("Calendar$") then tRet[3] = "home-calendar" elseif v[1] == "Discovery Rewards" then tRet[3] = "discovery" else tRet[3] = "home-promotion" end tRet[4] = ".png|x25px|link=" .. v[1] .. "#" .. v[2].. "|" .. v[3] .. "]] "			if tRet[5] == "" then tRet[5] = "''Unlock [[" .. v[1] .. "#" .. v[2] .. "|" .. v[3] .. ": " .. v[2] .. "]] to get " .. pagename .. "!''" end elseif tArgs[1] == "I" then tRet[2] = "" .. v[3] .. ": " tRet[3] = v[2] if v[1]:match("Mini Event$") and v[4] then local mile, pos = string.match(v[4], "^([LM])(.*)") tRet[3] = util.ordinal(pos) tRet[4] = (mile == "M") and " Milestone" or " Leaderboard" end end space = " "

table.insert(tOut, table.concat(tRet)) end

if table.concat(tOut) ~= "" then table.insert(tOut, " ") end

return table.concat(tOut) end

function p.getLastCost(frame) local tArgs = util.getArgs(frame) local tOut = "" local prevTab = "2016/01/01" local pagename = tArgs["P"] if not pagename then pagename = mw.title.getCurrentTitle.text end pagename = mw.ustring.gsub(pagename, " Chests", "") or "" if not chestData[pagename] then return "" end

for cName, chest in pairs(chestData[pagename]) do		if chest ~= true and chest["D"] and chest["C"] and chest["D"][1] > prevTab then tOut = "" for costItem in mw.text.gsplit(chest["C"], "%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 "", "[,]", "")))

tOut = tOut .. EC({curName .. " #" .. sNumb}) .. ' '.. cNumb .. '</i><small style="border-radius: 10px 0 0 10px;padding: 2px 3px 2px 3px;background: #f20d07;box-shadow: 0 0 5px 0 #494444;border: 1px solid #feb226;outline: 1px solid #f20d07;margin-left: 5px;"> (-' .. (100-(string.format("%.2f", (sNumb/cNumb))*100)) .. '%) ' tCard[5] = '' else tOut = tOut .. EC({curName .. " #" .. curNumb}) .. (costNumb and (" (" .. costNumb .. ") ") or " ") end else tOut = tOut .. costName .. (costNumb and (" (" .. costNumb .. ") ") or " ") end end prevTab = chest["D"][1] end end

return tOut end

function p.availabilityEC(frame) local tArgs = util.getArgs(frame) local pagename = tArgs[1] or mw.title.getCurrentTitle.text pagename = mw.ustring.gsub(pagename, " Chests", "") or ""

local tOut = "" local space = "" local tItem = {}

for cName, chest in pairs(chestData) do		if pagename == cName then for n, v in pairs(chest) do				if v ~= true then if availableData[cName] and availableData[cName][n] then table.insert(tItem, {n, availableData[cName][n][1], availableData[cName][n][2], (availableData[cName][n][3] or util.dayStart), (cName .. " Chests"), n}) elseif v["D"] then table.insert(tItem, {n, v["D"][1], v["D"][2], (v["D"][3] or util.dayStart), (cName .. " Chests"), n}) end end end elseif pagename == "All" then for n, v in pairs(chest) do				if v ~= true then if availableData[cName] and availableData[cName][n] then table.insert(tItem, {n, availableData[cName][n][1], availableData[cName][n][2], (availableData[cName][n][3] or util.dayStart), (cName .. " Chests"), (n .. " Chests")}) elseif v["D"] and v["D"][2] ~= 0 then table.insert(tItem, {n, v["D"][1], v["D"][2], (v["D"][3] or util.dayStart), (cName .. " Chests"), (cName .. " Chests")}) 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 Header = "" .. (v[6] or v[5] or v[1]) .. ":  " local UnlockDate = v[2] .. util.dayStart local LockDate = date(v[2]):adddays(v[3]):fmt("%Y/%m/%d") .. v[4]

if today <= UnlockDate then tOut = tOut .. space .. Header .. ": " .. util.countdown(UnlockDate, " in ", " on ") space = " " elseif v[3] == 0 then tOut = tOut .. space .. Header .. ": Currently Available" space = " " elseif today <= LockDate then tOut = tOut .. space .. Header .. ": " .. util.countdown(LockDate, " for ", " until ") space = " " end end

if tOut ~= "" then return tOut else return "" .. pagename .. " Chests:  : Not Currently Available" end end

return p