- La Carte du jour: one zoomed card shared by all players each Paris day, six guesses with collection and rarity hints, a fixed stardust reward and an emoji result to share. - The Guilde des Veilleurs lists the quests, with a menu entry, a home banner and an admin section for quest settings. - The section menu folds into a dropdown below 960 px; the home pairs the guild with the best pull and moves the opening reserve under the menu. - The shop pack share moves to the shop collection admin page, which recalls where the pack draws its cards. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
36 lines
2.8 KiB
JavaScript
36 lines
2.8 KiB
JavaScript
// Rôle : règles pures de la poussière d'étoiles (recyclage des doublons, barème de la boutique, récompense de la Carte du jour).
|
||
// Le serveur s'en sert aussi pour l'aperçu envoyé au client, qui correspond donc exactement au recyclage appliqué.
|
||
|
||
export const MAX_STARDUST_VALUE = 100_000;
|
||
export const MAX_OPENING_PRICE = 100_000;
|
||
|
||
// Doublons disponibles d'une carte : la quantité possédée moins l'exemplaire toujours conservé et les doublons réservés par un
|
||
// transfert en cours. Seuls ces doublons s'échangent, se donnent ou se recyclent.
|
||
export const spareQuantity = ({ quantity, reserved = 0 }) => Math.max(0, quantity - 1 - reserved);
|
||
|
||
// `collection` : [{ editionId, quantity, reserved }] ; `rarityOf(editionId)` renvoie la rareté de la carte.
|
||
// Sans `editionId`, prépare le recyclage de tous les doublons disponibles ; avec, d'un seul doublon de cette carte.
|
||
export function planRecycling(collection, { rarityOf, stardustValues, editionId = null }) {
|
||
const items = collection
|
||
.filter((entry) => !editionId || entry.editionId === editionId)
|
||
.map((entry) => {
|
||
const count = editionId ? Math.min(1, spareQuantity(entry)) : spareQuantity(entry);
|
||
return { editionId: entry.editionId, count, stardust: count * (stardustValues[rarityOf(entry.editionId)] ?? 0) };
|
||
})
|
||
.filter((item) => item.count > 0);
|
||
return { items, count: items.reduce((total, item) => total + item.count, 0), stardust: items.reduce((total, item) => total + item.stardust, 0) };
|
||
}
|
||
|
||
export function validateShopSetting({ stardustValues, openingPrice, shopPackPrice, shopPackShare, dailyReward } = {}, rarityIds) {
|
||
const valid = (value, max) => Number.isInteger(value) && value >= 0 && value <= max;
|
||
if (!stardustValues || typeof stardustValues !== "object" || Array.isArray(stardustValues)) return "Barème de poussière invalide.";
|
||
for (const rarityId of rarityIds) {
|
||
if (!valid(stardustValues[rarityId], MAX_STARDUST_VALUE)) return `Valeur invalide pour la rareté ${rarityId} : un entier entre 0 et ${MAX_STARDUST_VALUE.toLocaleString("fr-FR")}.`;
|
||
}
|
||
if (Object.keys(stardustValues).some((rarityId) => !rarityIds.includes(rarityId))) return "Rareté inconnue dans le barème.";
|
||
if (!valid(openingPrice, MAX_OPENING_PRICE) || openingPrice < 1) return `Prix d’une ouverture invalide : un entier entre 1 et ${MAX_OPENING_PRICE.toLocaleString("fr-FR")}.`;
|
||
if (!valid(shopPackPrice, MAX_OPENING_PRICE) || shopPackPrice < 1) return `Prix du paquet de la boutique invalide : un entier entre 1 et ${MAX_OPENING_PRICE.toLocaleString("fr-FR")}.`;
|
||
if (!valid(shopPackShare, 100)) return "Part des cartes de la boutique invalide : un entier entre 0 et 100.";
|
||
if (!valid(dailyReward, MAX_STARDUST_VALUE)) return `Récompense de la Carte du jour invalide : un entier entre 0 et ${MAX_STARDUST_VALUE.toLocaleString("fr-FR")}.`;
|
||
return null;
|
||
}
|