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 attrData = mw.loadData('Module:Building/data') local enchData = mw.loadData('Module:ALU/data')

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

function p.getTrophies(frame) local tRet = {} local tAtt = {} local tPrem = {} local attractions = {} local reward = "magic" for item, data in pairs(attrData) do		if not data["R"][reward] then for k, v in pairs(data["R"]) do				reward = k				break end end if data["R"][reward][4] then local durNumb, durHMS = string.match(data["R"][reward][1], "^([%d%?]+)([hms])$") if durHMS == "m" then durNumb = durNumb / 60 end table.insert(attractions, {durNumb, data, item, reward}) end end table.sort(attractions, function(a,b) return a[1] > b[1] end) for _, item in pairs(attractions) do		tRet = {"|-\n| style=\"text-align: center;\"|", "", "\n|", "", "",				"", ": ", "", "", "", "", "\n|\n|", "", "\n| colspan=\"2\" nowrap|", "", "", ", ", "", "", "\n" }		local buildType = "Bc" if item[2]["S"] then buildType = "Ba" end tRet[ 2] = " " tRet[ 6] = item[3] tRet[ 8] = item[2]["A"] tRet[13] = item[2]["R"][item[4]][1] tRet[15] = EC({"XP"}) tRet[16] = item[2]["R"][item[4]][2] tRet[18] = EC({item[4]}) tRet[19] = item[2]["R"][item[4]][3] if collectionData["Items"][item[3]][3] and collectionData["Items"][item[3]][3] == true then table.insert(tPrem, table.concat(tRet)) else table.insert(tAtt, table.concat(tRet)) end end if tPrem ~= "" then table.insert(tAtt, '|-\n! colspan="5"|Premium\n') table.insert(tAtt, table.concat(tPrem)) end return table.concat(tAtt) .. "|}" end

function p.getFloats(frame) 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', '! colspan="3"| Rewards \n', '|-\n! width="1%"|Time\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})      	end	end	table.sort(floats, function(a,b) return a[2] < b[2] end)    for _, flt in pairs(floats) do		tFlt = {"\n|-\n| data-sort-value=\"", "", "\"|", "",				"\n| data-sort-value=\"", "", "\"|", "", " ", "", " ",				"\n|", "",				"\n|", "",				"\n| nowrap data-sort-value=\"", "", "\" nowrap|", "",				"\n| nowrap data-sort-value=\"", "2", "\" nowrap|", "2h",				"\n| nowrap data-sort-value=\"", "", "\" nowrap|", "",				"\n| nowrap data-sort-value=\"", "", "\" nowrap|", ""				}

tFlt[ 2] = flt[1] tFlt[ 4] = COLL.getCollection({flt[3], "P"}) tFlt[ 6] = flt[2] tFlt[ 8] = " " tFlt[10] = flt[3] tFlt[12] = flt[4] tFlt[15] = COLL.getPremium({flt[3]}) tFlt[17] = COLL.getLimited({flt[3]}) tFlt[19] = flt[5]["A"] tFlt[21] = EC({"Magic"}) .. tFlt[19] tFlt[27] = flt[5]["R"]["magic"][1] tFlt[29] = EC({"Gems"}) .. tFlt[27] tFlt[31] = flt[5]["R"]["magic"][2] tFlt[33] = EC({"Magic"}) .. tFlt[31] table.insert(tOut, table.concat(tFlt)) end return table.concat(tOut) .. "\n|}" end

function p.getBuildings(frame) local tArgs = util.getArgs(frame) local buildType = tArgs[1] or "Ba" local buildings = {} 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"| 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(attrData) do   	if collectionData["Items"][item] and collectionData["Items"][item][2] == buildType:lower then if data["R"]["magic"] and data["R"]["magic"][1] ~= "" 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})      		end       	end	end	table.sort(buildings, function(a,b) return a[2] < b[2] end)    for _, att in pairs(buildings) do		tAtt = {"\n|-\n| data-sort-value=\"", "", "\"|", "",				"\n| data-sort-value=\"", "", "\"|", "", " ", "", " ",				"\n|", "",				"\n|", "",				"\n| nowrap data-sort-value=\"", "", "\" nowrap|", "",				"\n| nowrap data-sort-value=\"", "", "\" nowrap|", "",				"\n| nowrap data-sort-value=\"", "", "\" nowrap|", "",				"\n| nowrap data-sort-value=\"", "", "\" nowrap|", "",				"\n| nowrap data-sort-value=\"", "", "\" nowrap|", "",				"\n| nowrap data-sort-value=\"", "", "\" nowrap|", ""				}

tAtt[ 2] = att[1] tAtt[ 4] = COLL.getCollection({att[3], "P"}) tAtt[ 6] = att[2] tAtt[ 8] = " " tAtt[10] = att[3] tAtt[13] = COLL.getPremium({att[3]}) tAtt[15] = COLL.getLimited({att[3]}) tAtt[19] = (att[4]["S"] or "5x5") if tAtt[19] ~= "" then local height, width = mw.ustring.match(tAtt[19], "^([^,]-)%s*x%s*(.-)$") tAtt[17] = height * width end local durNumb, durHMS = string.match(att[4]["R"]["magic"][1], "^([%d%?]+)([hms])$") if durHMS == "m" then durNumb = durNumb / 60 end tAtt[21] = durNumb tAtt[23] = att[4]["R"]["magic"][1] tAtt[25] = att[4]["R"]["magic"][2] tAtt[27] = EC({"XP"}) .. tAtt[25] tAtt[29] = att[4]["R"]["magic"][3] tAtt[31] = EC({"Magic"}) .. tAtt[29] tAtt[33] = string.format("%.2f", (tAtt[29] / tAtt[21])) tAtt[35] = EC({"Magic"}) .. tAtt[33] if tAtt[19] ~= "" then tAtt[37] = string.format("%.2f", (tAtt[33] / tAtt[17])) tAtt[39] = EC({"Magic"}) .. tAtt[37] end table.insert(tOut, table.concat(tAtt)) end return table.concat(tOut) .. "\n|}" end

function p.getEnchantments(frame) local tArgs = util.getArgs(frame) local buildings = {} local tOut = {	'{| class="article-table dmk-list2 sortable" style="width: 100%;"\n', '! width="10%"|Collection\n', '! width="20%"|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(tArgs) do   	if attrData[item] and attrData[item]["R"]["magic"] then local collNumb = collectionData["Items"][item][1] or 10000 table.insert(buildings, {collNumb, mw.ustring.gsub(mw.ustring.lower(item), "[':\"%,%.]", "") ,item, data})   	end	end	table.sort(buildings, function(a,b) return a[2] < b[2] 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] = COLL.getCollection({att[3], "P"}) tEnch[ 8] = " " tEnch[10] = att[3] local No = 0 local lvlNumb = "0" local durNumb = attrData[att[3]]["R"]["magic"][1] local tMag = attrData[att[3]]["R"]["magic"][3] local cData = collectionData["Items"][att[3]] att[4] = att[4] .. "/two chances" for iTok in mw.text.gsplit(att[4], "%s*%/%s*") do			if lvlNumb == "0" then tEnch[13] = TOK({iTok}) tEnch[16] = tMag else local mData = enchData["Magic Rewards"][durNumb][lvlNumb] if cData[4] and cData[4] == true then if cData[3] and cData[3] == true then iMag = mData[2] else if cData[1] and att[2] < "1170" then iMag = mData[1] else iMag = mData[2] end end elseif cData[3] and cData[3] == true then iMag = mData[2] else iMag = mData[1] end tMag = tMag + iMag tEnch[21 + No] = TOK({iTok}) tEnch[24 + No] = tMag tEnch[27 + No] = iMag No = No + 9 end lvlNumb = lvlNumb + 1 lvlNumb = tostring(lvlNumb) if lvlNumb == "6" then break end end tEnch[18] = durNumb table.insert(tOut, table.concat(tEnch)) end return table.concat(tOut) .. "\n|}" end

return p