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

Материал из Space Station 14 Вики
мНет описания правки
мНет описания правки
Строка 1: Строка 1:
local p = {}
local p = {}


local gearRoleLoadout   = mw.loadData("Модуль:IanComradeBot/roleLoadout.json/data")
local gearRoleLoadout = mw.loadData("Модуль:IanComradeBot/roleLoadout.json/data")
local gearloadoutGroup = mw.loadData("Модуль:IanComradeBot/loadoutGroup.json/data")
local gearloadoutGroup = mw.loadData("Модуль:IanComradeBot/loadoutGroup.json/data")
local gearloadout       = mw.loadData("Модуль:IanComradeBot/loadout.json/data")
local gearloadout = mw.loadData("Модуль:IanComradeBot/loadout.json/data")


function p.main(frame)
function p.main(frame)
Строка 13: Строка 13:
     end
     end
     local roleId = "Job" .. roleParam
     local roleId = "Job" .. roleParam
    local modeTrinkets = (searchKey == "trinkets")
     local results = {}
     local results = {}
     local role = nil
     local role = nil
     for _, r in ipairs(gearRoleLoadout) do
     for _, r in ipairs(gearRoleLoadout) do
         if r.id == roleId then
         if r.id == roleId then
Строка 22: Строка 22:
         end
         end
     end
     end
     if not role then
     if not role then
         return 'Роль с id "' .. roleId .. '" не найдена'
         return 'Роль с id "' .. roleId .. '" не найдена'
     end
     end
     for _, groupId in ipairs(role.groups or {}) do
     for _, groupId in ipairs(role.groups or {}) do
         local group = nil
         if (modeTrinkets and groupId == "Trinkets") or ((not modeTrinkets) and groupId ~= "Trinkets") then
        for _, g in ipairs(gearloadoutGroup) do
            local group = nil
            if g.id == groupId then
            for _, g in ipairs(gearloadoutGroup) do
                group = g
                if g.id == groupId then
                break
                    group = g
            end
                    break
        end
        if group then
            local loadouts = group.loadouts or {}
            if type(loadouts) == "string" then
                local success, decoded = pcall(mw.text.jsonDecode, loadouts)
                if success and type(decoded) == "table" then
                    loadouts = decoded
                else
                    loadouts = {}
                 end
                 end
             end
             end
 
             if group then
             for _, loadoutId in ipairs(loadouts) do
                 local loadouts = group.loadouts or {}
                 local loadout = nil
                 if type(loadouts) == "string" then
                 for _, l in ipairs(gearloadout) do
                    local success, decoded = pcall(mw.text.jsonDecode, loadouts)
                     if l.id == loadoutId then
                     if success and type(decoded) == "table" then
                         loadout = l
                         loadouts = decoded
                         break
                    else
                         loadouts = {}
                     end
                     end
                 end
                 end
                 if loadout and loadout.equipment then
                 for _, loadoutId in ipairs(loadouts) do
                    local skipLoadout = false
                    local loadout = nil
                    if loadout.effects then
                    for _, l in ipairs(gearloadout) do
                        for _, effect in ipairs(loadout.effects) do
                        if l.id == loadoutId then
                            if effect.proto == "EffectSpeciesVox" then
                            loadout = l
                                skipLoadout = true
                            break
                                 break
                        end
                    end
                    if loadout then
                        local skipLoadout = false
                        if loadout.effects then
                            for _, effect in ipairs(loadout.effects) do
                                if effect.proto == "EffectSpeciesVox" then
                                    skipLoadout = true
                                    break
                                 end
                             end
                             end
                         end
                         end
                    end
                        if not skipLoadout then
                    if not skipLoadout then
                            if modeTrinkets then
                        local eqValue = loadout.equipment[searchKey]
                                if loadout.storage and loadout.storage.back then
                        if eqValue then
                                    for _, item in ipairs(loadout.storage.back) do
                            local extraInfo = ""
                                        table.insert(results, '<div class="Trinkets">' .. item .. '</div>')
                            if loadout.effects then
                                    end
                                for _, effect in ipairs(loadout.effects) do
                                elseif loadout.equipment then
                                    if effect["!type"] == "GroupLoadoutEffect" then
                                    for _, eqValue in pairs(loadout.equipment) do
                                        local proto = effect.proto
                                        table.insert(results, '<div class="Trinkets">' .. eqValue .. '</div>')
                                        if proto then
                                        break
                                            for _, candidate in ipairs(gearloadout) do
                                    end
                                                if candidate.id == proto then
                                end
                                                    if candidate.effects then
                            else
                                                        for _, eff in ipairs(candidate.effects) do
                                if loadout.equipment then
                                                            if eff["!type"] == "JobRequirementLoadoutEffect" and eff.requirement then
                                    local eqValue = loadout.equipment[searchKey]
                                                                local req = eff.requirement
                                    if eqValue then
                                                                if req["!type"] == "DepartmentTimeRequirement" and req.department and req.time then
                                        local extraInfo = ""
                                                                    extraInfo = extraInfo .. "<b>{{ucfirst:{{#invoke:Ftl|main|translation|department-" .. req.department .. "}}}}</b>: " .. req.time .. "<br>"
                                        if loadout.effects then
                                                                elseif req["!type"] == "RoleTimeRequirement" and req.role and req.time then
                                            for _, effect in ipairs(loadout.effects) do
                                                                    extraInfo = extraInfo .. "<b>{{ucfirst:{{#invoke:Ftl|main|translation|" .. req.role .. "}}}}</b>: " .. req.time .. "<br>"
                                                if effect["!type"] == "GroupLoadoutEffect" then
                                                    local proto = effect.proto
                                                    if proto then
                                                        for _, candidate in ipairs(gearloadout) do
                                                            if candidate.id == proto then
                                                                if candidate.effects then
                                                                    for _, eff in ipairs(candidate.effects) do
                                                                        if eff["!type"] == "JobRequirementLoadoutEffect" and eff.requirement then
                                                                            local req = eff.requirement
                                                                            if req["!type"] == "DepartmentTimeRequirement" and req.department and req.time then
                                                                                extraInfo = extraInfo .. "<b>{{ucfirst:{{#invoke:Ftl|main|translation|department-" .. req.department .. "}}}}</b>: " .. req.time .. "<br>"
                                                                            elseif req["!type"] == "RoleTimeRequirement" and req.role and req.time then
                                                                                extraInfo = extraInfo .. "<b>{{ucfirst:{{#invoke:Ftl|main|translation|" .. req.role .. "}}}}</b>: " .. req.time .. "<br>"
                                                                            end
                                                                        end
                                                                    end
                                                                 end
                                                                 end
                                                                break
                                                             end
                                                             end
                                                         end
                                                         end
                                                     end
                                                     end
                                                    break
                                                 end
                                                 end
                                             end
                                             end
                                         end
                                         end
                                        local infoOutput = ""
                                        if extraInfo ~= "" then
                                            infoOutput = '<div class="роль-лодаут__time">{{AltTooltip|[[Файл:Small_watch.png|link=]]|' .. extraInfo .. '}}</div>'
                                        end
                                        table.insert(results, infoOutput .. '{{#invoke:Prototypes/Предмет/Содержание|image|' .. eqValue .. '}} [[File:Slot.png|64px|link=]]')
                                     end
                                     end
                                 end
                                 end
                             end
                             end
                            local infoOutput = ""
                            if extraInfo ~= "" then
                                infoOutput = '<div class="роль-лодаут__time">{{AltTooltip|[[Файл:Small_watch.png|link=]]|' .. extraInfo .. '}}</div>'
                            end
                            table.insert(results, infoOutput .. '{{#invoke:Prototypes/Предмет/Содержание|image|' .. eqValue .. '}} [[File:Slot.png|64px|link=]]')
                         end
                         end
                     end
                     end
Строка 105: Строка 119:
         end
         end
     end
     end
     local output = {}
     local output = {}
     for _, eq in ipairs(results) do
     if modeTrinkets then
         table.insert(output, '<div class="роль-лодаут__item">' .. eq .. '</div>')
        for _, eq in ipairs(results) do
            table.insert(output, eq)
         end
    else
        for _, eq in ipairs(results) do
            table.insert(output, '<div class="роль-лодаут__item">' .. eq .. '</div>')
        end
     end
     end
     return frame:preprocess(table.concat(output))
     return frame:preprocess(table.concat(output))
end
end


return p
return p

Версия от 16:58, 14 февраля 2025

Для документации этого модуля может быть создана страница Модуль:Prototypes/Роль/Лодаут/doc

local p = {}

local gearRoleLoadout = mw.loadData("Модуль:IanComradeBot/roleLoadout.json/data")
local gearloadoutGroup = mw.loadData("Модуль:IanComradeBot/loadoutGroup.json/data")
local gearloadout = mw.loadData("Модуль:IanComradeBot/loadout.json/data")

function p.main(frame)
    local args = frame.args
    local searchKey = args[1]
    local roleParam = args[2]
    if not roleParam then
        return 'Параметр roleId не указан'
    end
    local roleId = "Job" .. roleParam
    local modeTrinkets = (searchKey == "trinkets")
    local results = {}
    local role = nil
    for _, r in ipairs(gearRoleLoadout) do
        if r.id == roleId then
            role = r
            break
        end
    end
    if not role then
        return 'Роль с id "' .. roleId .. '" не найдена'
    end
    for _, groupId in ipairs(role.groups or {}) do
        if (modeTrinkets and groupId == "Trinkets") or ((not modeTrinkets) and groupId ~= "Trinkets") then
            local group = nil
            for _, g in ipairs(gearloadoutGroup) do
                if g.id == groupId then
                    group = g
                    break
                end
            end
            if group then
                local loadouts = group.loadouts or {}
                if type(loadouts) == "string" then
                    local success, decoded = pcall(mw.text.jsonDecode, loadouts)
                    if success and type(decoded) == "table" then
                        loadouts = decoded
                    else
                        loadouts = {}
                    end
                end
                for _, loadoutId in ipairs(loadouts) do
                    local loadout = nil
                    for _, l in ipairs(gearloadout) do
                        if l.id == loadoutId then
                            loadout = l
                            break
                        end
                    end
                    if loadout then
                        local skipLoadout = false
                        if loadout.effects then
                            for _, effect in ipairs(loadout.effects) do
                                if effect.proto == "EffectSpeciesVox" then
                                    skipLoadout = true
                                    break
                                end
                            end
                        end
                        if not skipLoadout then
                            if modeTrinkets then
                                if loadout.storage and loadout.storage.back then
                                    for _, item in ipairs(loadout.storage.back) do
                                        table.insert(results, '<div class="Trinkets">' .. item .. '</div>')
                                    end
                                elseif loadout.equipment then
                                    for _, eqValue in pairs(loadout.equipment) do
                                        table.insert(results, '<div class="Trinkets">' .. eqValue .. '</div>')
                                        break
                                    end
                                end
                            else
                                if loadout.equipment then
                                    local eqValue = loadout.equipment[searchKey]
                                    if eqValue then
                                        local extraInfo = ""
                                        if loadout.effects then
                                            for _, effect in ipairs(loadout.effects) do
                                                if effect["!type"] == "GroupLoadoutEffect" then
                                                    local proto = effect.proto
                                                    if proto then
                                                        for _, candidate in ipairs(gearloadout) do
                                                            if candidate.id == proto then
                                                                if candidate.effects then
                                                                    for _, eff in ipairs(candidate.effects) do
                                                                        if eff["!type"] == "JobRequirementLoadoutEffect" and eff.requirement then
                                                                            local req = eff.requirement
                                                                            if req["!type"] == "DepartmentTimeRequirement" and req.department and req.time then
                                                                                extraInfo = extraInfo .. "<b>{{ucfirst:{{#invoke:Ftl|main|translation|department-" .. req.department .. "}}}}</b>: " .. req.time .. "<br>"
                                                                            elseif req["!type"] == "RoleTimeRequirement" and req.role and req.time then
                                                                                extraInfo = extraInfo .. "<b>{{ucfirst:{{#invoke:Ftl|main|translation|" .. req.role .. "}}}}</b>: " .. req.time .. "<br>"
                                                                            end
                                                                        end
                                                                    end
                                                                end
                                                                break
                                                            end
                                                        end
                                                    end
                                                end
                                            end
                                        end
                                        local infoOutput = ""
                                        if extraInfo ~= "" then
                                            infoOutput = '<div class="роль-лодаут__time">{{AltTooltip|[[Файл:Small_watch.png|link=]]|' .. extraInfo .. '}}</div>'
                                        end
                                        table.insert(results, infoOutput .. '{{#invoke:Prototypes/Предмет/Содержание|image|' .. eqValue .. '}} [[File:Slot.png|64px|link=]]')
                                    end
                                end
                            end
                        end
                    end
                end
            end
        end
    end
    local output = {}
    if modeTrinkets then
        for _, eq in ipairs(results) do
            table.insert(output, eq)
        end
    else
        for _, eq in ipairs(results) do
            table.insert(output, '<div class="роль-лодаут__item">' .. eq .. '</div>')
        end
    end
    return frame:preprocess(table.concat(output))
end

return p