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 = 140 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)}) 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) 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 0px 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: 232px; background-position: -37px 0; text-align: left;"|') if bType ~= "default" then table.insert(tOut, 'Helps with Characters ') end if bHelp then table.insert(tOut, 'Helps with Characters') end table.insert(tOut, '')

table.insert(tOut, '\n|-\n| colspan="2" style="width: 230px !important; height: 298px; background-size: cover; background-position: 0 -37px; background-repeat: space; vertical-align: baseline; padding: 0 9px 0 4px;"|') table.insert(tOut, tableBundle(bNumb, bContent)) table.insert(tOut, ' ') table.insert(tOut, bName) table.insert(tOut, ' ') if not bLimit then bLimit = "1" end if bLimit ~= "0" then table.insert(tOut, ' Limit: 1/') table.insert(tOut, bLimit) table.insert(tOut, ' ') 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  \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 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) local bContent = {} local bHelp = nil if not tArgs[2] then return "" end

local tt = mw.text.split(tArgs[2], "%s*$%s*")

tt[1] = tonumber(tt[1]) if tt[1] and tt[1] == 1 then table.insert(bContent, (tt[4] or "")) if tt[5] then bHelp = tt[5] .. "$" .. (tt[6] or "") .. "$" .. (tt[7] or "") .. "$" .. (tt[8] or "") end elseif tt[1] and tt[1] == 2 then table.insert(bContent, (tt[4] or "")) table.insert(bContent, (tt[5] or "")) if tt[6] then bHelp = tt[6] .. "$" .. (tt[7] or "") .. "$" .. (tt[8] or "") .. "$" .. (tt[9] or "") end elseif tt[1] and (tt[1] == 3 or tt[1] == 32) then table.insert(bContent, (tt[4] or "")) table.insert(bContent, (tt[5] or "")) table.insert(bContent, (tt[6] or "")) if tt[7] then bHelp = tt[7] .. "$" .. (tt[8] or "") .. "$" .. (tt[9] or "") .. "$" .. (tt[10] or "") end elseif tt[1] and (tt[1] == 4 or tt[1] == 42) then table.insert(bContent, (tt[4] or "")) table.insert(bContent, (tt[5] or "")) table.insert(bContent, (tt[6] or "")) table.insert(bContent, (tt[7] or "")) if tt[8] then bHelp = tt[8] .. "$" .. (tt[9] or "") .. "$" .. (tt[10] or "") .. "$" .. (tt[11] or "") end elseif tt[1] and (tt[1] == 5 or tt[1] == 52) then table.insert(bContent, (tt[4] or "")) table.insert(bContent, (tt[5] or "")) table.insert(bContent, (tt[6] or "")) table.insert(bContent, (tt[7] or "")) table.insert(bContent, (tt[8] or "")) if tt[9] then bHelp = tt[9] .. "$" .. (tt[10] or "") .. "$" .. (tt[11] or "") .. "$" .. (tt[12] or "") end end

local bb = mw.text.split(tt[2], "%s*#%s*")

return tableItems(tArgs[1], (bb[1] or "?"), (tt[1] or 1), (tt[3] or "?"), bContent, bHelp, bb[2]) 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))) end

return table.concat(tOut) end

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

local pagename = tArgs[1] if not pagename then pagename = mw.title.getCurrentTitle.text end

local tOut = "" local tItem = {} local space = "" local today = os.date("%Y/%m/%d %H:%M:%S") for sName, data in pairs(bundleData) do		for bName, tab in pairs(data) do			for _, cName in pairs(tab["C"]) do				table.insert(tItem, {cName, tab["D"][1], tab["D"][2], (tab["D"][3] or util.dayStart), bName}) end end end

for _, values in pairs(tItem) do local UnlockDate = values[2] .. util.dayStart local LockDate = date(values[2]):adddays(values[3]):fmt("%Y/%m/%d") .. values[4] if pagename == values[1] and today >= UnlockDate and (today <= LockDate or values[3] == 0) then tOut = tOut .. space .. "" .. values[5] .. "" space = " " end end

if tOut ~= "" then tOut = tOut .. " " end

return tOut end

return p