Module:ALU

--[==[-- -- Lua script to get Attraction Enchantments -- getEnchantments: get Enchantment Level data based on input parameters name    = Building Name (PAGENAME 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") local LTE = require("Module:LTEvent").getLTE local ACT = require("Module:ActivityList").getAttractionActivities 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: 16%;"|') end

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

if nCount == 0 then tItem[3] = " ?" end if not colspan and count == "X" then tItem[3] = "" tItem[1] = '| style="width: 10%;"|' elseif not colspan then tItem[1] = '| style="width: 16%;"|' end

if item:match(" Chests") then return require("Module:EnchantedChest").getChest({item, "O"}) elseif item:match("^EC") then tItem[2] = EC({item}) if withName then tItem[5] = EC({item, "L", S=(nCount == 1)}) end else 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 function thrillTable(req, d, bc, ba, ench) local CAT = COLL.getCategory local requ = mw.text.split(req, "%s*%$%s*") local deco = mw.text.split(d, "%s*%$%s*") local cons = mw.text.split(bc, "%s*%$%s*") local attr = mw.text.split(ba, "%s*%$%s*")

local tEnch = ' Enchantment Level ' .. ench

local tItem = { '\n|-| Thrill Level Ups=\n', '{| class="article-table" style="width: 100%; text-align: center; line-height: 1.3;"\n', '! style="text-align: center;"| Level 1 (',			(requ[1] or "?"),			' Requests)\n! style="text-align: center;"| Level 2 (',			(requ[2] or "?"),			' Requests)\n! style="text-align: center;"| Level 3 (',			(requ[3] or "?"),			' Requests)\n|-\n|Magic Pedestal Level 1\n|Magic Pedestal Level 2 1 Special Request Wish every 24h\n|Magic Pedestal Level 3 +50% ', EC({"Magic", "N"}), '\n|}\n{| class="article-table" style="width: 100%; text-align: right; line-height: 1.3;"\n', '! colspan="2" style="text-align: center;"| Decorations Requests\n', '! colspan="2" style="text-align: center;"| Concessions Requests\n', '! colspan="2" style="text-align: center;"| Attractions Requests\n', '\n|-\n| nowrap|', CAT({"Amenity", "I"}), '\n| nowrap style="text-align: left;"|: ', (deco[1] or ""), '\n| nowrap|', CAT({"Food Stand", "I"}), '\n| nowrap style="text-align: left;"|: ', (cons[1] or ""), '\n| nowrap|', CAT({"Attraction", "I"}), '\n| nowrap style="text-align: left;"|: ', (attr[1] or ""), '\n|-\n| nowrap|', CAT({"Greenery", "I"}), '\n| nowrap style="text-align: left;"|: ', (deco[2] or ""), '\n| nowrap|', CAT({"Headwear Stand", "I"}), '\n| nowrap style="text-align: left;"|: ', (cons[2] or ""), '\n| nowrap|', CAT({"Attraction", "I"}), tEnch, '\n| nowrap style="text-align: left;"|: ', (attr[2] or ""), '\n|-\n| nowrap|', CAT({"Scenery", "I"}), '\n| nowrap style="text-align: left;"|: ', (deco[3] or ""), '\n| nowrap|', CAT({"Drink Stand", "I"}), '\n| nowrap style="text-align: left;"|: ', (cons[3] or ""), '\n| nowrap|', CAT({"Attraction", "I"}), tEnch, '\n| nowrap style="text-align: left;"|: ', (attr[3] or ""), '\n|-\n| nowrap|', CAT({"Monument", "I"}), '\n| nowrap style="text-align: left;"|: ', (deco[4] or ""), '\n| nowrap|', CAT({"Souvenir Stand", "I"}), '\n| nowrap style="text-align: left;"|: ', (cons[4] or ""), '\n| nowrap|', CAT({"Attraction", "I"}), tEnch, '\n| nowrap style="text-align: left;"|: ', (attr[4] or ""), '\n|-\n| nowrap|', CAT({"Trophy", "I"}), '\n| nowrap style="text-align: left;"|: ', (deco[5] or ""), '\n|', '\n|', '\n| nowrap|', CAT({"Attraction", "I"}), tEnch, '\n| nowrap style="text-align: left;"|: ', (attr[5] or ""), '\n|}\n', }

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 = " (First Release)" 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: 10%; text-align: center;"|Level\n', '! style="text-align: center;" colspan="4"|Requirements\n', '! style="width: 5%; text-align: center;"|Time\n', '! style="width: 20%; text-align: center;" colspan="2"|Rewards (Every ', attData["R"][reward][1], ') \n' }

if token[3] == "Collection" then tOut[9] = "" tOut[10] = "" tOut[11] = "" 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({P=pagename, "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", "B"}) 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

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

if tArgs["relic"] then token[2] = "Relic " .. tArgs["relic"]:upper end if tArgs["ip"] then token[3] = "IP-" .. tArgs["ip"]:upper 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 cat == "alu" 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 aluItems(value, tNo, num) elseif cat == "aluN" then if not alu[num] then alu[num] = { [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 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 = {}

if tArgs["req"] then table.insert(allTables, thrillTable(tArgs["req"], (tArgs["d"] or ""), (tArgs["bc"] or ""), (tArgs["ba"] or ""), (tArgs["ench"] or "?"))) else for tNo, tData in ipairs(alu) do			table.insert(allTables, aluTable(tData, tNo)) end end

table.insert(allTables, 2, ACT(pagename))

return table.concat(allTables) end

return p