Mudanças entre as edições de "Módulo:Quest"
Ir para navegação
Ir para pesquisar
| (27 revisões intermediárias pelo mesmo usuário não estão sendo mostradas) | |||
| Linha 2: | Linha 2: | ||
local itemData = require("Módulo:ItemData") | local itemData = require("Módulo:ItemData") | ||
local function formatNumber( | local function formatNumber(num) | ||
local s = tostring( | num = tonumber(num) or 0 | ||
if num >= 1e9 then | |||
return | 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 buscarChaveCorreta(nome) | |||
local base = mw.text.trim(nome):lower():gsub("_", " "):gsub("%.png$", ""):gsub("%.gif$", ""):gsub("%.jpg$", ""):gsub("%.webp$", "") | |||
for chave, dados in pairs(itemData) do | |||
local kbase = chave:lower():gsub("_", " "):gsub("%.png$", ""):gsub("%.gif$", ""):gsub("%.jpg$", ""):gsub("%.webp$", "") | |||
if kbase == base then | |||
return chave | |||
end | |||
local nomeTraduzido = (dados.nome or ""):lower():gsub("_", " "):gsub("%.png$", ""):gsub("%.gif$", ""):gsub("%.jpg$", ""):gsub("%.webp$", "") | |||
if nomeTraduzido == base then | |||
return chave | |||
end | |||
end | |||
return nil | |||
end | end | ||
| Linha 13: | Linha 36: | ||
local nome, qtd = item:match("^%s*(.-)%s*:%s*(%d+)%s*$") | local nome, qtd = item:match("^%s*(.-)%s*:%s*(%d+)%s*$") | ||
if nome and qtd then | if nome and qtd then | ||
local chave = buscarChaveCorreta(nome) or (nome .. ".png") | |||
qtd = tonumber(qtd) or 0 | qtd = tonumber(qtd) or 0 | ||
resultado[ | resultado[chave] = (resultado[chave] or 0) + qtd | ||
end | end | ||
end | end | ||
| Linha 26: | Linha 46: | ||
local function mergeRecompensas(lista) | local function mergeRecompensas(lista) | ||
local total = {} | local total = {} | ||
for _, | for _, item in ipairs(lista) do | ||
local dados = parseItens( | local dados = parseItens(item.itens) | ||
for nome, qtd in pairs(dados) do | for nome, qtd in pairs(dados) do | ||
total[nome] = | total[nome] = total[nome] or { qtd = 0 } | ||
total[nome].qtd = total[nome].qtd + qtd | |||
total[nome].ilha = item.ilha or total[nome].ilha | |||
end | end | ||
end | end | ||
| Linha 35: | Linha 57: | ||
end | end | ||
function p. | 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:getParent().args or {} | local args = frame:getParent().args or {} | ||
local bonus = args.bonus or "" | local bonus = args.bonus or "" | ||
local content = mw.title.getCurrentTitle():getContent() | local content = mw.title.getCurrentTitle():getContent() | ||
local rewardCalls = extrairRecompensasValidas(content) | |||
if bonus and bonus ~= "" then | |||
table.insert(rewardCalls, { itens = bonus }) | |||
end | end | ||
local total = mergeRecompensas(rewardCalls) | |||
return next(total) and "1" or "" | |||
end | |||
function p.total(frame) | |||
local args = frame:getParent().args or {} | |||
local bonus = args.bonus or "" | |||
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 | |||
if next(total) == nil then | |||
local html = mw.html.create("div") | local html = mw.html.create("div") | ||
html:addClass("introquest-items") | html:addClass("introquest-items") | ||
for nome, | local outros = {} | ||
local berries = {} | |||
for nome, info in pairs(total) do | |||
local qtd = info.qtd | |||
local ilha = info.ilha or "" | |||
local data = itemData[nome] or {} | local data = itemData[nome] or {} | ||
local nomeCompleto = data.nome or nome | local nomeCompleto = data.nome or nome | ||
local desc = data.desc | local desc = data.desc | ||
local tooltip = nomeCompleto | local tooltip = nomeCompleto | ||
if desc and desc ~= "" then | |||
if nome:lower() == "pose.png" and ilha ~= "" then | |||
tooltip = "Eternal Pose - " .. ilha | |||
elseif desc and desc ~= "" then | |||
tooltip = tooltip .. "\n—\n" .. desc | tooltip = tooltip .. "\n—\n" .. desc | ||
end | end | ||
local | local bloco = { | ||
arquivo = nome, | |||
qtd = formatNumber(qtd), | |||
tooltip = tooltip | |||
} | |||
if nome:lower() == "berries.gif" then | |||
table.insert(berries, bloco) | |||
else | |||
table.insert(outros, bloco) | |||
end | |||
end | |||
local function addBloco(bloco) | |||
local wrap = html:tag("span") | |||
wrap:addClass("item-wrapper") | |||
wrap:attr("data-tooltip", bloco.tooltip) | |||
wrap:attr("data-item", bloco.arquivo:lower()) | |||
wrap:tag("span"):wikitext(string.format("[[Arquivo:%s|link=]]", bloco.arquivo)) | |||
local quantidade = wrap:tag("span"):addClass("item-count") | |||
if bloco.arquivo:lower() ~= "berries.gif" then | |||
quantidade:tag("span"):addClass("item-count-x"):wikitext("x") | |||
end | |||
quantidade:wikitext(bloco.qtd) | |||
end | end | ||
for _, b in ipairs(outros) do addBloco(b) end | |||
for _, b in ipairs(berries) do addBloco(b) end | |||
return tostring(html) | return tostring(html) | ||
| Linha 88: | Linha 152: | ||
function p.requisitos(frame) | function p.requisitos(frame) | ||
local args = frame:getParent().args or | local args = frame:getParent().args or "" | ||
local raw = args.requisitos or "" | local raw = args.requisitos or "" | ||
if mw.text.trim(raw) == "" then return "" end | if mw.text.trim(raw) == "" then return "" end | ||
local | local output = {} | ||
for item in mw.text.gsplit(raw, ",", true) do | |||
local clean = mw.text.trim(item) | |||
for | if clean ~= "" then table.insert(output, "* " .. clean) end | ||
local clean = mw.text.trim( | |||
if clean ~= "" then | |||
end | end | ||
return table.concat(output, "\n") | |||
return | |||
end | end | ||
return p | return p | ||
Edição atual tal como às 00h48min de 16 de junho de 2025
A documentação para este módulo pode ser criada em Módulo:Quest/doc
local p = {}
local itemData = require("Módulo:ItemData")
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 buscarChaveCorreta(nome)
local base = mw.text.trim(nome):lower():gsub("_", " "):gsub("%.png$", ""):gsub("%.gif$", ""):gsub("%.jpg$", ""):gsub("%.webp$", "")
for chave, dados in pairs(itemData) do
local kbase = chave:lower():gsub("_", " "):gsub("%.png$", ""):gsub("%.gif$", ""):gsub("%.jpg$", ""):gsub("%.webp$", "")
if kbase == base then
return chave
end
local nomeTraduzido = (dados.nome or ""):lower():gsub("_", " "):gsub("%.png$", ""):gsub("%.gif$", ""):gsub("%.jpg$", ""):gsub("%.webp$", "")
if nomeTraduzido == base then
return chave
end
end
return nil
end
local function parseItens(raw)
local resultado = {}
for item in mw.text.gsplit(raw or "", ",", true) do
local nome, qtd = item:match("^%s*(.-)%s*:%s*(%d+)%s*$")
if nome and qtd then
local chave = buscarChaveCorreta(nome) or (nome .. ".png")
qtd = tonumber(qtd) or 0
resultado[chave] = (resultado[chave] or 0) + qtd
end
end
return resultado
end
local function mergeRecompensas(lista)
local total = {}
for _, item in ipairs(lista) do
local dados = parseItens(item.itens)
for nome, qtd in pairs(dados) do
total[nome] = total[nome] or { qtd = 0 }
total[nome].qtd = total[nome].qtd + qtd
total[nome].ilha = item.ilha or total[nome].ilha
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:getParent().args or {}
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:getParent().args or {}
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)
if next(total) == nil then return "" end
local html = mw.html.create("div")
html:addClass("introquest-items")
local outros = {}
local berries = {}
for nome, info in pairs(total) do
local qtd = info.qtd
local ilha = info.ilha or ""
local data = itemData[nome] or {}
local nomeCompleto = data.nome or nome
local desc = data.desc
local tooltip = nomeCompleto
if nome:lower() == "pose.png" and ilha ~= "" then
tooltip = "Eternal Pose - " .. ilha
elseif desc and desc ~= "" then
tooltip = tooltip .. "\n—\n" .. desc
end
local bloco = {
arquivo = nome,
qtd = formatNumber(qtd),
tooltip = tooltip
}
if nome:lower() == "berries.gif" then
table.insert(berries, bloco)
else
table.insert(outros, bloco)
end
end
local function addBloco(bloco)
local wrap = html:tag("span")
wrap:addClass("item-wrapper")
wrap:attr("data-tooltip", bloco.tooltip)
wrap:attr("data-item", bloco.arquivo:lower())
wrap:tag("span"):wikitext(string.format("[[Arquivo:%s|link=]]", bloco.arquivo))
local quantidade = wrap:tag("span"):addClass("item-count")
if bloco.arquivo:lower() ~= "berries.gif" then
quantidade:tag("span"):addClass("item-count-x"):wikitext("x")
end
quantidade:wikitext(bloco.qtd)
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:getParent().args or ""
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