[Lesen | Bearbeiten | Versionen | Aktualisieren]
DokumentationSpringe zum Quelltext ↴
Zum Gebrauch von Lua-Modulen siehe die Modul-Hilfe.

Diese Seite wird gerade von violine1101 neu erstellt oder grundlegend überarbeitet. Fragen und Vorschläge bitte in die Diskussion. Fortschritt: |
Tabellen | |
---|---|
Abbau |
local p = {}
local recipes = {
{
input = {
'Eisenbarren', 'Eisenbarren', 'Eisenbarren',
'', 'Stock', '',
'', 'Stock', ''
},
output = 'Eisenspitzhacke'
},
{
input = 'Eisenblock',
output = {
item = 'Eisenbarren',
count = 9
}
},
{
input = {
'', 'Buch', '',
'Diamant', 'Obsidian', 'Diamant',
'Obsidian', 'Obsidian', 'Obsidian'
},
output = 'Zaubertisch'
},
{
input = {
'Eisenklumpen', 'Eisenklumpen', 'Eisenklumpen',
'Eisenklumpen', 'Eisenklumpen', 'Eisenklumpen',
'Eisenklumpen', 'Eisenklumpen', 'Eisenklumpen'
},
output = 'Eisenbarren'
},
{
input = 'Eisenbarren',
output = {
item = 'Eisenklumpen',
count = 9
}
},
{
input = {
'Eisenbarren', 'Eisenbarren', 'Eisenbarren',
'Eisenbarren', 'Eisenbarren', 'Eisenbarren',
'Eisenbarren', 'Eisenbarren', 'Eisenbarren'
},
output = 'Eisenblock'
},
{
input = {
'', '', '',
'Eisenbarren', 'Eisenbarren', 'Eisenbarren',
'Eisenbarren', 'Eisenbarren', 'Eisenbarren'
},
output = 'Eisengitter'
},
{
input = {
'', '', '',
'', '', '',
'Eisenbarren', 'Eisenbarren', ''
},
output = 'Grobwägeplatte'
},
{
input = {
'', 'Eisenbarren', '',
'', 'Stock', '',
'', 'Stock', ''
},
output = 'Eisenschaufel'
},
{
input = {
'Eisenbarren', 'Eisenbarren', '',
'', 'Stock', '',
'', 'Stock', ''
},
output = 'Eisenhacke'
},
{
input = {
'Eisenbarren', 'Eisenbarren', '',
'Eisenbarren', 'Stock', '',
'', 'Stock', ''
},
output = 'Eisenaxt'
}
}
function normalizeRecipe(recipe)
recipe.input = recipe.input or {''}
recipe.output = recipe.output or {''}
recipe.category = recipe.category or ''
if type(recipe.input) == 'string' then
recipe.input = { '', '', '', '', recipe.input, '', '', '', '' }
recipe.shapeless = recipe.shapeless or recipe.shapeless == nil
end
if type(recipe.output) == 'string' then recipe.output = { item = recipe.output, count = 1 } end
local isSymmetric = (recipe.input[1] == recipe.input[3] and recipe.input[4] == recipe.input[6] and recipe.input[7] == recipe.input[9])
recipe.shapeless = recipe.shapeless or (recipe.shapeless == nil and #recipe.input == 1)
recipe.mirror = recipe.mirror or (recipe.mirror == nil and not isSymmetric and not oneItemNeeded(recipe))
return recipe
end
function getRecipeRelevance(recipe, item)
local items = 0
local allItems = 0
for id,element in pairs(recipe.input) do
if element == item then items = items + 1 end
if element ~= '' then allItems = allItems + 1 end
end
return { ratio = items / allItems, count = items }
end
function oneItemNeeded(recipe)
local item = ''
for id,element in pairs(recipe.input) do
if item == '' then item = element
elseif element ~= '' and item ~= element then return false end
end
return true
end
function isItemInList(itemList, item)
for id,element in pairs(itemList) do
if element.item == item then return true end
end
return false
end
function isElementInList(list, e)
for id,element in pairs(list) do
if element == e then return true end
end
return false
end
function getAllRecipesFor(item)
local recipesList = {}
for id,recipe in pairs(recipes) do
recipe = normalizeRecipe(recipe)
if recipe.output.item == item then table.insert(recipesList, recipe) end
end
return recipesList
end
function getAllRecipesWith(item)
local recipesList = {}
for id,recipe in pairs(recipes) do
recipe = normalizeRecipe(recipe)
if isElementInList(recipe.input, item) then table.insert(recipesList, recipe) end
end
return recipesList
end
function getIngredients(recipe)
local ingredients = {}
local ingredientsList = {}
for id,ingredient in pairs(recipe.input) do
if ingredient ~= '' then
if not isItemInList(ingredientsList, ingredient) then table.insert(ingredientsList, { item = ingredient, count = 1 })
else
for k,v in pairs(ingredientsList) do
if v.item == ingredient then
ingredientsList[k].count = ingredientsList[k].count + 1
break
end
end
end
end
end
local function compare(a, b)
return a.count > b.count
end
table.sort(ingredientsList, compare)
for id,ingredient in pairs(ingredientsList) do
ingredients[id] = ingredient.item
end
return '[[' .. table.concat(ingredients, ']]<br>[[') .. ']]'
end
function p.printRecipes(f)
local args = f
if f == mw.getCurrentFrame() then
args = require( 'Modul:ParameterUmwandeln' ).merge()
else
f = mw.getCurrentFrame()
end
local grid = require( 'Modul:UI' )
local relevantRecipes = {}
if args.item then relevantRecipes = getAllRecipesFor(args.item) end
if args.with then
relevantRecipes = getAllRecipesWith(args.with)
-- Zuerst nach Relevanz sortieren, dann nach Anzahl der verwendeten Gegenstände, dann alphabetisch
local function compare(a, b)
if getRecipeRelevance(a, args.with).ratio == getRecipeRelevance(b, args.with).ratio then
if getRecipeRelevance(a, args.with).count == getRecipeRelevance(b, args.with).count
then return a.output.item < b.output.item
else return getRecipeRelevance(a, args.with).count > getRecipeRelevance(b, args.with).count end
else return getRecipeRelevance(a, args.with).ratio > getRecipeRelevance(b, args.with).ratio end
end
table.sort(relevantRecipes, compare)
end
local showName = (args.with and args.showName ~= 'false') or args.showName == 'true'
local name = (showName and '! Name !') or ''
local createTable = args.createTable == 'true' or not args.createTable
header = (createTable and table.concat({
'{| class="wikitable"',
name .. '! width=100px | Zutaten !! Rezept'
}, '\n')) or ''
local tableContent = ''
for id,recipe in pairs(relevantRecipes) do
local newArgs = {
A1 = (recipe.input[1] and (recipe.input[1] ~= '') and recipe.input[1]) or '',
B1 = (recipe.input[2] and (recipe.input[2] ~= '') and recipe.input[2]) or '',
C1 = (recipe.input[3] and (recipe.input[3] ~= '') and recipe.input[3]) or '',
A2 = (recipe.input[4] and (recipe.input[4] ~= '') and recipe.input[4]) or '',
B2 = (recipe.input[5] and (recipe.input[5] ~= '') and recipe.input[5]) or '',
C2 = (recipe.input[6] and (recipe.input[6] ~= '') and recipe.input[6]) or '',
A3 = (recipe.input[7] and (recipe.input[7] ~= '') and recipe.input[7]) or '',
B3 = (recipe.input[8] and (recipe.input[8] ~= '') and recipe.input[8]) or '',
C3 = (recipe.input[9] and (recipe.input[9] ~= '') and recipe.input[9]) or '',
Output = recipe.output.item .. ',' .. recipe.output.count
}
if recipe.shapeless then newArgs.shapeless = 'true' end
if recipe.mirror then newArgs.mirror = 'true' end
name = (showName and '\n! [[' .. recipe.output.item .. ']]') or ''
tableContent = tableContent .. '\n' .. table.concat({
'|-' .. name,
'| style="text-align:center" | ' .. getIngredients(recipe),
'| ',
grid.craftingTable(newArgs)
}, '\n')
end
local footer = (createTable and '|}') or ''
return header .. '\n' .. tableContent .. '\n' .. footer
end
return p