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

Материал из Space Station 14 Вики
мНет описания правки
мНет описания правки
Строка 34: Строка 34:
         end
         end


         local twoHandDamage = entry.DamageOtherOnHit  
        -- Определяем дополнительный урон для двуручного хвата:
                                and entry.DamageOtherOnHit.damage  
        -- проверяем поля IncreaseDamageOnWield или DamageOtherOnHit
                                and entry.DamageOtherOnHit.damage.types
         local additionalDamage = nil
        if entry.IncreaseDamageOnWield and entry.IncreaseDamageOnWield.damage then
            additionalDamage = entry.IncreaseDamageOnWield.damage.types
        elseif entry.DamageOtherOnHit and entry.DamageOtherOnHit.damage then
            additionalDamage = entry.DamageOtherOnHit.damage.types
        end


         local lines = {}
         local lines = {}


         if twoHandDamage then
         -- Секция одноручного хвата
            -- Секция для одноручного хвата
        table.insert(lines, "В одноручном хвате:")
            table.insert(lines, "В одноручном хвате:")
        for dmgType, value in pairs(oneHandDamage) do
            table.insert(lines, value .. " " .. dmgType)
        end
 
        -- Если дополнительный урон присутствует, суммируем его с базовым
        if additionalDamage then
            local twoHandDamage = {}
            -- Копируем базовые повреждения
             for dmgType, value in pairs(oneHandDamage) do
             for dmgType, value in pairs(oneHandDamage) do
                 table.insert(lines, value .. " " .. dmgType)
                 twoHandDamage[dmgType] = value
            end
            -- Добавляем дополнительный урон
            for dmgType, addValue in pairs(additionalDamage) do
                if twoHandDamage[dmgType] then
                    twoHandDamage[dmgType] = twoHandDamage[dmgType] + addValue
                else
                    twoHandDamage[dmgType] = addValue
                end
             end
             end


            -- Секция для двуручного хвата
             table.insert(lines, "В двуручном хвате:")
             table.insert(lines, "В двуручном хвате:")
             for dmgType, value in pairs(twoHandDamage) do
             for dmgType, value in pairs(twoHandDamage) do
                table.insert(lines, value .. " " .. dmgType)
            end
        else
            for dmgType, value in pairs(oneHandDamage) do
                 table.insert(lines, value .. " " .. dmgType)
                 table.insert(lines, value .. " " .. dmgType)
             end
             end

Версия от 22:02, 22 февраля 2025

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

local weaponData = mw.loadData("Модуль:IanComradeBot/prototypes/weapon.json/data")

local p = {}

function p.main(frame)
    local mode = frame.args[1]
    local id = frame.args[2]

    if not id then
        return "Ошибка: не задан параметр id."
    end

    local entry = nil
    for _, weapon in ipairs(weaponData) do
        if weapon.id == id then
            entry = weapon
            break
        end
    end

    if not entry then
        return "Оружие с id '" .. tostring(id) .. "' не найдено."
    end

    if mode == "melee" then
        local melee = entry.MeleeWeapon
        if not melee then
            return "Нет данных о MeleeWeapon для оружия '" .. tostring(id) .. "'."
        end

        local oneHandDamage = melee.damage and melee.damage.types
        if not oneHandDamage then
            return "Нет данных о повреждениях (MeleeWeapon.damage.types) для оружия '" .. tostring(id) .. "'."
        end

        -- Определяем дополнительный урон для двуручного хвата: 
        -- проверяем поля IncreaseDamageOnWield или DamageOtherOnHit
        local additionalDamage = nil
        if entry.IncreaseDamageOnWield and entry.IncreaseDamageOnWield.damage then
            additionalDamage = entry.IncreaseDamageOnWield.damage.types
        elseif entry.DamageOtherOnHit and entry.DamageOtherOnHit.damage then
            additionalDamage = entry.DamageOtherOnHit.damage.types
        end

        local lines = {}

        -- Секция одноручного хвата
        table.insert(lines, "В одноручном хвате:")
        for dmgType, value in pairs(oneHandDamage) do
            table.insert(lines, value .. " " .. dmgType)
        end

        -- Если дополнительный урон присутствует, суммируем его с базовым
        if additionalDamage then
            local twoHandDamage = {}
            -- Копируем базовые повреждения
            for dmgType, value in pairs(oneHandDamage) do
                twoHandDamage[dmgType] = value
            end
            -- Добавляем дополнительный урон
            for dmgType, addValue in pairs(additionalDamage) do
                if twoHandDamage[dmgType] then
                    twoHandDamage[dmgType] = twoHandDamage[dmgType] + addValue
                else
                    twoHandDamage[dmgType] = addValue
                end
            end

            table.insert(lines, "В двуручном хвате:")
            for dmgType, value in pairs(twoHandDamage) do
                table.insert(lines, value .. " " .. dmgType)
            end
        end

        return table.concat(lines, "<br />")

    elseif mode == "attackRate" then
        local melee = entry.MeleeWeapon
        if not melee then
            return "Нет данных о MeleeWeapon для оружия '" .. tostring(id) .. "'."
        end

        if melee.attackRate then
            return tostring(melee.attackRate)
        else
            return "1"
        end

    else
        return "Неверный режим: " .. tostring(mode)
    end
end

return p