Let players pick the duplicates that awaken a card, shown as cards
The awakening with duplicates of the collection used to take them automatically, without showing them. It now opens a picker like the Atelier: the needed slots at the top, the usable duplicates below as illustrated cards with their free copies, and nothing is used before "Éveiller". The server lists the candidates and checks the chosen copies. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
055f8cf17b
commit
0533a8f766
10 changed files with 142 additions and 45 deletions
|
|
@ -94,7 +94,7 @@ Le seuil se mesure **sur l'exigence solo**, pas sur celle relevée du groupe : s
|
|||
- Un doublon de la carte donne 1 niveau.
|
||||
- **Paliers d'Éveil à Puissance 70, 85 et 100.** Le niveau qui atteint un palier ne s'obtient ni par Éclats, ni par doublon ordinaire, ni par expérience (qui retombe à 0 et ne progresse plus). La carte s'éveille, **sans Éclats**, avec :
|
||||
- un doublon d'elle-même (pour une mythique, sa version légendaire compte aussi : même carte, même « essence ») ;
|
||||
- ou des doublons de sa collection et de sa rareté : 6 rares, 2 épiques, 1 légendaire ; pour une mythique, 1 légendaire ou mythique. Le serveur prend les doublons les plus nombreux d'abord, jamais une mythique pour une autre rareté, et l'interface les montre avant de les consommer.
|
||||
- ou des doublons de sa collection et de sa rareté : 6 rares, 2 épiques, 1 légendaire ; pour une mythique, 1 légendaire ou mythique. Le joueur les choisit en cartes illustrées, dans une fenêtre comme celle de l'atelier (les plus nombreux d'abord, une mythique en dernier, jamais une mythique pour une autre rareté).
|
||||
- Une rare ou une épique franchit trois paliers, une légendaire deux (elle part de 70), une mythique un (elle part de 85).
|
||||
- **Pourquoi 6 / 2 / 1** : le nombre suit les taux de tirage (24/8/3), pas le prestige. Un palier coûte ainsi environ 8 paquets à chaque rareté. Avec 2 épiques ou 2 légendaires, un palier coûtait 8 paquets à une épique et 22 à une légendaire.
|
||||
- **Le recyclage en masse** s'arrête à une rareté choisie (Commune par défaut), et ne prend jamais les mythiques, pour ne pas jeter les doublons utiles à un Éveil.
|
||||
|
|
|
|||
|
|
@ -2076,10 +2076,23 @@ test("an administrator opens expeditions and a player leaves alone, follows the
|
|||
await expect(summary).toContainText("Éveil nécessaire pour atteindre la Puissance\u00a085");
|
||||
const awakening = sheet.getByRole("region", { name: "Éveil · Puissance\u00a085", exact: true });
|
||||
await expect(awakening.getByRole("button", { name: "Éveiller avec un doublon", exact: true })).toBeEnabled();
|
||||
await expect(awakening.getByRole("button", { name: "Éveiller avec 1 doublon de la collection", exact: true })).toBeVisible();
|
||||
await expect(awakening).toContainText(/Doublons de rareté Légendaire disponibles dans .+ : [01] sur 1\./);
|
||||
await expect(awakening).toContainText(/Doublons de rareté Légendaire disponibles dans .+ : 1 sur 1\./);
|
||||
await expect(sheet.getByRole("region", { name: "Améliorer", exact: true })).toHaveCount(0);
|
||||
await awakening.screenshot({ path: join(tmpdir(), "sokkog-cards-awakening.png") });
|
||||
// Les doublons de la collection se choisissent en cartes illustrées, comme à l'atelier ; rien n'est utilisé avant « Éveiller ».
|
||||
await awakening.getByRole("button", { name: "Choisir 1 doublon de la collection", exact: true }).click();
|
||||
const awakeningPicker = partner.getByRole("dialog", { name: /^Éveil de Loup des Aurores/ });
|
||||
const awakenButton = awakeningPicker.getByRole("button", { name: "Éveiller", exact: true });
|
||||
await expect(awakeningPicker.getByRole("heading", { name: "Votre sélection (0/1)", exact: true })).toBeVisible();
|
||||
await expect(awakenButton).toBeDisabled();
|
||||
const candidates = awakeningPicker.getByRole("list", { name: "Vos doublons utilisables", exact: true }).getByRole("listitem");
|
||||
await expect(candidates).toHaveCount(1);
|
||||
await candidates.first().getByRole("button", { name: /^Ajouter .+ à la sélection$/ }).click();
|
||||
await expect(awakeningPicker.getByRole("heading", { name: "Votre sélection (1/1)", exact: true })).toBeVisible();
|
||||
await expect(awakenButton).toBeEnabled();
|
||||
await awakeningPicker.screenshot({ path: join(tmpdir(), "sokkog-cards-awakening-picker.png") });
|
||||
await awakeningPicker.getByRole("button", { name: "Annuler", exact: true }).click();
|
||||
await expect(awakeningPicker).toHaveCount(0);
|
||||
await partner.keyboard.press("Escape");
|
||||
// La suite du parcours reprend le Loup au niveau 0.
|
||||
setWolfLevel(0);
|
||||
|
|
|
|||
|
|
@ -341,7 +341,7 @@ export function createCardsApiHandler({
|
|||
}
|
||||
if (req.method === "POST" && url.pathname === "/api/cards/progress/upgrade") {
|
||||
const body = await readBody(req);
|
||||
json(res, 200, service.expeditions.upgradeCard(session.player.id, { editionId: body.editionId, method: body.method }));
|
||||
json(res, 200, service.expeditions.upgradeCard(session.player.id, { editionId: body.editionId, method: body.method, editionIds: body.editionIds ?? null }));
|
||||
return true;
|
||||
}
|
||||
if (req.method === "POST" && url.pathname === "/api/cards/expeditions/atelier") {
|
||||
|
|
|
|||
|
|
@ -124,8 +124,8 @@ export const progressMethods = {
|
|||
},
|
||||
|
||||
// Éveil d'une carte arrêtée devant un palier, ou null : la Puissance du palier, le doublon de la même carte qui l'éveille
|
||||
// (`exact`, pour une mythique sa version légendaire aussi) et les doublons de sa collection et de sa rareté qui le remplacent
|
||||
// (`needed` au plus, choisis dans `picks` : les plus nombreux d'abord, une mythique en dernier ; vide s'il en manque).
|
||||
// (`exact`, pour une mythique sa version légendaire aussi), et les doublons de sa collection et de sa rareté qui le remplacent :
|
||||
// `needed` à choisir parmi `candidates` (doublons libres de chaque carte, les plus nombreux d'abord, une mythique en dernier).
|
||||
awakeningOf(editionId, rarity, level, collection, settings) {
|
||||
const power = awakeningPower(rarity, level, settings);
|
||||
if (power == null) return null;
|
||||
|
|
@ -138,25 +138,39 @@ export const progressMethods = {
|
|||
const exact = spares.find((entry) => entry.editionId === editionId)
|
||||
?? (rarity === "mythic" ? spares.find((entry) => sameCard(entry) && rarityOf(entry) === "legendary") : null);
|
||||
const accepted = rarity === "mythic" ? ["legendary", "mythic"] : [rarity];
|
||||
const pool = spares
|
||||
const candidates = spares
|
||||
.filter((entry) => !sameCard(entry) && accepted.includes(rarityOf(entry)) && cards.get(editions.get(entry.editionId)?.cardId)?.collectionId === collectionId)
|
||||
.sort((left, right) => (rarityOf(left) === "mythic") - (rarityOf(right) === "mythic") || right.spare - left.spare || left.editionId.localeCompare(right.editionId));
|
||||
const needed = settings.awakening[rarity];
|
||||
.sort((left, right) => (rarityOf(left) === "mythic") - (rarityOf(right) === "mythic") || right.spare - left.spare || left.editionId.localeCompare(right.editionId))
|
||||
.map((entry) => ({ editionId: entry.editionId, spare: entry.spare }));
|
||||
return { power, exact: exact?.editionId ?? null, needed: settings.awakening[rarity], available: candidates.reduce((total, entry) => total + entry.spare, 0), candidates };
|
||||
},
|
||||
|
||||
// Doublons consommés par un Éveil de substitution : ceux choisis par le joueur (`editionIds`, une entrée par exemplaire), vérifiés,
|
||||
// sinon les premiers candidats. Vide s'il en manque.
|
||||
awakeningPicks(awakening, editionIds) {
|
||||
const spareOf = new Map(awakening.candidates.map((entry) => [entry.editionId, entry.spare]));
|
||||
if (editionIds != null) {
|
||||
const counts = new Map();
|
||||
for (const id of Array.isArray(editionIds) ? editionIds : [null]) counts.set(id, (counts.get(id) ?? 0) + 1);
|
||||
const valid = Array.isArray(editionIds) && editionIds.length === awakening.needed && [...counts].every(([id, count]) => count <= (spareOf.get(id) ?? 0));
|
||||
if (!valid) fail(400, "AWAKENING_SELECTION_INVALID", `Choisissez ${awakening.needed} doublon${awakening.needed > 1 ? "s" : ""} libres de cette rareté et de cette collection.`);
|
||||
return [...counts].map(([editionId, count]) => ({ editionId, count }));
|
||||
}
|
||||
const picks = [];
|
||||
let missing = needed;
|
||||
for (const entry of pool) {
|
||||
let missing = awakening.needed;
|
||||
for (const entry of awakening.candidates) {
|
||||
if (missing <= 0) break;
|
||||
const count = Math.min(entry.spare, missing);
|
||||
picks.push({ editionId: entry.editionId, count });
|
||||
missing -= count;
|
||||
}
|
||||
return { power, exact: exact?.editionId ?? null, needed, available: pool.reduce((total, entry) => total + entry.spare, 0), picks: missing > 0 ? [] : picks };
|
||||
return missing > 0 ? [] : picks;
|
||||
},
|
||||
|
||||
// Monte une carte d'un niveau avec des Éclats, ou de `duplicateLevels` niveaux en consommant un doublon de la même édition.
|
||||
// Devant un palier, seul l'Éveil la fait monter, sans Éclats : un doublon de la même carte (`duplicate`) ou des doublons de sa
|
||||
// collection et de sa rareté (`awaken`).
|
||||
upgradeCard(playerId, { editionId, method } = {}) {
|
||||
// collection et de sa rareté (`awaken`, choisis dans `editionIds`).
|
||||
upgradeCard(playerId, { editionId, method, editionIds = null } = {}) {
|
||||
const settings = this.settings;
|
||||
if (!["eclats", "duplicate", "awaken"].includes(method)) fail(400, "UPGRADE_METHOD_INVALID", "Choisissez des Éclats, un doublon ou un Éveil.");
|
||||
this.cards.database.transaction(() => {
|
||||
|
|
@ -174,7 +188,7 @@ export const progressMethods = {
|
|||
if (method !== "eclats" && this.db.prepare("SELECT 1 FROM openings WHERE player_id = ? AND status = 'pending'").get(playerId)) fail(409, "PENDING_OPENING", "Terminez d'abord l'ouverture en cours.");
|
||||
if (awakening) {
|
||||
if (method === "eclats") fail(409, "AWAKENING_REQUIRED", `Cette carte atteint un palier d’Éveil (Puissance ${awakening.power}) : éveillez-la avec des doublons.`);
|
||||
const used = method === "duplicate" ? (awakening.exact ? [{ editionId: awakening.exact, count: 1 }] : []) : awakening.picks;
|
||||
const used = method === "duplicate" ? (awakening.exact ? [{ editionId: awakening.exact, count: 1 }] : []) : this.awakeningPicks(awakening, editionIds);
|
||||
if (!used.length) fail(409, "NOT_ENOUGH_DUPLICATES", method === "duplicate" ? "Il faut un doublon libre de cette carte." : `Il faut ${awakening.needed} doublons libres de cette rareté et de cette collection.`);
|
||||
for (const item of used) this.cards.removeDuplicates(playerId, item.editionId, item.count);
|
||||
next = { level: progress.level + 1, fieldXp: 0 };
|
||||
|
|
|
|||
|
|
@ -309,11 +309,17 @@ export function validateSiteContent(site) {
|
|||
"cards.cardSheet.awakeningText",
|
||||
"cards.cardSheet.awakenExact",
|
||||
"cards.cardSheet.awakenLegendary",
|
||||
"cards.cardSheet.awakenPool",
|
||||
"cards.cardSheet.awakenPoolCount",
|
||||
"cards.cardSheet.awakenConfirmTitle",
|
||||
"cards.cardSheet.awakenConfirmText",
|
||||
"cards.cardSheet.awakenConfirm",
|
||||
"cards.cardSheet.awakenChoose",
|
||||
"cards.cardSheet.awakenPickerTitle",
|
||||
"cards.cardSheet.awakenPickerHelp",
|
||||
"cards.cardSheet.awakenSelection",
|
||||
"cards.cardSheet.awakenCandidates",
|
||||
"cards.cardSheet.awakenAdd",
|
||||
"cards.cardSheet.awakenRemove",
|
||||
"cards.cardSheet.awakenNoCandidates",
|
||||
"cards.cardSheet.awakenCancel",
|
||||
"cards.cardSheet.upgradeHelp",
|
||||
"cards.cardSheet.plan.title",
|
||||
"cards.cardSheet.plan.pointsGained",
|
||||
|
|
|
|||
|
|
@ -712,22 +712,28 @@ test("a card at an awakening tier awakens with its own duplicate or duplicates o
|
|||
database.db.prepare("UPDATE players SET eclats = 1000 WHERE id = ?").run(player.id);
|
||||
// Niveau 5 d'une rare : Puissance 65, le niveau suivant atteint le palier de 70.
|
||||
database.db.prepare("INSERT INTO card_progress(player_id, edition_id, level, field_xp, updated_at) VALUES (?, ?, 5, 0, 0)").run(player.id, card);
|
||||
assert.deepEqual(progressOf().awakening, { power: 70, exact: null, needed: 6, available: 0, picks: [] });
|
||||
assert.deepEqual(progressOf().awakening, { power: 70, exact: null, needed: 6, available: 0, candidates: [] });
|
||||
assert.throws(() => service.expeditions.upgradeCard(player.id, { editionId: card, method: "eclats" }), (error) => error.code === "AWAKENING_REQUIRED");
|
||||
assert.throws(() => service.expeditions.upgradeCard(player.id, { editionId: card, method: "awaken" }), (error) => error.code === "NOT_ENOUGH_DUPLICATES");
|
||||
assert.throws(() => service.expeditions.upgradeCard(player.id, { editionId: second, method: "awaken" }), (error) => error.code === "NOT_AT_AWAKENING");
|
||||
|
||||
// Six doublons rares de la Nébuleuse : les plus nombreux partent d'abord, sans Éclats ; une rare d'une autre collection ne compte pas.
|
||||
// Six doublons rares de la Nébuleuse, choisis par le joueur parmi les candidats (les plus nombreux d'abord), sans Éclats ;
|
||||
// une rare d'une autre collection ne compte pas.
|
||||
database.transaction(() => {
|
||||
for (let count = 0; count < 4; count += 1) service.addCard(player.id, second);
|
||||
for (let count = 0; count < 3; count += 1) service.addCard(player.id, third);
|
||||
service.addCard(player.id, editionsOf("rare", "dream-arcade")[0]);
|
||||
service.addCard(player.id, editionsOf("rare", "dream-arcade")[0]);
|
||||
});
|
||||
assert.deepEqual(progressOf().awakening, { power: 70, exact: null, needed: 6, available: 7, picks: [{ editionId: second, count: 4 }, { editionId: third, count: 2 }] });
|
||||
const awakened = service.expeditions.upgradeCard(player.id, { editionId: card, method: "awaken" });
|
||||
assert.deepEqual(progressOf().awakening, { power: 70, exact: null, needed: 6, available: 7, candidates: [{ editionId: second, spare: 4 }, { editionId: third, spare: 3 }] });
|
||||
const invalid = (editionIds) => assert.throws(() => service.expeditions.upgradeCard(player.id, { editionId: card, method: "awaken", editionIds }), (error) => error.code === "AWAKENING_SELECTION_INVALID");
|
||||
invalid([second, second, third, third, third]);
|
||||
invalid([second, second, second, second, second, third]);
|
||||
invalid([second, second, second, third, third, editionsOf("rare", "dream-arcade")[0]]);
|
||||
invalid("all");
|
||||
const awakened = service.expeditions.upgradeCard(player.id, { editionId: card, method: "awaken", editionIds: [third, second, third, second, third, second] });
|
||||
assert.deepEqual([awakened.progress.level, awakened.progress.power, awakened.progress.awakening, awakened.state.wallet.eclats], [6, 70, null, 1000]);
|
||||
assert.deepEqual([service.quantityOf(player.id, second), service.quantityOf(player.id, third)], [1, 2]);
|
||||
assert.deepEqual([service.quantityOf(player.id, second), service.quantityOf(player.id, third)], [2, 1]);
|
||||
assert.deepEqual(awakened.progress.awakeningsAhead, [85, 100]);
|
||||
|
||||
// Le doublon de la carte elle-même éveille aussi, et un doublon ordinaire ne franchit jamais un palier.
|
||||
|
|
@ -749,7 +755,7 @@ test("a card at an awakening tier awakens with its own duplicate or duplicates o
|
|||
service.reloadCatalog();
|
||||
database.transaction(() => { service.addCard(player.id, mythic); service.addCard(player.id, legendary); service.addCard(player.id, legendary); });
|
||||
database.db.prepare("INSERT INTO card_progress(player_id, edition_id, level, field_xp, updated_at) VALUES (?, ?, 2, 0, 0)").run(player.id, mythic);
|
||||
assert.deepEqual(progressOf(mythic).awakening, { power: 100, exact: legendary, needed: 1, available: 0, picks: [] });
|
||||
assert.deepEqual(progressOf(mythic).awakening, { power: 100, exact: legendary, needed: 1, available: 0, candidates: [] });
|
||||
const mythicAwakened = service.expeditions.upgradeCard(player.id, { editionId: mythic, method: "duplicate" });
|
||||
assert.deepEqual([mythicAwakened.progress.level, mythicAwakened.progress.power, service.quantityOf(player.id, legendary)], [3, 100, 1]);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -223,11 +223,17 @@
|
|||
"awakeningText": "Pour franchir ce palier, la carte doit s’éveiller. L’Éveil ne coûte pas d’Éclats : il consomme un doublon de la carte ou plusieurs doublons de sa collection. En attendant, l’expérience des expéditions ne progresse plus.",
|
||||
"awakenExact": "Éveiller avec un doublon",
|
||||
"awakenLegendary": "Éveiller avec sa version légendaire",
|
||||
"awakenPool": "Éveiller avec {count} doublon{s} de la collection",
|
||||
"awakenPoolCount": "Doublons de rareté {rarity} disponibles dans {collection} : {available} sur {count}.",
|
||||
"awakenConfirmTitle": "Éveiller la carte ?",
|
||||
"awakenConfirmText": "Ces doublons quittent votre collection : {cards}.",
|
||||
"awakenConfirm": "Éveiller",
|
||||
"awakenChoose": "Choisir {count} doublon{s} de la collection",
|
||||
"awakenPickerTitle": "Éveil de {card} · Puissance {power}",
|
||||
"awakenPickerHelp": "Choisissez {count} doublon{s} de rareté {rarity} de {collection}. Rien n’est utilisé avant « Éveiller ».",
|
||||
"awakenSelection": "Votre sélection ({count}/{needed})",
|
||||
"awakenCandidates": "Vos doublons utilisables",
|
||||
"awakenAdd": "Ajouter {card} à la sélection",
|
||||
"awakenRemove": "Retirer {card} de la sélection",
|
||||
"awakenNoCandidates": "Vous n’avez pas encore de doublon de rareté {rarity} dans {collection}.",
|
||||
"awakenCancel": "Annuler",
|
||||
"plan": {
|
||||
"title": "Répartition des statistiques",
|
||||
"pointsGained": "{count} point{s} gagné{s} en améliorant la carte.",
|
||||
|
|
|
|||
57
website/src/features/cards/AwakeningPicker.jsx
Normal file
57
website/src/features/cards/AwakeningPicker.jsx
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
// Rôle : choix des doublons d'un Éveil de substitution, en fenêtre, comme l'atelier : le joueur pose dans sa sélection autant de
|
||||
// doublons de la collection et de la rareté de la carte qu'il en faut (cartes illustrées, doublons libres en pastille), puis éveille.
|
||||
// Rien n'est consommé avant « Éveiller » ; « Annuler » ferme sans rien utiliser.
|
||||
import { useState } from "react";
|
||||
import { Modal } from "../../components/Modal.jsx";
|
||||
import { fillTemplate } from "./dailyShare.js";
|
||||
import { editionEntry } from "./expeditionFormat.js";
|
||||
import { NebulaCard } from "./NebulaCard.jsx";
|
||||
|
||||
// `awakening` : vue du serveur (needed, candidates) ; `onAwaken(editionIds)` renvoie le résultat de la mutation, null en cas d'échec.
|
||||
export function AwakeningPicker({ catalog, cardName, awakening, rarityLabel, collectionName, content, busy, onAwaken, onClose }) {
|
||||
const [chosen, setChosen] = useState([]);
|
||||
const { needed, candidates } = awakening;
|
||||
const plural = needed > 1 ? "s" : "";
|
||||
const used = (editionId) => chosen.filter((id) => id === editionId).length;
|
||||
const nameOf = (editionId) => editionEntry(catalog, editionId)?.card.name || "";
|
||||
const add = (entry) => {
|
||||
if (chosen.length < needed && used(entry.editionId) < entry.spare) setChosen([...chosen, entry.editionId]);
|
||||
};
|
||||
const awaken = async () => {
|
||||
if (await onAwaken(chosen)) onClose();
|
||||
};
|
||||
|
||||
return <Modal dialogClassName="confirm-modal nds-modal nebula-expedition-picker nebula-atelier nebula-awakening-picker" labelledBy="nebula-awakening-picker-title" onRequestClose={onClose} canClose={!busy}>
|
||||
<h2 id="nebula-awakening-picker-title">{fillTemplate(content.awakenPickerTitle, { card: cardName, power: awakening.power })}</h2>
|
||||
<p className="nebula-form-help">{fillTemplate(content.awakenPickerHelp, { count: needed, s: plural, rarity: rarityLabel, collection: collectionName })}</p>
|
||||
{/* Sélection : une place par doublon demandé ; une carte posée se retire d'un clic. */}
|
||||
<section className="nebula-atelier-selection" aria-labelledby="nebula-awakening-selection-title">
|
||||
<h3 id="nebula-awakening-selection-title">{fillTemplate(content.awakenSelection, { count: chosen.length, needed })}</h3>
|
||||
<ol>{Array.from({ length: needed }, (_, index) => {
|
||||
const editionId = chosen[index];
|
||||
const entry = editionId && editionEntry(catalog, editionId);
|
||||
return <li key={index} data-empty={!entry || undefined}>
|
||||
{entry ? <NebulaCard catalog={catalog} entry={entry} size="sm" onSelect={busy ? undefined : () => setChosen(chosen.filter((_, position) => position !== index))}
|
||||
selectLabel={fillTemplate(content.awakenRemove, { card: entry.card.name })} /> : <span aria-hidden="true" />}
|
||||
</li>;
|
||||
})}</ol>
|
||||
</section>
|
||||
{candidates.length ? <ul className="nebula-equipment-choices-grid" aria-label={content.awakenCandidates}>{candidates.map((entry) => {
|
||||
const card = editionEntry(catalog, entry.editionId);
|
||||
if (!card) return null;
|
||||
const left = entry.spare - used(entry.editionId);
|
||||
const full = chosen.length >= needed || left <= 0;
|
||||
return <li key={entry.editionId} data-equipped={used(entry.editionId) > 0 || undefined} data-unavailable={(full && !used(entry.editionId)) || undefined}>
|
||||
<span className="nebula-equipment-choice">
|
||||
<NebulaCard catalog={catalog} entry={card} size="sm" quantity={left} disabled={busy || full} onSelect={() => add(entry)}
|
||||
selectLabel={fillTemplate(content.awakenAdd, { card: nameOf(entry.editionId) })} />
|
||||
</span>
|
||||
<strong>{card.card.name}</strong>
|
||||
</li>;
|
||||
})}</ul> : <p className="nebula-form-help">{fillTemplate(content.awakenNoCandidates, { rarity: rarityLabel, collection: collectionName })}</p>}
|
||||
<div className="nds-toolbar nebula-expedition-picker-actions">
|
||||
<button className="nds-button" data-variant="secondary" type="button" disabled={busy} onClick={onClose}>{content.awakenCancel}</button>
|
||||
<button className="nds-button" data-variant="primary" type="button" disabled={busy || chosen.length !== needed} onClick={awaken}>{content.awakenConfirm}</button>
|
||||
</div>
|
||||
</Modal>;
|
||||
}
|
||||
|
|
@ -6,9 +6,9 @@
|
|||
// `focus` (« plan ») ouvre « Amélioration » et fait défiler la fiche jusqu'à cette section, depuis un objet du Sac.
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { Modal } from "../../components/Modal.jsx";
|
||||
import { ConfirmModal } from "../../components/ToolboxModals.jsx";
|
||||
import { Tabs } from "../../components/Tabs.jsx";
|
||||
import { recycleDuplicates, setFavorite, upgradeCard } from "./cardsApi.js";
|
||||
import { AwakeningPicker } from "./AwakeningPicker.jsx";
|
||||
import { CardPlan } from "./CardPlan.jsx";
|
||||
import { CurrencyAmount } from "./Currency.jsx";
|
||||
import { readCollection } from "./collectionState.js";
|
||||
|
|
@ -51,33 +51,27 @@ function CardSummary({ progress, preview, content }) {
|
|||
}
|
||||
|
||||
// Éveil d'une carte arrêtée devant un palier : un doublon d'elle-même (pour une mythique, sa version légendaire), ou des doublons de
|
||||
// sa collection et de sa rareté, montrés avant d'être consommés. L'Éveil ne coûte pas d'Éclats.
|
||||
// sa collection et de sa rareté, choisis dans une fenêtre comme à l'atelier. L'Éveil ne coûte pas d'Éclats.
|
||||
function CardAwakening({ catalog, progress, busy, runMutation, content }) {
|
||||
const [confirming, setConfirming] = useState(false);
|
||||
const [choosing, setChoosing] = useState(false);
|
||||
const { awakening } = progress;
|
||||
const editionOf = (id) => catalog.editions.find((edition) => edition.id === id);
|
||||
const cardName = (id) => catalog.cards.find((card) => card.id === editionOf(id)?.cardId)?.name ?? id;
|
||||
const own = editionOf(progress.editionId);
|
||||
const own = catalog.editions.find((edition) => edition.id === progress.editionId);
|
||||
const card = catalog.cards.find((item) => item.id === own?.cardId);
|
||||
const rarityLabel = (id) => catalog.rarities.find((item) => item.id === id)?.label ?? id;
|
||||
const accepted = own?.rarity === "mythic" ? `${rarityLabel("legendary")} ou ${rarityLabel("mythic")}` : rarityLabel(own?.rarity);
|
||||
const collectionName = catalog.collections.find((item) => item.id === catalog.cards.find((card) => card.id === own?.cardId)?.collectionId)?.name ?? "";
|
||||
const collectionName = catalog.collections.find((item) => item.id === card?.collectionId)?.name ?? "";
|
||||
const exactIsOther = awakening.exact && awakening.exact !== progress.editionId;
|
||||
const plural = awakening.needed > 1 ? "s" : "";
|
||||
const used = awakening.picks.map((item) => `${cardName(item.editionId)}${item.count > 1 ? ` ×${item.count}` : ""}`).join(", ");
|
||||
return <section className="nebula-card-upgrade nebula-card-awakening" aria-labelledby="nebula-card-awakening-title">
|
||||
<h3 id="nebula-card-awakening-title">{fillTemplate(content.awakeningTitle, { power: awakening.power })}</h3>
|
||||
<p className="nebula-form-help">{content.awakeningText}</p>
|
||||
<div className="nds-toolbar">
|
||||
<button className="nds-button" data-variant="primary" type="button" disabled={busy || !awakening.exact} onClick={() => runMutation(() => upgradeCard(progress.editionId, "duplicate"))}>{exactIsOther ? content.awakenLegendary : content.awakenExact}</button>
|
||||
<button className="nds-button" data-variant="secondary" type="button" disabled={busy || !awakening.picks.length} onClick={() => setConfirming(true)}>{fillTemplate(content.awakenPool, { count: awakening.needed, s: plural, rarity: accepted })}</button>
|
||||
<button className="nds-button" data-variant="secondary" type="button" disabled={busy} onClick={() => setChoosing(true)}>{fillTemplate(content.awakenChoose, { count: awakening.needed, s: plural })}</button>
|
||||
</div>
|
||||
<p className="nebula-form-help">{fillTemplate(content.awakenPoolCount, { available: Math.min(awakening.available, awakening.needed), count: awakening.needed, s: plural, rarity: accepted, collection: collectionName })}</p>
|
||||
{confirming && <ConfirmModal
|
||||
title={content.awakenConfirmTitle}
|
||||
message={fillTemplate(content.awakenConfirmText, { cards: used })}
|
||||
confirmLabel={content.awakenConfirm}
|
||||
onClose={(confirmed) => { setConfirming(false); if (confirmed) void runMutation(() => upgradeCard(progress.editionId, "awaken")); }}
|
||||
/>}
|
||||
{choosing && <AwakeningPicker catalog={catalog} cardName={card?.name ?? ""} awakening={awakening} rarityLabel={accepted} collectionName={collectionName} content={content} busy={busy}
|
||||
onAwaken={(editionIds) => runMutation(() => upgradeCard(progress.editionId, "awaken", editionIds))} onClose={() => setChoosing(false)} />}
|
||||
</section>;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -219,9 +219,10 @@ export function departExpedition(expeditionId) {
|
|||
return request(`/expeditions/${encodeURIComponent(expeditionId)}/depart`, { method: "POST" });
|
||||
}
|
||||
|
||||
// Améliore une carte d'un niveau : `method` vaut « eclats » ou « duplicate » (un doublon de la même édition).
|
||||
export function upgradeCard(editionId, method) {
|
||||
return request("/progress/upgrade", { method: "POST", body: JSON.stringify({ editionId, method }) });
|
||||
// Améliore une carte d'un niveau : `method` vaut « eclats », « duplicate » (un doublon de la même carte) ou « awaken » (Éveil avec
|
||||
// les doublons de sa collection choisis dans `editionIds`, une entrée par exemplaire).
|
||||
export function upgradeCard(editionId, method, editionIds = null) {
|
||||
return request("/progress/upgrade", { method: "POST", body: JSON.stringify({ editionId, method, ...(editionIds ? { editionIds } : {}) }) });
|
||||
}
|
||||
|
||||
// Plan de progression d'une carte : « collection », une vocation (leader, guardian, seeker, navigator) ou « free » avec ses points placés.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue