Módulo:Gb

De Wiki Gla
Revisão de 21h11min de 26 de setembro de 2025 por GhoulBlack (discussão | contribs)
Ir para navegação Ir para pesquisar

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

-- [[Module:Gb]] — Calculadora de custos de tiers/estrelas
-- Idiomático para MediaWiki (Scribunto), com parsing de argumentos via Module:Arguments (se existir)
-- Autor: Você ; Licença: CC BY-SA 4.0 (ajuste conforme a wiki)


local p = {}


-- Dependências opcionais
local getArgs
local ok, Args = pcall(require, 'Module:Arguments')
if ok and type(Args) == 'table' then
getArgs = function(frame)
return Args.getArgs(frame, { remap = { ["mostrar_tabela"] = "mostrar_tabela" } })
end
else
-- Fallback simples se Module:Arguments não existir
getArgs = function(frame)
return frame:getParent() and frame:getParent().args or frame.args or {}
end
end


-- =============== CONFIG ===============
local CONFIG = {
tiers = { 'bronze', 'prata', 'ouro', 'diamante' },
labels = { berry = 'Berry', frag = 'Fragmentos', pedras = 'Pedras' },
costs = {
star = {
bronze = { [2]={berry=270,frag=40}, [3]={berry=1800,frag=80}, [4]={berry=13500,frag=180}, [5]={berry=75000,frag=540} },
prata = { [2]={berry=540,frag=40}, [3]={berry=3600,frag=80}, [4]={berry=27000,frag=180}, [5]={berry=180000,frag=540} },
ouro = { [2]={berry=1800,frag=40}, [3]={berry=18000,frag=80}, [4]={berry=180000,frag=180}, [5]={berry=1800000,frag=540} },
diamante={ [2]={berry=18000,frag=40}, [3]={berry=180000,frag=80}, [4]={berry=1800000,frag=180}, [5]={berry=5000000,frag=0,pedras=100} },
},
tierUp = { bronze={berry=0,frag=0,pedras=0}, prata={berry=0,frag=0,pedras=0}, ouro={berry=0,frag=0,pedras=0}, diamante=nil },
},
aliases = { ouro = {'gold'} },
}


-- ============== UTIL ==================
local function norm(s)
if type(s) ~= 'string' then return nil end
s = mw.ustring.lower(s)
s = s:gsub('á','a'):gsub('â','a'):gsub('ã','a'):gsub('é','e'):gsub('ê','e'):gsub('í','i'):gsub('ó','o'):gsub('ô','o'):gsub('ú','u')
return s
end


local function yesno(v)
local t = type(v)
if t == 'boolean' then return v end
if t == 'number' then return v ~= 0 end
if t == 'string' then
v = norm(v)
return not (v == 'nao' or v == 'não' or v == 'n' or v == 'no' or v == 'false' or v == '0' or v == '')
end
return false
end


local function clamp(v, lo, hi)
v = tonumber(v) or lo
if v < lo then return lo end
if v > hi then return hi end
return math.floor(v)
end


local function tierIndex(name)
local n = norm(name)
if not n then return nil end
for i, t in ipairs(CONFIG.tiers) do if n == t then return i end end
for base, list in pairs(CONFIG.aliases or {}) do
for _, alias in ipairs(list) do if n == alias then return tierIndex(base) end end
end
return nil
end


local function getTierName(idx) return CONFIG.tiers[idx] end


local function addCost(a, b)
a = a or { berry=0, frag=0, pedras=0 }
b = b or { berry=0, frag=0, pedras=0 }
return { berry=(a.berry or 0)+(b.berry or 0), frag=(a.frag or 0)+(b.frag or 0), pedras=(a.pedras or 0)+(b.pedras or 0) }
end


local function starCost(tierName, starTo)
local t = CONFIG.costs.star[tierName]
return p
end