Fix pack openings failing when they draw a destination card already owned
The server builds the card service without a random source. Pack draws fall back to crypto randomness, but replacing a destination card the player already owns called the missing source and threw "this.random is not a function". The service now defaults to crypto randomness itself. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
01683ab2b8
commit
8b76570e7a
3 changed files with 19 additions and 4 deletions
|
|
@ -1,6 +1,6 @@
|
|||
// Rôle : applique les règles des Expéditions Sokko TCG avec la base (destinations du jour, aperçu, retour, réglages d'administration).
|
||||
// Branché sur CardsService (`service.expeditions`) : il réutilise sa base, son horloge, son hasard, son audit et sa collection.
|
||||
import { randomInt, randomUUID } from "node:crypto";
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { dailyDayKey, nextDailyAt, shiftDayKey } from "./daily.js";
|
||||
import { drawCollectionCard } from "./game-rules.js";
|
||||
import {
|
||||
|
|
@ -42,7 +42,7 @@ export class ExpeditionService {
|
|||
}
|
||||
|
||||
random(max) {
|
||||
return this.cards.random ? this.cards.random(max) : randomInt(max);
|
||||
return this.cards.random(max);
|
||||
}
|
||||
|
||||
// Réglages en vigueur : un champ stocké invalide reprend sa valeur par défaut, pour que le jeu reste jouable.
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// Rôle : applique les règles serveur de propriété, paquets, transferts et distributions Sokko TCG.
|
||||
import { createHash, randomBytes, randomUUID } from "node:crypto";
|
||||
import { createHash, randomBytes, randomInt, randomUUID } from "node:crypto";
|
||||
import { normalizeReward } from "./rewards.js";
|
||||
import { MASS_RECYCLE_RARITIES, planRecycling, spareQuantity, validateShopSetting } from "./stardust.js";
|
||||
import { FULL_ART_FORMAT, buildPublishedCatalog, collectionDrawableEditions, createCatalogIndex, holographicFinishIds, legendaryParentEdition, MATCH_HOLO_PALETTE_ID, mythicEditionId, publicCatalog, validateRarityWeights } from "./catalog.js";
|
||||
|
|
@ -59,7 +59,8 @@ export class CardsService {
|
|||
// Catalogue versionné préparé par loadCardsCatalog / prepareVersionedCatalog (finitions générées, sans mythiques).
|
||||
this.versionedCatalog = catalog;
|
||||
this.now = now;
|
||||
this.random = random;
|
||||
// Tirage d'un entier de 0 à max − 1. Sans source fournie (le serveur), le hasard cryptographique, comme les paquets.
|
||||
this.random = random ?? ((max) => randomInt(max));
|
||||
this.reloadCatalog();
|
||||
this.expeditions = new ExpeditionService(this, destinations || loadExpeditionDestinations(DEFAULT_DESTINATIONS_PATH, catalog), alerts);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -690,6 +690,20 @@ test("cards level up with Éclats or a duplicate, gain field experience and stro
|
|||
assert.equal(database.db.prepare("SELECT COUNT(*) AS count FROM card_progress WHERE player_id = ?").get(player.id).count, 0);
|
||||
});
|
||||
|
||||
test("a pack that draws a destination card already owned replaces it, also without an injected random source", () => {
|
||||
// Le serveur crée le service sans source de hasard : le remplacement d'une carte de destination déjà possédée doit tout de même tirer.
|
||||
const database = new CardsDatabase(":memory:");
|
||||
const service = new CardsService({ database, catalog: baseCatalog, now: () => Date.parse("2026-11-15T09:00:00Z") });
|
||||
const player = service.upsertPlayer({ discordId: "destination-owner", displayName: "Player" });
|
||||
const [destination] = destinationEditions;
|
||||
database.transaction(() => service.addCard(player.id, destination));
|
||||
const [replaced] = service.uniqueDestinationCards(player.id, [destination]);
|
||||
const edition = published.editions.find((item) => item.id === replaced);
|
||||
assert.notEqual(replaced, destination);
|
||||
assert.equal(edition.rarity, published.editions.find((item) => item.id === destination).rarity);
|
||||
database.close();
|
||||
});
|
||||
|
||||
test("a card at an awakening tier awakens with its own duplicate or duplicates of its collection and rarity, never with Éclats", () => {
|
||||
const { service, player, open, rares, database } = expeditionService();
|
||||
open();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue