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

мНет описания правки
мНет описания правки
Строка 187: Строка 187:
     end
     end


     local results = {}
     local resultsMap = {}


     -- Обработка startingGear (gearData)
     -- Обработка startingGear (gearData)
Строка 195: Строка 195:
             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
                     for jobId, job in pairs(jobData) do
                     for jobId, job in pairs(jobData) do
                         if job.startingGear == currentGearId then
                         if job.startingGear == currentGearId then
                             foundJob = jobId
                             resultsMap[jobId] = true
                             break
                             break
                         end
                         end
                    end
                    if foundJob then
                        table.insert(results, createJobLink(foundJob))
                     end
                     end
                 end
                 end
Строка 210: Строка 206:
     end
     end


     -- Обработка loadout (loadoutData)
     -- для loadout + loadoutGroup + roleLoadout
     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
                     -- для каждого loadout ищем все группы, где он упоминается
                     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
                                     -- для каждой найденной группы ищем все роли
                                     break
                                     for _, role in pairs(gearRoleLoadout) do
                                end
                                        if role.groups and type(role.groups) == "table" then
                            end
                                            for _, g in ipairs(role.groups) do
                        end
                                                if g == group.id then
                        if foundGroupId then break end
                                                    resultsMap[role.id] = 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