sokko-g/services/cards/expedition-settings.js
Shinuwa 30413de036 Rework the expedition screens: in-place return, illustrated bag and workshop, card sheet tabs and an engraving workshop
Expeditions
- The journey keeps the destination landscape still while a sky scenery
  (clouds, floating isles, shards, sparkles) drifts behind the cards.
- A returned expedition shows only what the player receives, in place and
  without a window; claiming it removes the card and confirms with a notice,
  and the page reloads by itself when an expedition comes back.
- The Guild Keeper slots are gone: group requirements scale with the players.
- Local development adds a 20-second test duration, a test player for groups
  and keeps the dev account stocked with every item.
- The Wind Rose has no daily limit and is used from the destinations step.
- The Guide Star opens a destination one level below the player's highest daily
  level, the Sky Chart one at that level; bonus destinations are badged with
  the item that opened them.

Bag and workshop
- The Watcher's bag is a grid of illustrated item cards, ordered from the
  destination items, with a short "Utiliser" button; the six missing item
  illustrations are added.
- The workshop opens in a window with illustrated commons, spare counts on the
  cards, cancel without spending anything, and shows the crafted card with its
  description and power.
- The engraving workshop picks a common first, then a tag from a chosen
  character card (in its tag colours) or from every tag, filtered by name and
  family; card lists filter by name, collection and stat.

Card sheet
- Two tabs: the card and its lore (default from the collection), and its
  improvement (default from the expeditions) with a summary of power, level,
  experience and stats.
- "Répartition des statistiques" offers Par défaut, Personnalisé and profiles,
  previews the change in the summary, and a Parchemin d'oubli resets it to
  Personnalisé so the next choice is free again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 13:36:01 +01:00

269 lines
15 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 },
// Étoiles des destinations : celles du niveau le plus bas, puis une de plus par niveau, sans dépasser le maximum. Elles ne dépendent
// pas du nombre de joueurs.
stars: { min: 1, max: 5 },
// Une expédition s'ouvre avec une carte et part quand son créateur le décide (tout de suite pour un solo), au plus tard à la fin de
// l'inscription : seule, c'est un solo (une place) ; avec d'autres joueurs, c'est un groupe. Groupe : places au plus (les exigences
// suivent le nombre de joueurs), période d'inscription, multiplicateur de butin selon le nombre de joueurs (2, 3, 4) et bonus de
// cohésion (collections toutes différentes).
group: { slots: 4, recruitHours: 1, lootPct: [150, 175, 200], cohesionPct: 10 },
power: { rare: 40, epic: 55, legendary: 70, mythic: 85, perLevel: 5, cap: 100 },
// 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), taux du pont depuis la poussière (poussières pour 1 Éclat)
// et prix en poussière des objets de la boutique : Parchemin d'oubli (changer le plan de progression d'une carte) et Rose des vents
// (retirer les destinations du jour).
progression: { costFactor: 2, costOffset: 35, duplicateLevels: 1, fieldXpPct: 10, stardustPerEclat: 3, oblivionPrice: 150, windRosePrice: 60 },
// Plans de progression : part maximale des points de niveau d'une carte dans une même stat (atteinte par les vocations).
plans: { maxStatPct: 60 },
// É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, madCompassMinPct: 80, madCompassMaxPct: 130, 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 : une récompense favorisée ×`boostPct` et les trois autres ×`otherPct`, ou deux
// récompenses favorisées ×`pairBoostPct` et les deux autres ×`pairOtherPct`.
specialty: { boostPct: 150, otherPct: 85, pairBoostPct: 130, pairOtherPct: 75 },
// 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, windRose: 5, oblivion: 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("stars.min", 1, 5),
int("stars.max", 1, 5),
int("group.slots", 2, 4),
int("group.recruitHours", 1, 48),
ints("group.lootPct", 3, 0, 1000),
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("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("progression.oblivionPrice", 1, 100000),
int("progression.windRosePrice", 1, 100000),
int("plans.maxStatPct", 25, 100),
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.madCompassMinPct", 10, 100),
int("powers.madCompassMaxPct", 100, 300),
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("specialty.pairBoostPct", 100, 300),
int("specialty.pairOtherPct", 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),
int("items.weights.windRose", 0, 100),
int("items.weights.oblivion", 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.stars.min > settings.stars.max) return "L'étoile minimale dépasse l'étoile maximale.";
if (settings.powers.madCompassMinPct > settings.powers.madCompassMaxPct) return "Coup de folie : le minimum des exigences dépasse le maximum.";
if (settings.equipment.secondSlotPower > settings.equipment.thirdSlotPower) return "La Puissance du 2e emplacement dépasse celle du 3e.";
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;
}