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>
This commit is contained in:
parent
0ef213cf4f
commit
8bb1d53d70
46 changed files with 4752 additions and 213 deletions
258
services/cards/expedition-rules.js
Normal file
258
services/cards/expedition-rules.js
Normal file
|
|
@ -0,0 +1,258 @@
|
|||
// Rôle : règles pures des Expéditions Sokko TCG (Puissance, stats, exigences par place, dangers, score, palier, butin, tirage du jour).
|
||||
// Aucune fonction ne lit la base ni l'horloge, et le hasard est toujours passé en paramètre : `random(max)` renvoie un entier dans [0, max).
|
||||
import { cardRarity } from "./daily.js";
|
||||
|
||||
export const STAT_IDS = Object.freeze(["bravoure", "endurance", "fortune", "orientation"]);
|
||||
// Rôle d'une place : il double la stat correspondante de la carte qui l'occupe.
|
||||
export const ROLE_BY_STAT = Object.freeze({ bravoure: "leader", endurance: "guardian", fortune: "seeker", orientation: "navigator" });
|
||||
export const STAT_BY_ROLE = Object.freeze(Object.fromEntries(Object.entries(ROLE_BY_STAT).map(([stat, role]) => [role, stat])));
|
||||
export const TIER_IDS = Object.freeze(["struggle", "success", "triumph"]);
|
||||
export const MAX_STARS = 5;
|
||||
// Nombre de stats exigées selon les étoiles : la 4e étoile ajoute un danger, la 5e la dernière stat et un second danger.
|
||||
const REQUIRED_STATS = Object.freeze([1, 2, 3, 3, 4]);
|
||||
const DANGER_COUNT = Object.freeze([0, 0, 0, 1, 2]);
|
||||
export const EXPEDITION_RARITIES = Object.freeze(["rare", "epic", "legendary", "mythic"]);
|
||||
|
||||
export const requiredStatCount = (stars) => REQUIRED_STATS[stars - 1];
|
||||
export const dangerCount = (stars) => DANGER_COUNT[stars - 1];
|
||||
export const hasCondition = (stars) => stars >= 3;
|
||||
|
||||
// Puissance d'une carte selon sa rareté et son niveau ; une commune n'en a pas (elle servira d'équipement).
|
||||
export function cardPower(rarity, level, settings) {
|
||||
const base = settings.power[rarity];
|
||||
if (!Number.isInteger(base)) return 0;
|
||||
return Math.min(settings.power.cap, base + Math.max(0, level) * settings.power.perLevel);
|
||||
}
|
||||
|
||||
// Niveau qui amène une rareté au plafond.
|
||||
export function maxLevel(rarity, settings) {
|
||||
const base = settings.power[rarity];
|
||||
if (!Number.isInteger(base) || base >= settings.power.cap) return 0;
|
||||
return Math.ceil((settings.power.cap - base) / settings.power.perLevel);
|
||||
}
|
||||
|
||||
// Répartit la Puissance selon le profil (pourcentages), au plus grand reste : la somme des stats vaut exactement la Puissance.
|
||||
export function splitPower(power, profile) {
|
||||
const raw = STAT_IDS.map((stat) => (power * profile[stat]) / 100);
|
||||
const stats = raw.map(Math.floor);
|
||||
let left = power - stats.reduce((sum, value) => sum + value, 0);
|
||||
const order = raw.map((value, index) => [value - Math.floor(value), index]).sort((a, b) => b[0] - a[0] || a[1] - b[1]);
|
||||
for (const [, index] of order) {
|
||||
if (left <= 0) break;
|
||||
stats[index] += 1;
|
||||
left -= 1;
|
||||
}
|
||||
return Object.fromEntries(STAT_IDS.map((stat, index) => [stat, stats[index]]));
|
||||
}
|
||||
|
||||
// Données d'expédition d'une carte : son profil (ou celui de sa collection), ses étiquettes et sa collection.
|
||||
export function cardExpeditionData(catalog, cardId) {
|
||||
const card = catalog.cards.find((item) => item.id === cardId);
|
||||
if (!card) return null;
|
||||
const collection = catalog.collections.find((item) => item.id === card.collectionId);
|
||||
return {
|
||||
cardId,
|
||||
collectionId: card.collectionId,
|
||||
tags: card.expedition?.tags || [],
|
||||
profile: card.expedition?.profile || collection?.expedition?.profile || null
|
||||
};
|
||||
}
|
||||
|
||||
// Ce qu'une édition apporte à une expédition : rareté de l'édition (une mythique garde la sienne), Puissance et stats.
|
||||
export function editionExpeditionData(catalog, editionId, level, settings) {
|
||||
const edition = catalog.editions.find((item) => item.id === editionId);
|
||||
if (!edition) return null;
|
||||
const data = cardExpeditionData(catalog, edition.cardId);
|
||||
if (!data?.profile || !EXPEDITION_RARITIES.includes(edition.rarity)) return null;
|
||||
const power = cardPower(edition.rarity, level, settings);
|
||||
return { ...data, editionId, rarity: edition.rarity, level, power, stats: splitPower(power, data.profile) };
|
||||
}
|
||||
|
||||
export const isExpeditionCard = (catalog, cardId) => EXPEDITION_RARITIES.includes(cardRarity(catalog, cardId));
|
||||
|
||||
// Rôles des places en solo : la destination fixe ceux de ses deux premières stats.
|
||||
export function soloRoles(destination, slotCount) {
|
||||
return destination.stats.slice(0, slotCount);
|
||||
}
|
||||
|
||||
// Exigence d'une stat = valeur par place × (nombre de places + places dont le rôle double cette stat).
|
||||
// Le solo et le groupe gardent ainsi le même rapport ; une place sans rôle (Veilleur de la Guilde) n'ajoute que sa part.
|
||||
export function requirementsFor(destination, stars, slotRoles, settings) {
|
||||
const perSlot = settings.requirements[`star${stars}`];
|
||||
return destination.stats.slice(0, requiredStatCount(stars)).map((stat, index) => ({
|
||||
stat,
|
||||
main: index === 0,
|
||||
value: perSlot[index] * (slotRoles.length + slotRoles.filter((role) => role === stat).length)
|
||||
}));
|
||||
}
|
||||
|
||||
// Somme des stats de l'équipe ; le rôle d'une place multiplie la stat correspondante de sa carte.
|
||||
export function teamStats(slots, settings) {
|
||||
const total = Object.fromEntries(STAT_IDS.map((stat) => [stat, 0]));
|
||||
for (const slot of slots) {
|
||||
for (const stat of STAT_IDS) {
|
||||
const multiplier = slot.role === stat ? settings.roles.multiplierPct / 100 : 1;
|
||||
total[stat] += (slot.stats?.[stat] || 0) * multiplier;
|
||||
}
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
const slotMatches = (slot, condition) => (condition.type === "tag" ? slot.tags?.includes(condition.tag) : slot.collectionId === condition.collectionId);
|
||||
|
||||
export function conditionMet(slots, condition) {
|
||||
return slots.some((slot) => slotMatches(slot, condition));
|
||||
}
|
||||
|
||||
export function dangerCountered(slots, danger) {
|
||||
return slots.some((slot) => danger.unlessTags.some((tag) => slot.tags?.includes(tag)));
|
||||
}
|
||||
|
||||
// Malus de durée et dangers. L'Endurance de l'équipe (avant malus) efface le malus de durée et sert de bouclier contre un danger.
|
||||
export function applyHazards(stats, { slotCount, durationIndex, dangers = [] }, settings) {
|
||||
const endurance = stats.endurance;
|
||||
const result = { ...stats };
|
||||
const durationMalus = settings.durations.malusPct[durationIndex] / 100;
|
||||
const durationCover = Math.min(1, endurance / (settings.durations.endurancePerSlot * slotCount));
|
||||
const durationFactor = 1 - durationMalus * (1 - durationCover);
|
||||
for (const stat of STAT_IDS) result[stat] *= durationFactor;
|
||||
const shield = Math.min(1, endurance / (settings.danger.endurancePerSlot * slotCount)) * (settings.danger.shieldMaxPct / 100);
|
||||
const dangerFactor = 1 - (settings.danger.malusPct / 100) * (1 - shield);
|
||||
const appliedDangers = dangers.map((danger) => {
|
||||
if (!danger.countered) result[danger.stat] *= dangerFactor;
|
||||
return { ...danger, factor: danger.countered ? 1 : dangerFactor };
|
||||
});
|
||||
return { stats: result, durationFactor, dangers: appliedDangers };
|
||||
}
|
||||
|
||||
// Rendement d'une exigence : plein jusqu'à 100 %, puis réduit, jusqu'au plafond.
|
||||
export function efficiency(ratio, settings) {
|
||||
const over = Math.min(Math.max(ratio - 1, 0), settings.score.overflowSpanPct / 100);
|
||||
return Math.min(ratio, 1) + (settings.score.overflowPct / 100) * over;
|
||||
}
|
||||
|
||||
export function tierFor(scorePct, settings) {
|
||||
if (scorePct >= settings.score.triumphPct) return "triumph";
|
||||
if (scorePct >= settings.score.successPct) return "success";
|
||||
return "struggle";
|
||||
}
|
||||
|
||||
// Score de l'équipe : moyenne pondérée des rendements (stat principale plus lourde), condition, bonus de synergies, plafond.
|
||||
export function scoreExpedition({ requirements, stats, conditionMet: met = null, synergyPct = 0 }, settings) {
|
||||
let weighted = 0;
|
||||
let weights = 0;
|
||||
const perRequirement = requirements.map((requirement) => {
|
||||
const ratio = requirement.value > 0 ? stats[requirement.stat] / requirement.value : 1;
|
||||
const weight = requirement.main ? settings.score.mainWeight : settings.score.otherWeight;
|
||||
const value = efficiency(ratio, settings);
|
||||
weighted += value * weight;
|
||||
weights += weight;
|
||||
return { ...requirement, team: stats[requirement.stat], ratioPct: ratio * 100, efficiencyPct: value * 100 };
|
||||
});
|
||||
const conditionFactor = met === false ? 1 - settings.requirements.conditionMissPct / 100 : 1;
|
||||
const raw = (weights ? weighted / weights : 0) * 100 * conditionFactor * (1 + synergyPct / 100);
|
||||
const scorePct = Math.min(settings.score.capPct, raw);
|
||||
return { perRequirement, conditionFactor, scorePct, tier: tierFor(scorePct, settings) };
|
||||
}
|
||||
|
||||
function evaluateAt({ destination, entry, stars, durationIndex, slots }, base, settings) {
|
||||
const slotRoles = slots.map((slot) => slot.role ?? null);
|
||||
const requirements = requirementsFor(destination, stars, slotRoles, settings);
|
||||
const condition = hasCondition(stars) ? entry.condition : null;
|
||||
const dangers = (entry.dangers || []).slice(0, dangerCount(stars)).map((danger) => ({ ...danger, countered: dangerCountered(slots, danger) }));
|
||||
const hazards = applyHazards(base, { slotCount: slots.length, durationIndex, dangers }, settings);
|
||||
const met = condition ? conditionMet(slots, condition) : null;
|
||||
const score = scoreExpedition({ requirements, stats: hazards.stats, conditionMet: met }, settings);
|
||||
return { requirements, baseStats: base, stats: hazards.stats, durationFactor: hazards.durationFactor, dangers: hazards.dangers, condition, conditionMet: met, ...score };
|
||||
}
|
||||
|
||||
// Évalue une équipe sur une destination du jour : c'est le calcul complet du départ et de l'aperçu.
|
||||
// `slots` : [{ stats, role (stat doublée ou null), tags, collectionId }]. `entry` : { condition, dangers } de la destination du jour.
|
||||
// Une étoile de plus ne peut jamais améliorer le score : sans cette règle, une équipe faible sur la stat principale
|
||||
// gagnerait des points en ajoutant une stat où elle est forte. Le score retenu est donc le plus bas des niveaux 1 à `stars`.
|
||||
export function evaluateTeam(input, settings) {
|
||||
const base = teamStats(input.slots, settings);
|
||||
const result = evaluateAt(input, base, settings);
|
||||
let scorePct = result.scorePct;
|
||||
let limitedByStars = null;
|
||||
for (let stars = input.stars - 1; stars >= 1; stars -= 1) {
|
||||
const lower = evaluateAt({ ...input, stars }, base, settings).scorePct;
|
||||
if (lower < scorePct) {
|
||||
scorePct = lower;
|
||||
limitedByStars = stars;
|
||||
}
|
||||
}
|
||||
return { ...result, scorePct, limitedByStars, tier: tierFor(scorePct, settings) };
|
||||
}
|
||||
|
||||
// Butin espéré (valeurs fractionnaires) : il est proportionnel à la durée choisie, donc identique par heure.
|
||||
export function expectedLoot({ hours, stars, tier, fortune, slotCount, bonusSlot = null }, settings) {
|
||||
const { loot } = settings;
|
||||
const bonus = bonusSlot ? loot.bonusSlotPct[bonusSlot - 5] / 100 : 1;
|
||||
const base = hours * (loot.difficultyPct[stars - 1] / 100) * (loot.tierPct[TIER_IDS.indexOf(tier)] / 100) * bonus;
|
||||
const fortuneBonusPct = Math.min(loot.fortuneCapPct, (fortune / Math.max(1, slotCount)) * loot.fortunePerPointPct);
|
||||
return {
|
||||
eclats: base * (loot.eclatsPerHourCents / 100),
|
||||
stardust: base * (loot.stardustPerHourCents / 100),
|
||||
packs: Math.min(loot.maxPacks, base * (loot.packPerHourPermille / 1000) * (1 + fortuneBonusPct / 100)),
|
||||
fortuneBonusPct
|
||||
};
|
||||
}
|
||||
|
||||
// Arrondi aléatoire qui conserve la moyenne : partie entière, plus une unité avec la probabilité de la partie décimale.
|
||||
export function roundStochastic(value, random) {
|
||||
const whole = Math.floor(value);
|
||||
return whole + (random(1000) < Math.round((value - whole) * 1000) ? 1 : 0);
|
||||
}
|
||||
|
||||
export function rollLoot(expected, settings, random) {
|
||||
return {
|
||||
eclats: roundStochastic(expected.eclats, random),
|
||||
stardust: roundStochastic(expected.stardust, random),
|
||||
packs: Math.min(settings.loot.maxPacks, roundStochastic(expected.packs, random))
|
||||
};
|
||||
}
|
||||
|
||||
function weightedPick(entries, random) {
|
||||
const total = entries.reduce((sum, entry) => sum + entry.weight, 0);
|
||||
let cursor = random(total);
|
||||
for (const entry of entries) {
|
||||
cursor -= entry.weight;
|
||||
if (cursor < 0) return entry;
|
||||
}
|
||||
return entries.at(-1);
|
||||
}
|
||||
|
||||
// Destinations du jour : tirées selon leur poids parmi les destinations actives et non cachées, en évitant celles des jours précédents
|
||||
// tant qu'il en reste assez. Pour chacune : l'indice de sa condition et ceux de deux dangers (le second sert au 5 ★).
|
||||
export function drawExpeditionDay(destinations, settings, recentIds, random) {
|
||||
const candidates = destinations
|
||||
.filter((destination) => !destination.hidden)
|
||||
.map((destination) => ({ destination, ...(settings.destinations[destination.id] || { active: true, weight: 1 }) }))
|
||||
.filter((entry) => entry.active && entry.weight > 0);
|
||||
const count = Math.min(settings.day.destinationsPerDay, candidates.length);
|
||||
const recent = new Set(recentIds);
|
||||
const fresh = candidates.filter((entry) => !recent.has(entry.destination.id));
|
||||
let pool = fresh.length >= count ? fresh : candidates;
|
||||
const picked = [];
|
||||
while (picked.length < count && pool.length) {
|
||||
const entry = weightedPick(pool, random);
|
||||
picked.push(entry.destination);
|
||||
pool = pool.filter((item) => item !== entry);
|
||||
}
|
||||
return picked.map((destination) => {
|
||||
const first = random(destination.dangers.length);
|
||||
const second = destination.dangers.length > 1 ? (first + 1 + random(destination.dangers.length - 1)) % destination.dangers.length : first;
|
||||
return { destinationId: destination.id, conditionIndex: random(destination.conditions.length), dangerIndexes: [first, second] };
|
||||
});
|
||||
}
|
||||
|
||||
// Destination du jour prête à jouer : condition et dangers résolus. Null si la destination a disparu du contenu.
|
||||
export function resolveDayEntry(destinations, draw) {
|
||||
const destination = destinations.find((item) => item.id === draw.destinationId);
|
||||
if (!destination) return null;
|
||||
const condition = destination.conditions[draw.conditionIndex] || destination.conditions[0];
|
||||
const indexes = [...new Set(draw.dangerIndexes)];
|
||||
const dangers = indexes.map((index) => destination.dangers[index]).filter(Boolean);
|
||||
return { destination, entry: { condition, dangers } };
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue