Module:ALU

--[==[-- -- Lua script to get Attraction Enchantments -- getEnchantments: get Enchantment Level data based on input parameters name    = Building Name (PAGENAME by default) tokens  = Tokens (format "Character,Token") separate tokens with dollar sign "$" one token per enchantment level 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 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 attrData[pagename] then attData = attrData[pagename] else return "Unknown Building" end local tOut = {} local tokens = {} local tRet = {} local reward = "magic" if event and event ~= "" and attData["R"][event] then reward = event elseif not attData["R"][reward] then for k, v in pairs(attData["R"]) do			reward = k			break end end

local cData = "" if itemData["Items"][pagename] then cData = itemData["Items"][pagename] end local numb = 0

table.insert(tOut, '{| class="article-table" style="width: 100%; text-align: center; line-height: 1.0;"\n') if reward ~= "magic" then table.insert(tOut, '|-\n! colspan="8" style="text-align: center;"|') table.insert(tOut, LTE({reward, "N"})) table.insert(tOut, '\n|-\n') end table.insert(tOut, '! width="15%"|Enchantment\n! colspan="4"|Requirements\n! width="10%"|Time\n! colspan="2" width="17%"|Rewards (Every ')	table.insert(tOut, attData["R"][reward][1])	table.insert(tOut, ') \n')

if tArgs["tokens"] then for item in mw.text.gsplit(tArgs["tokens"], "%s*%/%s*") do      			table.insert(tokens, {numb, item}) numb = numb + 1 if numb == 6 then break end end if numb > 1 then table.insert(tokens, {numb, "two chances"}) end table.sort(tokens, function(a,b) return a[1] < b[1] end) 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;\"|" tRet[ 6] = tArgs["cost"] or CHEST({"L"}) tRet[ 9] = "" tRet[12] = "" tRet[16] = tArgs["building"] or "Instant" tRet[19] = TOK({item[2], "P-25"}) tRet[22] = EC({reward}) tRet[23] = attData["R"][reward][3] 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["Requirements"][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["Requirements"][rItem][item[1]] tRet[10] = TOK({("IP-" .. (tArgs["ip"] or coll))}) tRet[11] = tData[3] tRet[13] = EC({"Magic"}) tRet[14] = tData[4] if oldtime[reward] then tRet[16] = tData[6] or tData[5] 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" then tRet[21] = "+" tRet[22] = EC({reward}) local durNumb = attData["R"]["magic"][1] or "?h" local mData = enchData["Magic Rewards"][durNumb][tostring(item[1])] if cData[4] and cData[4] == true then if cData[3] and cData[3] == true then tRet[23] = mData[2] else if cData[1] and cData[1] > 1170 then tRet[23] = mData[1] else tRet[23] = mData[2] end end elseif cData[3] and cData[3] == true then tRet[23] = mData[2] else tRet[23] = mData[1] end 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'} tRet[ 2] = tArgs["cost"] or CHEST({"L"}) tRet[ 4] = tArgs["building"] or "Instant"

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

return p