|
|
| (не показаны 172 промежуточные версии этого же участника) |
| Строка 1: |
Строка 1: |
| local weaponData = mw.loadData("Модуль:IanComradeBot/prototypes/weapon.json/data")
| |
|
| |
| local p = {} | | local p = {} |
| | local getArgs = require('Module:Arguments').getArgs |
|
| |
|
| function p.main(frame) | | function p.main(frame) |
| local mode = frame.args[1] | | local args = getArgs(frame, { removeBlanks = false }) |
| local id = frame.args[2] | | local name = args[1] or "" |
| | local attributes = args[2] or "" |
| | if name == "" then |
| | return "<span class=\"error\">Ошибка: не указано имя файла.</span>" |
| | end |
| | local ext = (args["ext"] or "png"):gsub("^%.", "") |
| | local namespace = args["namespace"] or "Файл" |
| | local max = tonumber(args["max"]) or 50 |
| | local include_base = (args["base"] ~= "no") |
| | |
| | local found = {} |
|
| |
|
| if not id then | | if include_base then |
| return "Ошибка: не задан параметр id." | | local t = mw.title.new("Файл:" .. name .. "." .. ext) |
| | if t and t.exists then |
| | table.insert(found, "") |
| | end |
| end | | end |
|
| |
|
| local entry = nil | | for i = 1, max do |
| for _, weapon in ipairs(weaponData) do
| | local t = mw.title.new("Файл:" .. name .. "-" .. i .. "." .. ext) |
| if weapon.id == id then | | if t and t.exists then |
| entry = weapon | | table.insert(found, "-" .. i) |
| break
| |
| end | | end |
| end | | end |
|
| |
|
| if not entry then | | if #found == 0 then |
| return "Оружие с id '" .. tostring(id) .. "' не найдено." | | return "" |
| end | | end |
|
| |
|
| if mode == "melee" then | | local before = "[[" .. namespace .. ":" .. name |
| local melee = entry.MeleeWeapon
| | local after = "." .. ext .. "|" .. attributes .. "]]" |
| if not melee then
| |
| return "Нет данных о MeleeWeapon для оружия '" .. tostring(id) .. "'."
| |
| end
| |
|
| |
|
| local oneHandDamage = melee.damage and melee.damage.types
| | local parts = {} |
| if not oneHandDamage then
| | table.insert(parts, "<choose before=\"" .. before .. "\" after=\"" .. after .. "\">") |
| return "Нет данных о повреждениях (MeleeWeapon.damage.types) для оружия '" .. tostring(id) .. "'."
| | for _, suf in ipairs(found) do |
| end
| | table.insert(parts, "<option>" .. suf .. "</option>") |
| | end |
| | table.insert(parts, "</choose>") |
|
| |
|
| -- Определяем дополнительный урон для двуручного хвата:
| | return frame:preprocess(table.concat(parts, "\n")) |
| -- проверяем поля IncreaseDamageOnWield или DamageOtherOnHit
| |
| local additionalDamage = nil
| |
| if entry.IncreaseDamageOnWield and entry.IncreaseDamageOnWield.damage then
| |
| additionalDamage = entry.IncreaseDamageOnWield.damage.types
| |
| elseif entry.DamageOtherOnHit and entry.DamageOtherOnHit.damage then
| |
| additionalDamage = entry.DamageOtherOnHit.damage.types
| |
| end
| |
| | |
| local lines = {}
| |
| | |
| -- Секция одноручного хвата
| |
| table.insert(lines, "В одной руке:")
| |
| for dmgType, value in pairs(oneHandDamage) do
| |
| table.insert(lines, "{{#invoke:Ftl|main|translation|item-component-size-" .. value .. "}} {{ColorPalette|Damage|" .. dmgType .. "|" .. dmgType .. "}}")
| |
| end
| |
| | |
| -- Если дополнительный урон присутствует, суммируем его с базовым
| |
| if additionalDamage then
| |
| local twoHandDamage = {}
| |
| -- Копируем базовые повреждения
| |
| for dmgType, value in pairs(oneHandDamage) do
| |
| twoHandDamage[dmgType] = value
| |
| end
| |
| -- Добавляем дополнительный урон
| |
| for dmgType, addValue in pairs(additionalDamage) do
| |
| if twoHandDamage[dmgType] then
| |
| twoHandDamage[dmgType] = twoHandDamage[dmgType] + addValue
| |
| else
| |
| twoHandDamage[dmgType] = addValue
| |
| end
| |
| end
| |
| | |
| table.insert(lines, "В двух руках:")
| |
| for dmgType, value in pairs(twoHandDamage) do
| |
| table.insert(lines, "{{#invoke:Ftl|main|translation|item-component-size-" .. value .. "}} {{ColorPalette|Damage|" .. dmgType .. "|" .. dmgType .. "}}")
| |
| end
| |
| end
| |
| | |
| return frame:preprocess(table.concat(lines))
| |
| | |
| elseif mode == "attackRate" then
| |
| local melee = entry.MeleeWeapon
| |
| if not melee then
| |
| return "Нет данных о MeleeWeapon для '" .. tostring(id) .. "'."
| |
| end
| |
| | |
| if melee.attackRate then
| |
| return frame:preprocess(tostring(melee.attackRate))
| |
| else
| |
| return frame:preprocess("1")
| |
| end
| |
| | |
| else
| |
| return "Неверный режим: " .. tostring(mode)
| |
| end
| |
| end | | end |
|
| |
|
| return p | | return p |