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>
This commit is contained in:
parent
b2e46b1d2a
commit
155187d01f
11 changed files with 167 additions and 26 deletions
|
|
@ -238,6 +238,31 @@ export function isDrawableEdition(edition) {
|
|||
return !edition.promotional && !edition.retired;
|
||||
}
|
||||
|
||||
// Éditions tirables d'une collection.
|
||||
export function collectionDrawableEditions(catalog, collectionId) {
|
||||
const cardIds = new Set(catalog.cards.filter((card) => card.collectionId === collectionId).map((card) => card.id));
|
||||
return catalog.editions.filter((edition) => cardIds.has(edition.cardId) && isDrawableEdition(edition));
|
||||
}
|
||||
|
||||
// Paquet de la Boutique : les cartes de toutes les autres collections actives, plus les légendaires et mythiques de sa propre collection.
|
||||
const SHOP_FEATURED_RARITIES = new Set(["legendary", "mythic"]);
|
||||
export function shopPackPools(catalog, collectionId) {
|
||||
const sourceOf = new Map(catalog.cards.map((card) => [card.id, card.collectionId]));
|
||||
const activeIds = new Set(catalog.collections.filter((item) => item.active && item.packCategory !== "shop").map((item) => item.id));
|
||||
const drawable = catalog.editions.filter(isDrawableEdition);
|
||||
return {
|
||||
others: drawable.filter((edition) => activeIds.has(sourceOf.get(edition.cardId))),
|
||||
featured: drawable.filter((edition) => sourceOf.get(edition.cardId) === collectionId && SHOP_FEATURED_RARITIES.has(edition.rarity))
|
||||
};
|
||||
}
|
||||
|
||||
// Raretés qu'un paquet peut réellement donner, quels que soient ses taux.
|
||||
export function drawableRarities(catalog, collection) {
|
||||
const pools = collection.packCategory === "shop" ? shopPackPools(catalog, collection.id) : null;
|
||||
const editions = pools ? [...pools.others, ...pools.featured] : collectionDrawableEditions(catalog, collection.id);
|
||||
return catalog.rarities.map((rarity) => rarity.id).filter((rarity) => editions.some((edition) => edition.rarity === rarity));
|
||||
}
|
||||
|
||||
export function holographicFinishIds(catalog) {
|
||||
return new Set(catalog.finishes.filter((finish) => finish.effectPresetId != null).map((finish) => finish.id));
|
||||
}
|
||||
|
|
@ -297,5 +322,7 @@ export function buildPublishedCatalog(versionedCatalog, { variations = [], openi
|
|||
}
|
||||
|
||||
export function publicCatalog(catalog) {
|
||||
return JSON.parse(JSON.stringify(catalog));
|
||||
const published = JSON.parse(JSON.stringify(catalog));
|
||||
published.collections = published.collections.map((collection) => ({ ...collection, drawableRarities: drawableRarities(published, collection) }));
|
||||
return published;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Rôle : calcule la recharge des ouvertures et sélectionne les éditions d'un paquet.
|
||||
import { randomInt } from "node:crypto";
|
||||
import { isDrawableEdition } from "./catalog.js";
|
||||
import { collectionDrawableEditions, shopPackPools } from "./catalog.js";
|
||||
|
||||
// Réglage de recharge unique (table recharge_settings) : un délai entre deux ouvertures et une réserve maximale.
|
||||
// Un changement de délai s'applique aussi au temps déjà écoulé depuis la dernière recharge du joueur.
|
||||
|
|
@ -53,18 +53,12 @@ function weightedChoice(entries, random = (max) => randomInt(max)) {
|
|||
|
||||
const pick = (random, max) => (random || ((limit) => randomInt(limit)))(max);
|
||||
|
||||
// Paquet de la Boutique : les cartes de toutes les autres collections actives, plus les légendaires et mythiques de sa propre collection.
|
||||
// Quand une de ces deux raretés sort, `share` % des tirages reviennent aux cartes de sa collection, quel que soit leur nombre.
|
||||
const FEATURED_RARITIES = new Set(["legendary", "mythic"]);
|
||||
// Quand une légendaire ou une mythique sort du paquet de la Boutique, `share` % des tirages reviennent aux cartes de sa collection, quel que soit leur nombre.
|
||||
export function drawShopPack(catalog, collectionId, random, share) {
|
||||
const collection = catalog.collections.find((item) => item.id === collectionId && item.active);
|
||||
if (!collection) throw Object.assign(new Error("Ce paquet n'est pas disponible."), { status: 404, code: "COLLECTION_UNAVAILABLE" });
|
||||
if (!collection.dropWeights) throw new TypeError(`No drop rates for ${collectionId}.`);
|
||||
const sourceOf = new Map(catalog.cards.map((card) => [card.id, card.collectionId]));
|
||||
const activeIds = new Set(catalog.collections.filter((item) => item.active && item.packCategory !== "shop").map((item) => item.id));
|
||||
const drawableEditions = catalog.editions.filter(isDrawableEdition);
|
||||
const others = drawableEditions.filter((edition) => activeIds.has(sourceOf.get(edition.cardId)));
|
||||
const featured = drawableEditions.filter((edition) => sourceOf.get(edition.cardId) === collectionId && FEATURED_RARITIES.has(edition.rarity));
|
||||
const { others, featured } = shopPackPools(catalog, collectionId);
|
||||
const ofRarity = (editions, rarity) => editions.filter((edition) => edition.rarity === rarity);
|
||||
const rarityEntries = Object.entries(collection.dropWeights).filter(([rarity, weight]) => weight > 0 && (ofRarity(others, rarity).length || ofRarity(featured, rarity).length));
|
||||
if (!rarityEntries.length) throw Object.assign(new Error("Aucune carte ne peut être tirée avec ces taux."), { status: 409, code: "NOTHING_DRAWABLE" });
|
||||
|
|
@ -89,7 +83,7 @@ export function drawPack(catalog, collectionId, random, { weights = null, guaran
|
|||
const rarityWeights = weights || collection.dropWeights;
|
||||
if (!rarityWeights) throw new TypeError(`No drop rates for ${collectionId}.`);
|
||||
const cardIds = new Set(catalog.cards.filter((card) => card.collectionId === collectionId).map((card) => card.id));
|
||||
const editions = catalog.editions.filter((edition) => cardIds.has(edition.cardId) && isDrawableEdition(edition));
|
||||
const editions = collectionDrawableEditions(catalog, collectionId);
|
||||
const drawable = (rarity) => editions.some((edition) => edition.rarity === rarity);
|
||||
const rarityEntries = Object.entries(rarityWeights).filter(([rarity, weight]) => weight > 0 && drawable(rarity));
|
||||
if (!rarityEntries.length) throw Object.assign(new Error("Aucune carte ne peut être tirée avec ces taux."), { status: 409, code: "NOTHING_DRAWABLE" });
|
||||
|
|
|
|||
|
|
@ -389,7 +389,7 @@ export class CardsService {
|
|||
const pulls = this.db.prepare(`SELECT oc.edition_id, oc.position, o.id AS opening_id, o.created_at AS opened_at
|
||||
FROM opening_cards oc
|
||||
JOIN openings o ON o.id = oc.opening_id
|
||||
WHERE o.player_id = ?
|
||||
WHERE o.player_id = ? AND o.status = 'completed'
|
||||
ORDER BY o.created_at DESC, oc.position DESC`).all(playerId);
|
||||
let rarest = null;
|
||||
for (const pull of pulls) {
|
||||
|
|
@ -417,15 +417,27 @@ export class CardsService {
|
|||
};
|
||||
}
|
||||
|
||||
// Les cartes d'une ouverture en attente sont déjà attribuées, mais ne doivent pas se dévoiler avant la révélation.
|
||||
visibleCollection(playerId, pendingOpeningId) {
|
||||
const collection = this.collectionOf(playerId);
|
||||
if (!pendingOpeningId) return collection;
|
||||
const hidden = new Map();
|
||||
for (const { edition_id: editionId } of this.db.prepare("SELECT edition_id FROM opening_cards WHERE opening_id = ?").all(pendingOpeningId)) hidden.set(editionId, (hidden.get(editionId) || 0) + 1);
|
||||
return collection.map((entry) => {
|
||||
const visible = { ...entry, quantity: entry.quantity - (hidden.get(entry.editionId) || 0) };
|
||||
return { ...visible, spare: spareQuantity(visible) };
|
||||
}).filter((entry) => entry.quantity > 0);
|
||||
}
|
||||
|
||||
getState(playerId) {
|
||||
const recharge = this.database.transaction(() => this.refreshRecharge(playerId));
|
||||
this.expireTransfers();
|
||||
const player = this.db.prepare("SELECT * FROM players WHERE id = ?").get(playerId);
|
||||
if (!player) fail(404, "PLAYER_NOT_FOUND", "Profil introuvable.");
|
||||
const owned = this.collectionOf(playerId);
|
||||
const pending = this.db.prepare("SELECT id FROM openings WHERE player_id = ? AND status = 'pending' ORDER BY created_at DESC LIMIT 1").get(playerId);
|
||||
const owned = this.visibleCollection(playerId, pending?.id);
|
||||
const collection = owned.map((entry) => this.cardEntry(entry.editionId, entry));
|
||||
const favorites = this.db.prepare("SELECT edition_id FROM favorites WHERE player_id = ?").all(playerId).map((row) => row.edition_id);
|
||||
const pending = this.db.prepare("SELECT id FROM openings WHERE player_id = ? AND status = 'pending' ORDER BY created_at DESC LIMIT 1").get(playerId);
|
||||
const history = this.db.prepare("SELECT event_type, entity_id, details_json, created_at FROM audit_log WHERE player_id = ? AND event_type IN (" + PLAYER_HISTORY_EVENTS.map(() => "?").join(", ") + ") ORDER BY created_at DESC LIMIT 100").all(playerId, ...PLAYER_HISTORY_EVENTS)
|
||||
.map((row) => ({ type: row.event_type, entityId: row.entity_id, details: JSON.parse(row.details_json), createdAt: row.created_at }));
|
||||
const transferRows = this.db.prepare("SELECT * FROM transfers WHERE initiator_id = ? OR recipient_id = ? ORDER BY created_at DESC LIMIT 50").all(playerId, playerId);
|
||||
|
|
@ -679,6 +691,7 @@ export class CardsService {
|
|||
const transferId = randomUUID();
|
||||
this.database.transaction(() => {
|
||||
this.expireTransfers();
|
||||
if (this.db.prepare("SELECT 1 FROM openings WHERE player_id = ? AND status = 'pending'").get(playerId)) fail(409, "PENDING_OPENING", "Terminez d'abord l'ouverture en cours.");
|
||||
this.requireRecipient(playerId, recipientId);
|
||||
this.requireSpare(playerId, editionId);
|
||||
const now = this.now();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue