Модуль:Prototypes/Оружия
Материал из Space Station 14 Вики
Версия от 20:00, 23 февраля 2025; Pok (обсуждение | вклад)
Для документации этого модуля может быть создана страница Модуль:Prototypes/Оружия/doc
local weaponData = mw.loadData("Модуль:IanComradeBot/prototypes/weapon.json/data")
local p = {}
-- Функция для формирования строки с использованием ColorPalette
local function formatColorPalette(module, key, value)
return "{{ColorPalette|" .. module .. "|" .. key .. "|" .. tostring(value) .. "}}"
end
-- Функция для форматирования списка повреждений с разделением запятой
local function formatDamageList(damageTable)
local items = {}
for dmgType, value in pairs(damageTable) do
table.insert(items, formatColorPalette("Damage", dmgType, value) .. " {{#invoke:Ftl|main|translation|damage-type-" .. dmgType .. "}}")
end
return table.concat(items, ", ")
end
-- Функция для объединения двух таблиц повреждений
local function combineDamageTables(base, addition)
local result = {}
for dmgType, value in pairs(base) do
result[dmgType] = value
end
for dmgType, addValue in pairs(addition) do
result[dmgType] = (result[dmgType] or 0) + addValue
end
return result
end
-- Функция для форматирования скорости атаки
local function formatAttackRate(attackRate)
return formatColorPalette("Weapon", "attackRate", attackRate)
end
function p.main(frame)
local mode = frame.args[1]
local id = frame.args[2]
if not id then
return "Ошибка: не задан параметр id."
end
local entry = nil
for _, weapon in ipairs(weaponData) do
if weapon.id == id then
entry = weapon
break
end
end
if not entry then
return "нет"
end
if mode == "melee" then
local melee = entry.MeleeWeapon
if not (melee and melee.damage and 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 resultParts = {}
table.insert(resultParts, "В одной руке: " .. formatDamageList(oneHandDamage))
if additionalDamage then
local twoHandDamage = combineDamageTables(oneHandDamage, additionalDamage)
table.insert(resultParts, "В двух руках: " .. formatDamageList(twoHandDamage))
end
local attackRate = melee.attackRate or 1
table.insert(resultParts, "Скорость атаки: " .. formatAttackRate(attackRate))
return frame:preprocess(table.concat(resultParts, "<br>"))
elseif mode == "attackRate" then
local melee = entry.MeleeWeapon
if not melee then
return "нет"
end
local attackRate = melee.attackRate or 1
return frame:preprocess(formatAttackRate(attackRate))
else
return "Неверный режим: " .. tostring(mode)
end
end
return p