Module:ALU

--[==[-- -- Lua script to get Enchantments Information -- 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:Enchantment/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") 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.getEnchantments(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 tokens = {} local tRet = {} local tOut = {'{| class="article-table" style="width: 100%;"\n'} if event and event ~= "" then table.insert(tOut, '|-\n! colspan="8" style="text-align: center;"|') table.insert(tOut, LTE({event, "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\n') if tArgs["tokens"] then 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 numb = 0 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| style=\"text-align: center;\"|", "Level " .. item[1], "\n| nowrap|", "", "", "\n| nowrap|", "", "", "\n| nowrap|", "", "", "\n| nowrap|", "", "", "\n|", "", "\n| colspan=\"2\"|", "", "", "", "", "", "", "\n" }			if item[1] == 0 then tRet[ 2] = "Building" tRet[ 3] = "\n| colspan=\"4\" style=\"text-align: center;\"|" if tArgs["cost"] then tRet[ 6] = tArgs["cost"] else tRet[ 6] = CHEST({"L"}) end tRet[ 9] = "" tRet[12] = "" tRet[16] = tArgs["building"] or "Instant" tRet[17] = "\n| nowrap|" tRet[19] = TOK.getToken({item[2]}) tRet[20] = "\n| nowrap|" tRet[22] = EC({reward}) tRet[23] = attData["R"][reward][3] else local coll = COLL({pagename, "S"}) local tData = enchData["Requirements"][tostring(item[1])] local tItem = TOK.getToken({"Relic " .. (tArgs["relic"] or coll), "T"}) local tNumb = TOK.tokenType({tItem}) tRet[ 4] = TOK.getToken({"Blueprint " .. tData[1]}) tRet[ 5] = tData[2] tRet[ 7] = TOK.getToken({("Relic " .. (tArgs["relic"] or coll))}) tRet[ 8] = enchData["Requirements"][tNumb:gsub(" relic", "")][item[1]] tRet[10] = TOK.getToken({("IP-" .. (tArgs["ip"] or coll))}) tRet[11] = tData[3] tRet[13] = EC({"Magic"}) tRet[14] = tData[4] tRet[16] = tData[5] if item[1] ~= 5 then tRet[18] = "+" end tRet[19] = TOK.getToken({item[2]}) if not event then tRet[17] = "\n| nowrap|" tRet[20] = "\n| nowrap|" tRet[21] = "+" tRet[22] = EC({"magic"}) local durNumb = attData["R"]["magic"][1] local mData = enchData["Magic Rewards"][durNumb][tostring(item[1])] if itemData["Items"][pagename] then local cData = itemData["Items"][pagename] 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 end table.insert(tOut, table.concat(tRet)) end end return table.concat(tOut) .. "|}" end

return p