From a38d4fd02ad75f66d119171d0a43e9476aa9d35d Mon Sep 17 00:00:00 2001 From: Shinuwa Date: Tue, 17 Nov 2026 18:55:29 +0100 Subject: [PATCH] Make one expedition at a time a fixed rule so older stored settings cannot raise it The limit was a setting whose default had moved to one, but settings saved before still allowed two expeditions per player. It is now a game rule: the setting and its admin field are gone, an old stored value has no effect, and the refusal tells the player to claim their current expedition first. Co-Authored-By: Claude Opus 5.5 --- docs/STORAGE_SCHEMA.md | 6 +++--- services/cards/expedition-group.js | 8 ++++---- services/cards/expedition-rules.js | 3 +++ services/cards/expedition-service.js | 4 ++-- services/cards/expedition-settings.js | 6 ++---- tests/nebula-cards-expedition-service.test.mjs | 7 +++++-- .../src/features/cards/admin/expeditionSettingFields.js | 1 - 7 files changed, 19 insertions(+), 16 deletions(-) diff --git a/docs/STORAGE_SCHEMA.md b/docs/STORAGE_SCHEMA.md index f7c992a..ce5b1f3 100644 --- a/docs/STORAGE_SCHEMA.md +++ b/docs/STORAGE_SCHEMA.md @@ -193,9 +193,9 @@ Expéditions (migration 8, règles pures dans `services/cards/expedition-rules.j - `POST /api/cards/expeditions` (`Idempotency-Key`, `{ day, destinationId, durationHours, editionId }` ; une `difficulty` envoyée est ignorée, les étoiles viennent du niveau) ouvre l'expédition au tableau (voir « Ouverture et départ ») : `EXPEDITIONS_CLOSED`, `EXPEDITION_DAY_EXPIRED`, `EXPEDITION_INVALID`, - `EXPEDITION_CARD_INVALID`, `CARD_NOT_OWNED`, `EXPEDITION_CARD_BUSY`, `EXPEDITION_LIMIT` (au plus - `group.maxConcurrent` expéditions ouvertes ou en route par joueur, une par défaut : la préparation revient - quand le butin est récupéré). Avec `departNow: true`, l'expédition part aussitôt, seule, sans alerte + `EXPEDITION_CARD_INVALID`, `CARD_NOT_OWNED`, `EXPEDITION_CARD_BUSY`, `EXPEDITION_LIMIT` (une seule + expédition ouverte, rejointe ou en route par joueur, règle fixe `MAX_ACTIVE_EXPEDITIONS` et non un réglage : + la préparation revient quand le butin est récupéré). Avec `departNow: true`, l'expédition part aussitôt, seule, sans alerte d'ouverture. - `POST /api/cards/expeditions/:id/claim` : idempotent ; `EXPEDITION_NOT_FOUND`, `EXPEDITION_NOT_RETURNED`. Inscrit `expedition_completed` dans l'historique du joueur. diff --git a/services/cards/expedition-group.js b/services/cards/expedition-group.js index 7e4d03d..1edac6e 100644 --- a/services/cards/expedition-group.js +++ b/services/cards/expedition-group.js @@ -4,7 +4,7 @@ import { randomUUID } from "node:crypto"; import { dailyDayKey } from "./daily.js"; import { - cardExpeditionData, cohesionPct, dangerCount, editionExpeditionData, evaluateTeam, expectedLoot, groupLootPct, groupSlots, guildKeeperSlot, hasCondition, + cardExpeditionData, cohesionPct, MAX_ACTIVE_EXPEDITIONS, dangerCount, editionExpeditionData, evaluateTeam, expectedLoot, groupLootPct, groupSlots, guildKeeperSlot, hasCondition, requirementsFor, rollRequirementFactor, teamPowers, teamSynergy, travelHours } from "./expedition-rules.js"; @@ -108,7 +108,7 @@ export const groupMethods = { const day = dailyDayKey(this.now()); const plan = this.prepareGroup(playerId, body, settings, { day, entries: this.playerEntries(playerId, day, settings) }); if (plan.slot.busy) fail(409, "EXPEDITION_CARD_BUSY", "Cette carte est déjà en expédition."); - if (this.activeCount(playerId) >= settings.group.maxConcurrent) fail(409, "EXPEDITION_LIMIT", "Vous participez déjà au nombre maximal d’expéditions."); + if (this.activeCount(playerId) >= MAX_ACTIVE_EXPEDITIONS) fail(409, "EXPEDITION_LIMIT", "Vous avez déjà une expédition en cours : récupérez son butin avant d’en ouvrir ou d’en rejoindre une autre."); const now = this.now(); expeditionId = randomUUID(); this.db.prepare(`INSERT INTO expeditions(id, mode, day, destination_id, difficulty, duration_ms, creator_id, status, setup_json, created_at) @@ -147,7 +147,7 @@ export const groupMethods = { if (members.length >= slotCountOf(setup)) fail(409, "EXPEDITION_GROUP_FULL", "Cette expédition est complète."); const card = this.ownedCard(playerId, body?.editionId, settings); if (card.busy) fail(409, "EXPEDITION_CARD_BUSY", "Cette carte est déjà en expédition."); - if (this.activeCount(playerId) >= settings.group.maxConcurrent) fail(409, "EXPEDITION_LIMIT", "Vous participez déjà au nombre maximal d’expéditions."); + if (this.activeCount(playerId) >= MAX_ACTIVE_EXPEDITIONS) fail(409, "EXPEDITION_LIMIT", "Vous avez déjà une expédition en cours : récupérez son butin avant d’en ouvrir ou d’en rejoindre une autre."); const taken = new Set(members.map((slot) => slot.position)); const position = Array.from({ length: slotCountOf(setup) }, (_, index) => index).find((index) => !taken.has(index)); this.insertMember(row.id, playerId, card, position, this.now()); @@ -270,7 +270,7 @@ export const groupMethods = { // Expéditions que le joueur pourrait rejoindre maintenant (place libre, une carte jouable non occupée, sous sa limite). joinableGroupCount(playerId, settings, busy) { - if (this.activeCount(playerId) >= settings.group.maxConcurrent) return 0; + if (this.activeCount(playerId) >= MAX_ACTIVE_EXPEDITIONS) return 0; const free = this.cards.collectionOf(playerId).some((entry) => !busy.has(entry.editionId) && editionExpeditionData(this.cards.catalog, entry.editionId, 0, settings)); if (!free) return 0; return this.db.prepare("SELECT e.setup_json, (SELECT COUNT(*) FROM expedition_members m WHERE m.expedition_id = e.id) AS members FROM expeditions e WHERE e.status = 'forming' AND NOT EXISTS (SELECT 1 FROM expedition_members m WHERE m.expedition_id = e.id AND m.player_id = ?)") diff --git a/services/cards/expedition-rules.js b/services/cards/expedition-rules.js index ff35b98..21f50ca 100644 --- a/services/cards/expedition-rules.js +++ b/services/cards/expedition-rules.js @@ -9,6 +9,9 @@ export const ROLE_BY_STAT = Object.freeze({ bravoure: "leader", endurance: "guar export const STAT_BY_ROLE = Object.freeze(Object.fromEntries(Object.entries(ROLE_BY_STAT).map(([stat, role]) => [role, stat]))); export const TIER_IDS = Object.freeze(["struggle", "success", "triumph"]); export const MAX_STARS = 5; +// Expéditions qu'un joueur peut avoir à la fois (ouverte, rejointe ou en route, butin pas encore récupéré) : une seule. C'est une +// règle du jeu, pas un réglage : un ancien réglage enregistré ne peut pas la changer. +export const MAX_ACTIVE_EXPEDITIONS = 1; // Nombre de stats exigées selon les étoiles : la 4e étoile ajoute un danger, la 5e la dernière stat et un second danger. const REQUIRED_STATS = Object.freeze([1, 2, 3, 3, 4]); const DANGER_COUNT = Object.freeze([0, 0, 0, 1, 2]); diff --git a/services/cards/expedition-service.js b/services/cards/expedition-service.js index 27c0f0c..95bccf4 100644 --- a/services/cards/expedition-service.js +++ b/services/cards/expedition-service.js @@ -4,7 +4,7 @@ import { randomInt, randomUUID } from "node:crypto"; import { dailyDayKey, nextDailyAt, shiftDayKey } from "./daily.js"; import { drawCollectionCard } from "./game-rules.js"; import { - dangerCount, drawExpeditionDay, editionExpeditionData, hasCondition, MAX_STARS, requirementsFor, resolveDayEntry, + dangerCount, drawExpeditionDay, MAX_ACTIVE_EXPEDITIONS, editionExpeditionData, hasCondition, MAX_STARS, requirementsFor, resolveDayEntry, HIDDEN_ITEMS, ITEM_IDS, levelCount, pickItems, starsForLevel, rollLoot, roundStochastic, travelHours } from "./expedition-rules.js"; import { @@ -407,7 +407,7 @@ export class ExpeditionService { specialty: { ...settings.specialty }, // Valeurs des pouvoirs des communes, pour en détailler les effets exacts au survol. powers: { ...settings.powers }, - group: { slots: settings.group.slots, limit: settings.group.maxConcurrent, active: this.activeCount(playerId), recruitHours: settings.group.recruitHours, lootPct: settings.group.lootPct }, + group: { slots: settings.group.slots, limit: MAX_ACTIVE_EXPEDITIONS, active: this.activeCount(playerId), recruitHours: settings.group.recruitHours, lootPct: settings.group.lootPct }, expeditions: this.playerExpeditionIds(playerId).map((id) => this.expeditionView(id, playerId)), journal: this.journalIds(playerId).map((id) => this.expeditionView(id, playerId)), groups: this.boardView(playerId, settings), diff --git a/services/cards/expedition-settings.js b/services/cards/expedition-settings.js index b590dfd..fb9b8f4 100644 --- a/services/cards/expedition-settings.js +++ b/services/cards/expedition-settings.js @@ -13,10 +13,9 @@ export const DEFAULT_EXPEDITION_SETTINGS = Object.freeze({ stars: { min: 1, max: 5 }, // Une expédition s'ouvre avec une carte et part quand son créateur le décide (tout de suite pour un solo), au plus tard à la fin de // l'inscription : seule, c'est un solo (une place) ; avec d'autres joueurs, c'est un groupe. Groupe : places (le Veilleur de la Guilde - // tient celles restées vides, sans rôle), expéditions ouvertes ou en route à la fois par joueur (une seule : la préparation revient - // quand le butin est récupéré), période d'inscription, multiplicateur de butin selon le nombre de + // tient celles restées vides), période d'inscription, multiplicateur de butin selon le nombre de // joueurs (2, 3, 4), stats du Veilleur et bonus de cohésion (collections toutes différentes). - group: { slots: 4, maxConcurrent: 1, recruitHours: 12, lootPct: [150, 175, 200], npcStat: 8, cohesionPct: 10 }, + group: { slots: 4, recruitHours: 12, lootPct: [150, 175, 200], npcStat: 8, cohesionPct: 10 }, power: { rare: 40, epic: 55, legendary: 70, mythic: 85, perLevel: 5, cap: 100 }, // Améliorations : coût d'un niveau en Éclats = costFactor × (Puissance actuelle − costOffset), niveaux donnés par un doublon, // expérience de terrain par retour d'expédition (% d'un niveau), taux du pont depuis la poussière (poussières pour 1 Éclat) @@ -88,7 +87,6 @@ export const EXPEDITION_SETTINGS_SCHEMA = Object.freeze([ int("stars.min", 1, 5), int("stars.max", 1, 5), int("group.slots", 2, 4), - int("group.maxConcurrent", 1, 6), int("group.recruitHours", 1, 48), ints("group.lootPct", 3, 0, 1000), int("group.npcStat", 0, 100), diff --git a/tests/nebula-cards-expedition-service.test.mjs b/tests/nebula-cards-expedition-service.test.mjs index 6589518..da3b0ff 100644 --- a/tests/nebula-cards-expedition-service.test.mjs +++ b/tests/nebula-cards-expedition-service.test.mjs @@ -149,7 +149,7 @@ test("players receive a starter destination card, then find more on expeditions test("an expedition launched alone is a solo: one card, its result hidden until it returns, paid once", () => { const { clock, service, player, open, rares, database } = expeditionService(); - open({ group: { ...DEFAULT_GROUP, maxConcurrent: 1 } }); + open(); const view = service.expeditions.getExpeditions(player.id); // Une difficulté envoyée par un ancien client est ignorée : les étoiles sont celles de la destination. const body = soloBody(view, rares[0], { difficulty: 4, durationHours: 6 }); @@ -215,8 +215,11 @@ test("an expedition launched alone is a solo: one card, its result hidden until // Parcours du joueur : la carte de destination offerte se présente une fois ; « Partir seul maintenant » ouvre et lance l'expédition // d'un coup, sans alerte d'ouverture ; une seule expédition à la fois ; une fois le butin récupéré, elle passe au Journal. test("a player sees the offered destination card once, leaves alone at once, one expedition at a time, then finds it in the Journal", () => { - const { clock, service, player, open, rares } = expeditionService({ allDestinations: false }); + const { clock, service, player, open, rares, database } = expeditionService({ allDestinations: false }); open(); + // Une ancienne limite enregistrée dans les réglages (avant qu'elle devienne une règle fixe) n'a plus d'effet. + const stored = JSON.parse(database.db.prepare("SELECT settings_json FROM expedition_settings").get().settings_json); + database.db.prepare("UPDATE expedition_settings SET settings_json = ?").run(JSON.stringify({ ...stored, group: { ...stored.group, maxConcurrent: 3 } })); const first = service.expeditions.getExpeditions(player.id); assert.equal(first.starterCard, "light-currents-standard"); assert.equal(service.expeditions.getExpeditions(player.id).starterCard, "light-currents-standard"); diff --git a/website/src/features/cards/admin/expeditionSettingFields.js b/website/src/features/cards/admin/expeditionSettingFields.js index 78ee6c6..5e0209a 100644 --- a/website/src/features/cards/admin/expeditionSettingFields.js +++ b/website/src/features/cards/admin/expeditionSettingFields.js @@ -56,7 +56,6 @@ export const EXPEDITION_SETTING_GROUPS = [ help: "Une expédition s’ouvre avec une carte. Son créateur la lance quand il veut ; à la fin de l’inscription, elle part d’elle-même. Seule, c’est un solo : une place, le butin d’un joueur. Avec d’autres joueurs, c’est un groupe : le Veilleur de la Guilde tient les places vides et le butin de chacun est multiplié.", fields: [ { path: "group.slots", label: "Places par groupe" }, - { path: "group.maxConcurrent", label: "Expéditions en même temps par joueur" }, { path: "group.recruitHours", label: "Période d’inscription maximale", unit: "h" }, { path: "group.lootPct", label: "Multiplicateur de butin selon les joueurs", unit: "%", items: ["2 joueurs", "3 joueurs", "4 joueurs"] }, { path: "group.npcStat", label: "Stats du Veilleur de la Guilde (chacune)" },