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 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="24%"|Rewards (Every ')	table.insert(tOut, attData["R"][reward][1])	table.insert(tOut, ') \n')

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

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[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], "C"}) tRet[ 5] = tData[2] tRet[ 7] = TOK({("Relic " .. (tArgs["relic"] or coll)), "C"}) tRet[ 8] = enchData[rItem][item[1]] tRet[10] = TOK({("IP-" .. (tArgs["ip"] or coll)), "C"}) 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" 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'} 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