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

мНет описания правки
м Поправил опечатку
 
(не показано 5 промежуточных версий 1 участника)
Строка 1: Строка 1:
local weaponData = mw.loadData("Модуль:IanComradeBot/prototypes/weapon.json/data")
local weaponData = mw.loadData("Модуль:IanComradeBot/prototypes/weapon.json/data")
local p = {}


local p = {}
-- Функция для формирования строки с использованием ColorPalette
local function formatColorPalette(module, key, value)
    return "{{ColorPalette|" .. module .. "|" .. key .. "|" .. tostring(value) .. "}}"
end


-- Функция для форматирования списка повреждений с разделением запятой
local function formatDamageList(damageTable)
local function formatDamageList(damageTable)
     local lines = {}
     local items = {}
     for dmgType, value in pairs(damageTable) do
     for dmgType, value in pairs(damageTable) do
         table.insert(lines, "{{ColorPalette|Damage|" .. dmgType .. "|" .. value .. "}} {{#invoke:Ftl|main|translation|damage-type-" .. dmgType .. "}}")
         table.insert(items, formatColorPalette("Damage", dmgType, value) .. " {{#invoke:Ftl|main|translation|damage-type-" .. dmgType .. "}}")
    end
    return table.concat(items, ", ")
end
 
-- Функция для объединения двух таблиц повреждений
local function combineDamageTables(base, addition)
    local result = {}
    for dmgType, value in pairs(base) do
        result[dmgType] = value
    end
    for dmgType, addValue in pairs(addition) do
        result[dmgType] = (result[dmgType] or 0) + addValue
     end
     end
     return table.concat(lines)
     return result
end
 
-- Функция для форматирования скорости атаки
local function formatAttackRate(attackRate)
    return formatColorPalette("Weapon", "attackRate", attackRate)
end
end


Строка 32: Строка 54:


     if mode == "melee" then
     if mode == "melee" then
        local resultParts = {}
         local melee = entry.MeleeWeapon
         local melee = entry.MeleeWeapon
         if not melee or not melee.damage or not melee.damage.types then
         if melee and melee.damage and melee.damage.types then
             return "Нет данных о повреждениях (MeleeWeapon.damage.types) для оружия '" .. tostring(id) .. "'."
             local oneHandDamage = melee.damage.types
        end
            table.insert(resultParts, "В одной руке: " .. formatDamageList(oneHandDamage))


        local oneHandDamage = melee.damage.types
            if entry.IncreaseDamageOnWield  
        local additionalDamage = (entry.IncreaseDamageOnWield and entry.IncreaseDamageOnWield.damage and entry.IncreaseDamageOnWield.damage.types) or
                and entry.IncreaseDamageOnWield.damage  
                                (entry.DamageOtherOnHit and entry.DamageOtherOnHit.damage and entry.DamageOtherOnHit.damage.types)
                and entry.IncreaseDamageOnWield.damage.types then
                local twoHandDamage = combineDamageTables(oneHandDamage, entry.IncreaseDamageOnWield.damage.types)
                table.insert(resultParts, "В двух руках: " .. formatDamageList(twoHandDamage))
            end


        local result = "В одной руке:" .. "<br>" .. formatDamageList(oneHandDamage)
            local attackRate = melee.attackRate or 1
            table.insert(resultParts, "Скорость атаки: " .. formatAttackRate(attackRate))
        end


         if additionalDamage then
         if entry.DamageOtherOnHit
             local twoHandDamage = {}
             and entry.DamageOtherOnHit.damage
             for dmgType, value in pairs(oneHandDamage) do
             and entry.DamageOtherOnHit.damage.types then
                twoHandDamage[dmgType] = value
             local throwingDamage = entry.DamageOtherOnHit.damage.types
             end
             table.insert(resultParts, "Метательный: " .. formatDamageList(throwingDamage))
            for dmgType, addValue in pairs(additionalDamage) do
                twoHandDamage[dmgType] = (twoHandDamage[dmgType] or 0) + addValue
             end
            result = result .. "В двух руках:" .. "<br>" .. formatDamageList(twoHandDamage)
         end
         end


         local attackRate = melee.attackRate or 1
         if #resultParts == 0 then
        result = result .. "Скорость атаки:" .. "{{ColorPalette|Weapon|attackRate|" .. tostring(attackRate) .. "}}<br>"
            return "Нет данных для оружия '" .. tostring(id) .. "'."
        else
            return frame:preprocess(table.concat(resultParts, "<br>"))
        end


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


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