Модуль:Местонахождение: различия между версиями

мНет описания правки
мНет описания правки
Строка 19: Строка 19:
local latheData            = mw.loadData("Модуль:IanComradeBot/prototypes/lathe.json/data")
local latheData            = mw.loadData("Модуль:IanComradeBot/prototypes/lathe.json/data")
local recipeData          = mw.loadData("Модуль:IanComradeBot/prototypes/lathe/recipes.json/data")
local recipeData          = mw.loadData("Модуль:IanComradeBot/prototypes/lathe/recipes.json/data")
local recipePackData      = mw.loadData("Модуль:IanComradeBot/prototypes/lathe/recipe pack.json/data")
local researchData        = mw.loadData("Модуль:IanComradeBot/prototypes/research.json/data")
local researchData        = mw.loadData("Модуль:IanComradeBot/prototypes/research.json/data")
local materialData        = mw.loadData("Модуль:IanComradeBot/prototypes/materials.json/data")
local materialData        = mw.loadData("Модуль:IanComradeBot/prototypes/materials.json/data")
Строка 311: Строка 312:


function p.reverseLathe(frame)
function p.reverseLathe(frame)
     local targetResult = frame.args[2]
     local targetRecipe = frame.args[2]
     if not targetResult or targetResult == "" then
     if not targetRecipe or targetRecipe == "" then
         return "Ошибка: не указан результат рецепта для обратного поиска."
         return "Ошибка: не указан результат рецепта для обратного поиска."
     end
     end


     local matchingLathes = {}
     local matchingPacks = {}
     local function checkRecipes(recipeIds)
    for _, pack in ipairs(recipePackData) do
         for _, recipeId in ipairs(recipeIds or {}) do
        if pack.recipes then
             local recipe = getRecipeById(recipeId)
            for _, recipe in ipairs(pack.recipes) do
            if recipe and recipe.result == targetResult then
                if recipe == targetRecipe then
                return true
                    table.insert(matchingPacks, pack.id)
                    break
                end
            end
        end
    end
 
    if #matchingPacks == 0 then
        return ""
    end
 
     local function containsAny(array, targets)
         for _, v in ipairs(array or {}) do
             for _, t in ipairs(targets) do
                if v == t then  
                    return true  
                end
             end
             end
         end
         end
Строка 327: Строка 344:
     end
     end


    local matchingLathes = {}
     for _, lathe in ipairs(latheData) do
     for _, lathe in ipairs(latheData) do
         local found = false
         local found = false
         if lathe.Lathe then
         if lathe.Lathe then
             if checkRecipes(lathe.Lathe.staticRecipes) or checkRecipes(lathe.Lathe.dynamicRecipes) then
             if containsAny(lathe.Lathe.staticPacks, matchingPacks) or containsAny(lathe.Lathe.dynamicPacks, matchingPacks) then
                 found = true
                 found = true
             end
             end
         end
         end
         if not found and lathe.EmagLatheRecipes then
         if not found and lathe.EmagLatheRecipes then
             if checkRecipes(lathe.EmagLatheRecipes.emagStaticRecipes) or checkRecipes(lathe.EmagLatheRecipes.emagDynamicRecipes) then
             if containsAny(lathe.EmagLatheRecipes.emagStaticRecipes, matchingPacks) or containsAny(lathe.EmagLatheRecipes.emagDynamicPacks, matchingPacks) then
                 found = true
                 found = true
             end
             end