- Every common carries equipment spreading six points (+6, +3/+3, +2/+2/+2 or +8/−2), validated at load; every rare or better card shares a tag with at least three commons. - Power opens up to three equipment slots; a common sharing a tag with its card adds synergy points, and a common equips one card at a time without ever leaving the collection. - Teams earn score bonuses from destination affinity and resonances (Écho, Lignée, Étoiles sœurs), capped together with group cohesion. - The Grimoire records lore pairs when equipping and resonances at departure for every player of the team. - The card sheet lists equipment slots with synergy hints; previews, groups and reports show affinity and resonance badges; Administration › Guilde tunes slots, synergy points and score bonuses. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
157 lines
12 KiB
JavaScript
157 lines
12 KiB
JavaScript
// 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, synergyLabels } 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({ catalog, 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>
|
|
{synergyLabels(preview, catalog, content).map((label) => <span key={label} className="nds-badge" data-variant="success">{label}</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>;
|
|
}
|
|
|
|
// `mode` : « solo » (toutes les places à soi, rôles fixés par la destination) ou « group » (une carte et un rôle choisi, les autres places au tableau).
|
|
export function ExpeditionPlanner({ catalog, view, mode = "solo", content, busy, onStart }) {
|
|
const group = mode === "group";
|
|
const slotCount = group ? 1 : view.soloCards;
|
|
const [destinationId, setDestinationId] = useState(view.destinations[0]?.id || "");
|
|
const [stars, setStars] = useState(group ? view.group.stars.min : view.stars.min);
|
|
const [hours, setHours] = useState(view.durations[0]);
|
|
const [slots, setSlots] = useState(() => Array.from({ length: slotCount }, () => null));
|
|
const [groupRole, setGroupRole] = useState(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 starOptions = group ? destination?.groupStars : destination?.stars;
|
|
const option = starOptions?.[stars];
|
|
const chosenRole = group ? (destination?.groupRoles.includes(groupRole) ? groupRole : destination?.groupRoles[0]) : null;
|
|
const slotRoles = group ? [chosenRole] : destination?.roles || [];
|
|
const complete = Boolean(destination && slots.every(Boolean));
|
|
const body = useMemo(() => (group
|
|
? { mode: "group", day: view.day, destinationId: destination?.id, difficulty: stars, durationHours: hours, editionId: slots[0], role: chosenRole }
|
|
: { day: view.day, destinationId: destination?.id, difficulty: stars, durationHours: hours, slots }), [group, view.day, destination?.id, stars, hours, slots, chosenRole]);
|
|
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 = slotRoles[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">{(group ? item.groupRoles : 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(starOptions).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">{group ? content.groupTeamHelp : fillTemplate(content.teamHelp, { count: view.soloCards })}</p>
|
|
{group && <div role="group" aria-label={content.joinRole} className="nds-toolbar">{destination.groupRoles.map((stat) => <button key={stat} type="button" className="nds-button" data-size="sm" data-variant={stat === chosenRole ? "primary" : "secondary"} aria-pressed={stat === chosenRole} onClick={() => setGroupRole(stat)}>
|
|
{fillTemplate(content.roleBadge, { role: content.roles[stat], stat: content.stats[stat] })}
|
|
</button>)}</div>}
|
|
<div className="nebula-expedition-slots">{slots.map((editionId, index) => {
|
|
const entry = editionId && editionEntry(catalog, editionId);
|
|
const stat = slotRoles[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: slotCount })}</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: slotCount })}</p>}
|
|
{group && <p className="nebula-form-help">{content.groupPreviewNote}</p>}
|
|
{shownPreview?.error && <p className="nds-inline-notice" data-variant="warning" role="status">{shownPreview.error}</p>}
|
|
{shownPreview?.value && <Preview catalog={catalog} 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)); }}>{group ? content.groupStart : content.start}</button>
|
|
</div>
|
|
</section>
|
|
</div>;
|
|
}
|