sokko-g/website/src/features/cards/dropRates.js
Shinuwa 155187d01f Hide unrevealed Cards pulls and show the odds players really get
Keep a pending opening's cards out of the home highlight and collection until
they are revealed, and refuse transfers meanwhile. Odds now ignore rarities a
pack cannot give. Stable files gain an ETag so card images revalidate instead
of downloading again, and logging out clears the local collection copy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 18:00:32 +01:00

18 lines
1.1 KiB
JavaScript

// Rôle : présente les taux de tirage publiés sur chaque collection (`dropWeights`) et les poids recommandés.
// Poids recommandés des raretés, déclarés dans catalog.json.
export function recommendedWeights(rarities) {
return Object.fromEntries(rarities.map((rarity) => [rarity.id, rarity.recommendedWeight]));
}
// Pourcentage de chaque rareté pour une carte tirée, dans l'ordre des raretés du catalogue.
// `drawable` : raretés que le paquet peut réellement donner, les autres ne comptent pas dans le tirage. Sans cette liste, les poids sont pris tels quels.
export function rarityPercentages(rarities, weights = {}, drawable = null) {
const weightOf = (rarity) => (!drawable || drawable.includes(rarity.id) ? Number(weights[rarity.id]) || 0 : 0);
const total = rarities.reduce((sum, rarity) => sum + weightOf(rarity), 0);
return rarities.map((rarity) => ({ rarity, weight: weightOf(rarity), percent: total ? weightOf(rarity) / total * 100 : 0 }));
}
export function formatPercent(value, maximumFractionDigits = 2) {
return `${value.toLocaleString("fr-FR", { maximumFractionDigits })} %`;
}