- Expeditions bring back objects by weight, proportional to the loot; treasure-map fragments, burins and workshop plans need enough average Orientation. - A guide star adds a fifth destination to the player's day, a sky chart a sixth with richer loot, and enough fragments open one of two hidden destinations: Le Passage Écarlate and L'Observatoire perdu. - An anchor recalls a running solo expedition and keeps the Éclats and stardust already earned; a burin engraves a tag on a common to create the synergy a player wants. - The Veilleur's bag lists objects with their use, reports show brought-back objects, and Administration › Guilde tunes object chances, weights, the Orientation threshold and hidden-destination loot. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
104 lines
6.8 KiB
JavaScript
104 lines
6.8 KiB
JavaScript
// Rôle : améliorations des cartes Sokko TCG pour les Expéditions : niveaux par Éclats ou doublon, expérience de terrain, pont depuis la poussière.
|
||
// Ces méthodes s'ajoutent à ExpeditionService (Object.assign sur son prototype) et utilisent `this` comme lui.
|
||
import { editionExpeditionData, gainProgress, maxLevel, upgradeCost } from "./expedition-rules.js";
|
||
|
||
function fail(status, code, message) {
|
||
throw Object.assign(new Error(message), { status, code });
|
||
}
|
||
|
||
// Au plus ce nombre d'Éclats par conversion, pour qu'une faute de frappe ne vide pas un solde de poussière.
|
||
export const MAX_CONVERT_ECLATS = 10_000;
|
||
|
||
export const progressMethods = {
|
||
levelsOf(playerId) {
|
||
return new Map(this.db.prepare("SELECT edition_id, level, field_xp FROM card_progress WHERE player_id = ?").all(playerId)
|
||
.map((row) => [row.edition_id, { level: row.level, fieldXp: row.field_xp }]));
|
||
},
|
||
|
||
progressOf(playerId, editionId) {
|
||
const row = this.db.prepare("SELECT level, field_xp FROM card_progress WHERE player_id = ? AND edition_id = ?").get(playerId, editionId);
|
||
return { level: row?.level ?? 0, fieldXp: row?.field_xp ?? 0 };
|
||
},
|
||
|
||
writeProgress(playerId, editionId, { level, fieldXp }) {
|
||
this.db.prepare(`INSERT INTO card_progress(player_id, edition_id, level, field_xp, updated_at) VALUES (?, ?, ?, ?, ?)
|
||
ON CONFLICT(player_id, edition_id) DO UPDATE SET level = excluded.level, field_xp = excluded.field_xp, updated_at = excluded.updated_at`)
|
||
.run(playerId, editionId, level, fieldXp, this.now());
|
||
},
|
||
|
||
// Progression de chaque carte jouable du joueur : niveau, expérience, Puissance, stats, niveau maximal et coût du suivant.
|
||
cardProgressView(playerId, settings = this.settings) {
|
||
const levels = this.levelsOf(playerId);
|
||
const equipment = this.equipmentOf(playerId);
|
||
const engravings = this.engravingsOf(playerId);
|
||
return this.cards.collectionOf(playerId).map((entry) => {
|
||
const progress = levels.get(entry.editionId) || { level: 0, fieldXp: 0 };
|
||
const data = this.loadout(entry.editionId, progress.level, equipment.get(entry.editionId), settings, engravings);
|
||
if (!data) return null;
|
||
return {
|
||
editionId: entry.editionId, level: progress.level, fieldXp: progress.fieldXp, power: data.power, baseStats: data.baseStats, stats: data.stats,
|
||
maxLevel: maxLevel(data.rarity, settings), nextCost: upgradeCost(data.rarity, progress.level, settings), spare: entry.spare,
|
||
slots: data.slots, maxSlots: settings.equipment.maxPerCard, tags: data.tags, equipment: data.equipment,
|
||
slotPowers: [0, settings.equipment.secondSlotPower, settings.equipment.thirdSlotPower].slice(0, settings.equipment.maxPerCard)
|
||
};
|
||
}).filter(Boolean);
|
||
},
|
||
|
||
// Monte une carte d'un niveau avec des Éclats, ou de `duplicateLevels` niveaux en consommant un doublon de la même édition.
|
||
upgradeCard(playerId, { editionId, method } = {}) {
|
||
const settings = this.settings;
|
||
if (!["eclats", "duplicate"].includes(method)) fail(400, "UPGRADE_METHOD_INVALID", "Choisissez des Éclats ou un doublon.");
|
||
this.cards.database.transaction(() => {
|
||
const owned = this.cards.collectionOf(playerId).find((entry) => entry.editionId === editionId);
|
||
if (!owned) fail(404, "CARD_NOT_OWNED", "Vous ne possédez pas cette carte.");
|
||
const data = editionExpeditionData(this.cards.catalog, editionId, 0, settings);
|
||
if (!data) fail(400, "EXPEDITION_CARD_INVALID", "Seules les cartes rares, épiques, légendaires et mythiques s’améliorent.");
|
||
const progress = this.progressOf(playerId, editionId);
|
||
const cost = upgradeCost(data.rarity, progress.level, settings);
|
||
if (cost == null) fail(409, "CARD_MAX_LEVEL", "Cette carte a atteint la Puissance maximale.");
|
||
let next;
|
||
let details;
|
||
if (method === "eclats") {
|
||
const paid = this.db.prepare("UPDATE players SET eclats = eclats - ? WHERE id = ? AND eclats >= ?").run(cost, playerId, cost);
|
||
if (!paid.changes) fail(409, "NOT_ENOUGH_ECLATS", "Pas assez d’Éclats d’étoile.");
|
||
next = gainProgress(progress, data.rarity, { levels: 1 }, settings);
|
||
details = { method, eclats: cost };
|
||
} else {
|
||
if (settings.progression.duplicateLevels < 1) fail(409, "UPGRADE_METHOD_INVALID", "Les doublons ne donnent pas de niveau pour le moment.");
|
||
if (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 (!owned.spare) fail(409, "NOT_A_DUPLICATE", "Il faut un doublon libre de cette carte.");
|
||
this.cards.removeDuplicates(playerId, editionId, 1);
|
||
next = gainProgress(progress, data.rarity, { levels: settings.progression.duplicateLevels }, settings);
|
||
details = { method };
|
||
}
|
||
this.writeProgress(playerId, editionId, next);
|
||
this.cards.audit(playerId, "card_upgraded", editionId, { ...details, level: next.level, power: editionExpeditionData(this.cards.catalog, editionId, next.level, settings).power });
|
||
});
|
||
return { progress: this.cardProgressView(playerId, settings).find((item) => item.editionId === editionId), state: this.cards.getState(playerId) };
|
||
},
|
||
|
||
// Pont à sens unique : de la poussière vers les Éclats, au taux réglé. La conversion inverse n'existe pas.
|
||
convertStardust(playerId, { eclats } = {}) {
|
||
const settings = this.settings;
|
||
if (!Number.isInteger(eclats) || eclats < 1 || eclats > MAX_CONVERT_ECLATS) fail(400, "CONVERT_INVALID", `Nombre d’Éclats invalide : un entier entre 1 et ${MAX_CONVERT_ECLATS.toLocaleString("fr-FR")}.`);
|
||
const cost = eclats * settings.progression.stardustPerEclat;
|
||
this.cards.database.transaction(() => {
|
||
// Compte de développement : son solde figé doit être appliqué avant de vérifier le prix.
|
||
this.cards.refreshRecharge(playerId);
|
||
const paid = this.db.prepare("UPDATE players SET stardust = stardust - ?, eclats = eclats + ? WHERE id = ? AND stardust >= ?").run(cost, eclats, playerId, cost);
|
||
if (!paid.changes) fail(409, "NOT_ENOUGH_STARDUST", "Pas assez de poussière d’étoiles.");
|
||
this.cards.audit(playerId, "eclats_converted", "bridge", { eclats, stardust: cost });
|
||
});
|
||
return this.cards.getState(playerId);
|
||
},
|
||
|
||
// Expérience de terrain : chaque carte du joueur revenue d'expédition gagne une part de niveau.
|
||
gainFieldXpInTx(playerId, editionIds, settings) {
|
||
if (!settings.progression.fieldXpPct) return;
|
||
for (const editionId of editionIds) {
|
||
const data = editionExpeditionData(this.cards.catalog, editionId, 0, settings);
|
||
if (!data || !this.cards.quantityOf(playerId, editionId)) continue;
|
||
this.writeProgress(playerId, editionId, gainProgress(this.progressOf(playerId, editionId), data.rarity, { xpPct: settings.progression.fieldXpPct }, settings));
|
||
}
|
||
}
|
||
};
|