Mudanças entre as edições de "Módulo:Quest"

De Wiki Gla
Ir para navegação Ir para pesquisar
m
 
(32 revisões intermediárias pelo mesmo usuário não estão sendo mostradas)
Linha 1: Linha 1:
local p = {}
local p = {}
local itemData = require("Módulo:ItemData")
local Item = require("Módulo:Item")


local function formatNumber(n)
local function formatNumber(num)
     local s = tostring(n)
     num = tonumber(num) or 0
    local result = s:reverse():gsub("(%d%d%d)", "%1,"):reverse()
    if num >= 1e9 then
    return result:gsub("^,", "")
        return string.format("%.0f", num / 1e6) .. "KKK"
    elseif num >= 1e6 then
        return string.format("%.0f", num / 1e6) .. "KK"
    elseif num >= 1e4 then
        return string.format("%.0f", num / 1e3) .. "K"
    else
        local s = tostring(num)
        return s:reverse():gsub("(%d%d%d)", "%1,"):reverse():gsub("^,", "")
    end
end
end


local function parseItens(raw)
local function parseItemEntry(entry)
    entry = mw.text.trim(entry)
    if entry == "" then return nil, nil end
 
    local ident, qtdStr
 
    if entry:find(";") then
        ident, qtdStr = entry:match("^(.-)%s*;%s*(%d+)$")
    else
        ident, qtdStr = entry:match("^(.-)%s*:%s*(%d+)$")
    end
 
    if not ident or not qtdStr then return nil, nil end
    return mw.text.trim(ident), tonumber(qtdStr)
end
 
local function parseItens(raw, ilha)
     local resultado = {}
     local resultado = {}
     for item in mw.text.gsplit(raw or "", ",", true) do
 
         local nome, qtd = item:match("^%s*(.-)%s*:%s*(%d+)%s*$")
     for entry in mw.text.gsplit(raw or "", ",", true) do
         if nome and qtd then
         local ident, qtd = parseItemEntry(entry)
             nome = mw.text.trim(nome)
         if ident and qtd then
             if not nome:match("%.png$") and not nome:match("%.gif$") and not nome:match("%.jpg$") and not nome:match("%.webp$") then
             local item = Item.resolve(ident)
                 nome = nome .. ".png"
             if not item then
                item = {
                    id = 0,
                    image = ident:match("%.%w+$") and ident or (ident .. ".png"),
                    names = { pt = ident, en = ident },
                    category = "unknown"
                }
            end
 
            local key = tostring(item.id or (Item.getImage(item) or ident):lower())
            if not resultado[key] then
                 resultado[key] = { item = item, qtd = 0, ilha = nil }
            end
            resultado[key].qtd = resultado[key].qtd + qtd
            if ilha and ilha ~= "" and not resultado[key].ilha then
                resultado[key].ilha = ilha
             end
             end
            qtd = tonumber(qtd) or 0
            resultado[nome] = (resultado[nome] or 0) + qtd
         end
         end
     end
     end
     return resultado
     return resultado
end
end
Linha 26: Linha 64:
local function mergeRecompensas(lista)
local function mergeRecompensas(lista)
     local total = {}
     local total = {}
     for _, raw in ipairs(lista) do
     for _, item in ipairs(lista) do
         local dados = parseItens(raw)
         local dados = parseItens(item.itens, item.ilha)
         for nome, qtd in pairs(dados) do
         for key, info in pairs(dados) do
             total[nome] = (total[nome] or 0) + qtd
             if not total[key] then
                total[key] = { item = info.item, qtd = 0, ilha = nil }
            end
            total[key].qtd = total[key].qtd + info.qtd
            if info.ilha and info.ilha ~= "" and not total[key].ilha then
                total[key].ilha = info.ilha
            end
         end
         end
     end
     end
Linha 35: Linha 79:
end
end


function p.total(frame)
local function extrairRecompensasValidas(content)
     local args = frame:getParent().args or {}
    local recompensas = {}
    for bloco in content:gmatch("{{%s*[Rr]eward.-}}") do
        if not bloco:match("ignore%s*=") then
            local itens = bloco:match("itens%s*=%s*([^|}]+)")
            if itens then
                local ilha = bloco:match("ilha%s*=%s*([^|}]+)")
                table.insert(recompensas, { itens = itens, ilha = ilha })
            end
        end
    end
    return recompensas
end
 
function p.hasRewards(frame)
     local args = frame.args or {}
    if not next(args) and frame:getParent() then
        args = frame:getParent().args or {}
    end
     local bonus = args.bonus or ""
     local bonus = args.bonus or ""
     local content = mw.title.getCurrentTitle():getContent()
     local content = mw.title.getCurrentTitle():getContent()
    local rewardCalls = {}


     for bloco in content:gmatch("{{%s*[Rr]eward.-}}") do
     local rewardCalls = extrairRecompensasValidas(content)
        local itens = bloco:match("itens%s*=%s*([^|}]+)")
    if bonus and bonus ~= "" then
         if itens then
         table.insert(rewardCalls, { itens = bonus })
            table.insert(rewardCalls, itens)
        end
     end
     end


    local total = mergeRecompensas(rewardCalls)
    return next(total) and "1" or ""
end
function p.total(frame)
    local args = frame.args or {}
    if not next(args) and frame:getParent() then
        args = frame:getParent().args or {}
    end
    local bonus = args.bonus or ""
    local lang = args.lang or "pt"
    local content = mw.title.getCurrentTitle():getContent()
    local rewardCalls = extrairRecompensasValidas(content)
     if bonus and bonus ~= "" then
     if bonus and bonus ~= "" then
         table.insert(rewardCalls, bonus)
         table.insert(rewardCalls, { itens = bonus })
     end
     end


     local total = mergeRecompensas(rewardCalls)
     local total = mergeRecompensas(rewardCalls)
    if next(total) == nil then return "" end


     local html = mw.html.create("div")
     local html = mw.html.create("div")
     html:addClass("introquest-items")
     html:addClass("introquest-items")


     for nome, qtd in pairs(total) do
    local outros = {}
         local data = itemData[nome] or {}
    local berries = {}
         local nomeCompleto = data.nome or nome
 
         local desc = data.desc
     for _, info in pairs(total) do
         local tooltip = nomeCompleto
         local qtd = info.qtd
         if desc and desc ~= "" then
         local ilha = info.ilha or ""
             tooltip = tooltip .. "\n—\n" .. desc
         local item = info.item
         local image = (Item.getImage(item) or ""):lower()
 
         if image == "pose.png" and ilha ~= "" then
             local newNames = {}
            if item.names then
                for k, v in pairs(item.names) do newNames[k] = v end
            end
            newNames.pt = "Eternal Pose - " .. ilha
            newNames.en = "Eternal Pose - " .. ilha
            local cloned = {}
            for k, v in pairs(item) do cloned[k] = v end
            cloned.names = newNames
            cloned.desc = nil
            item = cloned
         end
         end


         local wrapper = html:tag("span")
         local bloco = {
        wrapper:addClass("introquest-item")
            item = item,
        wrapper:addClass("item-wrapper")  
            qtd = formatNumber(qtd),
         wrapper:attr("data-tooltip", tooltip)
            isBerries = info.item and info.item.category == "currency"
                and image:find("berries")
         }


         wrapper:tag("span")
         if bloco.isBerries then
             :wikitext(string.format("[[Arquivo:%s|link=]]", nome))
            table.insert(berries, bloco)
        else
             table.insert(outros, bloco)
        end
    end


        wrapper:tag("span")
    local function addBloco(bloco)
            :addClass("introquest-count")
        html:wikitext(Item.renderOne(bloco.item, bloco.qtd, lang, {
            :wikitext((nome:lower():match("^berries") and "" or "x") .. formatNumber(qtd))
            showTooltip = true,
            showCount = true
        }))
     end
     end


     if next(total) == nil then
     for _, b in ipairs(outros) do addBloco(b) end
     return ""
    for _, b in ipairs(berries) do addBloco(b) end
 
     return tostring(html)
end
end


return tostring(html)
function p.requisitos(frame)
    local args = frame.args or {}
    if not next(args) and frame:getParent() then
        args = frame:getParent().args or {}
    end
    local raw = args.requisitos or ""
    if mw.text.trim(raw) == "" then return "" end


    local output = {}
    for item in mw.text.gsplit(raw, ",", true) do
        local clean = mw.text.trim(item)
        if clean ~= "" then table.insert(output, "* " .. clean) end
    end
    return table.concat(output, "\n")
end
end


return p
return p

Edição atual tal como às 02h43min de 17 de março de 2026

A documentação para este módulo pode ser criada em Módulo:Quest/doc

local p = {}
local Item = require("Módulo:Item")

local function formatNumber(num)
    num = tonumber(num) or 0
    if num >= 1e9 then
        return string.format("%.0f", num / 1e6) .. "KKK"
    elseif num >= 1e6 then
        return string.format("%.0f", num / 1e6) .. "KK"
    elseif num >= 1e4 then
        return string.format("%.0f", num / 1e3) .. "K"
    else
        local s = tostring(num)
        return s:reverse():gsub("(%d%d%d)", "%1,"):reverse():gsub("^,", "")
    end
end

local function parseItemEntry(entry)
    entry = mw.text.trim(entry)
    if entry == "" then return nil, nil end

    local ident, qtdStr

    if entry:find(";") then
        ident, qtdStr = entry:match("^(.-)%s*;%s*(%d+)$")
    else
        ident, qtdStr = entry:match("^(.-)%s*:%s*(%d+)$")
    end

    if not ident or not qtdStr then return nil, nil end
    return mw.text.trim(ident), tonumber(qtdStr)
end

local function parseItens(raw, ilha)
    local resultado = {}

    for entry in mw.text.gsplit(raw or "", ",", true) do
        local ident, qtd = parseItemEntry(entry)
        if ident and qtd then
            local item = Item.resolve(ident)
            if not item then
                item = {
                    id = 0,
                    image = ident:match("%.%w+$") and ident or (ident .. ".png"),
                    names = { pt = ident, en = ident },
                    category = "unknown"
                }
            end

            local key = tostring(item.id or (Item.getImage(item) or ident):lower())
            if not resultado[key] then
                resultado[key] = { item = item, qtd = 0, ilha = nil }
            end
            resultado[key].qtd = resultado[key].qtd + qtd
            if ilha and ilha ~= "" and not resultado[key].ilha then
                resultado[key].ilha = ilha
            end
        end
    end

    return resultado
end

local function mergeRecompensas(lista)
    local total = {}
    for _, item in ipairs(lista) do
        local dados = parseItens(item.itens, item.ilha)
        for key, info in pairs(dados) do
            if not total[key] then
                total[key] = { item = info.item, qtd = 0, ilha = nil }
            end
            total[key].qtd = total[key].qtd + info.qtd
            if info.ilha and info.ilha ~= "" and not total[key].ilha then
                total[key].ilha = info.ilha
            end
        end
    end
    return total
end

local function extrairRecompensasValidas(content)
    local recompensas = {}
    for bloco in content:gmatch("{{%s*[Rr]eward.-}}") do
        if not bloco:match("ignore%s*=") then
            local itens = bloco:match("itens%s*=%s*([^|}]+)")
            if itens then
                local ilha = bloco:match("ilha%s*=%s*([^|}]+)")
                table.insert(recompensas, { itens = itens, ilha = ilha })
            end
        end
    end
    return recompensas
end

function p.hasRewards(frame)
    local args = frame.args or {}
    if not next(args) and frame:getParent() then
        args = frame:getParent().args or {}
    end
    local bonus = args.bonus or ""
    local content = mw.title.getCurrentTitle():getContent()

    local rewardCalls = extrairRecompensasValidas(content)
    if bonus and bonus ~= "" then
        table.insert(rewardCalls, { itens = bonus })
    end

    local total = mergeRecompensas(rewardCalls)
    return next(total) and "1" or ""
end

function p.total(frame)
    local args = frame.args or {}
    if not next(args) and frame:getParent() then
        args = frame:getParent().args or {}
    end
    local bonus = args.bonus or ""
    local lang = args.lang or "pt"
    local content = mw.title.getCurrentTitle():getContent()

    local rewardCalls = extrairRecompensasValidas(content)
    if bonus and bonus ~= "" then
        table.insert(rewardCalls, { itens = bonus })
    end

    local total = mergeRecompensas(rewardCalls)
    if next(total) == nil then return "" end

    local html = mw.html.create("div")
    html:addClass("introquest-items")

    local outros = {}
    local berries = {}

    for _, info in pairs(total) do
        local qtd = info.qtd
        local ilha = info.ilha or ""
        local item = info.item
        local image = (Item.getImage(item) or ""):lower()

        if image == "pose.png" and ilha ~= "" then
            local newNames = {}
            if item.names then
                for k, v in pairs(item.names) do newNames[k] = v end
            end
            newNames.pt = "Eternal Pose - " .. ilha
            newNames.en = "Eternal Pose - " .. ilha
            local cloned = {}
            for k, v in pairs(item) do cloned[k] = v end
            cloned.names = newNames
            cloned.desc = nil
            item = cloned
        end

        local bloco = {
            item = item,
            qtd = formatNumber(qtd),
            isBerries = info.item and info.item.category == "currency"
                and image:find("berries")
        }

        if bloco.isBerries then
            table.insert(berries, bloco)
        else
            table.insert(outros, bloco)
        end
    end

    local function addBloco(bloco)
        html:wikitext(Item.renderOne(bloco.item, bloco.qtd, lang, {
            showTooltip = true,
            showCount = true
        }))
    end

    for _, b in ipairs(outros) do addBloco(b) end
    for _, b in ipairs(berries) do addBloco(b) end

    return tostring(html)
end

function p.requisitos(frame)
    local args = frame.args or {}
    if not next(args) and frame:getParent() then
        args = frame:getParent().args or {}
    end
    local raw = args.requisitos or ""
    if mw.text.trim(raw) == "" then return "" end

    local output = {}
    for item in mw.text.gsplit(raw, ",", true) do
        local clean = mw.text.trim(item)
        if clean ~= "" then table.insert(output, "* " .. clean) end
    end
    return table.concat(output, "\n")
end

return p