Module:ItemCollection

--[==[-- -- Lua script to get Collection Icon for Character or Collection Name --

Function: getCollection

Parameters:i 1: Character Name (or Collection short Name) Separate multiple characters with a dollar sign "$" 2: Icon Size in pixels "L" = include Text name/link, size = 25 "A" = link to section/anchor on current page "N" = Collection Name (Text only) "S" = IP/Collection Short Name (Text only) "P" = include small Name/Link bellow, size = 40 3: Filtered list if present, then filtered list of collections is displayed filtering out collections with item [2] not nil

Function: getGallery --]==]

local p = {}

local collectionData = mw.loadData( 'Module:ItemCollection/data' ) local util = require('Module:Utility')

function oneCollection(collection, size, outType, pageName, collNo) local fileLink = ""

if collection then local collName = collection[2] if outType == 3 then return collName elseif outType == 4 then return collection["S"] or collName elseif outType == 8 then return collection["D"] or collName end local file = mw.ustring.gsub(collName, "[\,\.']", "") file = mw.ustring.gsub(file, " ", "_") file = mw.ustring.lower(file)

if outType == 1 then fileLink = ""               .. collName                .. " ("        elseif outType == 7 then            return ""                .. collName                .. ""        elseif outType == 11 then            fileLink = "[[Category:"                .. collName                .. "]]"                .. collName                .. " (" else fileLink = "" end

fileLink = fileLink .. "[[File:cc-"           .. file            .. "-l.png|x"            .. size            .. "px|"            .. collName            .. "|link="

if outType == 2 then fileLink = fileLink .. "#"                       .. mw.uri.anchorEncode(collection["A"] or collName) else fileLink = fileLink .. "Category:" .. collName end fileLink = fileLink .. "]]"

if outType == 1 or outType == 11 then fileLink = fileLink .. ")"       end

fileLink = fileLink .. " "       if outType == 5 then fileLink = fileLink .. " "               .. collName                .. " " elseif outType == 6 then fileLink = "This is one of the few collections that has been present in the game since its first release." if collection[1] ~= 0 then fileLink = "This is the " .. util.wordinal(collection[1]) .. " collection created by an Update." end if collNo >= 1000 and collNo <= 9900 and collNo ~= 1185 then fileLink = fileLink .. "\n* This is the " .. util.wordinal(math.ceil(collNo/10-100)) .. " collection created by a Limited-Time Event." end end end return fileLink end

function oneImage(collection) local fileLink = ""

if collection then local collName = collection[2] local file = mw.ustring.gsub(collName, "[\,\.']", "") file = mw.ustring.gsub(file, " ", "_") file = mw.ustring.lower(file)

fileLink = fileLink .. "cc-" .. file .. "-l.png|"           .. collName            .. "|link=Category:" .. collName end return fileLink end

function p.getCollection(frame) local tArgs = util.getArgs(frame) local character = tArgs[1] or "" local size = tArgs[2] local filter = tArgs[3] or ""

local outType = 0

if not size or size == "" then size = "50" elseif not tonumber(size) then if size == "N" then outType = 3 size = "0" elseif size == "D" then outType = 8 size = "0" elseif size == "L" then outType = 7 size = "0" elseif size == "S" then outType = 4 size = "0" elseif size == "A" then outType = 2 size = tonumber(filter) or "40" elseif size == "P" then outType = 5 size = "40" elseif size == "U" then outType = 6 elseif size == "T" then outType = 11 size = "25" else outType = 1 size = "25" end end

local collectionFile = "" if outType == 2 then collectionFile = " Go to: " end local space = "" local pageName = mw.title.getCurrentTitle.prefixedText local collections = {} character = mw.ustring.gsub(character, "^%s*(.-)%s*$", "%1") or '' if character == "" then character = mw.title.getCurrentTitle.text end

for cName in mw.text.gsplit(character, "%s*%$%s*") do           cName = mw.text.decode(cName) if collectionData["Items"][cName] and collectionData["Items"][cName][1] then local collNo = collectionData["Items"][cName][1] -- If the line below is added, then in case of multiple items, if any one -- item has collNo = nil then the empty string will be returned, -- instead of just skipping that one item --               if collNo == nil then return "" end

if not collections[collNo] then local collData = collectionData["Collections"][collNo] collectionFile = collectionFile .. space .. oneCollection(collData, size, outType, pageName, collNo) if outType == 1 or outType == 3 or outType == 4 then space = ", " else space = " " end

collections[collNo] = 1 end end end

if outType == 2 then collectionFile = collectionFile .. " " end

return collectionFile end

function p.getCategory(frame) local tArgs = util.getArgs(frame) if not tArgs[1] then return "" end local tOut = "Unknown Category" if collectionData["Categories"][tArgs[1]] then local category = collectionData["Categories"][tArgs[1]] local file = tArgs[1]:lower:gsub(" stand$", "")

tOut = "" .. tArgs[1] .. " "

if not tArgs[2] then tOut = tOut .. ""		elseif tArgs[2] and tArgs[2] == "C" then tOut = "" elseif tArgs[2] and tArgs[2] == "P" then tOut = " " .. tArgs[1] .. " " end end

return tOut end

-- to be called only from other LUA modules function p.getItemType(item) local itemType = ""

if collectionData["Items"][item] then itemType = collectionData["Items"][item][2] end return itemType end

function p.getCollItem(item) local collNumb = "" local collItem = {}

for k, v in pairs(collectionData["Collections"]) do		if (v["S"] or v[2]):upper == item and not v["A"] then collNumb = k		end end

if collNumb ~= "" then for name, data in pairs(collectionData["Items"]) do			if data[1] and data[1] == collNumb and data[2] then if not collItem[data[2]] then collItem[data[2]] = {} end table.insert(collItem[data[2]], name) end end end

return collItem end

function p.getGallery(frame) local cHeader = '")

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

function p.getIteminfo(frame) local tArgs = util.getArgs(frame) local VL = mw.ext.VariablesLua local LINK = require("Module:Storyline").getLink local EC = require("Module:EC").getEC

local conv = { ["ch"] = "cp", ["cos"] = "cp", ["tp"] = "npc", ["mb"] = "npc", }	local itemName = tArgs[1] or mw.title.getCurrentTitle.text itemName = itemName:gsub("^%s*(.-)%s*$", "%1") or ''

local data = collectionData["Items"][itemName] if not data then return "" end

local cName, cCostume = mw.ustring.match(itemName, "^([^,]-)%s*/%s*(.-)$") VL.vardefine("pagename", (cCostume or itemName)) VL.vardefine("charname", (cName or "Unknown"))

local fname = mw.ustring.gsub(mw.ustring.lower(itemName), "[':\"%,%.]", "")	fname = fname:gsub(" ", "_")	if data[2] == "pf" then		fname = fname:gsub("_float$", "")	elseif data[2] == "ec" then		fname = fname:gsub("_chests$", "")	else		fname = fname:gsub("^([^,]-)%s*/%s*(.-)$", "%1-%2")		fname = mw.ustring.gsub(fname, "^([^%(]-) *%(([^%(]-)%)$", "%1_%2")	end	VL.vardefine("file", (string.gsub(data[2], ".+", conv) .. "-" .. fname .. ".png"))

VL.vardefine("premium", "") if data[3] and data[3] == true then VL.vardefine("premium", "") end

VL.vardefine("limited", "") if data[4] and data[4] == true then VL.vardefine("limited", "") end

VL.vardefine("collection", p.getCollection({itemName, "T"})) VL.vardefine("shortcollection", p.getCollection({itemName, "S"})) VL.vardefine("music", p.getCollection({itemName, "N"}))

if not data[3] and not data[4] then VL.vardefine("storyline", "No Level Required") end

VL.vardefine("rarity", require('Module:Rarity').rarity({(data["R"] or "")})) if collectionData["MerlinExchange"][data[2]] then local exchange = {'{|\n|Cost\n|Reward\n|-', '\n|', EC({"Magic"}), collectionData["MerlinExchange"][data[2]][(data["R"] or "?")][1], '\n|', EC({"Elixirs"}), collectionData["MerlinExchange"][data[2]][(data["R"] or "?")][2], '\n|}' }		VL.vardefine("exchange", table.concat(exchange)) end

VL.vardefine("size", data["S"])

VL.vardefine("category", p.getCategory({data["C"] or ""}))

if tArgs["requirement"] then VL.vardefine("requirement", LINK(tArgs["requirement"])) end if tArgs["unlock"] then VL.vardefine("unlock", LINK(tArgs["unlock"])) end if tArgs["cost"] then if tArgs["cost"]:match("^EC") then VL.vardefine("cost", EC({tArgs["cost"]})) else VL.vardefine("cost", tArgs["cost"]) end end if tArgs["building rewards"] then if tArgs["building rewards"]:match("^EC") then VL.vardefine("building rewards", EC({tArgs["building rewards"]})) else VL.vardefine("building rewards", tArgs["building rewards"]) end end local i = 0 repeat i = i + 1 if tArgs["requirement " .. i] then VL.vardefine("requirement " .. i, LINK(tArgs["requirement " .. i])) end if tArgs["unlock " .. i] then VL.vardefine("unlock " .. i, LINK(tArgs["unlock " .. i])) end if tArgs["cost " .. i] then if tArgs["cost " .. i]:match("^EC") then VL.vardefine("cost " .. i, EC({tArgs["cost " .. i]})) else VL.vardefine("cost " .. i, tArgs["cost " .. i]) end end until i == 4

if tArgs["theme"] then local tOut = {} local space = "" for land in mw.text.gsplit(tArgs["theme"], '%s*%$%s*') do table.insert(tOut, space .. "" .. land .. "") space = " " end

VL.vardefine("theme", table.concat(tOut)) end

return "" end

return p