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

Материал из Space Station 14 Вики
мНет описания правки
мНет описания правки
Строка 6: Строка 6:
     local lines = {}
     local lines = {}
     for dmgType, value in pairs(damageTable) do
     for dmgType, value in pairs(damageTable) do
         table.insert(lines, "<li>{{ColorPalette|Damage|" .. dmgType .. "|" .. value .. "}} {{#invoke:Ftl|main|translation|damage-type-" .. dmgType .. "}}</li>")
         table.insert(lines, "{{ColorPalette|Damage|" .. dmgType .. "|" .. value .. "}} {{#invoke:Ftl|main|translation|damage-type-" .. dmgType .. "}}")
     end
     end
     return table.concat(lines)
     return table.concat(lines)
Строка 41: Строка 41:
                                 (entry.DamageOtherOnHit and entry.DamageOtherOnHit.damage and entry.DamageOtherOnHit.damage.types)
                                 (entry.DamageOtherOnHit and entry.DamageOtherOnHit.damage and entry.DamageOtherOnHit.damage.types)


         local result = "В одной руке:" .. "<ul>" .. formatDamageList(oneHandDamage) .. "</ul>"
         local result = "В одной руке:" .. "<br>" .. formatDamageList(oneHandDamage)


         if additionalDamage then
         if additionalDamage then
Строка 51: Строка 51:
                 twoHandDamage[dmgType] = (twoHandDamage[dmgType] or 0) + addValue
                 twoHandDamage[dmgType] = (twoHandDamage[dmgType] or 0) + addValue
             end
             end
             result = result .. "В двух руках:" .. "<ul>" .. formatDamageList(twoHandDamage) .. "</ul>"
             result = result .. "В двух руках:" .. "<br>" .. formatDamageList(twoHandDamage)
         end
         end


         local attackRate = melee.attackRate or 1
         local attackRate = melee.attackRate or 1
         result = result .. "Скорость атаки:" .. "<ul><li>{{ColorPalette|Weapon|attackRate|" .. tostring(attackRate) .. "}}</li></ul>"
         result = result .. "Скорость атаки:" .. "{{ColorPalette|Weapon|attackRate|" .. tostring(attackRate) .. "}}<br>"


         return frame:preprocess(result)
         return frame:preprocess(result)
Строка 65: Строка 65:


         local attackRate = melee.attackRate or 1
         local attackRate = melee.attackRate or 1
         return frame:preprocess("<ul><li>{{ColorPalette|Weapon|attackRate|" .. tostring(attackRate) .. "}}</li></ul>")
         return frame:preprocess("{{ColorPalette|Weapon|attackRate|" .. tostring(attackRate) .. "}}<br>")
     else
     else
         return "Неверный режим: " .. tostring(mode)
         return "Неверный режим: " .. tostring(mode)

Версия от 19:54, 23 февраля 2025

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

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

local p = {}

local function formatDamageList(damageTable)
    local lines = {}
    for dmgType, value in pairs(damageTable) do
        table.insert(lines, "{{ColorPalette|Damage|" .. dmgType .. "|" .. value .. "}} {{#invoke:Ftl|main|translation|damage-type-" .. dmgType .. "}}")
    end
    return table.concat(lines)
end

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 "нет"
    end

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

        local oneHandDamage = melee.damage.types
        local additionalDamage = (entry.IncreaseDamageOnWield and entry.IncreaseDamageOnWield.damage and entry.IncreaseDamageOnWield.damage.types) or
                                 (entry.DamageOtherOnHit and entry.DamageOtherOnHit.damage and entry.DamageOtherOnHit.damage.types)

        local result = "В одной руке:" .. "<br>" .. formatDamageList(oneHandDamage)

        if additionalDamage then
            local twoHandDamage = {}
            for dmgType, value in pairs(oneHandDamage) do
                twoHandDamage[dmgType] = value
            end
            for dmgType, addValue in pairs(additionalDamage) do
                twoHandDamage[dmgType] = (twoHandDamage[dmgType] or 0) + addValue
            end
            result = result .. "В двух руках:" .. "<br>" .. formatDamageList(twoHandDamage)
        end

        local attackRate = melee.attackRate or 1
        result = result .. "Скорость атаки:" .. "{{ColorPalette|Weapon|attackRate|" .. tostring(attackRate) .. "}}<br>"

        return frame:preprocess(result)
    elseif mode == "attackRate" then
        local melee = entry.MeleeWeapon
        if not melee then
            return "нет"
        end

        local attackRate = melee.attackRate or 1
        return frame:preprocess("{{ColorPalette|Weapon|attackRate|" .. tostring(attackRate) .. "}}<br>")
    else
        return "Неверный режим: " .. tostring(mode)
    end
end

return p