|
|
| (не показана 421 промежуточная версия этого же участника) |
| Строка 1: |
Строка 1: |
| local p = {}
| |
|
| |
|
| -- Функция для загрузки данных плат из JSON-файла
| |
| local function loadData()
| |
| return mw.text.jsonDecode(mw.title.new("User:IanComradeBot/armor_prototypes.json"):getContent())
| |
| end
| |
|
| |
| -- Функция для поиска данных по ID
| |
| local function findDataById(dataCache, id)
| |
| for _, item in ipairs(dataCache) do
| |
| if item.id == id then
| |
| return item
| |
| end
| |
| end
| |
| return nil
| |
| end
| |
|
| |
| -- Функция для точного округления до ближайшего целого числа
| |
| local function round(num)
| |
| return math.floor(num + 0.5)
| |
| end
| |
|
| |
| -- Функция для преобразования значения в проценты
| |
| local function formatPercentage(value)
| |
| return value and round((1 - value) * 100) .. "%" or "-"
| |
| end
| |
|
| |
| function p.main(frame)
| |
| local dataCache = loadData()
| |
| local id = frame.args.id or "" -- ID предмета
| |
| local itemData = findDataById(dataCache, id)
| |
|
| |
| local protBlunt = formatPercentage(itemData and itemData.Blunt)
| |
| local protSlash = formatPercentage(itemData and itemData.Slash)
| |
| local protPiercing = formatPercentage(itemData and itemData.Piercing)
| |
| local protHeat = formatPercentage(itemData and itemData.Heat)
| |
| local protRadiation = formatPercentage(itemData and itemData.Radiation)
| |
| local protCaustic = formatPercentage(itemData and itemData.Caustic)
| |
| local protExplosion = formatPercentage(itemData and itemData.ExplosionResistance)
| |
|
| |
| -- Получаем значения sprintModifier и walkModifier
| |
| local sprintModifier = itemData and itemData.sprintModifier
| |
| local walkModifier = itemData and itemData.walkModifier
| |
| local speedDescription = ""
| |
|
| |
| -- Формируем сообщение в зависимости от значений sprintModifier и walkModifier
| |
| if sprintModifier and walkModifier then
| |
| local sprintPercent = round((1 - sprintModifier) * 100)
| |
| local walkPercent = round((1 - walkModifier) * 100)
| |
|
| |
| if sprintModifier == walkModifier then
| |
| speedDescription = "* Понижает скорость передвижения на <span style=\"color:yellow\">'''" .. sprintPercent .. " %'''</span>\n"
| |
| else
| |
| speedDescription = "* Понижает скорость бега на <span style=\"color:yellow\">'''" .. sprintPercent .. " %'''</span>\n"
| |
| speedDescription = speedDescription .. "* Понижает скорость ходьбы на <span style=\"color:yellow\">'''" .. walkPercent .. " %'''</span>\n"
| |
| end
| |
| end
| |
|
| |
| -- Описание и местоположение
| |
| local description = speedDescription .. (frame.args.description or "") -- Описание
| |
| local location = frame.args.location or "" -- Местонахождения
| |
| local created = frame.args.created or "" -- Создаётя
| |
|
| |
| local anchorName = frame.args.anchorName or "" -- Название якоря
| |
| local backgroundColor = frame.args.backgroundColor or "" -- Цвет фона первой ячейки
| |
| local class = frame.args.class or "" -- Класс
| |
|
| |
| -- Формирование строк для ячеек таблицы
| |
| local out = ""
| |
| 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 .. '<br>' .. frame:preprocess('{{#invoke:Entity Lookup|getname|' .. id .. '}}') .. '\n'
| |
| out = out .. '|class="' .. class .. '" style="font-weight:bold;color: crimson;"|' .. protBlunt .. '\n'
| |
| out = out .. '|class="' .. class .. '" style="font-weight:bold;color: indianred;"|' .. protSlash .. '\n'
| |
| out = out .. '|class="' .. class .. '" style="font-weight:bold;color: darksalmon;"|' .. protPiercing .. '\n'
| |
| out = out .. '|class="' .. class .. '" style="font-weight:bold;color: orange;"|' .. protHeat .. '\n'
| |
| out = out .. '|class="' .. class .. '" style="font-weight:bold;color: plum;"|' .. protCaustic .. '\n'
| |
| out = out .. '|class="' .. class .. '" style="font-weight:bold;color: limegreen;"|' .. protRadiation .. '\n'
| |
| out = out .. '|class="' .. class .. '" style="font-weight:bold;color: tan;"|' .. protExplosion .. '\n'
| |
| out = out .. '|class="' .. class .. '" style=""|\n' .. description .. '\n'
| |
| out = out .. '|class="' .. class .. '" style=""|\n' .. location .. '\n|-'
| |
| -- Местоположение
| |
| out = out .. '|class="' .. class .. '" style=""|\n'
| |
| if location ~= "" then
| |
| out = out .. frame:preprocess('{{SlideMenu|overlay|color=#e1f6ff|title=Список [[File:Examine.svg.192dpi.png|24x24px]]|content=<p></p>\n' .. location .. '}}\n')
| |
| end
| |
|
| |
| -- Создаётся
| |
| if created ~= "" then
| |
| out = out .. frame:preprocess('{{SlideMenu|overlay|color=#e1f6ff|border-color=#4c4c61|title=Создаётся [[File:hammer.svg.192dpi.png|24x24px]]|content=Создаётся в панели строительства<hr>\n' .. created .. '}}\n')
| |
| elseif location == "" then
| |
| out = out .. frame:preprocess('{{FrameText|color=#82d1c4|content=Нет гарантированных мест спавна}}\n')
| |
| end
| |
|
| |
| out = out .. '|-\n'
| |
|
| |
| return out
| |
| end
| |
|
| |
| return p
| |