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 size = 65 local size2 = nil local catsize = 35

if type == 5 then size = 40 elseif type == 42 then size = 78 elseif type == 4 then size = 55 elseif type == 32 then size = 78 size2 = 140 elseif type == 22 then size = 140 size2 = 100 elseif type == 2 then size = 140 size2 = 85 elseif type == 1 then size = 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", }

local iData = cData["Items"][iName]

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, ((size2 or size)-10)}) end elseif iData and iData[2] then if type == 5 then catsize = 25 elseif type == 4 then catsize = 30 elseif type == "C" then catsize = 32 elseif type == 1 then catsize = 40 end local iDisp = iName:gsub("^([^%(]-)%/([^%(]-)$", "%2") if type == "N" then tItem[2] = "" .. (iDisp or iName) .. "" tItem[4] = '' else 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			tItem[2] = ""			if cData["Items"][iName]["C"] and cData["Categories"][cData["Items"][iName]["C"]] then				local category = cData["Items"][iName]["C"]

if type == "C" then tItem[3] = ' ' else tItem[3] = ' ' end end end elseif item:match("^EC") then if type == 3 then size = 50 end if type == "N" then tItem[2] = EC({iName, "L", S=(nCount == "1")}) tItem[4] = '' else tItem[2] = EC({iName, nil, nil, "F", (size2 or size)}) 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, (size2 or size)}) 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) local tOut = {}

table.insert(tOut, '{| class="card ')	if not bType or bType == "zz" then bType = "default" end	table.insert(tOut, bType)	table.insert(tOut, '" style="text-align: center; line-height: normal; border-spacing: 0px; color: white; display: inline-table; margin: 0 0 10px 0;"\n| style="width: 37px !important; height: 37px; background-size: 232px; background-position: inherit;"|') table.insert(tOut, ' ') table.insert(tOut, '\n| style="width: 190px !important; background-size: 231px; background-position: -40px 0; text-align: left; text-shadow: 2px 1px 2px #3a3a3a;"|') if bEvent then table.insert(tOut, 'Helps with Event ') end if bHelp and bHelp ~= "" then table.insert(tOut, 'Helps with Characters') elseif bRequ and bRequ ~= "Discovery Rewards #6" then table.insert(tOut, '(Need Requirements)') end table.insert(tOut, '')

table.insert(tOut, '\n|-\n| colspan="2" style="width: 230px !important; height: 210px; background-size: cover; background-position: 0 -37px; padding: 0px;"|') table.insert(tOut, tableBundle(bNumb, bContent)) table.insert(tOut, '\n|-\n| colspan="2" style="width: 230px !important; height: 89px; background-size: cover; background-position: 0 -246px; background-repeat: space; vertical-align: baseline; padding: 0 9px 0 4px;"|') table.insert(tOut, ' ') table.insert(tOut, bName) table.insert(tOut, ' ') if bLimit ~= 0 then table.insert(tOut, ' ') if not bCost then table.insert(tOut, ' ') end table.insert(tOut, 'Limit: ') table.insert(tOut, bLimit) table.insert(tOut, '/') table.insert(tOut, bLimit) table.insert(tOut, ' ') end if bCost then local CostTable = require("Module:Card").getCost table.insert(tOut, CostTable({bCost})) end

table.insert(tOut, '\n|-\n| colspan="2" style="background-size: cover;background-position: 0 -335px;background-repeat: space;"| ') table.insert(tOut, '\n|}\n')

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: 10px; 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 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 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