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

мНет описания правки
мНет описания правки
Строка 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
     end
     return table.concat(lines)
     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
    return result
end
 
-- Функция для форматирования скорости атаки
local function formatAttackRate(attackRate)
    return formatColorPalette("Weapon", "attackRate", attackRate)
end
end


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


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


         local result = "В одной руке:" .. "<br>" .. formatDamageList(oneHandDamage)
         local resultParts = {}
        table.insert(resultParts, "В одной руке: " .. formatDamageList(oneHandDamage))


         if additionalDamage then
         if additionalDamage then
             local twoHandDamage = {}
             local twoHandDamage = combineDamageTables(oneHandDamage, additionalDamage)
            for dmgType, value in pairs(oneHandDamage) do
             table.insert(resultParts, "В двух руках: " .. formatDamageList(twoHandDamage))
                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
         end


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


         return frame:preprocess(result)
         return frame:preprocess(table.concat(resultParts, ", "))
     elseif mode == "attackRate" then
     elseif mode == "attackRate" then
         local melee = entry.MeleeWeapon
         local melee = entry.MeleeWeapon
Строка 65: Строка 82:


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