Module:EnchantedChest

--[=[ Lua script replacement for wikitext template



Parameters: 1: Enchanted Chest name 2: Size in pixels optional, defaults to 25 If equal to "N", includes the chest Name Link also If equal to "L", includes the chest Name Link only 3: Enchanted Chest link if diffrent from name -- Unknown is returned if Enchanted Chest is not in data.

--]=]

local p = {}

local chestData = mw.loadData( 'Module:EnchantedChest/data' ) local cData = mw.loadData( 'Module:ItemCollection/data' )

local COLL = require("Module:ItemCollection").getCollection local util = require('Module:Utility')

local function getCollection(item) local collName = "" for _, data in pairs(cData.Collections) do		if (data[3] and data[3] == item) or item == data[1] then collName = data[1] end end if collName == "" then collName = COLL({item, "N"}) end if collName == "" then collName = item end return collName end

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

local allChest = tArgs[1] or "" local size = tArgs[2] local plural = tArgs[3] local outType = ""

if not tonumber(size) then outType = size if outType == "P" then size = 35 else size = 25 end end

local tAll = {} local space = ""

for chest in mw.text.gsplit(allChest, "%s*$%s*") do		local tChest = {space, "", "", "", "", "",	   				"", "", "", "", ""	    				}

local vName, count = mw.ustring.match(chest, "^([^,]-)%s*#%s*(.-)$") if not vName then vName = chest end

local cName, version = mw.ustring.match(vName, "^([^,]-)%s*-%s*(.-)$") if not cName then cName = vName end

cName = mw.ustring.gsub(cName, " Chests", "") local cFile = "work_in_progress" local cLink = "Work In Progress" local cDisp = cName .. " Chest" if chestData[cName] then tChest[ 7] = "ec-" cFile = mw.ustring.lower(mw.ustring.gsub(cName, " ", "_")) cLink = cName .. " Chests" cDisp = cName .. " Chest" if plural or (count and count > "1") then cDisp = cDisp .. "s" end

local cVers = "" if version then cVers = getCollection(version) end

if chestData[cName][cVers] then cLink = cLink .. "#" .. cVers if outType ~= "S" and cName == "Legendary" then cDisp = cVers .. " " .. cDisp end if outType ~= "L" and size ~= 100 and cName == "Legendary" then tChest[ 6] = "" .. COLL({cVers, math.floor(size / 1.6)}) .. " [[File:"					tChest[15] = "]] " end end end if outType == "N" then tChest[ 2] = "" .. cDisp			tChest[ 5] = " ("			tChest[16] = ")" elseif outType == "L" then tChest[ 6] = ""			tChest[11] = cDisp			tChest[13] = ""		elseif outType == "P" then			tChest[16] = " [["			tChest[17] = cLink			tChest[18] = "|"			tChest[19] = cDisp			tChest[20] = " "		elseif outType == "S" then			tChest[ 6] = ""			tChest[11] = cDisp			tChest[13] = ""			space = " "		elseif outType == "O" then			tChest[ 6] = "Open a [["			tChest[ 7] = cLink			tChest[ 9] = "|"			tChest[10] = cDisp			tChest[11] = " for a chance to get "			tChest[13] = version			tChest[15] = "!"		end		if outType ~= "L" and outType ~= "O" and outType ~= "S" then			tChest[ 8] = cFile			tChest[12] = cDisp			tChest[14] = cLink			space = " "			if count and count > "1" then 				if outType == "N" then					tChest[ 5] = tChest[ 5] .. " x" .. count				else					tChest[15] = tChest[15] .. count 				end			end		end   	table.insert(tAll, table.concat(tChest))	end    return table.concat(tAll) end

-- return all Chest Types in horizontal format function p.getChestList local tIndex = {}

for k, v in pairs(chestData) do       table.insert(tIndex, k)    end

table.sort(tIndex)

local outText = {} local space = ""

for _, chest in ipairs(tIndex) do       table.insert(outText, space .. "" .. chest .. "")

space = " · " end

return table.concat(outText) end

return p