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:
Shinuwa 2026-11-15 14:29:05 +01:00
parent 0ef213cf4f
commit 8bb1d53d70
46 changed files with 4752 additions and 213 deletions

View file

@ -0,0 +1,143 @@
// Rôle : prépare une expédition solo : destination du jour, difficulté, durée, équipe par rôle et aperçu exact avant le départ.
import { useEffect, useMemo, useState } from "react";
import { previewExpedition } from "./cardsApi.js";
import { fillTemplate } from "./dailyShare.js";
import { conditionText, coverEntry, dangerText, editionEntry, formatDecimal, formatEclats, STAT_IDS } from "./expeditionFormat.js";
import { NebulaCard } from "./NebulaCard.jsx";
const PREVIEW_DELAY_MS = 250;
const TIER_VARIANTS = { struggle: "neutral", success: "success", triumph: "gold" };
function StatLine({ stats, content }) {
return <span className="nebula-expedition-stats">{STAT_IDS.map((stat) => <span key={stat} title={content.stats[stat]}>{content.statShort[stat]} {formatDecimal(stats[stat])}</span>)}</span>;
}
function Requirements({ catalog, option, content }) {
return <div className="nebula-expedition-requirements">
<h4>{content.requirementsTitle}</h4>
<ul>{option.requirements.map((requirement) => <li key={requirement.stat}>
<span>{content.stats[requirement.stat]}{requirement.main && <span className="nds-badge" data-variant="neutral">{content.main}</span>}</span>
<strong>{requirement.value}</strong>
</li>)}</ul>
{option.condition && <p>{conditionText(option.condition, catalog, content)}</p>}
{option.dangers.map((danger) => <p key={danger.id}>{dangerText(danger, catalog, content)}</p>)}
</div>;
}
function Preview({ preview, content }) {
return <div className="nebula-expedition-preview" aria-live="polite">
<div className="nebula-expedition-rewards">
<span className="nds-badge" data-variant={TIER_VARIANTS[preview.tier]}>{content.tiers[preview.tier]}</span>
<span className="nds-badge" data-variant="neutral">{fillTemplate(content.score, { score: formatEclats(preview.scorePct) })}</span>
{preview.limitedByStars && <span className="nds-badge" data-variant="warning">{fillTemplate(content.limitedByStars, { stars: preview.limitedByStars })}</span>}
</div>
<ul className="nebula-expedition-checks">{preview.requirements.map((requirement) => <li key={requirement.stat} data-met={requirement.ratioPct >= 100 || undefined}>
<span>{content.stats[requirement.stat]}</span><strong>{fillTemplate(content.teamVersus, { team: formatDecimal(requirement.team), value: requirement.value })}</strong>
</li>)}</ul>
{preview.conditionMet != null && <p className="nds-inline-notice" data-variant={preview.conditionMet ? "success" : "warning"}>{preview.conditionMet ? content.conditionMet : content.conditionUnmet}</p>}
{preview.dangers.map((danger) => <p key={danger.id} className="nds-inline-notice" data-variant={danger.countered ? "success" : "warning"}>{fillTemplate(danger.countered ? content.dangerCountered : content.dangerActive, { label: danger.label })}</p>)}
{preview.durationFactor < 1 && <p className="nds-inline-notice" data-variant="warning">{content.durationMalus}</p>}
<p className="nebula-expedition-expected">{fillTemplate(content.expected, { eclats: formatEclats(preview.expected.eclats), stardust: formatEclats(preview.expected.stardust), pack: formatEclats(preview.expected.packChancePct) })}</p>
</div>;
}
export function ExpeditionPlanner({ catalog, view, content, busy, onStart }) {
const [destinationId, setDestinationId] = useState(view.destinations[0]?.id || "");
const [stars, setStars] = useState(view.stars.min);
const [hours, setHours] = useState(view.durations[0]);
const [slots, setSlots] = useState(() => Array.from({ length: view.soloCards }, () => null));
const [activeSlot, setActiveSlot] = useState(0);
const [preview, setPreview] = useState({ key: "", value: null, error: "" });
const destination = view.destinations.find((item) => item.id === destinationId) || view.destinations[0];
const option = destination?.stars[stars];
const complete = Boolean(destination && slots.every(Boolean));
const body = useMemo(() => ({ day: view.day, destinationId: destination?.id, difficulty: stars, durationHours: hours, slots }), [view.day, destination?.id, stars, hours, slots]);
const bodyKey = JSON.stringify(body);
// Aperçu demandé au serveur dès que l'équipe est complète, après une courte pause pour ne pas l'interroger à chaque clic.
useEffect(() => {
if (!complete) return undefined;
let active = true;
const timer = setTimeout(() => {
previewExpedition(JSON.parse(bodyKey))
.then((result) => { if (active) setPreview({ key: bodyKey, value: result.preview, error: "" }); })
.catch((error) => { if (active) setPreview({ key: bodyKey, value: null, error: error.message }); });
}, PREVIEW_DELAY_MS);
return () => { active = false; clearTimeout(timer); };
}, [bodyKey, complete]);
const roleStat = destination?.roles[activeSlot];
const cards = useMemo(() => [...view.cards].sort((a, b) => Number(a.busy) - Number(b.busy) || (b.stats[roleStat] ?? 0) - (a.stats[roleStat] ?? 0) || b.power - a.power), [view.cards, roleStat]);
if (!destination) return <div className="nds-empty-state"><p>{content.noDestination}</p></div>;
function choose(card) {
const next = slots.map((editionId, index) => (index !== activeSlot && editionId && editionEntry(catalog, editionId)?.card.id === card.cardId ? null : editionId));
next[activeSlot] = card.editionId;
setSlots(next);
const empty = next.findIndex((editionId) => !editionId);
if (empty >= 0) setActiveSlot(empty);
}
const shownPreview = complete && preview.key === bodyKey ? preview : null;
return <div className="nebula-expedition-planner">
<section className="nds-panel nebula-expedition-step" aria-labelledby="nebula-expedition-destinations-title">
<h3 id="nebula-expedition-destinations-title">{content.destinationsTitle}</h3>
<div className="nebula-expedition-destinations">{view.destinations.map((item) => {
const cover = item.coverCardId && coverEntry(catalog, item.coverCardId);
return <button key={item.id} type="button" className="nebula-expedition-destination" aria-pressed={item.id === destination.id} onClick={() => setDestinationId(item.id)}>
{cover && <img src={cover.card.image} alt="" />}
<span className="nebula-expedition-destination-copy">
<strong>{item.name}</strong>
<span>{item.description}</span>
<span className="nebula-expedition-destination-roles">{item.roles.map((stat) => <span key={stat} className="nds-badge" data-variant="neutral">{fillTemplate(content.roleBadge, { role: content.roles[stat], stat: content.stats[stat] })}</span>)}</span>
</span>
</button>;
})}</div>
</section>
<section className="nds-panel nebula-expedition-step" aria-labelledby="nebula-expedition-settings-title">
<h3 id="nebula-expedition-settings-title">{content.difficultyTitle}</h3>
<div className="nebula-expedition-choices">
<div role="group" aria-label={content.difficultyLabel} className="nds-toolbar">{Object.keys(destination.stars).map(Number).map((value) => <button key={value} type="button" className="nds-button" data-size="sm" data-variant={value === stars ? "primary" : "secondary"} aria-pressed={value === stars} onClick={() => setStars(value)}>{"★".repeat(value)}</button>)}</div>
<div role="group" aria-label={content.durationLabel} className="nds-toolbar">{view.durations.map((value) => <button key={value} type="button" className="nds-button" data-size="sm" data-variant={value === hours ? "primary" : "secondary"} aria-pressed={value === hours} onClick={() => setHours(value)}>{fillTemplate(content.hours, { hours: value })}</button>)}</div>
</div>
{option && <Requirements catalog={catalog} option={option} content={content} />}
</section>
<section className="nds-panel nebula-expedition-step" aria-labelledby="nebula-expedition-team-title">
<h3 id="nebula-expedition-team-title">{content.teamTitle}</h3>
<p className="nebula-form-help">{fillTemplate(content.teamHelp, { count: view.soloCards })}</p>
<div className="nebula-expedition-slots">{slots.map((editionId, index) => {
const entry = editionId && editionEntry(catalog, editionId);
const stat = destination.roles[index];
return <div key={index} className="nebula-expedition-slot" data-active={index === activeSlot || undefined}>
<button type="button" className="nds-button" data-size="sm" data-variant={index === activeSlot ? "primary" : "secondary"} aria-pressed={index === activeSlot} onClick={() => setActiveSlot(index)}>
{fillTemplate(content.roleBadge, { role: content.roles[stat], stat: content.stats[stat] })}
</button>
<span>{entry ? entry.card.name : content.slotEmpty}</span>
{entry && <button type="button" className="nds-button" data-size="sm" data-variant="secondary" onClick={() => { setSlots(slots.map((value, position) => (position === index ? null : value))); setActiveSlot(index); }}>{content.remove}</button>}
</div>;
})}</div>
{cards.length ? <ul className="nebula-expedition-cards" aria-label={content.cardsLabel}>{cards.map((card) => {
const entry = editionEntry(catalog, card.editionId);
if (!entry) return null;
const selected = slots.includes(card.editionId);
return <li key={card.editionId} data-busy={card.busy || undefined}>
<NebulaCard catalog={catalog} entry={entry} size="sm" selected={selected} disabled={card.busy} onSelect={card.busy ? undefined : () => choose(card)} selectLabel={fillTemplate(content.chooseCard, { card: entry.card.name, role: content.roles[roleStat] })} />
<span className="nebula-expedition-card-power">{card.busy ? content.busy : fillTemplate(content.power, { power: card.power })}</span>
<StatLine stats={card.stats} content={content} />
</li>;
})}</ul> : <p className="nds-inline-notice" data-variant="info">{fillTemplate(content.noCards, { count: view.soloCards })}</p>}
</section>
<section className="nds-panel nebula-expedition-step" aria-labelledby="nebula-expedition-preview-title">
<h3 id="nebula-expedition-preview-title">{content.previewTitle}</h3>
{!complete && <p className="nebula-form-help">{fillTemplate(content.previewEmpty, { count: view.soloCards })}</p>}
{shownPreview?.error && <p className="nds-inline-notice" data-variant="warning" role="status">{shownPreview.error}</p>}
{shownPreview?.value && <Preview preview={shownPreview.value} content={content} />}
<div className="nds-toolbar">
<button className="nds-button" data-variant="primary" type="button" disabled={busy || !complete} onClick={async () => { if (await onStart(body)) setSlots(slots.map(() => null)); }}>{content.start}</button>
</div>
</section>
</div>;
}