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

мНет описания правки
мНет описания правки
 
(не показаны 4 промежуточные версии этого же участника)
Строка 3: Строка 3:
-- Функция для загрузки данных плат из JSON-файла
-- Функция для загрузки данных плат из JSON-файла
local function loadData()
local function loadData()
return mw.text.jsonDecode(mw.title.new("User:IanComradeBot/armor_prototypes.json"):getContent())
return mw.text.jsonDecode(mw.title.new("Участник:IanComradeBot/prototypes/armor.json"):getContent())
end
end


Строка 36: Строка 36:
local itemData = findDataById(dataCache, id)
local itemData = findDataById(dataCache, id)


-- Получаем защитные значения из coefficients, если они присутствуют
-- Получаем защитные значения из armor, если они присутствуют
local coefficients = itemData and itemData.coefficients
local armor = itemData and itemData.Armor and itemData.Armor.modifiers and itemData.Armor.modifiers.coefficients
local protBlunt = formatPercentage(coefficients and coefficients.Blunt)
local protBlunt = formatPercentage(armor and armor.Blunt)
local protSlash = formatPercentage(coefficients and coefficients.Slash)
local protSlash = formatPercentage(armor and armor.Slash)
local protPiercing = formatPercentage(coefficients and coefficients.Piercing)
local protPiercing = formatPercentage(armor and armor.Piercing)
local protHeat = formatPercentage(coefficients and coefficients.Heat)
local protHeat = formatPercentage(armor and armor.Heat)
local protRadiation = formatPercentage(coefficients and coefficients.Radiation)
local protRadiation = formatPercentage(armor and armor.Radiation)
local protCaustic = formatPercentage(coefficients and coefficients.Caustic)
local protCaustic = formatPercentage(armor and armor.Caustic)
local protExplosion = formatPercentage(itemData and itemData.ExplosionResistance and itemData.ExplosionResistance.damageCoefficient)
local protExplosion = formatPercentage(itemData and itemData.ExplosionResistance and itemData.ExplosionResistance.damageCoefficient)


-- Получаем значения sprintModifier, walkModifier, fireProtection
-- Получаем значения sprintModifier, walkModifier, fireProtection
local sprintModifier = itemData and itemData.ClothingSpeedModifier and itemData.ClothingSpeedModifier.walkModifier
local sprintModifier = itemData and itemData.ClothingSpeedModifier and itemData.ClothingSpeedModifier.sprintModifier
local walkModifier = itemData and itemData.ClothingSpeedModifier and itemData.ClothingSpeedModifier.walkModifier  
local walkModifier = itemData and itemData.ClothingSpeedModifier and itemData.ClothingSpeedModifier.walkModifier  
local fireProtection = itemData and itemData.FireProtection and itemData.FireProtection.reduction
local fireProtection = itemData and itemData.FireProtection and itemData.FireProtection.reduction
Строка 55: Строка 55:
-- Формируем сообщение в зависимости от значений sprintModifier и walkModifier
-- Формируем сообщение в зависимости от значений sprintModifier и walkModifier
if sprintModifier and walkModifier then
if sprintModifier and walkModifier then
    -- Условие, когда оба модификатора равны 1 (ничего не делаем)
    if sprintModifier == 1 and walkModifier == 1 then
    if sprintModifier == 1 and walkModifier == 1 then
        speedDescription = ""
        speedDescription = ""
    elseif sprintModifier == walkModifier then
        local percent = round(math.abs(sprintModifier - 1) * 100)
        local action = sprintModifier > 1 and "Повышает" or "Понижает"
        speedDescription = string.format("* %s скорость передвижения на <span style=\"color:yellow\">'''%d %%'''</span>\n", action, percent)
    else
    else
        -- Проверка и описание для sprintModifier
        speedDescription = ""
        if sprintModifier ~= 1 then
            if sprintModifier > 1 then
        for _, modifier in ipairs({{sprintModifier, "бега"}, {walkModifier, "ходьбы"}}) do
                local sprintPercent = round((sprintModifier - 1) * 100)
            local value, actionType = modifier[1], modifier[2]
                speedDescription = "* Повышает скорость бега на <span style=\"color:yellow\">'''" .. sprintPercent .. " %'''</span>\n"
            if value ~= 1 then
            else
                local percent = round(math.abs(value - 1) * 100)
                local sprintPercent = round((1 - sprintModifier) * 100)
                local action = value > 1 and "Повышает" or "Понижает"
                speedDescription = "* Понижает скорость бега на <span style=\"color:yellow\">'''" .. sprintPercent .. " %'''</span>\n"
                speedDescription = speedDescription .. string.format("* %s скорость %s на <span style=\"color:yellow\">'''%d %%'''</span>\n", action, actionType, percent)
            end
        end
       
        -- Проверка и описание для walkModifier
        if walkModifier ~= 1 then
            if walkModifier > 1 then
                local walkPercent = round((walkModifier - 1) * 100)
                speedDescription = (speedDescription or "") .. "* Повышает скорость ходьбы на <span style=\"color:yellow\">'''" .. walkPercent .. " %'''</span>\n"
            else
                local walkPercent = round((1 - walkModifier) * 100)
                speedDescription = (speedDescription or "") .. "* Понижает скорость ходьбы на <span style=\"color:yellow\">'''" .. walkPercent .. " %'''</span>\n"
            end
            end
        end
        end