Модуль:Песочница/Pok: различия между версиями

Нет описания правки
Нет описания правки
 
(не показано 167 промежуточных версий этого же участника)
Строка 1: Строка 1:
local weaponData = mw.loadData("Модуль:IanComradeBot/prototypes/weapon.json/data")
local p = {}
local p = {}
local getArgs = require('Module:Arguments').getArgs


local function formatDamageList(damageTable)
function p.main(frame)
     local lines = {}
     local args = getArgs(frame, { removeBlanks = false })
     for dmgType, value in pairs(damageTable) do
     local name = args[1] or ""
         table.insert(lines, "<li>{{ColorPalette|Damage|" .. dmgType .. "|" .. value .. "}} {{#invoke:Ftl|main|translation|damage-type-" .. dmgType .. "}}</li>")
    local attributes = args[2] or ""
    if name == "" then
         return "<span class=\"error\">Ошибка: не указано имя файла.</span>"
     end
     end
     return table.concat(lines)
     local ext = (args["ext"] or "png"):gsub("^%.", "")
end
    local namespace = args["namespace"] or "Файл"
    local max = tonumber(args["max"]) or 50
    local include_base = (args["base"] ~= "no")


function p.main(frame)
     local found = {}
     local mode = frame.args[1]
    local id = frame.args[2]


     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 or not melee.damage or not melee.damage.types then
            return "Нет данных о повреждениях (MeleeWeapon.damage.types) для оружия '" .. tostring(id) .. "'."
        end


        local oneHandDamage = melee.damage.types
    local parts = {}
        local additionalDamage = (entry.IncreaseDamageOnWield and entry.IncreaseDamageOnWield.damage and entry.IncreaseDamageOnWield.damage.types) or
    table.insert(parts, "<choose before=\"" .. before .. "\" after=\"" .. after .. "\">")
                                (entry.DamageOtherOnHit and entry.DamageOtherOnHit.damage and entry.DamageOtherOnHit.damage.types)
    for _, suf in ipairs(found) do
 
        table.insert(parts, "<option>" .. suf .. "</option>")
        local result = "В одной руке:" .. "<ul>" .. formatDamageList(oneHandDamage) .. "</ul>"
    end
 
     table.insert(parts, "</choose>")
        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(table.concat(parts, "\n"))
        return frame:preprocess("<ul><li>{{ColorPalette|Weapon|attackRate|" .. tostring(attackRate) .. "}}</li></ul>")
    else
        return "Неверный режим: " .. tostring(mode)
    end
end
end


return p
return p