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)			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| 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] = 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] = COLL.getPremium({flt[3]}) tFlt[20] = COLL.getLimited({flt[3]}) 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.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) 			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		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] = 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] = COLL.getPremium({att[3]}) tAtt[18] = COLL.getLimited({att[3]}) tAtt[22] = (att[4]["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.getEnchantments local buildings = {} local tOut = {	'{| class="article-table dmk-list2 sortable" style="width: 100%;"\n', '! width="10%" class="unsortable"|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)			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] = 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[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