|
|
| Строка 1: |
Строка 1: |
| local weaponData = mw.loadData("Модуль:IanComradeBot/prototypes/weapon.json/data") | | -- Загрузка данных |
| | local priceData = mw.loadData("Модуль:IanComradeBot/prototypes/StaticPrice.json/data") |
|
| |
|
| local p = {} | | local p = {} |
|
| |
| local function formatDamageList(damageTable)
| |
| local lines = {}
| |
| for dmgType, value in pairs(damageTable) do
| |
| table.insert(lines, "<li>{{ColorPalette|Damage|" .. dmgType .. "|" .. value .. "}} {{#invoke:Ftl|main|translation|damage-type-" .. dmgType .. "}}</li>")
| |
| end
| |
| return table.concat(lines)
| |
| end
| |
|
| |
|
| function p.main(frame) | | function p.main(frame) |
| local mode = frame.args[1] | | -- Получаем первый параметр, который должен быть id |
| local id = frame.args[2]
| | local id = frame.args[1] or frame.args.id |
| | |
| if not id then | | if not id then |
| return "Ошибка: не задан параметр id." | | return "Ошибка: не передан id" |
| end | | end |
|
| |
|
| local entry = nil | | -- Проходим по всем записям в priceData |
| for _, weapon in ipairs(weaponData) do | | for _, item in ipairs(priceData) do |
| if weapon.id == id then | | if item.id == id then |
| entry = weapon | | return frame:preprocess("{{ColorPalette|Other|price|" .. item.StaticPrice.price .. "}}$") |
| break
| |
| end | | end |
| end | | end |
|
| |
|
| if not entry then | | -- Если не нашли совпадение, возвращаем стандартный текст |
| return "Оружие с id '" .. tostring(id) .. "' не найдено."
| | return "{{ColorPalette|Other|price|0}}$" |
| end
| |
| | |
| if mode == "melee" then
| |
| local melee = entry.MeleeWeapon
| |
| if not melee or not melee.damage or not melee.damage.types then
| |
| return "Нет данных о повреждениях (MeleeWeapon.damage.types) для оружия '" .. tostring(id) .. "'."
| |
| end
| |
| | |
| local oneHandDamage = melee.damage.types
| |
| local additionalDamage = (entry.IncreaseDamageOnWield and entry.IncreaseDamageOnWield.damage and entry.IncreaseDamageOnWield.damage.types) or
| |
| (entry.DamageOtherOnHit and entry.DamageOtherOnHit.damage and entry.DamageOtherOnHit.damage.types)
| |
| | |
| local result = "В одной руке:" .. "<ul>" .. formatDamageList(oneHandDamage) .. "</ul>"
| |
| | |
| if additionalDamage then
| |
| local twoHandDamage = {}
| |
| for dmgType, value in pairs(oneHandDamage) do
| |
| twoHandDamage[dmgType] = value
| |
| end
| |
| for dmgType, addValue in pairs(additionalDamage) do
| |
| twoHandDamage[dmgType] = (twoHandDamage[dmgType] or 0) + addValue
| |
| end
| |
| result = result .. "В двух руках:" .. "<ul>" .. formatDamageList(twoHandDamage) .. "</ul>"
| |
| end
| |
| | |
| return frame:preprocess(result)
| |
| elseif mode == "attackRate" then | |
| local melee = entry.MeleeWeapon
| |
| if not melee then
| |
| return "Нет данных о MeleeWeapon для '" .. tostring(id) .. "'."
| |
| end
| |
| | |
| local attackRate = melee.attackRate or 1
| |
| return frame:preprocess("<ul><li>{{ColorPalette|Weapon|attackRate|" .. tostring(attackRate) .. "}}</li></ul>")
| |
| else
| |
| return "Неверный режим: " .. tostring(mode)
| |
| end
| |
| end | | end |
|
| |
|
| return p | | return p |