diff --git a/.beads/interactions.jsonl b/.beads/interactions.jsonl index bedbd38..1532db0 100644 --- a/.beads/interactions.jsonl +++ b/.beads/interactions.jsonl @@ -363,3 +363,6 @@ {"id":"int-151e0bb31a60207a5d75f1624a62ff5c","kind":"field_change","created_at":"2026-11-16T13:52:04.970910466Z","actor":"Shinuwa","issue_id":"sokko-g-yjr0","extra":{"field":"status","new_value":"closed","old_value":"in_progress","reason":"14 paysages générés, recadrés en 800×359 et branchés (champ image), guide à jour"}} {"id":"int-8d9e443292c148cbf0dbaf676f3f3453","kind":"field_change","created_at":"2026-11-16T14:31:07.79037084Z","actor":"Shinuwa","issue_id":"sokko-g-q2qs.2","extra":{"field":"status","new_value":"closed","old_value":"open","reason":"Destination « Le Cœur du Nuage Cosmique » créée (contenu, paysage, carte rare de la Nébuleuse)"}} {"id":"int-0c2c020967ab6888f956075ee19b028d","kind":"field_change","created_at":"2026-11-16T14:45:13.277051047Z","actor":"Shinuwa","issue_id":"sokko-g-duga","extra":{"field":"status","new_value":"closed","old_value":"in_progress","reason":"Onglets de la Guilde et réglages des Expéditions refondus (commit 4d05d81)"}} +{"id":"int-75660b406b7b2464bc61e2592656fef2","kind":"field_change","created_at":"2026-11-16T14:54:51.283828577Z","actor":"Shinuwa","issue_id":"sokko-g-q2qs.1","extra":{"field":"status","new_value":"closed","old_value":"in_progress","reason":"Type de carte destination (commit 89eee7c)"}} +{"id":"int-fce5ec74633346dda24000b0367ecccd","kind":"field_change","created_at":"2026-11-16T14:55:10.19202341Z","actor":"Shinuwa","issue_id":"sokko-g-q2qs.4","extra":{"field":"status","new_value":"closed","old_value":"open","reason":"Tirage du jour personnel parmi les destinations débloquées"}} +{"id":"int-fce12a00be56979a9c47b9ca6b4d92eb","kind":"field_change","created_at":"2026-11-16T14:55:22.933981509Z","actor":"Shinuwa","issue_id":"sokko-g-q2qs.5","extra":{"field":"status","new_value":"closed","old_value":"open","reason":"Niveaux de 1 au nombre de destinations tirées"}} diff --git a/docs/STORAGE_SCHEMA.md b/docs/STORAGE_SCHEMA.md index a6e2500..790c1b1 100644 --- a/docs/STORAGE_SCHEMA.md +++ b/docs/STORAGE_SCHEMA.md @@ -123,12 +123,18 @@ Expéditions (migration 8, règles pures dans `services/cards/expedition-rules.j bornes). À la lecture, un champ absent ou invalide reprend sa valeur par défaut (`DEFAULT_EXPEDITION_SETTINGS`) : une valeur ajoutée plus tard ne demande pas de migration. Les Expéditions sont fermées (`enabled: false`) jusqu'à ce qu'un administrateur les ouvre. -- `expedition_days(day, draw_json, created_at)` : destinations du jour de Paris, tirées au premier - appel (identifiant, indice de la condition, indices de deux dangers, niveau de difficulté). Un niveau - de chaque est réparti au hasard entre les destinations ; il donne les étoiles du solo (`solo.minStars` - + niveau) et du groupe (`group.minStars` + niveau). Un tirage plus ancien, sans niveau, prend celui de - sa place. La 5e et la 6e destination tirent un niveau stable (hachage du joueur, du jour et de la - destination), la destination cachée prend le plus haut. Les exigences chiffrées sont +- `expedition_days(day, draw_json, created_at)` : une ligne par jour de Paris, que les expéditions + référencent (`draw_json` vide depuis la migration 14 ; les anciennes lignes gardent le tirage commun). +- `player_expedition_days(player_id, day, draw_json, created_at)` (migration 14) : tirage du jour de chaque + joueur, parmi les destinations visibles et proposées que ses cartes de destination débloquent (une + destination sans carte au catalogue reste ouverte à tous), 4 au plus (`day.destinationsPerDay`). + Chaque entrée garde l'identifiant, l'indice de la condition, les indices de deux dangers et le niveau. + Un niveau de chaque, du plus facile au nombre de destinations tirées (2 destinations : niveaux 1 et 2), + est réparti au hasard ; il donne les étoiles du solo (`solo.minStars` + niveau) et du groupe + (`group.minStars` + niveau). Une carte de destination obtenue dans la journée complète le tirage (il est + refait), une carte donnée retire sa destination. La 5e et la 6e destination tirent un niveau stable + (hachage du joueur, du jour et de la destination), la destination cachée prend le plus haut. Rejoindre + un groupe ne demande pas la carte de sa destination. Les exigences chiffrées sont calculées à la lecture avec les réglages en vigueur, puis figées au départ. - `expeditions(id, mode, day, destination_id, difficulty, duration_ms, creator_id, status, setup_json, result_json, created_at, departs_at, returns_at, completed_at)` : `mode` `solo` ou `group`, diff --git a/services/cards/database.js b/services/cards/database.js index b72699c..95cf76e 100644 --- a/services/cards/database.js +++ b/services/cards/database.js @@ -381,6 +381,17 @@ const MIGRATIONS = [ // Pouvoirs des Carnets des Veilleurs portés par la carte d'une place, figés à l'inscription ou au départ. ` ALTER TABLE expedition_slots ADD COLUMN powers_json TEXT NOT NULL DEFAULT '[]' CHECK (json_valid(powers_json)); + `, + // Tirage du jour personnel : chaque joueur tire ses destinations parmi celles qu'il a débloquées (cartes de destination). + // expedition_days garde une ligne par jour, que les expéditions référencent. + ` + CREATE TABLE player_expedition_days ( + player_id TEXT NOT NULL REFERENCES players(id) ON DELETE CASCADE, + day TEXT NOT NULL, + draw_json TEXT NOT NULL CHECK (json_valid(draw_json)), + created_at INTEGER NOT NULL, + PRIMARY KEY (player_id, day) + ) STRICT; ` ]; diff --git a/services/cards/expedition-items.js b/services/cards/expedition-items.js index 5fa1200..982f8fa 100644 --- a/services/cards/expedition-items.js +++ b/services/cards/expedition-items.js @@ -40,7 +40,7 @@ export const itemMethods = { // Destinations jouables du joueur : celles du jour, puis ses destinations bonus. À appeler dans une transaction. playerEntries(playerId, day, settings) { - return [...this.ensureDay(day, settings), ...this.bonusEntries(playerId, day, settings)]; + return [...this.ensureDay(playerId, day, settings), ...this.bonusEntries(playerId, day, settings)]; }, // Ajoute une destination bonus à la journée du joueur, en consommant l'objet correspondant (4 fragments pour une carte au trésor). diff --git a/services/cards/expedition-rules.js b/services/cards/expedition-rules.js index aaabf0a..69488fc 100644 --- a/services/cards/expedition-rules.js +++ b/services/cards/expedition-rules.js @@ -266,9 +266,10 @@ export function bonusLevel(key, settings) { return hash % levelCount(settings); } -export function drawExpeditionDay(destinations, settings, recentIds, random) { +// Tirage du jour d'un joueur : parmi les destinations visibles et proposées, limitées à `allowedIds` (ses destinations débloquées). +export function drawExpeditionDay(destinations, settings, recentIds, random, allowedIds = null) { const candidates = destinations - .filter((destination) => !destination.hidden) + .filter((destination) => !destination.hidden && (!allowedIds || allowedIds.has(destination.id))) .map((destination) => ({ destination, ...(settings.destinations[destination.id] || { active: true, weight: 1 }) })) .filter((entry) => entry.active && entry.weight > 0); const count = Math.min(settings.day.destinationsPerDay, candidates.length); @@ -281,8 +282,9 @@ export function drawExpeditionDay(destinations, settings, recentIds, random) { picked.push(entry.destination); pool = pool.filter((item) => item !== entry); } - // Un niveau de chaque, répartis au hasard entre les destinations ; au-delà du nombre de niveaux, la suite recommence. - const levels = Array.from({ length: levelCount(settings) }, (_, index) => index); + // Un niveau de chaque, du plus facile au nombre de destinations tirées (2 destinations : niveaux 1 et 2), répartis au hasard ; + // au-delà du nombre de niveaux, la suite recommence. + const levels = Array.from({ length: Math.max(1, Math.min(levelCount(settings), picked.length)) }, (_, index) => index); for (let index = levels.length - 1; index > 0; index -= 1) { const other = random(index + 1); [levels[index], levels[other]] = [levels[other], levels[index]]; diff --git a/services/cards/expedition-service.js b/services/cards/expedition-service.js index 0aa13ea..24cd029 100644 --- a/services/cards/expedition-service.js +++ b/services/cards/expedition-service.js @@ -79,25 +79,51 @@ export class ExpeditionService { }; } - // Destinations du jour, tirées au premier appel du jour de Paris. À appeler dans une transaction. - ensureDay(day, settings) { - const stored = () => this.db.prepare("SELECT draw_json FROM expedition_days WHERE day = ?").get(day); - if (!stored()) { - const recentDays = settings.day.avoidRepeatDays ? this.db.prepare("SELECT draw_json FROM expedition_days WHERE day >= ? AND day < ?").all(shiftDayKey(day, -settings.day.avoidRepeatDays), day) : []; + // Destinations débloquées d'un joueur : les visibles dont il possède la carte de destination. Une destination qui n'a pas + // encore de carte dans le catalogue reste ouverte à tous. + unlockedDestinationIds(playerId) { + const cardOf = new Map(this.cards.catalog.cards.filter((card) => card.kind === "destination").map((card) => [card.destinationId, card.id])); + const cardOfEdition = new Map(this.cards.catalog.editions.map((edition) => [edition.id, edition.cardId])); + const owned = new Set(this.db.prepare("SELECT edition_id FROM collection_cards WHERE player_id = ?").all(playerId).map((row) => cardOfEdition.get(row.edition_id))); + return new Set(this.destinations + .filter((destination) => !destination.hidden && (!cardOf.has(destination.id) || owned.has(cardOf.get(destination.id)))) + .map((destination) => destination.id)); + } + + // Destinations du jour d'un joueur, tirées parmi celles qu'il a débloquées (4 au plus, moins s'il en a moins), avec un niveau + // de chaque. Une carte de destination obtenue dans la journée complète le tirage, et une carte donnée retire sa destination. + // À appeler dans une transaction. + ensureDay(playerId, day, settings) { + // Les expéditions référencent le jour : sa ligne existe dès le premier tirage. + this.db.prepare("INSERT OR IGNORE INTO expedition_days(day, draw_json, created_at) VALUES (?, '[]', ?)").run(day, this.now()); + const unlocked = this.unlockedDestinationIds(playerId); + const proposed = (destination) => { + const setting = settings.destinations[destination.id] || { active: true, weight: 1 }; + return unlocked.has(destination.id) && setting.active && setting.weight > 0; + }; + const target = Math.min(settings.day.destinationsPerDay, this.destinations.filter(proposed).length); + const read = () => this.db.prepare("SELECT draw_json FROM player_expedition_days WHERE player_id = ? AND day = ?").get(playerId, day); + const playable = (row) => JSON.parse(row.draw_json).filter((entry) => unlocked.has(entry.destinationId)); + let stored = read(); + if (!stored || playable(stored).length < target) { + const recentDays = settings.day.avoidRepeatDays + ? this.db.prepare("SELECT draw_json FROM player_expedition_days WHERE player_id = ? AND day >= ? AND day < ?").all(playerId, shiftDayKey(day, -settings.day.avoidRepeatDays), day) + : []; const recent = recentDays.flatMap((row) => JSON.parse(row.draw_json).map((entry) => entry.destinationId)); - const draw = drawExpeditionDay(this.destinations, settings, recent, (max) => this.random(max)); - if (!draw.length) fail(409, "EXPEDITIONS_UNAVAILABLE", "Aucune destination n’est ouverte aujourd’hui."); - this.db.prepare("INSERT INTO expedition_days(day, draw_json, created_at) VALUES (?, ?, ?)").run(day, JSON.stringify(draw), this.now()); + const draw = drawExpeditionDay(this.destinations, settings, recent, (max) => this.random(max), unlocked); + this.db.prepare(`INSERT INTO player_expedition_days(player_id, day, draw_json, created_at) VALUES (?, ?, ?, ?) + ON CONFLICT(player_id, day) DO UPDATE SET draw_json = excluded.draw_json`).run(playerId, day, JSON.stringify(draw), this.now()); + stored = read(); } // Une destination retirée du contenu après le tirage disparaît simplement de la liste du jour. const levels = levelCount(settings); - return JSON.parse(stored().draw_json).map((draw, index) => resolveDayEntry(this.destinations, draw, index % levels)).filter(Boolean); + return playable(stored).map((draw, index) => resolveDayEntry(this.destinations, draw, index % levels)).filter(Boolean); } - // Destinations du jour ; avec `playerId`, ses destinations bonus en plus. - today(settings, playerId = null) { + // Destinations du jour du joueur, ses destinations bonus comprises. + today(settings, playerId) { const day = dailyDayKey(this.now()); - return { day, entries: this.cards.database.transaction(() => (playerId ? this.playerEntries(playerId, day, settings) : this.ensureDay(day, settings))) }; + return { day, entries: this.cards.database.transaction(() => this.playerEntries(playerId, day, settings)) }; } // Éditions occupées : celles d'un groupe en formation ou d'une expédition en route dont le butin n'a pas encore été récupéré. @@ -384,7 +410,9 @@ export class ExpeditionService { // Fermées : le joueur peut encore récupérer le butin de ses expéditions, mais aucune destination n'est tirée. if (!settings.enabled) return { ...base, day: dailyDayKey(now), destinations: [], cards: [] }; const { day, entries } = this.today(settings, playerId); - return { ...base, day, destinations: entries.map((entry) => this.destinationView(entry, settings)), cards: this.eligibleCards(playerId, settings) }; + // Progression : destinations débloquées par les cartes de destination, sur toutes les destinations visibles. + const unlocked = { count: this.unlockedDestinationIds(playerId).size, total: this.destinations.filter((destination) => !destination.hidden).length }; + return { ...base, day, unlocked, destinations: entries.map((entry) => this.destinationView(entry, settings)), cards: this.eligibleCards(playerId, settings) }; } claim(playerId, expeditionId) { diff --git a/tests/helpers/data-validation.mjs b/tests/helpers/data-validation.mjs index d864f5b..37eb4f1 100644 --- a/tests/helpers/data-validation.mjs +++ b/tests/helpers/data-validation.mjs @@ -381,6 +381,7 @@ export function validateSiteContent(site) { "cards.expeditions.nextDay", "cards.expeditions.noDestination", "cards.expeditions.destinationsTitle", + "cards.expeditions.unlockedDestinations", "cards.expeditions.difficultyTitle", "cards.expeditions.starsLabel", "cards.expeditions.durationLabel", diff --git a/tests/nebula-cards-expedition-service.test.mjs b/tests/nebula-cards-expedition-service.test.mjs index 1977e0f..77a7e7b 100644 --- a/tests/nebula-cards-expedition-service.test.mjs +++ b/tests/nebula-cards-expedition-service.test.mjs @@ -55,10 +55,38 @@ test("expeditions stay closed until an administrator opens them", () => { assert.equal(view.destinations.find((item) => item.soloStar === 4).stars[4].dangers.length, 1); assert.equal(view.destinations.find((item) => item.soloStar === 2).stars[2].condition, null); assert.equal(view.cards.length, 4); - // Le tirage du jour est commun à tous et gardé en base. + // Le tirage du jour du joueur est gardé en base. assert.deepEqual(service.expeditions.getExpeditions(player.id).destinations.map((item) => item.id), view.destinations.map((item) => item.id)); }); +// Cartes de destination : on ne tire que les destinations débloquées (une destination sans carte au catalogue reste ouverte), +// avec un niveau de chaque jusqu'au nombre de destinations tirées ; une carte obtenue dans la journée complète le tirage. +test("each player draws the day among the destinations their cards unlock", () => { + const { service, player, open, database } = expeditionService(); + const other = service.upsertPlayer({ discordId: "expedition-other", displayName: "Other" }); + const cloud = published.cards.find((card) => card.kind === "destination" && card.destinationId === "cosmic-cloud-heart"); + const cloudEdition = published.editions.find((edition) => edition.cardId === cloud.id).id; + assert.equal(service.expeditions.unlockedDestinationIds(player.id).has("cosmic-cloud-heart"), false); + assert.equal(service.expeditions.unlockedDestinationIds(player.id).has("light-currents"), true); + assert.equal(service.expeditions.unlockedDestinationIds(player.id).has("crimson-passage"), false); + // Seules trois destinations restent proposées : les Courants, le Grand Vide et le Cœur du Nuage. + const kept = new Set(["light-currents", "great-void", "cosmic-cloud-heart"]); + open({ destinations: Object.fromEntries(Object.entries(service.expeditions.settings.destinations).map(([id, value]) => [id, { ...value, active: kept.has(id) }])) }); + const before = service.expeditions.getExpeditions(player.id).destinations; + assert.deepEqual(before.map((item) => item.id).sort(), ["great-void", "light-currents"]); + assert.deepEqual(before.map((item) => item.level).sort(), [0, 1]); + assert.deepEqual(before.map((item) => item.soloStar).sort(), [1, 2]); + // Sa carte du Cœur du Nuage complète le tirage du jour ; l'autre joueur, sans la carte, ne la voit pas. + database.transaction(() => service.addCard(player.id, cloudEdition)); + const after = service.expeditions.getExpeditions(player.id).destinations; + assert.deepEqual(after.map((item) => item.id).sort(), ["cosmic-cloud-heart", "great-void", "light-currents"]); + assert.deepEqual(after.map((item) => item.level).sort(), [0, 1, 2]); + assert.deepEqual(service.expeditions.getExpeditions(other.id).destinations.map((item) => item.id).sort(), ["great-void", "light-currents"]); + // Une destination qui n'est pas dans son tirage ne se lance pas. + const view = service.expeditions.getExpeditions(other.id); + assert.throws(() => service.expeditions.preview(other.id, { day: view.day, destinationId: "cosmic-cloud-heart", durationHours: 2, slots: [] }), (error) => error.code === "EXPEDITION_INVALID"); +}); + test("a solo expedition freezes its team, hides its result until it returns and pays once", () => { const { clock, service, player, open, rares, database } = expeditionService(); open(); diff --git a/tests/nebula-cards-expeditions.test.mjs b/tests/nebula-cards-expeditions.test.mjs index 00f2d64..35e06ed 100644 --- a/tests/nebula-cards-expeditions.test.mjs +++ b/tests/nebula-cards-expeditions.test.mjs @@ -232,6 +232,11 @@ test("each daily destination draws a difficulty level, one of each", () => { for (const random of [() => 0, (max) => max - 1, (max) => Math.floor(max / 2)]) { assert.deepEqual(drawExpeditionDay(destinations, settings, [], random).map((entry) => entry.level).sort(), [0, 1, 2, 3]); } + // Limité aux destinations débloquées : avec deux destinations, seulement les deux premiers niveaux. + const two = drawExpeditionDay(destinations, settings, [], (max) => max - 1, new Set(["light-currents", "great-void"])); + assert.deepEqual(two.map((entry) => entry.destinationId).sort(), ["great-void", "light-currents"]); + assert.deepEqual(two.map((entry) => entry.level).sort(), [0, 1]); + assert.deepEqual(drawExpeditionDay(destinations, settings, [], () => 0, new Set()), []); const six = drawExpeditionDay(destinations, { ...settings, day: { ...settings.day, destinationsPerDay: 6 } }, [], () => 0).map((entry) => entry.level); assert.deepEqual(six.slice(4), six.slice(0, 2)); // Une destination bonus garde son niveau toute la journée ; un tirage d'avant les niveaux prend celui de sa place. diff --git a/website/public/data/site.json b/website/public/data/site.json index b847b51..1793d10 100644 --- a/website/public/data/site.json +++ b/website/public/data/site.json @@ -269,6 +269,7 @@ "nextDay": "Nouvelles destinations dans {time}.", "noDestination": "Aucune destination n’est proposée aujourd’hui.", "destinationsTitle": "1. Destination du jour", + "unlockedDestinations": "{count} destinations débloquées sur {total}. Les autres s’ouvrent avec leur carte de destination.", "difficultyTitle": "2. Durée et exigences", "starsLabel": "Difficulté : {stars}", "durationLabel": "Durée", diff --git a/website/src/features/cards/ExpeditionPlanner.jsx b/website/src/features/cards/ExpeditionPlanner.jsx index 1147d79..bcb725e 100644 --- a/website/src/features/cards/ExpeditionPlanner.jsx +++ b/website/src/features/cards/ExpeditionPlanner.jsx @@ -116,6 +116,7 @@ export function ExpeditionPlanner({ catalog, view, mode = "solo", content, busy, return

{content.destinationsTitle}

+ {view.unlocked && view.unlocked.count < view.unlocked.total &&

{fillTemplate(content.unlockedDestinations, view.unlocked)}

}
{view.destinations.map((item) => { return