Module:Bundle

--[=[ -- LUA script to get Bundles -- --]=]

local p = {}

---[=[ For testing remove 1 '-' from start of line local bundleData = mw.loadData('Module:Bundle/data') --[==[]=] local bundleData = { ["rh"] = { ["Parade"] = {4, ["D"] = {"2022/03/13", 18, " 19:00:00 UTC"}, ["C"] = {"Robin Hood Float", "IP-RH #5", "Maid Marian,2 #5", "Maid Marian,3 #5"}, ["H"] = "Sir Hiss$Maid Marian$Prince John", },	}, } --]==] local cData = mw.loadData( 'Module:ItemCollection/data' )

local util = require('Module:Utility') local EC = require("Module:EC").getEC local TOK = require("Module:CharacterToken").getToken local CHEST = require("Module:EnchantedChest").getChest local ICON = require("Module:CharacterAvatar").getAvatar local date = require("Dev:Date") local today = os.date("%Y/%m/%d %H:%M:%S")

local function oneItem(item, type) if not item then return "" end local tt = mw.text.split(item, "%s*#%s*") local iName = tt[1] or item local nCount = tt[2] or 0

local height = 65 local width = nil local catsize = 35

if type == 5 then height = 40 elseif type == 42 then height = 80 elseif type == 4 then height = 55 elseif type == 32 then height = 80 width = 140 elseif type == 3 then height = 80 width = 55 elseif type == 22 then height = 140 width = 100 elseif type == 2 then height = 140 width = 85 elseif type == 1 then height = 120 end

local tItem = {' ', , , '', ' '} if type == "C" and nCount ~= 0 then tItem[4] = ' x' .. nCount .. ' ' elseif nCount ~= 0 then tItem[4] = ' x' .. nCount .. ' '	end

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

local iData = cData["Items"][iName] if iData == nil then iData = cData["Items"][iName:match("(.+)%-%d+$")] end

if item:match("Chests") and not iName:match("Wacky Lunch Chests") then if type == "N" then tItem[2] = CHEST({iName, "L", (nCount ~= "1")}) tItem[4] = '' else tItem[2] = CHEST({iName, ((width or height)-10)}) end elseif iData and iData[2] then if type == 5 then catsize = 25 elseif type == 4 or type == 3 then catsize = 30 elseif type == "C" then catsize = 32 elseif type == "H" then catsize = 25 height = 50 elseif type == 1 then catsize = 40 end

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		if not cData["Items"][iName] and iName:match("^.+%-%d+$") then iName = iName:match("(.+)%-%d+$") end		local iDisp = iName:gsub("^([^%(]-)%/([^%(]-)$", "%2")

if type == "N" then tItem[2] = "" .. (iDisp or iName) .. "" tItem[4] = '' else tItem[2] = ""

if iData["C"] and cData["Categories"][iData["C"]] then local category = iData["C"]

if type == "C" or type == "H" then tItem[3] = ' ' else tItem[3] = ' ' end end

if type == "H" then if string.gsub(iData[2], ".+", conv) == "cp" then tItem[2] = "" end tItem[2] = ' ' .. tItem[2] .. ' '				tItem[4] = " " .. (iDisp or iName) .. " " end end elseif item:match("^EC") then if type == 3 then height = 50 end if type == "N" then tItem[2] = EC({iName, "L", S=(nCount == "1")}) tItem[4] = '' else tItem[2] = EC({iName, nil, nil, "F", (width or height)}) end else if type == "N" then tItem[2] = TOK({iName, "L"}) if nCount ~= "1" then tItem[3] = "s" end tItem[4] = '' else tItem[2] = TOK({iName, (width or height)}) end end

if type == "C" then tItem[2] = ' ' .. tItem[2] .. ' '	end

return table.concat(tItem) end

local function tableBundle(tNumb, cData) local tOut = {' ' end

local function tableItems(bType, bName, bNumb, bDuration, bContent, bHelp, bLimit, bRequ, bEvent, bCost) if not bType or bType == "zz" then bType = "default" end bname = bName:gsub(" ", "_")

local tOut = {	'{| class="bundlecard ', bType, '"', '\n| class="Part_1"| ', '\n| class="Part_2"|', "", '', '\n|-\n| colspan="2" class="Part_3"|', tableBundle(bNumb, bContent), '\n|-\n| colspan="2" class="Part_4"| ', bName, ' ', ' ', "", "", '\n|-\n| colspan="2" class="Part_5"| ', '\n|}\n' }

if bEvent and bHelp and bHelp ~= "" then tOut[8] = 'Helps with Event Helps with Characters' elseif bEvent and bRequ and bRequ ~= "Discovery Rewards #6" then tOut[8] = 'Helps with Event (Need Requirements)' elseif bHelp and bHelp ~= "" and bRequ and bRequ ~= "Discovery Rewards #6" then tOut[8] = 'Helps with Characters (Need Requirements)' elseif bEvent then tOut[8] = 'Helps with Event' elseif bHelp and bHelp ~= "" then tOut[8] = 'Helps with Characters' elseif bRequ and bRequ ~= "Discovery Rewards #6" then tOut[8] = '(Need Requirements)' end

if bLimit ~= 0 then tOut[16] = 'Limit: ' .. bLimit .. '/' .. bLimit .. ' '	end

if bCost then if bCost:match("^EC-") then local curName, curNumb = mw.ustring.match(bCost, "^([^,]-)%s*#%s*(.-)$") if not curName then curName = bCost 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

bCost = " " .. EC({(curName .. " #" .. util.th_comma(sNumb)), nil, nil, nil, 30}) .. ' '.. util.th_comma(cNumb) .. ' (-' .. (100-(string.format("%.2f", (sNumb/cNumb))*100)) .. '%) ' tOut[8] = 'Special Promotion ' else curNumb = tonumber((string.gsub(curNumb or "", "[,]", ""))) or 0 bCost = " " .. EC({(curName .. " #" .. util.th_comma(curNumb)), nil, nil, nil, 30}) .. " "			end end tOut[15] = ' ' tOut[17] = tOut[17] .. ' '	end

local UnlockDate = bDuration[1] .. util.dayStart local LockDate = date(bDuration[1]):adddays(bDuration[2]):fmt("%Y/%m/%d") if bundleData[bType] and bundleData[bType][bName] then LockDate = LockDate .. (bundleData[bType][bName]["D"][3] or util.dayStart) else LockDate = LockDate .. (bDuration[3] or util.dayStart) end if today <= UnlockDate then return "" elseif bDuration[2] == 0 then tOut[19] = "Permanent Content" elseif today <= LockDate then tOut[19] = util.countdown(LockDate, " for ", " until ", true) elseif today > LockDate then tOut[19] = util.strDate(bDuration[1], bDuration[2]) end

table.insert(tOut, '{| class="bundle-content mw-collapsible mw-collapsed" id="mw-customcollapsible-')	table.insert(tOut, bname)	table.insert(tOut, '"\n! id="')	table.insert(tOut, bName)	table.insert(tOut, '" colspan="6"| Contents  ') if bEvent and bDuration[1] <= "2016/09/10" then bRequ = bRequ or "Mickey's Fun Wheel" elseif bEvent and bDuration[1] <= "2016/11/10" then bRequ = bRequ or "California Screamin'" elseif bEvent and bDuration[1] <= "2021/01/10" then bRequ = bRequ or "Mickey Mouse/Pirate" elseif bEvent then bRequ = bRequ or "Discovery Rewards #6" end if bRequ then table.insert(tOut, " (Requires ")			bRequ = mw.ustring.gsub(bRequ, "-" .. bType:upper, "")			table.insert(tOut, bRequ)		elseif bRequ:match("^.+ %#%d$") then      			local bRequ, bLvl = bRequ:match("^(.+) %#(%d)$")			table.insert(tOut, bRequ)			table.insert(tOut, "|")			table.insert(tOut, bRequ)			table.insert(tOut, " (Level ")			table.insert(tOut, bLvl)			table.insert(tOut, ")")		else			table.insert(tOut, bRequ)		end		table.insert(tOut, " to unlock this bundle) ") end table.insert(tOut, '\n|-')

local cIcon = "" local cName = "" for _, v in pairs(bContent) do cIcon = '\n|' .. oneItem(v, "C") .. cIcon cName = '\n| ' .. oneItem(v, "N") .. ' ' .. cName end table.insert(tOut, cIcon)

if bHelp and bHelp ~= "" then table.insert(tOut, '\n| rowspan="2" style="vertical-align: top; border: 4px solid #f5b90c; border-radius: 23px; width: 1%; padding: 0;"| ') end

table.insert(tOut, '\n|-') table.insert(tOut, cName) table.insert(tOut, '\n|}\n')

return table.concat(tOut) end

function p.getBundle(frame) local tArgs = util.getArgs(frame) if not tArgs[2] then return "" end local tt = mw.text.split(tArgs[2], "%s*$%s*")

local bContent = {} local bHelp = nil local bReq = nil local bLim = 1

local bName, bNumb, bType = mw.ustring.match(tt[2], "^([^,]-)%s*#%s*(%d+)%s*-*%s*([^,]*)$") if not bName then bName, bType = mw.ustring.match(tt[2], "^([^,]-)%s*#%s*(%d+)$") end

if not bName then bName = "?" end if not bNumb then bNumb = 1 else bNumb = tonumber(bNumb) end if not bType or bType == "" then bType = tArgs[1] end

if bNumb == 1 then bContent = {tt[3]} if tt[4] and tonumber(tt[4]) then bLim = tonumber(tt[4]) else bHelp = tt[4] end if tt[5] then bReq = tt[5] end elseif bNumb == 2 then bContent = {tt[3], tt[4]} if tt[5] and tonumber(tt[5]) then bLim = tonumber(tt[5]) else bHelp = tt[5] end if tt[6] then bReq = tt[6] end elseif bNumb == 3 or bNumb == 32 or bNumb == 33 then bContent = {tt[3], tt[4], tt[5]} if tt[6] and tonumber(tt[6]) then bLim = tonumber(tt[6]) else bHelp = tt[6] end if tt[7] then bReq = tt[7] end elseif bNumb == 4 or bNumb == 42 then bContent = {tt[3], tt[4], tt[5], tt[6]} if tt[7] and tonumber(tt[7]) then bLim = tonumber(tt[7]) else bHelp = tt[7] end if tt[8] then bReq = tt[8] end elseif bNumb == 5 or bNumb == 52 then bContent = {tt[3], tt[4], tt[5], tt[6], tt[7]} if tt[8] and tonumber(tt[8]) then bLim = tonumber(tt[8]) else bHelp = tt[8] end if tt[9] then bReq = tt[9] end elseif bNumb == 6 then bContent = {tt[3], tt[4], tt[5], tt[6], tt[7], tt[8]} if tt[9] and tonumber(tt[9]) then bLim = tonumber(tt[9]) else bHelp = tt[9] end if tt[10] then bReq = tt[10] end end

local bDur1, bDur2 = mw.ustring.match(tt[1], "^([^,]-)%s*#%s*(%d+)$") if not bDur1 then bDur1 = "2016/01/01" end if not bDur2 then bDur2 = 1 else bDur2 = tonumber(bDur2) end

return tableItems(bType, bName, bNumb, {bDur1, bDur2}, bContent, bHelp, bLim, bReq, true) end

function p.getList local tOut = {} local allBundles = {} for bType, v in pairs(bundleData) do		for bName, bData in pairs(v) do if bData["D"] and ((bData["D"][1] .. util.dayStart) < today) and ((date(bData["D"][1]):adddays(bData["D"][2]):fmt("%Y/%m/%d") .. (bData["D"][3] or util.dayStart)) > today) then if bType == "default" then bType = "zz" end table.insert(allBundles, {bData, bType, bName}) elseif bData["D"] and ((bData["D"][1] .. util.dayStart) < today) and bData["D"][2] == 0 then if bType == "default" then bType = "zz" end table.insert(allBundles, {bData, bType, bName}) end end end

table.sort(allBundles, function(a,b)			if a[1]["D"][1] == b[1]["D"][1] then				return a[3] < b[3]			else				return a[1]["D"][1] > b[1]["D"][1]			end		end)

for _, cItem in pairs(allBundles) do   		local data = cItem[1] table.insert(tOut, tableItems(cItem[2], cItem[3], data[1], data["D"], data["C"], data["H"], (data["L"] or 1), data["R"], data["E"], data["G"])) end

return table.concat(tOut) end

return p