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 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")

local alu     = {} local pagename = "" local token = {"", "", "", ""}

local function aluItems(inStr, tNo, num) local tOut = {} local tIn = mw.text.split(inStr, "%s*%$%s*") for idx = 1, #tIn do		if tIn[idx] ~= "" then if not alu[tNo][num] then alu[tNo][num] = {} end alu[tNo][num][idx] = tIn[idx] end end

return "" end

local function oneItem(item, count, withName, colspan) local nCount = tonumber((string.gsub(count or "", "[,]", ""))) if count == "X" then nCount = 1 end if not nCount then return (colspan and "" or '| style="width: 15%;"|') end

local tItem = {"", "", " " .. util.th_comma(nCount), (withName and " " or ""), "", "",			(withName and " " or ""), }

if nCount == 0 then tItem[3] = " ?" end if count == "X" then tItem[3] = "" end

if item:match("^EC") then if not colspan then tItem[1] = '| style="width: 15%;"|' end tItem[2] = EC({item}) if withName then tItem[5] = EC({item, "L", S=(nCount == 1)}) end else if not colspan then tItem[1] = '| style="width: 13%;"|' end tItem[2] = TOK({item}) if withName then tItem[5] = TOK({item, "L"}) if nCount ~= 1 then tItem[6] = "s" end end end

return table.concat(tItem) end

local reward = "magic"

local function aluTable(tableData, tableNo) local title = "" local tabName = "" local eName = "" local eType = ""

if tableNo and alu[tableNo]["name"] then eName = alu[tableNo]["name"][1] eType = alu[tableNo]["name"][2] or "N" if LTE({eName, eType}) == "Unknown Event 0001" and eName:lower ~= "after" then title = '! colspan="8" style="text-align: center;"|' .. eName .. '\n|-\n' tabName = " (" .. eName .. ")" elseif eName:lower ~= "after" then title = '! colspan="8" style="text-align: center;"|' .. LTE({eName, eType}) .. '\n|-\n' tabName = " (" .. LTE({eName:lower, eType, "K"}) .. " Event)" end end

if pagename == "Common" or pagename == "Uncommon" or pagename == "Rare" then token[2] = "Relic " .. pagename token[3] = "Collection" title = '|+ ' .. pagename .. ' Relics Tokens (' .. TOK({"multi", pagename .. " Relic", "Relic"}) .. ') \n|-\n' end

if attrData[pagename] then attData = attrData[pagename]

if eName ~= "" and attData["R"][eName:lower] then reward = eName:lower elseif not attData["R"][reward] then for k, v in pairs(attData["R"]) do				if k ~= "after" then reward = k					break end end end else attData = { ["R"] = { ["magic"] = {"?h", 0, 0, "?", "?", "?", "?", "?"}, }		}	end

if not attData["R"][reward][5] then alu[tableNo][2] = nil alu[tableNo][3] = nil alu[tableNo][4] = nil alu[tableNo][5] = nil alu[tableNo][6] = nil end

local rItem = TOK({token[2], "R"}):gsub(" relic", ""):lower if alu[tableNo][2] and rItem == "common" or pagename == "Common" then alu[tableNo][2][2] = 15 alu[tableNo][3][2] = 30 alu[tableNo][4][2] = 60 alu[tableNo][5][2] = 120 alu[tableNo][6][2] = 250 elseif alu[tableNo][2] and rItem == "uncommon" or pagename == "Uncommon" then alu[tableNo][2][2] = 10 alu[tableNo][3][2] = 20 alu[tableNo][4][2] = 40 alu[tableNo][5][2] = 80 alu[tableNo][6][2] = 150 elseif alu[tableNo][2] and rItem == "rare" or pagename == "Rare" then alu[tableNo][2][2] = 5 alu[tableNo][3][2] = 10 alu[tableNo][4][2] = 20 alu[tableNo][5][2] = 50 alu[tableNo][6][2] = 100 end

local prevToken = {} local blueprint = {"", "Blueprint Common", "Blueprint Uncommon", "Blueprint Rare", "Blueprint Epic", "Blueprint Legendary"}

local tOut = { --			'\n|-| Level Ups', tabName, '=\n', '{| class="article-table" style="width: 100%; text-align: center; line-height: 1.0;"\n', title, '! 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 ', attData["R"][reward][1], ') \n' }

if token[3] == "Collection" then --		tOut[9] = "" tOut[10] = "" tOut[11] = "" tOut[6] = "" tOut[7] = "" tOut[8] = "" end

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

for aluNo, aluData in ipairs(tableData) do local tRow = {'|-\n', '| nowrap|', ("Level " .. (aluNo - 1)), '\n', "", "", "", "", '|', "", '\n', "", , , "", '\n', }

for idx = 1, 6 do			if aluNo == 1 then tRow[3] = "Building" local iName, iCount = string.match((aluData[1] or ""), "^([^#]-)%s*#*%s*([%d%,]*)$") tRow[5] = '| colspan="4"|' if eName == "" then tRow[6] = CHEST({"L"}) end if iCount == "" and iName ~= "" then tRow[7] = aluData[1] else tRow[7] = oneItem(iName, iCount, true, true) end tRow[8] = '\n' tRow[10] = (aluData[2] or "Instant") if pagename ~= "Common" and pagename ~= "Uncommon" and pagename ~= "Rare" then tRow[12] = '| style="width: 15%;"|' .. TOK({(attData["R"][reward][4] or ""), "P"}) tRow[13] = '\n| nowrap|' tRow[14] = EC({reward}) tRow[15] = aMagic end break elseif idx < 5 then local iName = token[idx] if idx == 1 then iName = blueprint[aluNo] end local iCount = string.match((aluData[idx] or ""), "^[%d%,]*$") if not iCount then iName, iCount = string.match((aluData[idx] or ""), "^([^#]-)%s*#*%s*([%d%,]*)$") if iCount == "" then iCount = "1" end end tRow[4 + idx] = oneItem(iName, iCount, iName ~= prevToken[idx]) .. '\n' if iCount ~= "" then token[idx]    = iName prevToken[idx] = iName end elseif idx == 5 then tRow[10] = (aluData[idx] or "") elseif idx == 6 and pagename ~= "Common" and pagename ~= "Uncommon" and pagename ~= "Rare" then tRow[12] = oneItem((attData["R"][reward][3 + aluNo] or "two chances"), "X", true) tRow[13] = '\n| nowrap|'

if (reward == "magic" or reward == "after") and attData["R"][reward][1] == "?h" then tRow[14] = EC({reward}) tRow[15] = "?" tRow[16] = " (+"					tRow[17] = EC({"Magic", nil, nil, nil, "20"})					tRow[18] = "?"					tRow[19] = ") \n" elseif (reward == "magic" or reward == "after") then local eMagic = math.ceil(aMagic * (1 + aluData[idx])) tRow[14] = EC({reward}) tRow[15] = eMagic tRow[16] = " (+"					tRow[17] = EC({"Magic", nil, nil, nil, "20"})					tRow[18] = eMagic - pMagic					tRow[19] = ") \n" pMagic = eMagic end end end

table.insert(tOut, table.concat(tRow)) end

table.insert(tOut, '|}\n')

return table.concat(tOut) end

function p.getALU(frame) local tArgs = util.getArgs(frame)

pagename = tArgs["name"] or mw.title.getCurrentTitle.text

if tArgs["event"] or tArgs["title"] then tArgs["aluN1"] = (tArgs["event"] or tArgs["title"]) end

if tArgs["cost"] and tArgs["building"] then tArgs["alu1"] = tArgs["cost"] .. "$" .. tArgs["building"] elseif tArgs["cost"] then tArgs["alu1"] = tArgs["cost"] elseif tArgs["building"] then tArgs["alu1"] = "$" .. tArgs["building"] end

local collection = COLL({pagename, "S"}) token = {"", ("Relic " .. collection), ("IP-" .. collection), "EC-Magic"}

if tArgs["relic"] then token[2] = "Relic " .. tArgs["relic"] end if tArgs["ip"] then token[3] = "IP-" .. tArgs["ip"] end

alu[1] = { [1] = {"", "Instant"}, [2] = {"20", "0", "10", "2,000", "2h", 0.04}, [3] = {"15", "0", "20", "5,000", "4h", 0.1}, [4] = {"10", "0", "30", "15,000", "8h", 0.18}, [5] = { "7", "0", "40", "50,000", "12h", 0.28}, [6] = { "5", "0", "50", "150,000", "24h", 0.4}, }

local onetable = {}

for arg, value in pairs(tArgs) do		local cat, t, n = tostring(arg):match('^(%a+)([1-9]-)_?([1-9]%d*)$') local num = tonumber(n) local tNo = tonumber(t) or 1 if num then if not alu[tNo] then alu[tNo] = { [1] = {"", "Instant"}, [2] = {"20", "0", "10", "2,000", "2h", 0.04}, [3] = {"15", "0", "20", "5,000", "4h", 0.1}, [4] = {"10", "0", "30", "15,000", "8h", 0.18}, [5] = { "7", "0", "40", "50,000", "12h", 0.28}, [6] = { "5", "0", "50", "150,000", "24h", 0.4}, }			end if cat == "alu" then aluItems(value, tNo, num) elseif cat == "aluN" then alu[num]["name"] = mw.text.split(value, "%s*%$%s*") elseif cat == "aluA" then onetable = {num, tonumber(value)} end end end

if table.concat(onetable) ~= "" then alu[onetable[2]] = alu[onetable[1]] alu[onetable[1]] = nil end

local allTables = {}

for tNo, tData in ipairs(alu) do		table.insert(allTables, aluTable(tData, tNo)) end

return table.concat(allTables) end

return p