Simplify joining a Sokko TCG group and let a test player open one locally
Some checks failed
Validate and deploy Sokko G / deploy (push) Blocked by required conditions
Validate and deploy Sokko G / validate (push) Has been cancelled

- On the local dev server, a test player can open a group on one of its destinations, with the 20 s test trip; it departs by itself after 5 minutes, since only the creator may launch it.
- While a player chooses their card to join, the expedition planner is hidden; Cancel brings it back.
- Joining and readying are one button, "Valider et se mettre en prêt", at the bottom right of the loadout frame, also after "Modifier ma préparation", which now sits next to "Quitter l'expédition".
- The redundant "you are ready" block is gone: the member list already shows the Ready badge.
- The card a player sends is called their explorer in the texts about that role.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Shinuwa 2026-11-30 11:22:35 +01:00
parent 82cebd0fd1
commit 8eb7f2e53e
12 changed files with 196 additions and 88 deletions

View file

@ -494,6 +494,11 @@ export function createCardsApiHandler({
json(res, 200, service.expeditions.markStarterSeen(session.player.id));
return true;
}
// Serveur Vite local : un joueur de test ouvre une expédition à rejoindre.
if (req.method === "POST" && url.pathname === "/api/cards/expeditions/test-group") {
json(res, 200, service.expeditions.openTestGroup(session.player.id));
return true;
}
if (req.method === "POST" && url.pathname === "/api/cards/expeditions/reroll") {
json(res, 200, service.expeditions.rerollDestinations(session.player.id));
return true;
@ -508,7 +513,7 @@ export function createCardsApiHandler({
if (action === "join") {
rateLimit(req, "expedition-join", 30);
const body = await readBody(req);
json(res, 200, service.expeditions.joinGroup(session.player.id, expeditionId, { editionId: body.editionId }));
json(res, 200, service.expeditions.joinGroup(session.player.id, expeditionId, { editionId: body.editionId, ready: body.ready === true }));
} else if (action === "join-preview") {
rateLimit(req, "expedition-preview", 120);
const body = await readBody(req);

View file

@ -6,9 +6,14 @@ import { randomUUID } from "node:crypto";
import { dailyDayKey } from "./daily.js";
import {
cardExpeditionData, cohesionPct, MAX_ACTIVE_EXPEDITIONS, dangerCount, editionExpeditionData, evaluateTeam, expectedLoot, groupLootPct, hasCondition,
requirementsFor, rollRequirementFactor, teamPowers, teamSynergy, TEST_TRIP_MS, tierLootPct, travelHours
requirementsFor, rollRequirementFactor, teamPowers, teamSynergy, TEST_DURATION, TEST_TRIP_MS, tierLootPct, travelHours
} from "./expedition-rules.js";
// Serveur Vite local : identifiant Discord des joueurs de test (suivi de leur numéro).
const TEST_PLAYER_PREFIX = "dev-test-player-";
// Serveur Vite local : inscription d'une expédition ouverte par un joueur de test, avant son départ automatique.
const TEST_RECRUIT_MS = 5 * 60_000;
const HOUR_MS = 3_600_000;
function fail(status, code, message) {
@ -189,7 +194,8 @@ export const groupMethods = {
const row = this.formingRow(expeditionId);
const setup = JSON.parse(row.setup_json);
const { card, position } = this.joiningCard(playerId, setup, this.memberSlots(row.id), body, settings);
this.insertMember(row.id, playerId, card, position, this.now());
// `ready` : le joueur valide sa carte en rejoignant ; il peut ensuite modifier sa préparation jusqu'au départ.
this.insertMember(row.id, playerId, card, position, this.now(), { ready: body?.ready === true });
});
return { expeditions: this.getExpeditions(playerId), state: this.cards.getState(playerId) };
},
@ -225,25 +231,57 @@ export const groupMethods = {
},
// Serveur Vite local (`devPerks`) : un joueur de test rejoint une expédition ouverte au groupe avec une de ses cartes, pour essayer
// un groupe depuis un seul navigateur. Un joueur de test ne suit qu'une expédition à la fois : le premier libre est repris, sinon
// un nouveau est créé ; sans carte jouable libre, il reçoit une rare au hasard.
// un groupe depuis un seul navigateur.
addTestPlayer(playerId, expeditionId) {
if (!this.cards.devPerks) fail(404, "NOT_FOUND", "Joueurs de test indisponibles.");
const settings = this.settings;
const members = new Set(this.memberSlots(this.formingRow(expeditionId).id).map((slot) => slot.playerId));
const { tester, cards } = this.freeTestPlayer(settings, members);
this.joinGroup(tester.id, expeditionId, { editionId: cards[this.random(cards.length)].editionId });
return { expeditions: this.getExpeditions(playerId), state: this.cards.getState(playerId) };
},
// Serveur Vite local (`devPerks`) : un joueur de test ouvre une expédition au tableau, sur une destination de son jour et à la durée
// de test, pour essayer de rejoindre un groupe depuis un seul navigateur. Comme personne ne la lance, elle part d'elle-même au bout
// de quelques minutes (départ automatique de fin d'inscription).
openTestGroup(playerId) {
if (!this.cards.devPerks) fail(404, "NOT_FOUND", "Joueurs de test indisponibles.");
const settings = this.settings;
const { tester, cards } = this.freeTestPlayer(settings);
const day = dailyDayKey(this.now());
const entries = this.cards.database.transaction(() => {
// Les destinations se débloquent avec leur carte : le joueur de test reçoit celles qui lui manquent.
const { cards: catalogCards, editions } = this.cards.catalog;
const owned = new Set(this.cards.collectionOf(tester.id).map((entry) => editions.find((item) => item.id === entry.editionId)?.cardId));
for (const card of catalogCards.filter((item) => item.kind === "destination" && !owned.has(item.id))) {
const edition = editions.find((item) => item.cardId === card.id);
if (edition) this.cards.addCard(tester.id, edition.id);
}
return this.playerEntries(tester.id, day, settings);
});
const entry = entries[this.random(entries.length)];
const body = { day, destinationId: entry.destination.id, durationHours: TEST_DURATION, editionId: cards[this.random(cards.length)].editionId };
this.createGroup(tester.id, body, randomUUID());
const row = this.db.prepare("SELECT id, setup_json FROM expeditions WHERE creator_id = ? AND status = 'forming'").get(tester.id);
const setup = { ...JSON.parse(row.setup_json), recruitUntil: this.now() + TEST_RECRUIT_MS };
this.db.prepare("UPDATE expeditions SET setup_json = ? WHERE id = ?").run(JSON.stringify(setup), row.id);
return { expeditions: this.getExpeditions(playerId), state: this.cards.getState(playerId) };
},
// Joueur de test libre : il ne suit qu'une expédition à la fois, et n'est pas dans `excluded` ; le premier libre est repris, sinon un
// nouveau est créé. Sans carte jouable libre, il reçoit une rare au hasard. Renvoie le joueur et ses cartes libres.
freeTestPlayer(settings, excluded = new Set()) {
let tester = null;
for (let index = 1; !tester; index += 1) {
const candidate = this.cards.upsertPlayer({ discordId: `dev-test-player-${index}`, displayName: `Joueur de test ${index}` });
if (!members.has(candidate.id) && this.activeCount(candidate.id) < MAX_ACTIVE_EXPEDITIONS) tester = candidate;
const candidate = this.cards.upsertPlayer({ discordId: `${TEST_PLAYER_PREFIX}${index}`, displayName: `Joueur de test ${index}` });
if (!excluded.has(candidate.id) && this.activeCount(candidate.id) < MAX_ACTIVE_EXPEDITIONS) tester = candidate;
}
const freeCards = () => this.eligibleCards(tester.id, settings).filter((card) => !card.busy);
if (!freeCards().length) {
const rares = this.cards.catalog.editions.filter((edition) => edition.rarity === "rare" && !edition.promotional && editionExpeditionData(this.cards.catalog, edition.id, 0, settings));
this.cards.database.transaction(() => this.cards.addCard(tester.id, rares[this.random(rares.length)].id));
}
const cards = freeCards();
this.joinGroup(tester.id, expeditionId, { editionId: cards[this.random(cards.length)].editionId });
return { expeditions: this.getExpeditions(playerId), state: this.cards.getState(playerId) };
return { tester, cards: freeCards() };
},
// Quitter un groupe en formation ; s'il s'agit du créateur, le groupe est dissous.