Module:Lists

--[==[-- -- Lua script to get List Information -- --]==]

local p = {}

local util = require("Module:Utility")

local collectionData = mw.loadData( 'Module:ItemCollection/data' ) local floatData = mw.loadData('Module:Float/data') local buildData = mw.loadData('Module:Building/data')

local COLL = require("Module:ItemCollection") local RAR = require("Module:Rarity").rarity local TOK = require("Module:CharacterToken").getToken local EC = require("Module:EC").getEC

function p.getFloats local floats = {} local tOut = {	'{| class="article-table dmk-list sortable" style="width: 100%;"\n', '! rowspan="2" width="7%"|Collection\n', '! rowspan="2" width="10%"|Name\n', '! rowspan="2" width="1%"|Premium\n', '! rowspan="2" width="1%"|Limited Time\n', '! rowspan="2" width="10%"|Assign cost\n', '! rowspan="2" width="10%"|Base Rewards\n', '! colspan="2"| Chance of \n', '|-\n! width="1%"|Gems\n! width="1%"|Magic' }	local GoTo = {["S"] = ""} local tAtt = {} for item, data in pairs(floatData) do if collectionData["Items"][(item .. " Float")] then local itemData = collectionData["Items"][(item .. " Float")] local rewardData = data["R"]["after"] or  data["R"]["magic"]

if data["A"] and rewardData and rewardData[1] ~= "" then table.insert(floats, {itemData, item, data["A"], rewardData}) end end end table.sort(floats, function(a,b)			if a[1][1] == b[1][1] then				return a[2] < b[2]			else				return a[1][1] < b[1][1]			end		end) for _, flt in pairs(floats) do		local collData = collectionData["Collections"][flt[1][1]] or {}

if not GoTo[flt[1][1]] then GoTo["S"] = GoTo["S"] .. flt[2] .. "$"               	GoTo[flt[1][1]] = true end

tFlt = {'\n|- id="', (collData["A"] or collData[2] or ""), '"', '\n| data-sort-value="', (collData["D"] or collData[2] or ""), '"|', "", '\n| data-sort-value="', flt[2], '"|', "", '\n|', "", '\n|', "", '\n| data-sort-value="', flt[3], '" nowrap|', EC({"Magic"}), flt[3], '\n| data-sort-value="', flt[4][1], '" nowrap|', EC({"Magic"}), flt[4][1], '\n| data-sort-value="', flt[4][2], '" nowrap|', EC({"Gems"}), flt[4][2], '\n| data-sort-value="', flt[4][3], '" nowrap|', EC({"Magic"}), flt[4][3] }

if collData[2] then tFlt[ 7] = ' " .. (collData["D"] or collData[2]) .. " "		end		tFlt[11] = " " .. flt[2] .. " "		if flt[1][3] and flt[1][3] == true then			tFlt[13] = ""		end

if flt[1][4] and flt[1][4] == true then tFlt[15] = "" end table.insert(tOut, table.concat(tFlt)) end return COLL.getCollection({GoTo["S"], "A"}) .. "\n" .. table.concat(tOut) .. "\n|}" end

function p.getAttractions local attractions = {}

local tOut = {	'{| class="article-table dmk-list sortable" style="width: 100%;"\n', '! rowspan="2" width="7%"|Collection\n', '! rowspan="2" width="10%"|Name\n', '! rowspan="2" width="1%"|Premium\n', '! rowspan="2" width="1%"|Limited Time\n', '! rowspan="2" width="10%"|Size\n', '! colspan="3"|Base Rewards\n', '! rowspan="2" width="10%" nowrap|Magic / Hour\n', '! rowspan="2" width="10%" nowrap|Magic / Hour / Square\n', '|-\n! width="1%"|Time\n! width="1%"|XP\n! width="1%"|Magic' }	local GoTo = {["S"] = ""} local tAtt = {} for item, data in pairs(buildData) do   		if collectionData["Items"][item] then local itemData = collectionData["Items"][item] local rewardData = data["R"]["after"] or data["R"]["magic"]

if itemData[1] and itemData[2] == "ba" and rewardData and rewardData[1] ~= "" then table.insert(attractions, {itemData, item, rewardData}) end end end table.sort(attractions, function(a,b) 			if a[1][1] == b[1][1] then				return a[2] < b[2]			else				return a[1][1] < b[1][1]			end		end) for _, att in pairs(attractions) do		local collData = collectionData["Collections"][att[1][1]] or {}

if not GoTo[att[1][1]] then GoTo["S"] = GoTo["S"] .. att[2] .. "$"               	GoTo[att[1][1]] = true end

tAtt = {'\n|- id="', (collData["A"] or collData[2] or ""), '"', '\n| data-sort-value="', (collData["D"] or collData[2] or ""), '"|', "", '\n| data-sort-value="', att[2], '"|', "", '\n|', "", '\n|', "", '\n| data-sort-value="', 0, '" nowrap|', (att[1]["S"] or "?x?"), '\n| data-sort-value="', (att[3][1] or 0), '" nowrap|', (att[3][1] or "?h"), '\n| data-sort-value="', (att[3][2] or 0), '" nowrap|', EC({"XP"}), (att[3][2] or "?"), '\n| data-sort-value="', (att[3][3] or 0), '" nowrap|', EC({"Magic"}), (att[3][3] or "?"), '\n| data-sort-value="', 0, '" nowrap|', EC({"Magic"}), "?", '\n| data-sort-value="', 0, '" nowrap|', EC({"Magic"}), "?" }

if collData[2] then tAtt[ 7] = ' " .. (collData["D"] or collData[2]) .. " "		end		tAtt[11] = " " .. att[2] .. " "		if att[1][3] and att[1][3] == true then			tAtt[13] = ""		end

if att[1][4] and att[1][4] == true then tAtt[15] = "" end if tAtt[19] ~= "" and tAtt[19] ~= "?x?" then local height, width = mw.ustring.match(tAtt[19], "^([^,]-)%s*x%s*(.-)$") tAtt[17] = height * width end

local durNumb, durHMS = string.match(tAtt[23], "^([%d%?]+)([hms])$") if durHMS == "m" then durNumb = durNumb / 60 end tAtt[21] = tonumber(durNumb) or 0

if tonumber(tAtt[21]) and tonumber(tAtt[30]) then tAtt[35] = string.format("%.2f", (tAtt[30] / tAtt[21])) tAtt[38] = tAtt[35] end if tonumber(tAtt[17]) and tonumber(tAtt[35]) then tAtt[40] = string.format("%.2f", (tAtt[35] / tAtt[17])) tAtt[43] = tAtt[40] end

table.insert(tOut, table.concat(tAtt)) end return COLL.getCollection({GoTo["S"], "A"}) .. "\n" .. table.concat(tOut) .. "\n|}" end

function p.getConcessions local concessions = {}

local tOut = {	'{| class="article-table dmk-list sortable" style="width: 100%;"\n', '! rowspan="2" width="7%"|Collection\n', '! rowspan="2" width="8%"|Name\n', '! rowspan="2" width="1%"|Category\n', '! rowspan="2" width="1%"|Rarity\n', '! colspan="2"|Exchange Rate\n', '! colspan="3"|Base Rewards\n', '! rowspan="2" width="10%" nowrap|Magic / Hour\n', '|-\n! width="1%" class="unsortable"|Cost\n! width="1%" class="unsortable"|Reward\n! width="1%"|Time\n! width="1%"|XP\n! width="1%"|Magic' }	local GoTo = {["S"] = ""} local tCons = {} for item, data in pairs(buildData) do   		if collectionData["Items"][item] then local itemData = collectionData["Items"][item] local rewardData = data["R"]["after"] or data["R"]["magic"]

if itemData[2] == "bc" and rewardData and rewardData[1] ~= "" then table.insert(concessions, {itemData, item, rewardData}) end end end table.sort(concessions, function(a,b) 			if a[1][1] == b[1][1] then				return a[2] < b[2]			else				return a[1][1] < b[1][1]			end		end) for _, cons in pairs(concessions) do		local collData = collectionData["Collections"][cons[1][1]] or {} local iRarity = collectionData["MerlinExchange"]["bc"][(cons[1]["R"] or "?")]

if not GoTo[cons[1][1]] then GoTo["S"] = GoTo["S"] .. cons[2] .. "$"               	GoTo[cons[1][1]] = true end

tCons = {'\n|- id="', (collData["A"] or collData[2] or ""), '"', '\n| data-sort-value="', (collData["D"] or collData[2] or ""), '"|', "", '\n| data-sort-value="', cons[2], '"|', "", '\n|', COLL.getCategory({cons[1]["C"], "P"}), '\n| data-sort-value="', (iRarity[2] or 0), '" nowrap|', RAR({(cons[1]["R"] or "?"), "L"}), '\n| data-sort-value="', (iRarity[1] or 0), '" nowrap|', EC({"Magic"}), (iRarity[1] or "?"), '\n| data-sort-value="', (iRarity[2] or 0), '" nowrap|', EC({"Elixirs"}), (iRarity[2] or "?"), '\n| data-sort-value="', (cons[3][1] or 0), '" nowrap|', (cons[3][1] or "?h"), '\n| data-sort-value="', (cons[3][2] or 0), '" nowrap|', EC({"XP"}), (cons[3][2] or "?"), '\n| data-sort-value="', (cons[3][3] or 0), '" nowrap|', EC({"Magic"}), (cons[3][3] or "?"), '\n| data-sort-value="', 0, '" nowrap|', EC({"Magic"}), "?", }

if collData[2] then tCons[ 7] = ' " .. (collData["D"] or collData[2]) .. " "		end		tCons[11] = " " .. cons[2] .. " "

local durNumb, durHMS = string.match(tCons[31], "^([%d%?]+)([hms])$") if durHMS == "m" then durNumb = durNumb / 60 end tCons[29] = tonumber(durNumb) or 0

if tonumber(tCons[29]) and tonumber(tCons[38]) then tCons[43] = string.format("%.2f", (tCons[38] / tCons[29])) tCons[46] = tCons[43] end

table.insert(tOut, table.concat(tCons)) end return COLL.getCollection({GoTo["S"], "A"}) .. "\n" .. table.concat(tOut) .. "\n|}" end

function p.getDecorations local decorations = {}

local tOut = {	'{| class="article-table dmk-list sortable" style="width: 100%;"\n', '! rowspan="2" width="7%" height="78px"|Collection\n', '! rowspan="2" width="10%"|Name\n', '! rowspan="2" width="1%"|Category\n', '! rowspan="2" width="1%"|Rarity\n', '! colspan="2"|Exchange Rate\n', '! rowspan="2" width="10%"|Size\n', '|-\n! width="1%" class="unsortable"|Cost\n! width="1%" class="unsortable"|Reward' }	local GoTo = {["S"] = ""} local tDeco = {} for item, data in pairs(collectionData["Items"]) do		if data[2] and data[2] == "d" then table.insert(decorations, {data, item}) end end table.sort(decorations, function(a,b) 			if a[1][1] == b[1][1] then				return a[2] < b[2]			else				return a[1][1] < b[1][1]			end		end) for _, deco in pairs(decorations) do		local collData = collectionData["Collections"][deco[1][1]] or {} local iRarity = collectionData["MerlinExchange"]["d"][(deco[1]["R"] or "?")]

if not GoTo[deco[1][1]] then GoTo["S"] = GoTo["S"] .. deco[2] .. "$"               	GoTo[deco[1][1]] = true end

tDeco = {'\n|- id="', (collData["A"] or collData[2] or ""), '"', '\n| data-sort-value="', (collData["D"] or collData[2] or ""), '"|', "", '\n| data-sort-value="', deco[2], '"|', "", '\n|', COLL.getCategory({deco[1]["C"], "P"}), '\n| data-sort-value="', (iRarity[2] or 0), '" nowrap|', RAR({(deco[1]["R"] or "?"), "L"}), '\n| data-sort-value="', (iRarity[1] or 0), '" nowrap|', EC({"Magic"}), (iRarity[1] or "?"), '\n| data-sort-value="', (iRarity[2] or 0), '" nowrap|', EC({"Elixirs"}), (iRarity[2] or "?"), '\n| data-sort-value="', 0, '" nowrap|', (deco[1]["S"] or "?x?") }

if collData[2] then tDeco[ 7] = ' " .. (collData["D"] or collData[2]) .. " "		end		tDeco[11] = " " .. deco[2] .. " "		if tDeco[31] ~= "" and tDeco[31] ~= "?x?" then	   		local height, width = mw.ustring.match(tDeco[31], "^([^,]-)%s*x%s*(.-)$")			tDeco[29] = height * width		end

table.insert(tOut, table.concat(tDeco)) end return COLL.getCollection({GoTo["S"], "A"}) .. "\n" .. table.concat(tOut) .. "\n|}" end

function p.getCharacters local characters = {}

local tOut = {	'{| class="article-table dmk-list sortable" style="width: 100%;"\n', '! rowspan="2" width="7%" height="78px"|Collection\n', '! rowspan="2" width="10%"|Name\n', '! rowspan="2" width="1%"|Premium\n', '! rowspan="2" width="1%"|Limited Time\n', '! rowspan="2" width="1%"|Type\n', '! rowspan="2" width="1%"|Rarity\n', '! colspan="3"|Tokens\n', '|-\n! width="8%"|Collection\n! width="8%"|Personal\n! width="8%"|Ears Hat', }	local GoTo = {["S"] = ""} local tChar = {} for item, data in pairs(collectionData["Items"]) do		if data[2] and (data[2] == "ch" or data[2] == "cos") then table.insert(characters, {data, item}) end end table.sort(characters, function(a,b) 			if a[1][1] == b[1][1] then				return a[2] < b[2]			else				return a[1][1] < b[1][1]			end		end) for _, char in pairs(characters) do		local collData = collectionData["Collections"][char[1][1]] or {} local iRarity = {["common"] = 1, ["uncommon"] = 2, ["rare"] = 3, ["epic"] = 4, ["legendary"] = 5, ["unknown"] = 6}

if not GoTo[char[1][1]] then GoTo["S"] = GoTo["S"] .. char[2] .. "$"               	GoTo[char[1][1]] = true end

tChar = {'\n|- id="', (collData["A"] or collData[2] or ""), '"', '\n| data-sort-value="', (collData["D"] or collData[2] or ""), '"|', "", '\n| data-sort-value="', char[2], '"|', "", '\n|', "", '\n|', "", '\n|', COLL.getCategory({char[1]["C"], "P"}), '\n| data-sort-value="', (iRarity[(char[1]["R"] or "?"):lower] or 0), '" nowrap|', RAR({(char[1]["R"] or "?"), "L"}), '\n| data-sort-value="', 7, '"|', "", " ", "", '\n| data-sort-value="', 7, '"|', "", " ", "", '\n| data-sort-value="', 7, '"|', "", " ", "", }

if collData[2] then tChar[ 7] = ' " .. (collData["D"] or collData[2]) .. " "		end		tChar[11] = " " .. char[2] .. " "		if char[1][3] and char[1][3] == true then			tChar[13] = ""		end

if char[1][4] and char[1][4] == true then tChar[15] = "" end

if not char[1]["C"] then tChar[23] = 1 tChar[25] = TOK({("IP-" .. mw.ustring.upper(collData["S"] or collData[2])), 35}) tChar[27] = RAR({"Common", "S", 12})

tChar[29] = iRarity[TOK({char[2] .. ",2", "R"})] tChar[31] = TOK({char[2] .. ",2", 35}) if tChar[29] ~= 7 then tChar[33] = RAR({TOK({char[2] .. ",2", "R"}), "S", 12}) end

tChar[35] = iRarity[TOK({char[2] .. ",3", "R"})] tChar[37] = TOK({char[2] .. ",3", 35}) if tChar[35] ~= 7 then tChar[39] = RAR({TOK({char[2] .. ",3", "R"}), "S", 12}) end end

table.insert(tOut, table.concat(tChar)) end return COLL.getCollection({GoTo["S"], "A"}) .. "\n" .. table.concat(tOut) .. "\n|}" end

function p.getEnchantments local enchantments = {} local tOut = {	'{| class="article-table dmk-list2 sortable" style="width: 100%;"\n', '! width="7%" class="unsortable"|Collection\n', '! width="10%"|Name\n', '! width="10%" class="unsortable" colspan="2"|Building\n', '! width="10%" class="unsortable" colspan="2"|Level 1\n', '! width="10%" class="unsortable" colspan="2"|Level 2\n', '! width="10%" class="unsortable" colspan="2"|Level 3\n', '! width="10%" class="unsortable" colspan="2"|Level 4\n', '! width="10%" class="unsortable" colspan="2"|Level 5', }	local GoTo = {["S"] = ""} local tEnch = {} for item, data in pairs(buildData) do   		if collectionData["Items"][item] then local itemData = collectionData["Items"][item] local rewardData = data["R"]["after"] or data["R"]["magic"]

if rewardData and rewardData[1] ~= "" and rewardData[5] then table.insert(enchantments, {itemData, item, rewardData}) end end end table.sort(enchantments, function(a,b)			if a[1][1] == b[1][1] then				return a[2] < b[2]			else				return a[1][1] < b[1][1]			end		end) for _, ench in pairs(enchantments) do		local collData = collectionData["Collections"][ench[1][1]] or {}

if not GoTo[ench[1][1]] then GoTo["S"] = GoTo["S"] .. ench[2] .. "$"               	GoTo[ench[1][1]] = true end

tEnch = {'\n|- id="', (collData["A"] or collData[2] or ""), '"', '\n| rowspan="2" data-sort-value="', (collData["D"] or collData[2] or ""), '"|', "", '\n| rowspan="2" data-sort-value="', ench[2], '"|', "", '\n|', TOK({ench[3][4]}), ' ', TOK({ench[3][4], "L"}), ' ', '\n|', EC({"Magic"}), ench[3][3], '\n| rowspan="2"|', TOK({ench[3][5]}), ' ', TOK({ench[3][5], "L"}), ' ', '\n| rowspan="2"|', EC({"Magic"}), "", " (+", "", ") ", '\n| rowspan="2"|', TOK({ench[3][6]}), ' ', TOK({ench[3][6], "L"}), ' ', '\n| rowspan="2"|', EC({"Magic"}), "", " (+", "", ") ", '\n| rowspan="2"|', TOK({ench[3][7]}), ' ', TOK({ench[3][7], "L"}), ' ', '\n| rowspan="2"|', EC({"Magic"}), "", " (+", "", ") ", '\n| rowspan="2"|', TOK({ench[3][8]}), ' ', TOK({ench[3][8], "L"}), ' ', '\n| rowspan="2"|', EC({"Magic"}), "", " (+", "", ") ", '\n| rowspan="2"|', TOK({"Two Chances"}), ' ', TOK({"Two Chances", "L"}), ' ', '\n| rowspan="2"|', EC({"Magic"}), "", " (+", "", ") ", '\n|-\n| colspan="2" style="border-left: 1px solid #cbcbcb; border-right: 1px solid #cbcbcb;"|', " (Every ", ench[3][1], ") " }

if collData[2] then tEnch[ 7] = ' " .. (collData["D"] or collData[2]) .. " "		end		tEnch[11] = " " .. ench[2] .. " "

local magic = tonumber(ench[3][3]) or 0 local pMagic = magic local enchData = {0.04, 0.1, 0.18, 0.28, 0.4}

for item, data in ipairs(enchData) do			tEnch[16 + (item * 11)] = math.ceil(magic * (1 + data)) tEnch[18 + (item * 11)] = tEnch[16 + (item * 11)] - pMagic pMagic = tEnch[18 + (item * 11)] end table.insert(tOut, table.concat(tEnch)) end return COLL.getCollection({GoTo["S"], "A"}) .. "\n" .. table.concat(tOut) .. "\n|}" end

return p