sokko-g/services/cards/expedition-settings.js
Shinuwa 703697f1ac Reward single cards instead of packs and give each destination a loot specialty
Expeditions no longer hand out packs: they bring back single cards, with one hourly card chance that Fortune and the longsight still raise. A card comes from the destination's Carnets des Veilleurs; a destination tied to an open collection draws it from that collection most of the time, at the collection's rarity rates (a legendary can come as a mythic variation), with missing cards twice as likely.

Each destination has a loot specialty (Éclats, stardust, cards or items) that multiplies its reward and slightly lowers the others, and the planner shows it with the destination's collection. A destination tied to a collection cannot be rich in cards.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 20:33:01 +01:00

261 lines
14 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,
stormLanternDangerPct: 50, stormLanternExtraHours: 1, fogBellSynergyPct: 10, fogBellSoloLootPct: 20 },
// Cartes des Carnets des Veilleurs rapportées d'expédition (chance par heure, multipliée comme le butin) et au plus par expédition.
// Cartes de destination : chance d'en rapporter une que le joueur n'a pas (Carnets des Veilleurs), et chance d'obtenir la carte
// de la destination d'un groupe rejoint sans l'avoir. Une carte de destination de départ est offerte une fois.
destinationCards: { dropPct: 10, groupJoinPct: 60 },
// Spécialité de butin d'une destination : la récompense de sa spécialité est multipliée par `boostPct`, les autres par `otherPct`.
specialty: { boostPct: 150, otherPct: 85 },
// Carte gagnée en expédition : une destination rattachée à une collection la tire dans sa collection avec la probabilité
// `linkedCollectionPct`, sinon dans ses Carnets des Veilleurs ; dans la collection, poids d'une carte manquante (une carte
// possédée pèse 100).
rewardCards: { linkedCollectionPct: 75, missingWeightPct: 200 },
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,
// Chance d'une carte par heure : de la collection de la destination, sinon des Carnets des Veilleurs de la destination
// (la spécialité d'une destination la multiplie, comme les autres récompenses).
cardPerHourPermille: 20,
maxCards: 1,
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("powers.stormLanternDangerPct", 0, 100),
int("powers.stormLanternExtraHours", 0, 24),
int("powers.fogBellSynergyPct", 0, 100),
int("powers.fogBellSoloLootPct", 0, 90),
int("destinationCards.dropPct", 0, 100),
int("destinationCards.groupJoinPct", 0, 100),
int("specialty.boostPct", 100, 300),
int("specialty.otherPct", 0, 100),
int("rewardCards.linkedCollectionPct", 0, 100),
int("rewardCards.missingWeightPct", 100, 1000),
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.cardPerHourPermille", 0, 1000),
int("loot.maxCards", 0, 3),
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;
}