sokko-g/services/cards/expedition-content.js
Shinuwa 8bb1d53d70 Add solo Expeditions, the second Guilde des Veilleurs quest of Sokko TCG
- Every catalog card carries expedition tags and every collection a stat profile, validated at load; twelve destinations live server-side so hidden ones stay secret.
- Pure rules compute card power, per-slot requirements, roles, dangers, the long-trip malus, the score (one more star never raises it) and loot proportional to the chosen duration.
- A simulator script and a balance test guard the design thresholds; agent docs and a new-card skill explain how to tag new cards.
- Migration 8 adds Éclats d'étoile, expedition settings stored as one validated JSON, daily destinations, expeditions, members and slots, and rebuilds gift_packs so a pack can come from an expedition.
- Players launch a solo expedition from the Guild, see an exact preview, and claim their loot when it returns; the card sheet shows cards away on an expedition.
- Administration › Guilde tunes every value with server-side bounds, toggles destinations and cancels running expeditions; expeditions stay closed until an administrator opens them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 14:29:05 +01:00

72 lines
5.1 KiB
JavaScript

// Rôle : charge et valide les destinations des Expéditions Sokko TCG, définies dans un fichier du serveur pour garder secrètes les destinations cachées.
import { readFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
import { cardExpeditionData, isExpeditionCard, STAT_IDS } from "./expedition-rules.js";
export const DEFAULT_DESTINATIONS_PATH = fileURLToPath(new URL("./content/expedition-destinations.json", import.meta.url));
const ID_PATTERN = /^[a-z0-9-]+$/;
// Une condition ou un danger doit pouvoir être rempli par au moins ce nombre de cartes rare ou mieux.
export const MIN_MATCHING_CARDS = 3;
function fail(destination, message) {
throw new TypeError(`Expedition destination ${destination?.id ?? "?"}: ${message}`);
}
// Cartes rare ou mieux qui portent une des étiquettes, ou qui appartiennent à la collection.
function matchingCards(catalog, { tags = [], collectionId = null }) {
return catalog.cards.filter((card) => {
if (!isExpeditionCard(catalog, card.id)) return false;
const data = cardExpeditionData(catalog, card.id);
return collectionId ? data.collectionId === collectionId : data.tags.some((tag) => tags.includes(tag));
});
}
export function validateExpeditionDestinations(destinations, catalog) {
if (!Array.isArray(destinations) || !destinations.length) throw new TypeError("Expedition destinations must be a non-empty array.");
const tagIds = new Set(catalog.expeditionTags.map((tag) => tag.id));
const collectionIds = new Set(catalog.collections.map((collection) => collection.id));
const cardIds = new Set(catalog.cards.map((card) => card.id));
const ids = new Set();
for (const destination of destinations) {
if (!ID_PATTERN.test(destination?.id ?? "")) fail(destination, "needs a lowercase id.");
if (ids.has(destination.id)) fail(destination, "duplicate id.");
ids.add(destination.id);
if (typeof destination.name !== "string" || !destination.name || destination.name.length > 60) fail(destination, "name must contain 1 to 60 characters.");
if (typeof destination.description !== "string" || !destination.description || destination.description.length > 200) fail(destination, "description must contain 1 to 200 characters.");
if (destination.coverCardId != null && !cardIds.has(destination.coverCardId)) fail(destination, "unknown cover card.");
if (typeof destination.hidden !== "boolean") fail(destination, "hidden must be a boolean.");
if (!Array.isArray(destination.stats) || destination.stats.length !== STAT_IDS.length || new Set(destination.stats).size !== STAT_IDS.length
|| destination.stats.some((stat) => !STAT_IDS.includes(stat))) {
fail(destination, "stats must order the four stats.");
}
if (!Array.isArray(destination.conditions) || !destination.conditions.length) fail(destination, "needs at least one condition.");
for (const condition of destination.conditions) {
if (condition?.type === "tag") {
if (!tagIds.has(condition.tag)) fail(destination, `unknown condition tag ${condition.tag}.`);
if (matchingCards(catalog, { tags: [condition.tag] }).length < MIN_MATCHING_CARDS) fail(destination, `condition ${condition.tag} matches fewer than ${MIN_MATCHING_CARDS} rare or better cards.`);
} else if (condition?.type === "collection") {
if (!collectionIds.has(condition.collectionId)) fail(destination, `unknown condition collection ${condition.collectionId}.`);
if (matchingCards(catalog, { collectionId: condition.collectionId }).length < MIN_MATCHING_CARDS) fail(destination, `condition ${condition.collectionId} matches fewer than ${MIN_MATCHING_CARDS} rare or better cards.`);
} else {
fail(destination, "condition type must be tag or collection.");
}
}
if (!Array.isArray(destination.dangers) || !destination.dangers.length) fail(destination, "needs at least one danger.");
const dangerIds = new Set();
for (const danger of destination.dangers) {
if (!ID_PATTERN.test(danger?.id ?? "") || dangerIds.has(danger.id)) fail(destination, "every danger needs a unique lowercase id.");
dangerIds.add(danger.id);
if (typeof danger.label !== "string" || !danger.label || danger.label.length > 40) fail(destination, `danger ${danger.id} label must contain 1 to 40 characters.`);
if (!STAT_IDS.includes(danger.stat)) fail(destination, `danger ${danger.id} needs a known stat.`);
if (!Array.isArray(danger.unlessTags) || !danger.unlessTags.length || danger.unlessTags.some((tag) => !tagIds.has(tag))) fail(destination, `danger ${danger.id} needs known counter tags.`);
if (matchingCards(catalog, { tags: danger.unlessTags }).length < MIN_MATCHING_CARDS) fail(destination, `danger ${danger.id} can be countered by fewer than ${MIN_MATCHING_CARDS} rare or better cards.`);
}
}
if (!destinations.some((destination) => !destination.hidden)) throw new TypeError("Expedition destinations need at least one visible destination.");
return destinations;
}
export function loadExpeditionDestinations(path, catalog) {
return validateExpeditionDestinations(JSON.parse(readFileSync(path, "utf8")), catalog);
}