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.getTrophies(frame) local BUILDING = require("Module:Building").building local attractions = {} local reward = "magic" for item, data in pairs(buildData) do		if not data["R"][reward] then for k, v in pairs(data["R"]) do				if k ~= "after" then reward = k					break end end end if data["R"][reward]["T"] then local durNumb, durHMS = string.match(data["R"][reward][1], "^([%d%?]+)([hms])$") if not durNumb or durNumb == "?" then durNumb = 0 else durNumb = tonumber(durNumb) if durHMS == "m" then durNumb = durNumb / 60 end end table.insert(attractions, {durNumb, item}) end end table.sort(attractions, function(a,b) return a[1] < b[1] end)

local tOut = "" for _, item in pairs(attractions) do tOut = tOut .. BUILDING({item[2], "", "T"}) .."\n" end return tOut .. "|}" end

function p.getFloats local floats = {} local tOut = {	'{| class="article-table dmk-list sortable" style="width: 100%;"\n', '! rowspan="2" width="8%"|Collection\n', '! rowspan="2" width="12%"|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 collNumb = collectionData["Items"][(item .. " Float")][1] or 10000 if data["A"] and data["R"]["magic"] and data["R"]["magic"][1] ~= "" then table.insert(floats, {collNumb, mw.ustring.gsub(mw.ustring.lower(item), "[':\"%,%.]", ""), (item .. " Float"), item, data["R"]["magic"], data["A"], collectionData["Items"][(item .. " Float")]})      			elseif data["A"] and data["R"]["after"] and data["R"]["after"][1] ~= "" then    	   			table.insert(floats, {collNumb, mw.ustring.gsub(mw.ustring.lower(item), "[':\"%,%.]", ""), (item .. " Float"), item, data["R"]["after"], data["A"], collectionData["Items"][(item .. " Float")]}) end end end table.sort(floats, function(a,b)			if a[1] == b[1] then				return a[2] < b[2]			else				return a[1] < b[1]			end		end) for _, flt in pairs(floats) do		tFlt = {"\n|-\n| data-sort-value=\"", "", "\"|", "", " ", "\n| data-sort-value=\"", "", "\"|", "", " ", "", " ", "\n|", "", "\n|", "", "\n| data-sort-value=\"", "", "\" nowrap|", "", "\n| data-sort-value=\"", "", "\" nowrap|", "", "\n| data-sort-value=\"", "", "\" nowrap|", "", "\n| data-sort-value=\"", "", "\" nowrap|", "" }

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

tFlt[ 2] = flt[1] tFlt[ 4] = mw.ustring.gsub(COLL.getCollection({flt[3], "N"}), " ", "_") tFlt[ 6] = COLL.getCollection({flt[3], "P"}) tFlt[ 9] = flt[2] tFlt[11] = " " tFlt[13] = flt[3] tFlt[15] = flt[4] tFlt[18] = "" if flt[7][3] and flt[7][3] == true then tFlt[18] = "" end

tFlt[20] = "" if flt[7][4] and flt[7][4] == true then tFlt[20] = "" end tFlt[22] = flt[6] tFlt[24] = EC({"Magic"}) .. tFlt[22] tFlt[26] = flt[5][1] tFlt[28] = EC({"Magic"}) .. tFlt[26] tFlt[30] = flt[5][2] tFlt[32] = EC({"Gems"}) .. tFlt[30] tFlt[34] = flt[5][3] tFlt[36] = EC({"Magic"}) .. tFlt[34] 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="8%"|Collection\n', '! rowspan="2" width="12%"|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 collNumb = collectionData["Items"][item][1] or 10000 if collectionData["Items"][item] and collectionData["Items"][item][2] == "ba" then if data["R"]["magic"] and data["R"]["magic"][1] ~= "" and data["R"]["magic"][1] ~= "?h" then table.insert(attractions, {collNumb, mw.ustring.gsub(mw.ustring.lower(item), "[':\"%,%.]", ""), item, data["R"]["magic"], collectionData["Items"][item]})				elseif data["R"]["after"] and data["R"]["after"][1] ~= "" and data["R"]["after"][1] ~= "?h" then   					table.insert(attractions, {collNumb, mw.ustring.gsub(mw.ustring.lower(item), "[':\"%,%.]", ""), item, data["R"]["after"], collectionData["Items"][item]}) end end end end table.sort(attractions, function(a,b) 			if a[1] == b[1] then				return a[2] < b[2]			else				return a[1] < b[1]			end		end) for _, att in pairs(attractions) do		tAtt = {"\n|-\n| data-sort-value=\"", "", "\"|", "", " ", "\n| data-sort-value=\"", "", "\"|", "", " ", "", " ", "\n|", "", "\n|", "", "\n| data-sort-value=\"", 0, "\" nowrap|", "", "\n| data-sort-value=\"", "", "\" nowrap|", "", "\n| data-sort-value=\"", "", "\" nowrap|", "", "\n| data-sort-value=\"", "", "\" nowrap|", "", "\n| data-sort-value=\"", "", "\" nowrap|", "", "\n| data-sort-value=\"", "", "\" nowrap|", "" }

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

tAtt[ 2] = att[1] tAtt[ 4] = mw.ustring.gsub(COLL.getCollection({att[3], "N"}), " ", "_") tAtt[ 6] = COLL.getCollection({att[3], "P"}) tAtt[ 9] = att[2] tAtt[11] = " " tAtt[13] = att[3] tAtt[16] = "" if att[5][3] and att[5][3] == true then tAtt[16] = "" end

tAtt[18] = "" if att[5][4] and att[5][4] == true then tAtt[18] = "" end tAtt[22] = att[5]["S"] or "?x?" if tAtt[22] ~= "" and tAtt[22] ~= "?x?" then local height, width = mw.ustring.match(tAtt[22], "^([^,]-)%s*x%s*(.-)$") tAtt[20] = height * width end local durNumb, durHMS = string.match(att[4][1], "^([%d%?]+)([hms])$") if durHMS == "m" then durNumb = durNumb / 60 end tAtt[24] = tonumber(durNumb) or 1 tAtt[26] = att[4][1] tAtt[28] = att[4][2] tAtt[30] = EC({"XP"}) .. tAtt[28] tAtt[32] = att[4][3] tAtt[34] = EC({"Magic"}) .. tAtt[32]

tAtt[36] = string.format("%.2f", (tAtt[32] / tAtt[24])) tAtt[38] = EC({"Magic"}) .. tAtt[36] if tAtt[22] ~= "" then tAtt[40] = string.format("%.2f", (tAtt[36] / tAtt[20])) tAtt[42] = EC({"Magic"}) .. 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 concession = {}

local tOut = {	'{| class="article-table dmk-list sortable" style="width: 100%;"\n', '! rowspan="2" width="8%"|Collection\n', '! rowspan="2" width="12%"|Name\n', '! rowspan="2" width="10%"|Category\n', '! rowspan="2" width="10%"|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 collNumb = collectionData["Items"][item][1] or 10000 if collectionData["Items"][item] and collectionData["Items"][item][2] == "bc" then if data["R"]["magic"] and data["R"]["magic"][1] ~= "" and data["R"]["magic"][1] ~= "?h" then table.insert(concession, {collNumb, mw.ustring.gsub(mw.ustring.lower(item), "[':\"%,%.]", ""), item, data["R"]["magic"], collectionData["Items"][item]})				elseif data["R"]["after"] and data["R"]["after"][1] ~= "" and data["R"]["after"][1] ~= "?h" then   					table.insert(concession, {collNumb, mw.ustring.gsub(mw.ustring.lower(item), "[':\"%,%.]", ""), item, data["R"]["after"], collectionData["Items"][item]}) end end end end table.sort(concession, function(a,b) 			if a[1] == b[1] then				return a[2] < b[2]			else				return a[1] < b[1]			end		end) for _, cons in pairs(concession) do		tCons = {"\n|-\n| data-sort-value=\"", "", "\"|", "", " ", "\n| data-sort-value=\"", "", "\"|", "", " ", "", " ", "\n|", "", "\n| data-sort-value=\"", "", "\"|", "", "\n| data-sort-value=\"", "", "\" nowrap|", "", "\n| data-sort-value=\"", "", "\" nowrap|", "", "\n| data-sort-value=\"", "", "\" nowrap|", "", "\n| data-sort-value=\"", "", "\" nowrap|", "", "\n| data-sort-value=\"", "", "\" nowrap|", "", "\n| data-sort-value=\"", "", "\" nowrap|", "" }

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

tCons[ 2] = cons[1] tCons[ 4] = mw.ustring.gsub(COLL.getCollection({cons[3], "N"}), " ", "_") tCons[ 6] = COLL.getCollection({cons[3], "P"}) tCons[ 9] = cons[2] tCons[11] = " " tCons[13] = cons[3] tCons[16] = COLL.getCategory({cons[5]["C"], "P"})

local rType = { ["common"] = {"6,400", "1,000"}, ["uncommon"] = {"7,000", "1,250"}, ["rare"] = {"7,800", "1,625"}, ["epic"] = {"8,000", "2,000"}, ["legendary"] = {"8,000", "2,500"}, }

local iRarity = cons[5]["R"] or "?" tCons[18] = rType[iRarity:lower][2] tCons[20] = RAR({iRarity, "L"}) tCons[22] = rType[cons[5]["R"]:lower][1] or 0 tCons[24] = EC({"Magic"}) .. (rType[cons[5]["R"]:lower][1] or "?")

tCons[26] = rType[cons[5]["R"]:lower][2] or 0 tCons[28] = EC({"Elixirs"}) .. (rType[cons[5]["R"]:lower][2] or "?")

local durNumb, durHMS = string.match(cons[4][1], "^([%d%?]+)([hms])$") if durHMS == "m" then durNumb = durNumb / 60 end tCons[30] = tonumber(durNumb) or 1 tCons[32] = cons[4][1]

tCons[34] = cons[4][2] tCons[36] = EC({"XP"}) .. tCons[34] tCons[38] = cons[4][3] tCons[40] = EC({"Magic"}) .. tCons[38]

tCons[42] = string.format("%.2f", (tCons[38] / tCons[30])) tCons[44] = EC({"Magic"}) .. tCons[42]

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

function p.getDecorations local decoration = {}

local tOut = {	'{| class="article-table dmk-list sortable" style="width: 100%;"\n', '! rowspan="2" width="8%" height="78px"|Collection\n', '! rowspan="2" width="12%"|Name\n', '! rowspan="2" width="10%"|Category\n', '! rowspan="2" width="10%"|Rarity\n', '! rowspan="2" width="10%"|Size\n', '! colspan="2"|Exchange Rate\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] == "d" and data["R"] then local collNumb = data[1] or 10000 if collNumb == nil then collNumb = 10000 end table.insert(decoration, {collNumb, mw.ustring.gsub(mw.ustring.lower(item), "[':\"%,%.]", ""), item, data})		end	end	table.sort(decoration, function(a,b) 			if a[1] == b[1] then				return a[2] < b[2]			else				return a[1] < b[1]			end		end)	for _, deco in pairs(decoration) do		tDeco = {"\n|-\n| data-sort-value=\"", "", "\"|", "", " ",				"\n| data-sort-value=\"", "", "\"|", "", " ", "", " ",				"\n|", "",				"\n| data-sort-value=\"", "", "\"|", "",				"\n| data-sort-value=\"", "", "\" nowrap|", "",				"\n| data-sort-value=\"", "", "\" nowrap|", "",				"\n| data-sort-value=\"", "", "\" nowrap|", ""				}

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

tDeco[ 2] = deco[1] tDeco[ 4] = mw.ustring.gsub(COLL.getCollection({deco[3], "N"}), " ", "_") tDeco[ 6] = COLL.getCollection({deco[3], "P"}) tDeco[ 9] = deco[2] tDeco[11] = " " tDeco[13] = deco[3] tDeco[16] = COLL.getCategory({deco[4]["C"], "P"})

local rType = { ["common"] = {"800", "125"}, ["uncommon"] = {"1,400", "250"}, ["rare"] = {"2,400", "500"}, ["epic"] = {"4,000", "1,000"}, ["legendary"] = {"6,400", "2,000"}, ["?"] = {"?", "?"},				}

local iRarity = deco[4]["R"] or "?" tDeco[18] = rType[iRarity:lower][2] tDeco[20] = RAR({iRarity, "L"}) tDeco[24] = deco[4]["S"] or "?x?" if tDeco[24] ~= "" and tDeco[24] ~= "?x?" then local height, width = mw.ustring.match(tDeco[24], "^([^,]-)%s*x%s*(.-)$") tDeco[22] = height * width end tDeco[26] = rType[deco[4]["R"]:lower][1] or 0 tDeco[28] = EC({"Magic"}) .. (rType[iRarity:lower][1] or "?")

tDeco[30] = rType[deco[4]["R"]:lower][2] or 0 tDeco[32] = EC({"Elixirs"}) .. (rType[iRarity:lower][2] or "?")

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="20%" height="78px"|Collection\n', '! rowspan="2" width="20%"|Name\n', '! rowspan="2" width="15%"|Premium\n', '! rowspan="2" width="15%"|Limited Time\n', '! rowspan="2" width="15%"|Rarity\n', '! rowspan="2" width="15%"|Type\n', }	local GoTo = {["S"] = ""} local tChar = {} for item, data in pairs(collectionData["Items"]) do		if data[2] == "ch" or data[2] == "cos" then local collNumb = data[1] or 10000 if collNumb == nil then collNumb = 10000 end table.insert(characters, {collNumb, mw.ustring.gsub(mw.ustring.gsub(mw.ustring.lower(mw.ustring.gsub(item, "^([^%(]-) *%(([^%(]-)%)$", "%1_%2")), "[':\"%,%.]", ""), "^([^,]-)%s*/%s*(.-)$", "%1-%2"), item, data})		end	end	table.sort(characters, function(a,b) 			if a[1] == b[1] then				return a[2] < b[2]			else				return a[1] < b[1]			end		end)	for _, char in pairs(characters) do		tChar = {"\n|-\n| data-sort-value=\"", "", "\"|", "", " ",				"\n| data-sort-value=\"", "", "\"|", "", " ", "", " ",				"\n|", "",				"\n|", "",				"\n| data-sort-value=\"", "", "\" nowrap|", "",				"\n|", "",				}

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

tChar[ 2] = char[1] tChar[ 4] = mw.ustring.gsub(COLL.getCollection({char[3], "N"}), " ", "_") tChar[ 6] = COLL.getCollection({char[3], "P"}) tChar[ 9] = char[2] tChar[11] = " " tChar[13] = char[3] tChar[16] = (char[4][3] and "" or "") tChar[18] = (char[4][4] and "" or "")

local rType = {["common"] = 1, ["uncommon"] = 2, ["rare"] = 3, ["epic"] = 4, ["legendary"] = 5, ["?"] = 6, }

local iRarity = char[4]["R"] or "?" tChar[20] = rType[iRarity:lower] tChar[22] = RAR({iRarity, "L"})

tChar[24] = (char[4]["C"] and COLL.getCategory({char[4]["C"], "P"}) or "")

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

function p.getEnchantments local buildings = {} local tOut = {	'{| class="article-table dmk-list2 sortable" style="width: 100%;"\n', '! width="10%" class="unsortable"|Collection\n', '! width="10%"|Name\n', '! width="10%" class="unsortable"|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 collNumb = collectionData["Items"][item][1] or 10000 if data["R"]["magic"] and data["R"]["magic"][1] ~= "" and data["R"]["magic"][1] ~= "?h" and data["R"]["magic"][5] then table.insert(buildings, {collNumb, mw.ustring.gsub(mw.ustring.lower(item), "[':\"%,%.]", ""), item, data["R"]["magic"]})			elseif data["R"]["after"] and data["R"]["after"][1] ~= "" and data["R"]["after"][1] ~= "?h" and data["R"]["after"][5] then   					table.insert(buildings, {collNumb, mw.ustring.gsub(mw.ustring.lower(item), "[':\"%,%.]", ""), item, data["R"]["after"]}) end end end table.sort(buildings, function(a,b)			if a[1] == b[1] then				return a[2] < b[2]			else				return a[1] < b[1]			end		end) for _, att in pairs(buildings) do		tEnch = {"\n|-\n| data-sort-value=\"", att[1], "\"|", "", " ", "\n| data-sort-value=\"", att[2], "\"|", "", "  ", "", " ", "\n| nowrap style=\"line-height: 1.5;\"|", "", " ", EC({"Magic"}), "", " (Every ", "", ") ", "\n| nowrap|", "", "\n| nowrap|", EC({"Magic"}), "", " (+", EC({"Magic", nil, nil, nil, "20"}), "", ") ", "\n| nowrap|", "", "\n| nowrap|", EC({"Magic"}), "", " (+", EC({"Magic", nil, nil, nil, "20"}), "", ") ", "\n| nowrap|", "", "\n| nowrap|", EC({"Magic"}), "", " (+", EC({"Magic", nil, nil, nil, "20"}), "", ") ", "\n| nowrap|", "", "\n| nowrap|", EC({"Magic"}), "", " (+", EC({"Magic", nil, nil, nil, "20"}), "", ") ", "\n| nowrap|", TOK({"Two Chances"}), "\n| nowrap|", EC({"Magic"}), "", " (+", EC({"Magic", nil, nil, nil, "20"}), "", ") " }

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

tEnch[ 4] = mw.ustring.gsub(COLL.getCollection({att[3], "N"}), " ", "_") tEnch[ 6] = COLL.getCollection({att[3], "P"}) tEnch[11] = " " tEnch[13] = att[3]

local No = 0 local lvlNumb = "0"

tEnch[21] = att[4][1] local aMagic = att[4][3] local pMagic = aMagic local enchData = {0.04, 0.1, 0.18, 0.28, 0.4}

att[4] = att[4][4] .. "/" .. att[4][5] .. "/" .. att[4][6] .. "/" .. att[4][7] .. "/" .. att[4][8] .. "/two chances"

for iTok in mw.text.gsplit(att[4], "%s*%/%s*") do			if lvlNumb == "0" then tEnch[16] = TOK({iTok}) tEnch[19] = aMagic else tEnch[24 + No] = TOK({iTok}) local eMagic = math.ceil(aMagic * (1 + enchData[tonumber(lvlNumb)])) tEnch[27 + No] = eMagic tEnch[30 + No] = eMagic - pMagic pMagic = eMagic

No = No + 9 end

lvlNumb = lvlNumb + 1 lvlNumb = tostring(lvlNumb) if lvlNumb == "6" then break end end table.insert(tOut, table.concat(tEnch)) end return COLL.getCollection({GoTo["S"], "A"}) .. "\n" .. table.concat(tOut) .. "\n|}" end

function p.getAnimatedTasks(frame) local tArgs = util.getArgs(frame) local collections = {} local allcollections = {} local animtasks = "" local space = "" local name = ""

for k, v in pairs(collectionData["Collections"]) do		if k ~= 10 and k <= 9900 then table.insert(collections, {k, v}) end end

table.sort(collections, function(a,b) return a[1] < b[1] end)

for i, coll in pairs(collections) do		name = coll[2]["D"] or coll[2][2]

if tArgs[name] then table.insert(allcollections, name)

animtasks = animtasks .. space .. ' '

space = "\n\n" end end

local COLL = require("Module:ItemCollection").getCollection animtasks = COLL({table.concat(allcollections, "$"), "A"}) .. "\n" .. animtasks

return frame:preprocess(animtasks) end

return p