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 BUILDING = require("Module:Building").building 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]["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(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', '! 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})      		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=\"", "", "\" nowrap|", "",				"\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[23] = flt[5]["R"]["magic"][1] tFlt[25] = EC({"Magic"}) .. tFlt[23] tFlt[27] = flt[5]["R"]["magic"][2] tFlt[29] = EC({"Gems"}) .. tFlt[27] tFlt[31] = flt[5]["R"]["magic"][3] 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"|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(attrData) do		if collectionData["Items"][item] and collectionData["Items"][item][2] == buildType:lower 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(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=\"", 0, "\" 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] ~= "" 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(att[4]["R"]["magic"][1], "^([%d%?]+)([hms])$") if durHMS == "m" then durNumb = durNumb / 60 end tAtt[21] = tonumber(durNumb) or 1 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 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(attrData) 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) 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"

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

tEnch[18] = attrData[att[3]]["R"]["magic"][1] local aMagic = attrData[att[3]]["R"]["magic"][3] local pMagic = aMagic

for iTok in mw.text.gsplit(att[4], "%s*%/%s*") do			if lvlNumb == "0" then tEnch[13] = TOK({iTok}) tEnch[16] = aMagic else tEnch[21 + No] = TOK({iTok}) local eMagic = math.ceil(aMagic * (1 + enchData[tostring(lvlNumb)][7])) tEnch[24 + No] = eMagic tEnch[27 + 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