sokko-g/services/cards/expedition-settings.js
Shinuwa 21827a252b Add the Carnets des Veilleurs, the expedition-only Sokko TCG collection with power commons
- A new watchers-logbooks collection of category expedition never comes from packs, the shop or codes, and administrators cannot open it as a pack.
- Its six commons carry powers instead of stats (Longue-vue, Provisions, Carte au trésor, Talisman, Boussole folle, Filet à étoiles filantes); a card holds one power and each counts once per team.
- Powers change travel time, loot, score or tier, hide requirements, or catch a logbook card; each destination lists the logbook cards it can bring back.
- A workshop turns a plan and three duplicate commons into a power common.
- The fifteen cards ship without images with ready ChatGPT prompts; a card only drops or gets crafted once illustrated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 17:40:51 +01:00

242 lines
13 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Rôle : valeurs par défaut, bornes, fusion, validation et différences des réglages des Expéditions Sokko TCG.
// Règles pures : aucune lecture de la base ni de l'horloge. Le schéma est la seule source des bornes, pour le serveur comme pour l'administration.
// Valeurs du document de conception. Une clé ajoutée plus tard prend sa valeur par défaut à la fusion, sans migration.
export const DEFAULT_EXPEDITION_SETTINGS = Object.freeze({
enabled: false,
// Alertes Discord (messages privés envoyés par le bot) : chaque joueur choisit encore lesquelles il reçoit.
alerts: { enabled: true },
day: { destinationsPerDay: 4, avoidRepeatDays: 1 },
durations: { hours: [2, 6, 12], malusPct: [0, 0, 15], endurancePerSlot: 12 },
solo: { maxConcurrent: 1, cards: 2, minStars: 1, maxStars: 4 },
// Groupe : places (le Veilleur de la Guilde tient celles restées vides, sans rôle), joueurs minimum pour partir, 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, minPlayers: 2, maxConcurrent: 2, minStars: 2, maxStars: 5, recruitHours: 12, lootPct: [150, 175, 200], npcStat: 8, cohesionPct: 10 },
power: { rare: 40, epic: 55, legendary: 70, mythic: 85, perLevel: 5, cap: 100 },
roles: { multiplierPct: 200 },
// 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) et taux du pont depuis la poussière (poussières pour 1 Éclat).
progression: { costFactor: 2, costOffset: 35, duplicateLevels: 1, fieldXpPct: 10, stardustPerEclat: 3 },
// Équipements : emplacements au plus, Puissance qui ouvre le 2e et le 3e, points ajoutés quand une commune partage une étiquette avec sa carte.
equipment: { maxPerCard: 3, secondSlotPower: 70, thirdSlotPower: 100, synergyBonus: 2 },
// Synergies de score : Affinité avec la destination, Résonances (Écho, Lignée, Étoiles sœurs) et nombre de cartes d'un même thème.
synergy: { affinityPct: 10, resonancePct: 10, maxResonances: 2, sistersCount: 2 },
// Objets : chance par heure d'en rapporter un (‰, multipliée comme le butin), au plus par expédition, Orientation moyenne par place
// qui ouvre la partie cachée (fragments, burins, plans), fragments pour une carte au trésor, butin des destinations cachées et poids de tirage.
// Pouvoirs des communes des Carnets : avantage et contrepartie de chacun (le Talisman n'a pas de valeur : ni échec ni triomphe).
powers: { longsightPackPct: 25, longsightExtraHours: 2, rationsTimePct: 25, rationsLootPct: 15, treasureMapScorePct: 10, madCompassLootPct: 30, starNetCardPct: 20, starNetFortune: 2 },
// Cartes des Carnets des Veilleurs rapportées d'expédition (chance par heure, multipliée comme le butin) et au plus par expédition.
carnets: { cardPerHourPermille: 20, maxCards: 1 },
items: {
chancePerHourPermille: 50, maxPerExpedition: 2, orientationPerSlot: 15, fragmentsForMap: 4, hiddenLootPct: 150,
weights: { fragment: 30, engraving: 10, plan: 10, anchor: 15, guideStar: 20, skyChart: 5 }
},
// Exigence d'une stat, par place, pour chaque nombre d'étoiles : stat principale, puis seconde, troisième et quatrième.
requirements: { star1: [9], star2: [11, 10], star3: [15, 14, 11], star4: [19, 18, 14], star5: [22, 21, 17, 14], conditionMissPct: 25 },
danger: { malusPct: 20, shieldMaxPct: 50, endurancePerSlot: 14 },
score: { mainWeight: 2, otherWeight: 1, overflowPct: 50, overflowSpanPct: 100, capPct: 150, successPct: 80, triumphPct: 120, synergyCapPct: 25 },
loot: {
eclatsPerHourCents: 200,
stardustPerHourCents: 25,
packPerHourPermille: 12,
maxPacks: 2,
difficultyPct: [100, 130, 170, 220, 300],
tierPct: [40, 100, 150],
fortunePerPointPct: 2,
fortuneCapPct: 50,
// Multiplicateur de butin des destinations bonus : 5e, puis 6e.
bonusSlotPct: [100, 125]
},
destinations: {}
});
export const DEFAULT_DESTINATION_SETTING = Object.freeze({ active: true, weight: 1 });
export const MAX_DESTINATION_WEIGHT = 100;
const int = (path, min, max) => ({ path, kind: "int", min, max });
const ints = (path, length, min, max) => ({ path, kind: "ints", length, min, max });
// Bornes de chaque réglage. `ints` : liste de longueur fixe. Les réglages par destination sont validés à part.
export const EXPEDITION_SETTINGS_SCHEMA = Object.freeze([
{ path: "enabled", kind: "bool" },
{ path: "alerts.enabled", kind: "bool" },
int("day.destinationsPerDay", 1, 8),
int("day.avoidRepeatDays", 0, 7),
ints("durations.hours", 3, 1, 48),
ints("durations.malusPct", 3, 0, 50),
int("durations.endurancePerSlot", 1, 1000),
int("solo.maxConcurrent", 1, 3),
int("solo.cards", 1, 4),
int("solo.minStars", 1, 5),
int("solo.maxStars", 1, 5),
int("group.slots", 2, 4),
int("group.minPlayers", 2, 4),
int("group.maxConcurrent", 1, 5),
int("group.minStars", 1, 5),
int("group.maxStars", 1, 5),
int("group.recruitHours", 1, 48),
ints("group.lootPct", 3, 0, 1000),
int("group.npcStat", 0, 100),
int("group.cohesionPct", 0, 100),
int("power.rare", 1, 300),
int("power.epic", 1, 300),
int("power.legendary", 1, 300),
int("power.mythic", 1, 300),
int("power.perLevel", 0, 50),
int("power.cap", 1, 300),
int("roles.multiplierPct", 100, 400),
int("progression.costFactor", 0, 100),
int("progression.costOffset", 0, 300),
int("progression.duplicateLevels", 0, 12),
int("progression.fieldXpPct", 0, 100),
int("progression.stardustPerEclat", 1, 1000),
int("equipment.maxPerCard", 0, 3),
int("equipment.secondSlotPower", 1, 300),
int("equipment.thirdSlotPower", 1, 300),
int("equipment.synergyBonus", 0, 20),
int("synergy.affinityPct", 0, 100),
int("synergy.resonancePct", 0, 100),
int("synergy.maxResonances", 0, 3),
int("synergy.sistersCount", 2, 4),
int("powers.longsightPackPct", 0, 500),
int("powers.longsightExtraHours", 0, 24),
int("powers.rationsTimePct", 0, 90),
int("powers.rationsLootPct", 0, 90),
int("powers.treasureMapScorePct", 0, 90),
int("powers.madCompassLootPct", 0, 500),
int("powers.starNetCardPct", 0, 100),
int("powers.starNetFortune", 0, 100),
int("carnets.cardPerHourPermille", 0, 1000),
int("carnets.maxCards", 0, 3),
int("items.chancePerHourPermille", 0, 1000),
int("items.maxPerExpedition", 0, 5),
int("items.orientationPerSlot", 0, 1000),
int("items.fragmentsForMap", 1, 20),
int("items.hiddenLootPct", 0, 1000),
int("items.weights.fragment", 0, 100),
int("items.weights.engraving", 0, 100),
int("items.weights.plan", 0, 100),
int("items.weights.anchor", 0, 100),
int("items.weights.guideStar", 0, 100),
int("items.weights.skyChart", 0, 100),
ints("requirements.star1", 1, 1, 1000),
ints("requirements.star2", 2, 1, 1000),
ints("requirements.star3", 3, 1, 1000),
ints("requirements.star4", 3, 1, 1000),
ints("requirements.star5", 4, 1, 1000),
int("requirements.conditionMissPct", 0, 100),
int("danger.malusPct", 0, 90),
int("danger.shieldMaxPct", 0, 100),
int("danger.endurancePerSlot", 1, 1000),
int("score.mainWeight", 1, 10),
int("score.otherWeight", 1, 10),
int("score.overflowPct", 0, 100),
int("score.overflowSpanPct", 0, 300),
int("score.capPct", 100, 300),
int("score.successPct", 1, 300),
int("score.triumphPct", 1, 300),
int("score.synergyCapPct", 0, 100),
int("loot.eclatsPerHourCents", 0, 100_000),
int("loot.stardustPerHourCents", 0, 100_000),
int("loot.packPerHourPermille", 0, 1000),
int("loot.maxPacks", 0, 10),
ints("loot.difficultyPct", 5, 0, 1000),
ints("loot.tierPct", 3, 0, 1000),
int("loot.fortunePerPointPct", 0, 100),
int("loot.fortuneCapPct", 0, 500),
ints("loot.bonusSlotPct", 2, 0, 1000)
]);
const isObject = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
export function readPath(source, path) {
return path.split(".").reduce((value, key) => (isObject(value) ? value[key] : undefined), source);
}
function writePath(target, path, value) {
const keys = path.split(".");
let node = target;
for (const key of keys.slice(0, -1)) {
if (!isObject(node[key])) node[key] = {};
node = node[key];
}
node[keys.at(-1)] = value;
}
function validField(field, value) {
if (field.kind === "bool") return typeof value === "boolean";
const inRange = (item) => Number.isInteger(item) && item >= field.min && item <= field.max;
if (field.kind === "int") return inRange(value);
return Array.isArray(value) && value.length === field.length && value.every(inRange);
}
const validDestinationSetting = (value) => isObject(value) && typeof value.active === "boolean"
&& Number.isInteger(value.weight) && value.weight >= 0 && value.weight <= MAX_DESTINATION_WEIGHT;
const copy = (value) => (Array.isArray(value) ? [...value] : value);
// Réglages complets : chaque champ stocké et valide est gardé, sinon il reprend sa valeur par défaut ; les clés inconnues disparaissent.
export function mergeExpeditionSettings(stored, destinationIds = [], onInvalid = null) {
const merged = {};
for (const field of EXPEDITION_SETTINGS_SCHEMA) {
const value = readPath(stored, field.path);
const fallback = readPath(DEFAULT_EXPEDITION_SETTINGS, field.path);
if (value !== undefined && !validField(field, value)) onInvalid?.(field.path);
writePath(merged, field.path, copy(value !== undefined && validField(field, value) ? value : fallback));
}
merged.destinations = {};
for (const id of destinationIds) {
const value = isObject(stored?.destinations) ? stored.destinations[id] : undefined;
if (value !== undefined && !validDestinationSetting(value)) onInvalid?.(`destinations.${id}`);
merged.destinations[id] = validDestinationSetting(value) ? { active: value.active, weight: value.weight } : { ...DEFAULT_DESTINATION_SETTING };
}
return merged;
}
// Message en français, ou null si les réglages sont valides (bornes, puis contraintes entre réglages).
export function validateExpeditionSettings(settings, destinationIds = []) {
if (!isObject(settings)) return "Réglages des Expéditions invalides.";
for (const field of EXPEDITION_SETTINGS_SCHEMA) {
if (!validField(field, readPath(settings, field.path))) {
return field.kind === "bool"
? `Réglage ${field.path} invalide : oui ou non.`
: `Réglage ${field.path} invalide : ${field.kind === "ints" ? `${field.length} entiers` : "un entier"} entre ${field.min.toLocaleString("fr-FR")} et ${field.max.toLocaleString("fr-FR")}.`;
}
}
if (!isObject(settings.destinations)) return "Réglages des destinations invalides.";
for (const id of Object.keys(settings.destinations)) {
if (!destinationIds.includes(id)) return `Destination inconnue : ${id}.`;
if (!validDestinationSetting(settings.destinations[id])) return `Réglage de la destination ${id} invalide : active oui ou non, poids entre 0 et ${MAX_DESTINATION_WEIGHT}.`;
}
const { hours } = settings.durations;
if (hours.some((value, index) => index > 0 && value <= hours[index - 1])) return "Les durées doivent être croissantes.";
if (settings.solo.minStars > settings.solo.maxStars) return "L'étoile minimale du solo dépasse l'étoile maximale.";
if (settings.group.minStars > settings.group.maxStars) return "L'étoile minimale du groupe dépasse l'étoile maximale.";
if (settings.equipment.secondSlotPower > settings.equipment.thirdSlotPower) return "La Puissance du 2e emplacement dépasse celle du 3e.";
if (settings.group.minPlayers > settings.group.slots) return "Le nombre de joueurs minimum dépasse le nombre de places du groupe.";
const { successPct, triumphPct, capPct } = settings.score;
if (!(successPct < triumphPct && triumphPct <= capPct)) return "Les seuils doivent respecter Réussite < Triomphe ≤ plafond du score.";
const { perLevel, cap, ...bases } = settings.power;
if (Object.values(bases).some((base) => base > cap)) return "Une Puissance de base dépasse le plafond.";
if (perLevel === 0 && Object.values(bases).some((base) => base < cap)) return "Le gain par niveau doit être positif tant qu'une Puissance de base est sous le plafond.";
return null;
}
// Différences champ par champ, pour l'historique d'administration.
export function diffExpeditionSettings(previous, next) {
const changes = [];
for (const field of EXPEDITION_SETTINGS_SCHEMA) {
const before = readPath(previous, field.path);
const after = readPath(next, field.path);
if (JSON.stringify(before) !== JSON.stringify(after)) changes.push({ path: field.path, previous: before, next: after });
}
const ids = new Set([...Object.keys(previous?.destinations || {}), ...Object.keys(next?.destinations || {})]);
for (const id of ids) {
for (const key of ["active", "weight"]) {
const before = previous?.destinations?.[id]?.[key];
const after = next?.destinations?.[id]?.[key];
if (before !== after) changes.push({ path: `destinations.${id}.${key}`, previous: before, next: after });
}
}
return changes;
}