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 enchData = mw.loadData('Module:ALU/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				reward = k				break 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 tRet = "" local tPrem = "" for _, item in pairs(attractions) do		if collectionData["Items"][item[2]][3] and collectionData["Items"][item[2]][3] == true then tPrem = tPrem .. BUILDING({item[2], "", "T"}) .."\n" else tRet = tRet .. BUILDING({item[2], "", "T"}) .."\n" end end if tPrem ~= "" then tRet = tRet .. '|-\n! colspan="5"|Premium\n' .. tPrem end return tRet .. "|}" 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 tAtt = {} for item, data in pairs(floatData) do	   if data["A"] and data["R"]["magic"] and data["R"]["magic"][1] ~= "" then local collNumb = collectionData["Items"][item][1] if collNumb == nil then collNumb = 10000 end table.insert(floats, {collNumb, mw.ustring.gsub(mw.ustring.lower(item), "[':\"%,%.]", ""), (item .. " Float"), item, data, collectionData["Items"][item]})      		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|", ""				}

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[6][3] and flt[6][3] == true then tFlt[18] = "" end

tFlt[20] = "" if flt[6][4] and flt[6][4] == true then tFlt[20] = "" end tFlt[22] = flt[5]["A"] tFlt[24] = EC({"Magic"}) .. tFlt[22] tFlt[26] = flt[5]["R"]["magic"][1] tFlt[28] = EC({"Magic"}) .. tFlt[26] tFlt[30] = flt[5]["R"]["magic"][2] tFlt[32] = EC({"Gems"}) .. tFlt[30] tFlt[34] = flt[5]["R"]["magic"][3] tFlt[36] = EC({"Magic"}) .. tFlt[34] table.insert(tOut, table.concat(tFlt)) end return 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 tAtt = {} for item, data in pairs(buildData) do		if collectionData["Items"][item] and collectionData["Items"][item][2] == "ba" then if data["R"]["magic"] and data["R"]["magic"][1] ~= "" and data["R"]["magic"][2] ~= "" and data["R"]["magic"][3] ~= "" and data["R"]["magic"][1] ~= "?h" then local collNumb = collectionData["Items"][item][1] if collNumb == nil then collNumb = 10000 end table.insert(attractions, {collNumb, mw.ustring.gsub(mw.ustring.lower(item), "[':\"%,%.]", ""), item, data, collectionData["Items"][item]})			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|", ""				}

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 "5x5") 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]["R"]["magic"][1], "^([%d%?]+)([hms])$") if durHMS == "m" then durNumb = durNumb / 60 end tAtt[24] = tonumber(durNumb) or 1 tAtt[26] = att[4]["R"]["magic"][1] tAtt[28] = att[4]["R"]["magic"][2] tAtt[30] = EC({"XP"}) .. tAtt[28] tAtt[32] = att[4]["R"]["magic"][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 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', '! 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 tCons = {} for item, data in pairs(buildData) do		if collectionData["Items"][item] and collectionData["Items"][item][2] == "bc" then if data["R"]["magic"] and data["R"]["magic"][1] ~= "" and data["R"]["magic"][2] ~= "" and data["R"]["magic"][3] ~= "" and data["R"]["magic"][1] ~= "?h" then local collNumb = collectionData["Items"][item][1] if collNumb == nil then collNumb = 10000 end table.insert(concession, {collNumb, mw.ustring.gsub(mw.ustring.lower(item), "[':\"%,%.]", ""), item, data, collectionData["Items"][item]})			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=\"", 0, "\"|", "",				"\n|", "5x5",				"\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|", ""				}

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"], "C"})

local rType = {["common"] = 1,["uncommon"] = 2,["rare"] = 3,["epic"] = 4,["legendary"] = 5} tCons[18] = rType[cons[5]["R"]:lower] tCons[20] = RAR({cons[5]["R"], "S"}) local durNumb, durHMS = string.match(cons[4]["R"]["magic"][1], "^([%d%?]+)([hms])$") if durHMS == "m" then durNumb = durNumb / 60 end tCons[24] = tonumber(durNumb) or 1 tCons[26] = cons[4]["R"]["magic"][1]

tCons[28] = cons[4]["R"]["magic"][2] tCons[30] = EC({"XP"}) .. tCons[28] tCons[32] = cons[4]["R"]["magic"][3] tCons[34] = EC({"Magic"}) .. tCons[32]

tCons[36] = string.format("%.2f", (tCons[32] / tCons[24])) tCons[38] = EC({"Magic"}) .. tCons[36] if tCons[22] ~= "" then tCons[40] = string.format("%.2f", (tCons[36] / 25)) tCons[42] = EC({"Magic"}) .. tCons[40] end table.insert(tOut, table.concat(tCons)) end return 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', }	local tDeco = {} for item, data in pairs(collectionData["Items"]) do		if data[2] == "d" and data["R"] then local collNumb = data[1] 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=\"", 0, "\"|", "",				"\n| data-sort-value=\"", 0, "\" nowrap|", ""				}

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"], "C"})

local rType = {["common"] = 1,["uncommon"] = 2,["rare"] = 3,["epic"] = 4,["legendary"] = 5} tDeco[18] = rType[deco[4]["R"]:lower] tDeco[20] = RAR({deco[4]["R"], "S"}) tDeco[24] = deco[4]["S"] if tDeco[24] ~= "" and tDeco[24] ~= "?x?" then local height, width = mw.ustring.match(tDeco[24], "^([^,]-)%s*x%s*(.-)$") tDeco[22] = height * width end

table.insert(tOut, table.concat(tDeco)) end return 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 tEnch = {} for item, data in pairs(buildData) do		if data["R"]["magic"] and data["R"]["magic"][1] ~= "" and data["R"]["magic"][4] and data["R"]["magic"][5] then local collNumb = collectionData["Items"][item][1] if collNumb == nil then collNumb = 10000 end table.insert(buildings, {collNumb, mw.ustring.gsub(mw.ustring.lower(item), "[':\"%,%.]", ""), item, data["R"]["magic"]})		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"}), "", ") " }

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"

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

tEnch[21] = buildData[att[3]]["R"]["magic"][1] local aMagic = buildData[att[3]]["R"]["magic"][3] local pMagic = aMagic

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[tostring(lvlNumb)][7])) 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 table.concat(tOut) .. "\n|}" end

return p