Модуль:ArmorStats: различия между версиями
Pok (обсуждение | вклад) Нет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| (не показано 7 промежуточных версий этого же участника) | |||
| Строка 3: | Строка 3: | ||
-- Функция для загрузки данных плат из JSON-файла | -- Функция для загрузки данных плат из JSON-файла | ||
local function loadData() | local function loadData() | ||
return mw.text.jsonDecode(mw.title.new(" | 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) | ||
-- Получаем защитные значения из | -- Получаем защитные значения из armor, если они присутствуют | ||
local | local armor = itemData and itemData.Armor and itemData.Armor.modifiers and itemData.Armor.modifiers.coefficients | ||
local protBlunt = formatPercentage( | local protBlunt = formatPercentage(armor and armor.Blunt) | ||
local protSlash = formatPercentage( | local protSlash = formatPercentage(armor and armor.Slash) | ||
local protPiercing = formatPercentage( | local protPiercing = formatPercentage(armor and armor.Piercing) | ||
local protHeat = formatPercentage( | local protHeat = formatPercentage(armor and armor.Heat) | ||
local protRadiation = formatPercentage( | local protRadiation = formatPercentage(armor and armor.Radiation) | ||
local protCaustic = formatPercentage( | local protCaustic = formatPercentage(armor and armor.Caustic) | ||
local protExplosion = formatPercentage(itemData and itemData.ExplosionResistance) | |||
local protExplosion = formatPercentage(itemData and itemData.ExplosionResistance and itemData.ExplosionResistance.damageCoefficient) | |||
-- Получаем значения sprintModifier, walkModifier, fireProtection | -- Получаем значения sprintModifier, walkModifier, fireProtection | ||
local sprintModifier = itemData and itemData.sprintModifier | local sprintModifier = itemData and itemData.ClothingSpeedModifier and itemData.ClothingSpeedModifier.sprintModifier | ||
local walkModifier = itemData and itemData.walkModifier | local walkModifier = itemData and itemData.ClothingSpeedModifier and itemData.ClothingSpeedModifier.walkModifier | ||
local fireProtection = itemData and itemData.FireProtection | local fireProtection = itemData and itemData.FireProtection and itemData.FireProtection.reduction | ||
local speedDescription = "" | local speedDescription = "" | ||
-- Формируем сообщение в зависимости от значений sprintModifier и walkModifier | -- Формируем сообщение в зависимости от значений sprintModifier и walkModifier | ||
if sprintModifier and walkModifier then | if sprintModifier and walkModifier then | ||
if sprintModifier == 1 and walkModifier == 1 then | |||
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 | |||
speedDescription = "" | |||
for _, modifier in ipairs({{sprintModifier, "бега"}, {walkModifier, "ходьбы"}}) do | |||
local value, actionType = modifier[1], modifier[2] | |||
if value ~= 1 then | |||
local percent = round(math.abs(value - 1) * 100) | |||
local action = value > 1 and "Повышает" or "Понижает" | |||
speedDescription = speedDescription .. string.format("* %s скорость %s на <span style=\"color:yellow\">'''%d %%'''</span>\n", action, actionType, percent) | |||
end | |||
end | |||
end | |||
end | end | ||
| Строка 68: | Строка 78: | ||
local fireProtectionDescription = fireProtection and | local fireProtectionDescription = fireProtection and | ||
"* Имеет огневую защиту в <span style=\"color:OrangeRed\">'''" .. round((1 - fireProtection) * 100) .. " %'''</span>\n" or "" | "* Имеет огневую защиту в <span style=\"color:OrangeRed\">'''" .. round((1 - fireProtection) * 100) .. " %'''</span>\n" or "" | ||
-- Описание и местоположение | -- Описание и местоположение | ||
local description = (frame.args.description or "") .. '\n' .. speedDescription .. fireProtectionDescription | local description = (frame.args.description or "") .. '\n' .. speedDescription .. fireProtectionDescription -- Описание | ||
local location = frame.args.location or "" -- Местонахождение | local location = frame.args.location or "" -- Местонахождение | ||
local created = frame.args.created or "" -- Создание | local created = frame.args.created or "" -- Создание | ||
| Строка 85: | Строка 91: | ||
local out = '' | local out = '' | ||
out = out .. '!class="' .. class .. '" style="background-color: ' .. backgroundColor .. ';"|' .. frame:preprocess('{{Anchor|' .. anchorName .. '}}') | out = out .. '!class="' .. class .. '" style="background-color: ' .. backgroundColor .. ';"|' .. frame:preprocess('{{Anchor|' .. anchorName .. '}}') | ||
out = out .. frame:preprocess('{{#invoke:Entity Lookup|createimagetooltip|File:' .. id .. '|' .. id .. '|Мета=64x64px}}') | out = out .. frame:preprocess('{{#invoke:Entity Lookup|createimagetooltip|File:' .. id .. '.png|' .. id .. '|Мета=64x64px,link=}}') | ||
out = out .. '<br>' .. frame:preprocess('{{#invoke:Entity Lookup|getname|' .. id .. '}}') .. '\n' | out = out .. '<br>' .. frame:preprocess('{{#invoke:Entity Lookup|getname|' .. id .. '}}') .. '\n' | ||