Модуль:Prototypes/Роль/Экипировка: различия между версиями

мНет описания правки
мНет описания правки
Строка 21: Строка 21:
     if not str or str == "" then return "" end
     if not str or str == "" then return "" end
     return str:sub(1,1):upper() .. str:sub(2)
     return str:sub(1,1):upper() .. str:sub(2)
end
-- Функция для преобразования первой буквы
local function capitalize(s)
    return (s:gsub("^%l", string.upper))
end
end


function p.main(frame)
function p.main(frame)
     local args = frame.args
     local args = frame.args
     local modeOrSlot = mw.text.trim(args[1] or "")
     local slot  = mw.text.trim(args[1] or "")
   
    -- Режим "special": вывод специальных имплантов
    if modeOrSlot == "special" then
        local jobId = mw.text.trim(args[2] or "")
        if jobId == "" then
            return "Ошибка: Не задан jobId для режима special."
        end
       
        jobId = capitalizeFirst(jobId)
        local job = findById(jobData, jobId)
        if not job then
            return "Ошибка: не найдена должность с id " .. jobId
        end
       
        if not job.special or #job.special == 0 then
            return "Нет специальных данных для должности " .. jobId
        end
       
        local implantsFound = nil
        for _, spec in ipairs(job.special) do
            if spec["!type"] == "AddImplantSpecial" then
                implantsFound = spec.implants
                break
            end
        end
       
        if not implantsFound or #implantsFound == 0 then
            return "Специальных имплантов не найдено для должности " .. jobId
        end
       
        local resultList = {}
        for _, implant in ipairs(implantsFound) do
            table.insert(resultList, string.format("{{#invoke:Entity Lookup|getname|%s}}", implant))
        end
        local resultStr = table.concat(resultList, ", ")
        return resultStr
    end
 
    -- Если режим не "special", то первый параметр считается слотом,
    -- а второй – id должности, и используется базовая логика поиска экипировки.
    local slot  = modeOrSlot
     local jobId = mw.text.trim(args[2] or "")
     local jobId = mw.text.trim(args[2] or "")
      
      
Строка 82: Строка 36:
     if not job then
     if not job then
         return "Ошибка: не найдена должность с id " .. jobId
         return "Ошибка: не найдена должность с id " .. jobId
    end
    -- Новый режим обработки special
    if slot == "special" then
        local implants = {}
        if job.special then
            for _, special in ipairs(job.special) do
                if special["!type"] == "AddImplantSpecial" and special.implants then
                    for _, implant in ipairs(special.implants) do
                        table.insert(implants, string.format("{{#invoke:Entity Lookup|getname|%s}}", implant))
                    end
                end
            end
        end
        return table.concat(implants, ", ")
     end
     end


Строка 96: Строка 65:
     local gearEquipment = gear.equipment or {}
     local gearEquipment = gear.equipment or {}
     local itemId = gearEquipment[slot] or ""
     local itemId = gearEquipment[slot] or ""
     local sourceGear = gear
     local sourceGear = gear  


    -- Если в gearData для указанного слота ничего не найдено – ищем через loadoutGroup / loadout
     if itemId == "" then
     if itemId == "" then
        local function capitalize(s)
            return (s:gsub("^%l", string.upper))
        end
         local groupID = jobId .. capitalize(slot)
         local groupID = jobId .. capitalize(slot)
   
         local groupFound = nil
         local groupFound = nil
         for _, group in ipairs(gearloadoutGroup) do
         for _, group in ipairs(gearloadoutGroup) do
Строка 110: Строка 83:


         if not groupFound then
         if not groupFound then
             return "Группа не найдена: " .. groupID
             return ""
         end
         end


Строка 131: Строка 104:
     end
     end


    -- Если слот "back" и присутствует storage, добавляем обработку элементов из storage.back
     if slot == "back" and sourceGear.storage and sourceGear.storage.back then
     if slot == "back" and sourceGear.storage and sourceGear.storage.back then
         local storageBack = ""
         local storageBack = ""