Module:ALU

--[==[-- -- Lua script to get Attraction Enchantments -- getEnchantments: get Enchantment Level data based on input parameters name    = Building Name (PAGENAME by default) event   = Event Name / IP Short Name (optional) cost    = Building Cost (Legendary Chests by default) (optional) building = Building Time (Instant by default) relic   = if relic token different from the collection (optional) ip      = if collection token different from the collection (optional)

Unknown is returned if building is not in data. --]==]

local p = {}

local enchData = mw.loadData('Module:ALU/data')

local attrData = mw.loadData('Module:Building/data') local itemData = mw.loadData( 'Module:ItemCollection/data' )

local EC = require("Module:EC").getEC local NPC = require("Module:NPC").getNPC local TOK = require("Module:CharacterToken").getToken local CHEST = require("Module:ECR").getITEM local COLL = require("Module:ItemCollection").getCollection local LTE = require("Module:LTEvent").getLTE local util = require("Module:Utility")

function p.getALU(frame) local tArgs = util.getArgs(frame) local event = tArgs["event"] if event then event = event:lower:gsub("^%s*(.-)%s*$", "%1") or '' end local pagename = tArgs["name"] or mw.title.getCurrentTitle.text

if pagename == "Common" or pagename == "Uncommon" or pagename == "Rare" then attData = { ["R"] = { ["magic"] = {"?h", 0, 0, "", "", "", "", ""}, }		}		tArgs["relic"] = pagename tArgs["ip"] = "Collection" elseif attrData[pagename] then attData = attrData[pagename] else return "Unknown Building/Work In Progress" end local tOut = {} local tokens = {} local tRet = {} local reward = "magic" if event and attData["R"][event] then reward = event elseif not attData["R"][reward] then for k, v in pairs(attData["R"]) do			if k ~= "after" then reward = k				break end end end local numb = 0

table.insert(tOut, '{| class="article-table" style="width: 100%; text-align: center; line-height: 1.0;"\n') if reward ~= "magic" and reward ~= "after" then table.insert(tOut, '|-\n! colspan="8" style="text-align: center;"|') table.insert(tOut, LTE({reward, "N"})) table.insert(tOut, '\n|-\n') elseif pagename == "Common" or pagename == "Uncommon" or pagename == "Rare" then table.insert(tOut, '|+ ') table.insert(tOut, pagename) table.insert(tOut, ' Relics (')		table.insert(tOut, TOK({"multi", pagename .. " Relic", "Relic"}))		table.insert(tOut, ')  \n') end table.insert(tOut, '! style="width: 15%; text-align: center;"|Enchantment\n! style="text-align: center;" colspan="4"|Requirements\n! style="width: 10%; text-align: center;"|Time\n! style="width: 24%; text-align: center;" colspan="2"|Rewards (Every ')	table.insert(tOut, attData["R"][reward][1])	table.insert(tOut, ') \n')

local aMagic = attData["R"][reward][3] local pMagic = aMagic

if attData["R"][reward][5] then tokens = {	{0, attData["R"][reward][4]}, {1, attData["R"][reward][5]}, {2, attData["R"][reward][6]}, {3, attData["R"][reward][7]}, {4, attData["R"][reward][8]}, {5, "two chances"} }

for _, item in ipairs(tokens) do tRet = {"|-\n|", "Level " .. item[1], "\n| nowrap|", "", "", "\n| nowrap|", "", "", "\n| nowrap|", "", "", "\n| nowrap|", "", "", "\n|", "", '\n| style="width: 15%;"|', "", "", "\n| nowrap|", "", "", "", "", "", 				"", "\n" }			if item[1] == 0 then tRet[ 2] = "Building"

tRet[ 3] = "\n| colspan=\"4\" style=\"text-align: center;\"|" if not event then tRet[ 4] = CHEST({"L"}) end if tArgs["cost"] then local iName, iCount = string.match(tArgs["cost"], "^([^#]-)%s*#*%s*([%d%,]*)$") if not iCount or iCount == "" then tRet[ 5] = tArgs["cost"] else tRet[ 5] = EC({iName:gsub("^EC%-", "")}) .. " " .. iCount .. " " .. EC({iName:gsub("^EC%-", ""), "L", S=(nCount == "1")}) .. " "					end end tRet[ 6] = "" tRet[ 9] = "" tRet[12] = ""

tRet[16] = tArgs["building"] or "Instant"

tRet[19] = TOK({item[2], "P-25"})

tRet[21] = EC({reward}) tRet[22] = aMagic else local oldtime = {["fn"] = true, ["coco"] = true, ["frozen2"] = true, ["sw"] = true, ["onward"] = true, ["hercules"] = true, ["sw2"] = true, ["brave"] = true}

local coll = COLL({pagename, "S"}) local tData = enchData[tostring(item[1])] local rItem = TOK({"Relic " .. (tArgs["relic"] or coll), "R"}):gsub(" relic", "") tRet[ 4] = TOK({"Blueprint " .. tData[1]}) tRet[ 5] = tData[2]

tRet[ 7] = TOK({("Relic " .. (tArgs["relic"] or coll))}) tRet[ 8] = enchData[rItem][item[1]]

if tArgs["ip"] and tArgs["ip"] == "Collection" then tRet[10] = TOK({tArgs["ip"]}) else tRet[10] = TOK({("IP-" .. (tArgs["ip"] or coll))}) end tRet[11] = tData[3]

tRet[13] = EC({"Magic"}) tRet[14] = tData[4]

if oldtime[reward] then tRet[16] = tData[6] else tRet[16] = tData[5] end

if item[1] ~= 5 and item[2] ~= "" then tRet[18] = "+" end tRet[19] = TOK({item[2], "P-25"}) if reward == "magic" or reward == "after" then tRet[21] = EC({reward}) local eMagic = math.ceil(aMagic * (1 + tData[7])) tRet[22] = eMagic tRet[23] = " (+"					tRet[24] = EC({"Magic", nil, nil, nil, "20"})					tRet[25] = eMagic - pMagic					tRet[26] = ") " pMagic = eMagic end end table.insert(tOut, table.concat(tRet)) end else tRet = {'|-\n|Building\n| colspan="4" style="text-align: center;"|', "", "", "\n|", "", '\n| style="width: 15%;"|', "", "\n| nowrap|", "", "", "", "", "\n" }		if not event then tRet[ 2] = CHEST({"L"}) end if tArgs["cost"] then local iName, iCount = string.match(tArgs["cost"], "^([^#]-)%s*#*%s*([%d%,]*)$") if not iCount or iCount == "" then tRet[ 3] = tArgs["cost"] else tRet[ 3] = EC({iName:gsub("^EC%-", "")}) .. " " .. iCount .. " " .. EC({iName:gsub("^EC%-", ""), "L", S=(nCount == "1")}) .. " "			end end

tRet[ 5] = tArgs["building"] or "Instant"

tRet[ 7] = TOK({(attData["R"][reward][4] or ""), "P-25"})

tRet[ 9] = EC({reward}) tRet[10] = aMagic

table.insert(tOut, table.concat(tRet)) end return table.concat(tOut) .. "|}" end

return p