Add group Expeditions with a Guild board to Sokko TCG
- A player opens a group with one card and a chosen role; others join from the board with a free role, and the creator launches it once enough players are in. - At departure the Veilleur de la Guilde holds empty places without a role, each member rolls their own loot multiplied by the number of players, and distinct collections add a cohesion bonus. - An unlaunched group departs on its own at the end of recruitment with enough players, or dissolves and tells its members; leaving, dissolving and deleted accounts free cards or forfeit shares. - The Guild tile flags joinable groups; Administration › Guilde tunes group places, players, stars, recruitment, loot multipliers, keeper stats, cohesion and the score bonus cap. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
8bb1d53d70
commit
6b7605d04e
24 changed files with 858 additions and 99 deletions
|
|
@ -255,6 +255,40 @@ export function validateSiteContent(site) {
|
|||
"cards.guild.expeditionsClaim",
|
||||
"cards.guild.expeditionsOpen",
|
||||
"cards.packs.giftFromExpedition",
|
||||
"cards.guild.expeditionsGroups",
|
||||
"cards.guild.expeditionsForming",
|
||||
"cards.expeditions.modeLabel",
|
||||
"cards.expeditions.modeSolo",
|
||||
"cards.expeditions.modeGroup",
|
||||
"cards.expeditions.groupsTitle",
|
||||
"cards.expeditions.groupsEmpty",
|
||||
"cards.expeditions.groupMeta",
|
||||
"cards.expeditions.groupDeadline",
|
||||
"cards.expeditions.groupMembers",
|
||||
"cards.expeditions.groupFreeRole",
|
||||
"cards.expeditions.groupKeeper",
|
||||
"cards.expeditions.groupProjected",
|
||||
"cards.expeditions.cohesion",
|
||||
"cards.expeditions.lootBonus",
|
||||
"cards.expeditions.join",
|
||||
"cards.expeditions.joinRole",
|
||||
"cards.expeditions.joinConfirm",
|
||||
"cards.expeditions.cancel",
|
||||
"cards.expeditions.leave",
|
||||
"cards.expeditions.dissolve",
|
||||
"cards.expeditions.depart",
|
||||
"cards.expeditions.departWait",
|
||||
"cards.expeditions.groupLimit",
|
||||
"cards.expeditions.groupTeamHelp",
|
||||
"cards.expeditions.groupPreviewNote",
|
||||
"cards.expeditions.groupStart",
|
||||
"cards.expeditions.groupOpened",
|
||||
"cards.expeditions.joined",
|
||||
"cards.expeditions.left",
|
||||
"cards.expeditions.departed",
|
||||
"cards.expeditions.reportPlayers",
|
||||
"cards.expeditions.keeper",
|
||||
"cards.expeditions.you",
|
||||
"cards.expeditions.eyebrow",
|
||||
"cards.expeditions.title",
|
||||
"cards.expeditions.intro",
|
||||
|
|
|
|||
|
|
@ -9,6 +9,9 @@ import { buildPublishedCatalog, prepareVersionedCatalog } from "../services/card
|
|||
import { INITIAL_COLLECTION_STATES, INITIAL_DROP_RATES } from "../services/cards/admin-seed.js";
|
||||
import { CardsDatabase } from "../services/cards/database.js";
|
||||
import { CardsService } from "../services/cards/service.js";
|
||||
import { DEFAULT_EXPEDITION_SETTINGS } from "../services/cards/expedition-settings.js";
|
||||
|
||||
const DEFAULT_GROUP = DEFAULT_EXPEDITION_SETTINGS.group;
|
||||
|
||||
const baseCatalog = prepareVersionedCatalog(JSON.parse(await readFile("website/public/data/cards/catalog.json", "utf8")));
|
||||
const published = buildPublishedCatalog(baseCatalog, { collectionStates: INITIAL_COLLECTION_STATES, dropRates: INITIAL_DROP_RATES });
|
||||
|
|
@ -238,3 +241,159 @@ test("the expeditions API requires a session, CSRF protection, an administrator
|
|||
const cancelled = await call(handler, { method: "POST", path: `/api/cards/admin/expeditions/${started.json.expedition.id}/cancel`, headers });
|
||||
assert.equal(cancelled.status, 200);
|
||||
});
|
||||
|
||||
// Groupe : deux joueurs de plus, avec chacun des cartes rares de collections différentes (Nébuleuse, Arcade des Rêves).
|
||||
function groupService(options) {
|
||||
const context = expeditionService(options);
|
||||
const { service, database } = context;
|
||||
const second = service.upsertPlayer({ discordId: "expedition-second", displayName: "Second" });
|
||||
const third = service.upsertPlayer({ discordId: "expedition-third", displayName: "Third" });
|
||||
const arcade = editionsOf("rare", "dream-arcade");
|
||||
database.transaction(() => {
|
||||
arcade.slice(0, 2).forEach((editionId) => service.addCard(second.id, editionId));
|
||||
context.rares.slice(5, 7).forEach((editionId) => service.addCard(third.id, editionId));
|
||||
});
|
||||
return { ...context, second, third, arcade };
|
||||
}
|
||||
|
||||
const groupBody = (view, editionId, role, changes = {}) => ({ mode: "group", day: view.day, destinationId: view.destinations[0].id, difficulty: 2, durationHours: 2, editionId, role, ...changes });
|
||||
|
||||
test("a group opens on the Guild board, fills its roles and leaves when its creator launches it", () => {
|
||||
const { clock, service, player, second, third, open, rares, arcade, database } = groupService();
|
||||
open();
|
||||
const view = service.expeditions.getExpeditions(player.id);
|
||||
assert.deepEqual(view.group.stars, { min: 2, max: 5 });
|
||||
assert.equal(view.destinations[0].groupRoles.length, 4);
|
||||
assert.deepEqual(Object.keys(view.destinations[0].groupStars), ["2", "3", "4", "5"]);
|
||||
const [mainRole, secondRole] = view.destinations[0].groupRoles;
|
||||
// Aperçu du groupe que le joueur ouvrirait : les trois autres places tenues par le Veilleur.
|
||||
const preview = service.expeditions.preview(player.id, groupBody(view, rares[0], mainRole)).preview;
|
||||
assert.equal(preview.requirements.length, 2);
|
||||
assert.throws(() => service.expeditions.createGroup(player.id, groupBody(view, rares[0], mainRole, { difficulty: 1 }), "g0"), (error) => error.code === "EXPEDITION_INVALID");
|
||||
assert.throws(() => service.expeditions.createGroup(player.id, groupBody(view, rares[0], "nothing"), "g0"), (error) => error.code === "EXPEDITION_INVALID");
|
||||
|
||||
const created = service.expeditions.createGroup(player.id, groupBody(view, rares[0], mainRole), "g1");
|
||||
assert.equal(service.expeditions.createGroup(player.id, groupBody(view, rares[0], mainRole), "g1").expeditions.groups.length, 1);
|
||||
const group = created.expeditions.groups[0];
|
||||
assert.equal(group.isCreator, true);
|
||||
assert.equal(group.canDepart, false);
|
||||
assert.deepEqual(group.freeRoles, view.destinations[0].groupRoles.slice(1));
|
||||
assert.equal(created.state.expeditions.busyEditions[0].editionId, rares[0]);
|
||||
// La carte du créateur est occupée : elle ne peut pas partir en solo en même temps.
|
||||
assert.throws(() => service.expeditions.startSolo(player.id, soloBody(view, rares.slice(0, 2)), "solo-busy"), (error) => error.code === "EXPEDITION_CARD_BUSY");
|
||||
|
||||
// Le tableau est visible des autres joueurs, et la Guilde le signale à ceux qui peuvent rejoindre.
|
||||
assert.equal(service.getState(second.id).expeditions.joinableGroups, 1);
|
||||
const board = service.expeditions.getExpeditions(second.id).groups[0];
|
||||
assert.equal(board.canJoin, true);
|
||||
assert.equal(board.creatorName, "Player");
|
||||
assert.throws(() => service.expeditions.joinGroup(second.id, group.id, { editionId: arcade[0], role: mainRole }), (error) => error.code === "EXPEDITION_ROLE_TAKEN");
|
||||
assert.throws(() => service.expeditions.joinGroup(second.id, group.id, { editionId: rares[0], role: secondRole }), (error) => error.code === "CARD_NOT_OWNED");
|
||||
assert.throws(() => service.expeditions.joinGroup(player.id, group.id, { editionId: rares[1], role: secondRole }), (error) => error.code === "EXPEDITION_ALREADY_JOINED");
|
||||
service.expeditions.joinGroup(second.id, group.id, { editionId: arcade[0], role: secondRole });
|
||||
assert.throws(() => service.expeditions.departGroup(second.id, group.id), (error) => error.code === "EXPEDITION_NOT_CREATOR");
|
||||
|
||||
const before = service.expeditions.getExpeditions(player.id).groups[0];
|
||||
assert.equal(before.members.length, 2);
|
||||
assert.equal(before.canDepart, true);
|
||||
// Collections différentes : bonus de cohésion.
|
||||
assert.equal(before.projected.cohesionPct, 10);
|
||||
service.expeditions.departGroup(player.id, group.id);
|
||||
assert.deepEqual(service.expeditions.getExpeditions(third.id).groups, []);
|
||||
const slots = database.db.prepare("SELECT player_id, role FROM expedition_slots WHERE expedition_id = ? ORDER BY position").all(group.id);
|
||||
assert.equal(slots.length, 4);
|
||||
// Le Veilleur tient les deux places vides, sans rôle.
|
||||
assert.deepEqual(slots.filter((slot) => slot.player_id == null).map((slot) => slot.role), [null, null]);
|
||||
assert.throws(() => service.expeditions.joinGroup(third.id, group.id, { editionId: rares[5], role: view.destinations[0].groupRoles[2] }), (error) => error.code === "EXPEDITION_GROUP_DEPARTED");
|
||||
|
||||
clock.now += 2 * HOUR;
|
||||
const first = service.expeditions.claim(player.id, group.id);
|
||||
assert.equal(first.expedition.result.players, 2);
|
||||
assert.equal(first.expedition.result.lootPct, 150);
|
||||
assert.equal(first.expedition.status, "returned");
|
||||
assert.ok(first.state.wallet.eclats > 0);
|
||||
const last = service.expeditions.claim(second.id, group.id);
|
||||
assert.equal(last.expedition.status, "completed");
|
||||
assert.equal(last.state.history.find((entry) => entry.type === "expedition_completed").details.mode, "group");
|
||||
});
|
||||
|
||||
test("an unlaunched group departs alone with enough players at the end of recruitment, or dissolves", () => {
|
||||
const { clock, service, player, second, third, open, rares, arcade } = groupService();
|
||||
open({ group: { ...DEFAULT_GROUP, recruitHours: 1 } });
|
||||
const view = service.expeditions.getExpeditions(player.id);
|
||||
const roles = view.destinations[0].groupRoles;
|
||||
const lonely = service.expeditions.createGroup(third.id, groupBody(view, rares[5], roles[0]), "lonely").expeditions.groups[0];
|
||||
const full = service.expeditions.createGroup(player.id, groupBody(view, rares[0], view.destinations[1].groupRoles[0], { destinationId: view.destinations[1].id }), "full").expeditions.groups.find((group) => group.isCreator);
|
||||
service.expeditions.joinGroup(second.id, full.id, { editionId: arcade[0], role: view.destinations[1].groupRoles[1] });
|
||||
clock.now += HOUR + 1;
|
||||
const state = service.getState(third.id);
|
||||
assert.ok(state.history.some((entry) => entry.type === "expedition_dissolved"));
|
||||
assert.deepEqual(state.expeditions.busyEditions, []);
|
||||
const departed = service.expeditions.getExpeditions(player.id).expeditions.find((expedition) => expedition.id === full.id);
|
||||
assert.equal(departed.status, "running");
|
||||
// Le départ automatique a lieu à la fin de l'inscription, pas à la lecture.
|
||||
assert.equal(departed.departsAt, departed.returnsAt - 2 * HOUR);
|
||||
assert.equal(lonely.id === full.id, false);
|
||||
});
|
||||
|
||||
test("leaving a forming group frees the card, and the creator leaving dissolves it", () => {
|
||||
const { service, player, second, open, rares, arcade } = groupService();
|
||||
open();
|
||||
const view = service.expeditions.getExpeditions(player.id);
|
||||
const roles = view.destinations[0].groupRoles;
|
||||
const group = service.expeditions.createGroup(player.id, groupBody(view, rares[0], roles[0]), "leave").expeditions.groups[0];
|
||||
service.expeditions.joinGroup(second.id, group.id, { editionId: arcade[0], role: roles[1] });
|
||||
service.expeditions.leaveGroup(second.id, group.id);
|
||||
assert.deepEqual(service.getState(second.id).expeditions.busyEditions, []);
|
||||
assert.equal(service.expeditions.getExpeditions(player.id).groups[0].members.length, 1);
|
||||
service.expeditions.joinGroup(second.id, group.id, { editionId: arcade[0], role: roles[1] });
|
||||
service.expeditions.leaveGroup(player.id, group.id);
|
||||
assert.deepEqual(service.expeditions.getExpeditions(second.id).groups, []);
|
||||
assert.ok(service.getState(second.id).history.some((entry) => entry.type === "expedition_dissolved" && entry.details.reason === "creator_left"));
|
||||
assert.ok(!service.getState(player.id).history.some((entry) => entry.type === "expedition_dissolved"));
|
||||
});
|
||||
|
||||
test("a player deleted during a group expedition forfeits their share and the others still claim", () => {
|
||||
const { clock, service, player, second, open, rares, arcade, database } = groupService();
|
||||
open();
|
||||
const view = service.expeditions.getExpeditions(player.id);
|
||||
const roles = view.destinations[0].groupRoles;
|
||||
const group = service.expeditions.createGroup(player.id, groupBody(view, rares[0], roles[0]), "forfeit").expeditions.groups[0];
|
||||
service.expeditions.joinGroup(second.id, group.id, { editionId: arcade[0], role: roles[1] });
|
||||
service.expeditions.departGroup(player.id, group.id);
|
||||
service.deleteAccount(second.id);
|
||||
clock.now += 2 * HOUR;
|
||||
assert.equal(service.expeditions.claim(player.id, group.id).expedition.status, "completed");
|
||||
assert.equal(database.db.prepare("SELECT status FROM expeditions WHERE id = ?").get(group.id).status, "completed");
|
||||
});
|
||||
|
||||
test("the group API opens, joins, leaves and launches through dedicated routes", async (t) => {
|
||||
const handler = createCardsApiHandler({ projectRoot: resolve("."), enabled: true, devAuth: true, databasePath: ":memory:", env: { NODE_ENV: "test" }, random: () => 0 });
|
||||
t.after(() => handler.close());
|
||||
const login = await call(handler, { method: "POST", path: "/api/cards/auth/dev", body: {} });
|
||||
const cookie = login.headers["set-cookie"].split(";")[0];
|
||||
const headers = { cookie, "x-csrf-token": login.json.csrfToken };
|
||||
const { service } = handler;
|
||||
const devId = service.db.prepare("SELECT id FROM players WHERE discord_id = 'dev-admin'").get().id;
|
||||
const other = service.upsertPlayer({ discordId: "api-other", displayName: "Other" });
|
||||
service.database.transaction(() => {
|
||||
service.addCard(devId, editionsOf("rare")[0]);
|
||||
service.addCard(other.id, editionsOf("rare")[1]);
|
||||
});
|
||||
service.expeditions.updateSettings(devId, { ...service.expeditions.settings, enabled: true });
|
||||
const view = (await call(handler, { path: "/api/cards/expeditions", headers: { cookie } })).json;
|
||||
const roles = view.destinations[0].groupRoles;
|
||||
const created = await call(handler, { method: "POST", path: "/api/cards/expeditions", headers: { ...headers, "idempotency-key": "api-group" }, body: groupBody(view, view.cards[0].editionId, roles[0]) });
|
||||
assert.equal(created.status, 201);
|
||||
const groupId = created.json.expeditions.groups[0].id;
|
||||
const tooSmall = await call(handler, { method: "POST", path: `/api/cards/expeditions/${groupId}/depart`, headers });
|
||||
assert.equal(tooSmall.json.error.code, "EXPEDITION_GROUP_TOO_SMALL");
|
||||
service.expeditions.joinGroup(other.id, groupId, { editionId: editionsOf("rare")[1], role: roles[1] });
|
||||
const unknownRole = await call(handler, { method: "POST", path: `/api/cards/expeditions/${groupId}/join`, headers, body: { editionId: view.cards[0].editionId, role: roles[2] } });
|
||||
assert.equal(unknownRole.json.error.code, "EXPEDITION_ALREADY_JOINED");
|
||||
const departed = await call(handler, { method: "POST", path: `/api/cards/expeditions/${groupId}/depart`, headers });
|
||||
assert.equal(departed.status, 200);
|
||||
assert.equal(departed.json.expeditions.expeditions[0].status, "running");
|
||||
const leave = await call(handler, { method: "POST", path: `/api/cards/expeditions/${groupId}/leave`, headers });
|
||||
assert.equal(leave.json.error.code, "EXPEDITION_GROUP_DEPARTED");
|
||||
});
|
||||
|
|
|
|||
|
|
@ -216,6 +216,9 @@ test("the guild shows expeditions when open and flags them once a day or when on
|
|||
assert.equal(expeditionsPending({ ...summary, eligible: 1 }, now), false);
|
||||
assert.equal(expeditionsPending({ ...summary, running: 1, launchedToday: true, nextReturnAt: now + 1000 }, now), false);
|
||||
assert.equal(expeditionsPending({ ...summary, running: 1, launchedToday: true, nextReturnAt: now - 1000 }, now), true);
|
||||
// Un groupe à rejoindre attend le joueur ; son propre groupe en formation ne déclenche pas le rappel quotidien.
|
||||
assert.equal(expeditionsPending({ ...summary, launchedToday: true, joinableGroups: 1 }, now), true);
|
||||
assert.equal(expeditionsPending({ ...summary, forming: 1 }, now), false);
|
||||
// Fermées : la tuile disparaît, sauf tant qu'une expédition du joueur n'est pas terminée.
|
||||
assert.deepEqual(guildQuests({ expeditions: { ...summary, enabled: false } }, now), []);
|
||||
assert.equal(guildQuests({ expeditions: { ...summary, enabled: false, returned: 1 } }, now)[0].pending, true);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue