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

мНет описания правки
м Замена текста — «IanComradeBot/prototypes/сargo.json/data» на «IanComradeBot/prototypes/cargo.json/data»
 
(не показано 7 промежуточных версий этого же участника)
Строка 13: Строка 13:
local loadoutGroupData    = mw.loadData("Модуль:IanComradeBot/loadoutGroup.json/data")
local loadoutGroupData    = mw.loadData("Модуль:IanComradeBot/loadoutGroup.json/data")


local cargoData            = mw.loadData("Модуль:IanComradeBot/prototypes/сargo.json/base")
local itemBorgData        = mw.loadData("Модуль:IanComradeBot/prototypes/ItemBorgModule.json/data")
 
local cargoData            = mw.loadData("Модуль:IanComradeBot/prototypes/cargo.json/data")


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")
Строка 71: Строка 74:
-- Формирование ссылки для роли/джоба (reverseEquipment)
-- Формирование ссылки для роли/джоба (reverseEquipment)
local function createJobLink(jobId)
local function createJobLink(jobId)
     local translation = "{{#invoke:Ftl|main|translation|" .. jobId .. "}}"
     local translation = "{{#invoke:Ftl|main|translation|Job" .. jobId .. "}}"
     return "[[" .. translation .. "|{{ucfirst:" .. translation .. "}}]]"
     return "[[" .. translation .. "|{{ucfirst:" .. translation .. "}}]]"
end
end
Строка 174: Строка 177:
     end
     end


     return "Находится в хранилище (полном): " .. table.concat(links, ", ")
     return table.concat(links, ", ")
end
end


Строка 184: Строка 187:
     end
     end


     local results = {}
     local resultsMap = {}


     -- Обработка startingGear (gearData)
     -- Обработка startingGear (gearData)
     for _, gear in pairs(gearData) do
     for _, gear in pairs(gearData) do
        local currentGearId = gear.id or "Unknown"
         if gear.equipment then
         if gear.equipment then
             for slot, equipId in pairs(gear.equipment) do
             for slot, equipId in pairs(gear.equipment) do
                 if equipId == targetId and (not slotFilter or slot == slotFilter) then
                 if equipId == targetId and (not slotFilter or slot == slotFilter) then
                     local foundJob = nil
                     local gearId = gear.id
                     for jobId, job in pairs(jobData) do
                     if gearId then
                        if job.startingGear == currentGearId then
                        for _, job in ipairs(jobData) do
                            foundJob = jobId
                            if job.startingGear == gearId then
                             break
                                resultsMap[job.id] = true
                             end
                         end
                         end
                    end
                    if foundJob then
                        table.insert(results, createJobLink(foundJob))
                     end
                     end
                 end
                 end
Строка 206: Строка 206:
         end
         end
     end
     end
 
     -- loadout + loadoutGroup + roleLoadout
     -- Обработка loadout (loadoutData)
     for _, loadout in pairs(loadoutData) do
     for _, loadout in pairs(loadoutData) do
         if loadout.equipment then
         if loadout.equipment then
             for slot, equipId in pairs(loadout.equipment) do
             for slot, equipId in pairs(loadout.equipment) do
                 if equipId == targetId and (not slotFilter or slot == slotFilter) then
                 if equipId == targetId and (not slotFilter or slot == slotFilter) then
                    local foundGroupId = nil
                     for _, group in pairs(loadoutGroupData) do
                     for _, group in pairs(loadoutGroupData) do
                         if group.loadouts and type(group.loadouts) == "table" then
                         if group.loadouts and type(group.loadouts) == "table" then
                             for _, lId in ipairs(group.loadouts) do
                             for _, lId in ipairs(group.loadouts) do
                                 if lId == loadout.id then
                                 if lId == loadout.id then
                                     foundGroupId = group.id
                                     for _, role in pairs(gearRoleLoadout) do
                                    break
                                        if role.groups and type(role.groups) == "table" then
                                end
                                            for _, g in ipairs(role.groups) do
                            end
                                                if g == group.id then
                        end
                                                    local moduleKey = role.id:gsub("^Job", "")
                        if foundGroupId then break end
                                                    resultsMap[moduleKey] = true
                    end
                                                end
                    local foundJob = nil
                                            end
                    if foundGroupId then
                                         end
                        for _, role in pairs(gearRoleLoadout) do
                            if role.groups then
                                for _, g in ipairs(role.groups) do
                                    if g == foundGroupId then
                                        foundJob = role.id
                                         break
                                     end
                                     end
                                 end
                                 end
                             end
                             end
                            if foundJob then break end
                         end
                         end
                    end
                    if foundJob then
                        table.insert(results, createJobLink(foundJob))
                     end
                     end
                 end
                 end
             end
             end
         end
         end
    end
    -- Собираем результаты, убираем дубликаты
    local results = {}
    for jobId in pairs(resultsMap) do
        table.insert(results, createJobLink(jobId))
     end
     end


Строка 250: Строка 245:
     end
     end


     return "Начальная экипировка роли: " .. table.concat(results, ", ")
     return table.concat(results, ", ")
end
end


Строка 269: Строка 264:


     if #directCargo > 0 then
     if #directCargo > 0 then
local links = {}
        local links = {}
for _, storage in ipairs(directCargo) do
        for _, storage in ipairs(directCargo) do
table.insert(links, createCargoLink(storage))
            table.insert(links, createCargoLink(storage))
end
        end
return "Заказ груза: " .. table.concat(links, ", ")
        return table.concat(links, ", ")
     end
     end


Строка 296: Строка 291:
         table.insert(links, createCargoLink(storage))
         table.insert(links, createCargoLink(storage))
     end
     end
     return "Заказ груза: " .. table.concat(links, ", ")
     return table.concat(links, ", ")
end
end


Строка 309: Строка 304:


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
Строка 325: Строка 336:
     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
Строка 351: Строка 363:
     end
     end


     return "Может быть напечатано на станке: " .. table.concat(links, ", ")
     return table.concat(links, ", ")
end
end


Строка 418: Строка 430:
     end
     end


     -- Разные текстовые сообщения для каждого режима
     return table.concat(links, ", ")
     local modeTexts = {
end
         inventory  = "Содержится в торгомате: ",
 
         contraband = "Содержится в торгомате ([[Взламываемые криптографическим секвенсором предметы|EMAG]]): ",
function p.reverseBorg(frame)
        emag      = "Содержится в торгомате ([[Руководство по взлому|взлом]]): "
     local targetItem = frame.args[2]
     }
    if not targetItem or targetItem == "" then
     local outputText = modeTexts[invMode] or "Содержится в торгомате: "
         return "Ошибка: не указан искомый элемент для поиска в ItemBorgModule."
     return outputText .. table.concat(links, ", ")
    end
 
    local results = {}
    -- Проходим по всем записям из itemBorgData
    for _, entry in pairs(itemBorgData) do
         if type(entry) == "table" and entry.ItemBorgModule and type(entry.ItemBorgModule) == "table" then
            local items = entry.ItemBorgModule.items
            if type(items) == "table" then
                for _, item in ipairs(items) do
                    if item == targetItem then
                        table.insert(results, createEntityLink(entry.id))
                        break
                    end
                end
            end
        end
     end
 
     if #results == 0 then
        return ""
    end
 
     return table.concat(results, ", ")
end
end


Строка 443: Строка 477:
         reverseLathe    = p.reverseLathe,
         reverseLathe    = p.reverseLathe,
         reverseVending  = p.reverseVending,
         reverseVending  = p.reverseVending,
        reverseBorg      = p.reverseBorg,
     }
     }