Модуль:Песочница/Pok: различия между версиями

Нет описания правки
мНет описания правки
Строка 7: Строка 7:
local tableData          = mw.loadData("Модуль:IanComradeBot/prototypes/table.json/data")
local tableData          = mw.loadData("Модуль:IanComradeBot/prototypes/table.json/data")
local gearData          = mw.loadData("Модуль:IanComradeBot/startingGear.json/data")
local gearData          = mw.loadData("Модуль:IanComradeBot/startingGear.json/data")
local jobData            = mw.loadData("Модуль:IanComradeBot/job.json/data")
local gearRoleLoadout    = mw.loadData("Модуль:IanComradeBot/roleLoadout.json/data")
local gearRoleLoadout    = mw.loadData("Модуль:IanComradeBot/roleLoadout.json/data")
local loadoutData        = mw.loadData("Модуль:IanComradeBot/loadout.json/data")
local loadoutData        = mw.loadData("Модуль:IanComradeBot/loadout.json/data")
Строка 109: Строка 110:
function p.reverseEquipment(frame)
function p.reverseEquipment(frame)
     local targetId = frame.args[2]
     local targetId = frame.args[2]
    local slotFilter = frame.args[3]  -- если указан, фильтруем по конкретному слоту
     if not targetId or targetId == "" then
     if not targetId or targetId == "" then
         return "Ошибка: не указан id оборудования для обратного поиска."
         return "Ошибка: не указан id оборудования для обратного поиска."
     end
     end


     local results = {}
     local foundJobs = {}
     -- Поиск в startingGear (gearData)
     -- Ищем в startingGear (gearData)
     for gearId, gear in pairs(gearData) do
     for gearId, gear in pairs(gearData) do
         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 then
                    table.insert(results, "Gear: " .. gearId .. " (слот: " .. slot .. ")")
                    -- Нашли подходящую экипировку – ищем в jobData, где startingGear равен gearId
                    for _, job in pairs(jobData) do
                        if job.startingGear == gearId then
                            table.insert(foundJobs, job.id)
                        end
                    end
                 end
                 end
             end
             end
Строка 126: Строка 131:
     end
     end


     -- Поиск в loadout (loadoutData)
     if #foundJobs == 0 then
    for loadoutId, loadout in pairs(loadoutData) do
        return "Оборудование с id " .. targetId .. " не найдено в стартовых наборах экипировки."
        if loadout.equipment then
            for slot, equipId in pairs(loadout.equipment) do
                if equipId == targetId and (not slotFilter or slot == slotFilter) then
                    table.insert(results, "Loadout: " .. loadoutId .. " (слот: " .. slot .. ")")
                end
            end
        end
     end
     end


     if #results == 0 then
     -- Удаляем возможные дубликаты
         return "Оборудование с id " .. targetId .. " не найдено в наборах экипировки."
    local uniqueJobs = {}
    local seen = {}
    for _, jobId in ipairs(foundJobs) do
        if not seen[jobId] then
            table.insert(uniqueJobs, jobId)
            seen[jobId] = true
         end
     end
     end


     return "Найдено использование оборудования: " .. table.concat(results, "; ")
     return "Найден job: " .. table.concat(uniqueJobs, ", ")
end
end


Строка 149: Строка 153:
---------------------------------------------------------------------
---------------------------------------------------------------------
function p.reverseCargo(frame)
function p.reverseCargo(frame)
    local mode = frame.args[2]
     local searchValue = frame.args[3]
     local searchValue = frame.args[3]
     if not mode or mode == "" or not searchValue or searchValue == "" then
     if not searchValue or searchValue == "" then
         return "Ошибка: необходимо указать режим (product, cost, category, icon) и значение для поиска."
         return "Ошибка: необходимо указать значение для поиска."
     end
     end


     local foundIds = {}
     local foundIds = {}
     for _, entry in ipairs(cargoData) do
     for _, entry in ipairs(cargoData) do
         if mode == "product" and entry.product == searchValue then
         if entry.product == searchValue then
            table.insert(foundIds, entry.id)
        elseif mode == "cost" and tostring(entry.cost) == searchValue then
            table.insert(foundIds, entry.id)
        elseif mode == "category" and entry.category == searchValue then
            table.insert(foundIds, entry.id)
        elseif mode == "icon" and entry.icon and entry.icon.sprite == searchValue then
             table.insert(foundIds, entry.id)
             table.insert(foundIds, entry.id)
         end
         end
Строка 169: Строка 166:


     if #foundIds == 0 then
     if #foundIds == 0 then
         return "Запись для режима " .. mode .. " со значением '" .. searchValue .. "' не найдена."
         return "Запись для product со значением '" .. searchValue .. "' не найдена."
     end
     end