Add the Carnets des Veilleurs, the expedition-only Sokko TCG collection with power commons
- A new watchers-logbooks collection of category expedition never comes from packs, the shop or codes, and administrators cannot open it as a pack. - Its six commons carry powers instead of stats (Longue-vue, Provisions, Carte au trésor, Talisman, Boussole folle, Filet à étoiles filantes); a card holds one power and each counts once per team. - Powers change travel time, loot, score or tier, hide requirements, or catch a logbook card; each destination lists the logbook cards it can bring back. - A workshop turns a plan and three duplicate commons into a power common. - The fifteen cards ship without images with ready ChatGPT prompts; a card only drops or gets crafted once illustrated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
ae23adfdd9
commit
21827a252b
38 changed files with 939 additions and 76 deletions
|
|
@ -342,6 +342,10 @@ export function createCardsApiHandler({
|
|||
json(res, 200, service.expeditions.upgradeCard(session.player.id, { editionId: body.editionId, method: body.method }));
|
||||
return true;
|
||||
}
|
||||
if (req.method === "POST" && url.pathname === "/api/cards/expeditions/atelier") {
|
||||
json(res, 200, service.expeditions.craft(session.player.id, { editionIds: (await readBody(req)).editionIds }));
|
||||
return true;
|
||||
}
|
||||
if (req.method === "POST" && url.pathname === "/api/cards/expeditions/bonus") {
|
||||
json(res, 200, service.expeditions.addBonusDestination(session.player.id, { item: (await readBody(req)).item }));
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
// Rôle : charge et valide le catalogue public, ses finitions et effets Sokko TCG.
|
||||
import { readFileSync } from "node:fs";
|
||||
import { STAT_IDS } from "./expedition-rules.js";
|
||||
import { POWER_IDS, STAT_IDS } from "./expedition-rules.js";
|
||||
|
||||
const RARITY_IDS = new Set(["common", "rare", "epic", "legendary", "mythic"]);
|
||||
const PARTICLE_SHAPE_KINDS = new Set(["sparks", "snowflakes"]);
|
||||
const PACK_CATEGORIES = new Set(["permanent", "event", "shop"]);
|
||||
// `expedition` : collection qui ne s'obtient qu'en expédition (jamais en paquet, en boutique ni par un code).
|
||||
const PACK_CATEGORIES = new Set(["permanent", "event", "shop", "expedition"]);
|
||||
const PACK_BACK_SYMBOLS = new Set(["star", "rift", "orbit"]);
|
||||
const COLOR_PATTERN = /^#[0-9a-f]{6}$/i;
|
||||
// Formats d'une variation mythique : le premier est le format de référence ; `full-art` utilise `card.fullImage` sur toute la carte.
|
||||
|
|
@ -60,7 +61,9 @@ function validateCardExpedition(card, tagIds) {
|
|||
const unknown = expedition.tags.find((tag) => !tagIds.has(tag));
|
||||
if (unknown) throw new TypeError(`Card ${card.id} uses unknown expedition tag ${unknown}.`);
|
||||
if (expedition.profile != null && !validExpeditionProfile(expedition.profile)) throw new TypeError(`Card ${card.id} expedition profile must give integer shares of the four stats summing to 100.`);
|
||||
if (expedition.equipment != null) {
|
||||
if (expedition.equipment?.power != null) {
|
||||
if (!POWER_IDS.includes(expedition.equipment.power) || expedition.equipment.stats != null) throw new TypeError(`Card ${card.id} power equipment must name a known power and carry no stats.`);
|
||||
} else if (expedition.equipment != null) {
|
||||
const stats = expedition.equipment.stats;
|
||||
const values = stats && typeof stats === "object" && !Array.isArray(stats) ? Object.entries(stats) : null;
|
||||
if (!values?.length || values.some(([stat, value]) => !STAT_IDS.includes(stat) || !Number.isInteger(value) || value === 0)
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
"description": "Les courants qui relient les îles changent de route chaque nuit. Il faut lire les étoiles pour ne pas s'y perdre.",
|
||||
"coverCardId": "stellar-current-otter",
|
||||
"themeTags": ["theme:voyage"],
|
||||
"logbookCards": ["skyboat-pilot-otter"],
|
||||
"stats": ["orientation", "bravoure", "endurance", "fortune"],
|
||||
"conditions": [{ "type": "tag", "tag": "theme:voyage" }],
|
||||
"dangers": [
|
||||
|
|
@ -19,6 +20,7 @@
|
|||
"description": "Le cratère où la Salamandre a trouvé l'Écaille du Néant. Les météorites y tombent encore, toutes brûlantes.",
|
||||
"coverCardId": "astral-ember-salamander",
|
||||
"themeTags": ["theme:veilleurs", "theme:cometes"],
|
||||
"logbookCards": ["first-observatory-salamander"],
|
||||
"stats": ["bravoure", "orientation", "fortune", "endurance"],
|
||||
"conditions": [{ "type": "tag", "tag": "theme:veilleurs" }],
|
||||
"dangers": [
|
||||
|
|
@ -33,6 +35,7 @@
|
|||
"description": "Loin du Soleil, les îles se couvrent de glace. Seuls les plus endurants traversent les lacs gelés jusqu'au bout.",
|
||||
"coverCardId": "starlit-ice-penguin",
|
||||
"themeTags": ["theme:hiver", "lieu:glaces"],
|
||||
"logbookCards": ["drifting-isle-turtle"],
|
||||
"stats": ["endurance", "bravoure", "orientation", "fortune"],
|
||||
"conditions": [{ "type": "tag", "tag": "theme:hiver" }],
|
||||
"dangers": [
|
||||
|
|
@ -47,6 +50,7 @@
|
|||
"description": "Les rêves de jeu du Panda forment des îles pleines de blocs, de pièces et de coffres. Chaque niveau cache un trésor.",
|
||||
"coverCardId": "island-arcade-cabinet",
|
||||
"themeTags": ["lieu:iles-jeux"],
|
||||
"logbookCards": ["lookout-meerkat"],
|
||||
"stats": ["fortune", "bravoure", "endurance", "orientation"],
|
||||
"conditions": [{ "type": "tag", "tag": "lieu:iles-jeux" }],
|
||||
"dangers": [
|
||||
|
|
@ -61,6 +65,7 @@
|
|||
"description": "Là où dort le Panda, la poussière d'étoiles s'assemble en rêves. On y trouve parfois une île qui vient de naître.",
|
||||
"coverCardId": "milky-way-panda",
|
||||
"themeTags": ["theme:reves", "theme:poussiere"],
|
||||
"logbookCards": ["apprentice-watcher-owl"],
|
||||
"stats": ["fortune", "orientation", "bravoure", "endurance"],
|
||||
"conditions": [{ "type": "tag", "tag": "theme:reves" }],
|
||||
"dangers": [
|
||||
|
|
@ -75,6 +80,7 @@
|
|||
"description": "Sur les îles tournées vers le Soleil, le jour se lève avant partout ailleurs. Le vent brûlant y souffle fort.",
|
||||
"coverCardId": "solar-dawn-capybara",
|
||||
"themeTags": ["lieu:soleil"],
|
||||
"logbookCards": ["cartographer-gecko"],
|
||||
"stats": ["endurance", "fortune", "bravoure", "orientation"],
|
||||
"conditions": [{ "type": "tag", "tag": "lieu:soleil" }],
|
||||
"dangers": [
|
||||
|
|
@ -89,6 +95,7 @@
|
|||
"description": "L'eau des îles est arrivée avec les comètes. Leurs lacs les plus anciens gardent des pierres aux reflets argentés.",
|
||||
"coverCardId": "cosmic-water-axolotl",
|
||||
"themeTags": ["theme:eau", "theme:cometes"],
|
||||
"logbookCards": ["skyboat-pilot-otter"],
|
||||
"stats": ["fortune", "endurance", "orientation", "bravoure"],
|
||||
"conditions": [{ "type": "tag", "tag": "theme:eau" }],
|
||||
"dangers": [
|
||||
|
|
@ -103,6 +110,7 @@
|
|||
"description": "Entre les îles, le noir est profond et les repères rares. Les bateaux du ciel y voyagent lentement.",
|
||||
"coverCardId": "deep-sky-ray",
|
||||
"themeTags": ["lieu:vide"],
|
||||
"logbookCards": ["drifting-isle-turtle"],
|
||||
"stats": ["orientation", "endurance", "bravoure", "fortune"],
|
||||
"conditions": [{ "type": "tag", "tag": "lieu:vide" }],
|
||||
"dangers": [
|
||||
|
|
@ -117,6 +125,7 @@
|
|||
"description": "Les premiers observatoires des Veilleurs sont pleins de cartes, de carnets et d'instruments oubliés.",
|
||||
"coverCardId": "watchers-spyglass",
|
||||
"themeTags": ["theme:veilleurs", "personnage:hibou"],
|
||||
"logbookCards": ["map-keeper-owl", "lookout-meerkat"],
|
||||
"stats": ["orientation", "fortune", "endurance", "bravoure"],
|
||||
"conditions": [{ "type": "tag", "tag": "theme:veilleurs" }],
|
||||
"dangers": [
|
||||
|
|
@ -131,6 +140,7 @@
|
|||
"description": "Pendant la Longue Nuit, les îles se rapprochent pour la grande fête. Il y a des cadeaux à livrer dans tout l'archipel.",
|
||||
"coverCardId": "celestial-fox-mask",
|
||||
"themeTags": ["theme:fete", "theme:hiver"],
|
||||
"logbookCards": ["apprentice-watcher-owl"],
|
||||
"stats": ["bravoure", "fortune", "orientation", "endurance"],
|
||||
"conditions": [{ "type": "tag", "tag": "theme:fete" }],
|
||||
"dangers": [
|
||||
|
|
@ -145,6 +155,7 @@
|
|||
"description": "Des temples rêvés se cachent sous la végétation des îles-jeux. Leurs pièges gardent toujours un trésor.",
|
||||
"coverCardId": "lost-ruins-meerkat",
|
||||
"themeTags": ["theme:tresor", "theme:aventure"],
|
||||
"logbookCards": ["cartographer-gecko"],
|
||||
"stats": ["bravoure", "endurance", "orientation", "fortune"],
|
||||
"conditions": [{ "type": "tag", "tag": "theme:tresor" }],
|
||||
"dangers": [
|
||||
|
|
@ -159,6 +170,7 @@
|
|||
"description": "Sous la Lune Pâle, les roches bleues brillent dans le noir. Il fait froid, mais on y voit loin.",
|
||||
"coverCardId": "pale-moon-owl",
|
||||
"themeTags": ["theme:nuit"],
|
||||
"logbookCards": ["map-keeper-owl"],
|
||||
"stats": ["endurance", "orientation", "fortune", "bravoure"],
|
||||
"conditions": [{ "type": "tag", "tag": "theme:nuit" }],
|
||||
"dangers": [
|
||||
|
|
@ -173,6 +185,7 @@
|
|||
"description": "Les nuits de Lune Écarlate, le Kitsune ouvre un passage vers une île qu’on ne voit jamais autrement. Une carte au trésor en garde la trace.",
|
||||
"coverCardId": "crimson-moon-kitsune",
|
||||
"themeTags": ["lieu:lune-ecarlate", "theme:passages"],
|
||||
"logbookCards": ["watchers-guide-magpie"],
|
||||
"stats": ["orientation", "fortune", "bravoure", "endurance"],
|
||||
"conditions": [{ "type": "tag", "tag": "lieu:lune-ecarlate" }],
|
||||
"dangers": [
|
||||
|
|
@ -187,6 +200,7 @@
|
|||
"description": "Le premier observatoire des Veilleurs, bâti autour de l’Écaille du Néant, dérive quelque part dans le vide. Une carte au trésor complète y mène.",
|
||||
"coverCardId": "observatory-key",
|
||||
"themeTags": ["theme:veilleurs", "lieu:vide"],
|
||||
"logbookCards": ["scale-keeper-dragon", "first-observatory-salamander"],
|
||||
"stats": ["bravoure", "orientation", "endurance", "fortune"],
|
||||
"conditions": [{ "type": "tag", "tag": "theme:veilleurs" }],
|
||||
"dangers": [
|
||||
|
|
|
|||
|
|
@ -377,6 +377,10 @@ const MIGRATIONS = [
|
|||
created_at INTEGER NOT NULL,
|
||||
PRIMARY KEY (player_id, day, slot)
|
||||
) STRICT;
|
||||
`,
|
||||
// Pouvoirs des Carnets des Veilleurs portés par la carte d'une place, figés à l'inscription ou au départ.
|
||||
`
|
||||
ALTER TABLE expedition_slots ADD COLUMN powers_json TEXT NOT NULL DEFAULT '[]' CHECK (json_valid(powers_json));
|
||||
`
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -43,6 +43,12 @@ export function validateExpeditionDestinations(destinations, catalog) {
|
|||
// Thème de la destination : une carte qui porte l'une de ces étiquettes donne l'Affinité à l'équipe.
|
||||
if (!Array.isArray(destination.themeTags) || !destination.themeTags.length || destination.themeTags.some((tag) => !tagIds.has(tag))) fail(destination, "needs known theme tags.");
|
||||
if (matchingCards(catalog, { tags: destination.themeTags }).length < MIN_MATCHING_CARDS) fail(destination, `theme matches fewer than ${MIN_MATCHING_CARDS} rare or better cards.`);
|
||||
// Cartes des Carnets des Veilleurs que la destination peut rapporter : rare ou mieux, d'une collection des Expéditions.
|
||||
const expeditionCollections = new Set(catalog.collections.filter((collection) => collection.packCategory === "expedition").map((collection) => collection.id));
|
||||
if (!Array.isArray(destination.logbookCards) || destination.logbookCards.some((cardId) => {
|
||||
const card = catalog.cards.find((item) => item.id === cardId);
|
||||
return !card || !expeditionCollections.has(card.collectionId) || !isExpeditionCard(catalog, cardId);
|
||||
})) fail(destination, "logbookCards must list rare or better cards of an expedition collection.");
|
||||
if (!Array.isArray(destination.conditions) || !destination.conditions.length) fail(destination, "needs at least one condition.");
|
||||
for (const condition of destination.conditions) {
|
||||
if (condition?.type === "tag") {
|
||||
|
|
|
|||
|
|
@ -22,7 +22,8 @@ export const equipmentMethods = {
|
|||
const card = edition && this.cards.index.cards.get(edition.cardId);
|
||||
if (!card?.expedition?.equipment) return null;
|
||||
const engraved = engravings?.get(editionId) ?? null;
|
||||
return { editionId, cardId: card.id, name: card.name, stats: card.expedition.equipment.stats, tags: engraved ? [...card.expedition.tags, engraved] : card.expedition.tags, engraved };
|
||||
const { stats = {}, power = null } = card.expedition.equipment;
|
||||
return { editionId, cardId: card.id, name: card.name, stats, power, tags: engraved ? [...card.expedition.tags, engraved] : card.expedition.tags, engraved };
|
||||
},
|
||||
|
||||
// Une carte prête à partir : stats de sa Puissance, plus ses équipements (dans ses emplacements ouverts) et leurs synergies.
|
||||
|
|
@ -30,11 +31,12 @@ export const equipmentMethods = {
|
|||
const data = editionExpeditionData(this.cards.catalog, editionId, level, settings);
|
||||
if (!data) return null;
|
||||
const slots = unlockedSlots(data.power, settings);
|
||||
const items = (equipped || []).filter((item) => item.slot < slots).map((item) => ({ slot: item.slot, ...this.equipmentItem(item.equipmentEditionId, engravings) })).filter((item) => item.stats);
|
||||
const items = (equipped || []).filter((item) => item.slot < slots).map((item) => ({ slot: item.slot, ...this.equipmentItem(item.equipmentEditionId, engravings) })).filter((item) => item.editionId);
|
||||
const bonus = equipmentBonus(items, data.tags, settings);
|
||||
return {
|
||||
...data, baseStats: data.stats, stats: addStats(data.stats, bonus.stats), slots,
|
||||
equipment: items.map((item, index) => ({ slot: item.slot, editionId: item.editionId, cardId: item.cardId, name: item.name, stats: item.stats, engraved: item.engraved, synergyTag: bonus.pairs[index] }))
|
||||
powers: items.map((item) => item.power).filter(Boolean),
|
||||
equipment: items.map((item, index) => ({ slot: item.slot, editionId: item.editionId, cardId: item.cardId, name: item.name, stats: item.stats, power: item.power, engraved: item.engraved, synergyTag: bonus.pairs[index] }))
|
||||
};
|
||||
},
|
||||
|
||||
|
|
@ -58,6 +60,12 @@ export const equipmentMethods = {
|
|||
const item = this.equipmentItem(equipmentEditionId, this.engravingsOf(playerId));
|
||||
if (!item) fail(400, "EQUIPMENT_INVALID", "Seules les communes servent d’équipement.");
|
||||
if (!owned.has(equipmentEditionId)) fail(404, "CARD_NOT_OWNED", "Vous ne possédez pas cette commune.");
|
||||
// Un seul pouvoir par carte : une commune de pouvoir ne remplace qu'un emplacement qui en portait déjà un, ou s'ajoute s'il n'y en a aucun.
|
||||
if (item.power) {
|
||||
const powered = this.db.prepare("SELECT slot, equipment_edition_id FROM card_equipment WHERE player_id = ? AND edition_id = ?").all(playerId, editionId)
|
||||
.filter((row) => row.slot !== slot && row.equipment_edition_id !== equipmentEditionId && this.equipmentItem(row.equipment_edition_id)?.power);
|
||||
if (powered.length) fail(409, "POWER_LIMIT", "Cette carte porte déjà un pouvoir : retirez-le d’abord.");
|
||||
}
|
||||
const elsewhere = this.db.prepare("SELECT edition_id FROM card_equipment WHERE player_id = ? AND equipment_edition_id = ?").get(playerId, equipmentEditionId);
|
||||
if (elsewhere && elsewhere.edition_id !== editionId && busy.has(elsewhere.edition_id)) fail(409, "EQUIPMENT_IN_USE", "Cette commune équipe une carte partie en expédition.");
|
||||
this.db.prepare("DELETE FROM card_equipment WHERE player_id = ? AND (equipment_edition_id = ? OR (edition_id = ? AND slot = ?))").run(playerId, equipmentEditionId, editionId, slot);
|
||||
|
|
@ -91,7 +99,7 @@ export const equipmentMethods = {
|
|||
const engravings = this.engravingsOf(playerId);
|
||||
return this.cards.collectionOf(playerId).map((entry) => {
|
||||
const item = this.equipmentItem(entry.editionId, engravings);
|
||||
return item && { editionId: item.editionId, cardId: item.cardId, stats: item.stats, tags: item.tags, engraved: item.engraved, equippedOn: placed.get(item.editionId) ?? null };
|
||||
return item && { editionId: item.editionId, cardId: item.cardId, stats: item.stats, power: item.power, tags: item.tags, engraved: item.engraved, equippedOn: placed.get(item.editionId) ?? null };
|
||||
}).filter(Boolean);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import { randomUUID } from "node:crypto";
|
|||
import { dailyDayKey } from "./daily.js";
|
||||
import {
|
||||
cardExpeditionData, cohesionPct, dangerCount, editionExpeditionData, evaluateTeam, expectedLoot, groupLootPct, groupSlots, guildKeeperSlot, hasCondition, requirementsFor,
|
||||
ROLE_BY_STAT, STAT_BY_ROLE, teamSynergy
|
||||
ROLE_BY_STAT, STAT_BY_ROLE, teamPowers, teamSynergy, travelHours
|
||||
} from "./expedition-rules.js";
|
||||
|
||||
const HOUR_MS = 3_600_000;
|
||||
|
|
@ -18,13 +18,13 @@ const roleStat = (role) => (role ? STAT_BY_ROLE[role] : null);
|
|||
export const groupMethods = {
|
||||
// Places des joueurs d'un groupe, prêtes pour l'évaluation (stats figées à l'inscription, étiquettes et collection du catalogue).
|
||||
memberSlots(expeditionId) {
|
||||
return this.db.prepare(`SELECT s.position, s.role, s.player_id, s.edition_id, s.card_id, s.level, s.stats_json, p.display_name
|
||||
return this.db.prepare(`SELECT s.position, s.role, s.player_id, s.edition_id, s.card_id, s.level, s.stats_json, s.powers_json, p.display_name
|
||||
FROM expedition_slots s LEFT JOIN players p ON p.id = s.player_id WHERE s.expedition_id = ? AND s.player_id IS NOT NULL ORDER BY s.position`).all(expeditionId)
|
||||
.map((row) => {
|
||||
const data = cardExpeditionData(this.cards.catalog, row.card_id);
|
||||
return {
|
||||
position: row.position, role: roleStat(row.role), playerId: row.player_id, playerName: row.display_name, editionId: row.edition_id, cardId: row.card_id,
|
||||
level: row.level, stats: JSON.parse(row.stats_json), tags: data?.tags || [], collectionId: data?.collectionId ?? null
|
||||
level: row.level, stats: JSON.parse(row.stats_json), powers: JSON.parse(row.powers_json || "[]"), tags: data?.tags || [], collectionId: data?.collectionId ?? null
|
||||
};
|
||||
});
|
||||
},
|
||||
|
|
@ -36,9 +36,10 @@ export const groupMethods = {
|
|||
const durationIndex = Math.max(0, settings.durations.hours.indexOf(setup.hours));
|
||||
const cohesion = cohesionPct(playerSlots, settings);
|
||||
const synergy = teamSynergy({ destination, slots: playerSlots, cohesionPct: cohesion }, settings);
|
||||
const powers = teamPowers(playerSlots);
|
||||
// Le nombre de places est celui de l'ouverture du groupe (un rôle par place), même si le réglage a changé depuis.
|
||||
const evaluation = evaluateTeam({ destination, entry, stars: setup.stars, durationIndex, slots: groupSlots(playerSlots, settings, setup.roles.length), synergyPct: synergy.totalPct }, settings);
|
||||
return { evaluation, cohesion, synergy };
|
||||
const evaluation = evaluateTeam({ destination, entry, stars: setup.stars, durationIndex, slots: groupSlots(playerSlots, settings, setup.roles.length), synergyPct: synergy.totalPct, powers }, settings);
|
||||
return { evaluation, cohesion, synergy, powers, destination };
|
||||
},
|
||||
|
||||
// Rôles d'un groupe : un par place, dans l'ordre des stats de la destination.
|
||||
|
|
@ -56,9 +57,9 @@ export const groupMethods = {
|
|||
const slot = { ...card, role: body.role, position: 0 };
|
||||
const setup = this.groupSetup(resolved, stars, hours, settings);
|
||||
setup.bonusSlot = resolved.bonusSlot ?? null;
|
||||
const { evaluation, cohesion, synergy } = this.evaluateGroup(setup, [slot], settings);
|
||||
const expected = expectedLoot({ hours, stars, tier: evaluation.tier, fortune: evaluation.stats.fortune, slotCount: settings.group.slots, multiplierPct: groupLootPct(1, settings), bonusSlot: setup.bonusSlot }, settings);
|
||||
return { day, resolved, stars, durationIndex, hours, slot, setup, evaluation, cohesion, synergy, expected };
|
||||
const { evaluation, cohesion, synergy, powers } = this.evaluateGroup(setup, [slot], settings);
|
||||
const expected = expectedLoot({ hours, stars, tier: evaluation.tier, fortune: evaluation.stats.fortune, slotCount: settings.group.slots, multiplierPct: groupLootPct(1, settings), bonusSlot: setup.bonusSlot, powers }, settings);
|
||||
return { day, resolved, stars, durationIndex, hours, slot, setup, evaluation, cohesion, synergy, powers, expected };
|
||||
},
|
||||
|
||||
groupSetup({ destination, entry }, stars, hours, settings) {
|
||||
|
|
@ -104,8 +105,8 @@ export const groupMethods = {
|
|||
|
||||
insertMember(expeditionId, playerId, slot, position, now) {
|
||||
this.db.prepare("INSERT INTO expedition_members(expedition_id, player_id, joined_at) VALUES (?, ?, ?)").run(expeditionId, playerId, now);
|
||||
this.db.prepare("INSERT INTO expedition_slots(expedition_id, position, role, player_id, edition_id, card_id, level, stats_json) VALUES (?, ?, ?, ?, ?, ?, ?, ?)")
|
||||
.run(expeditionId, position, ROLE_BY_STAT[slot.role], playerId, slot.editionId, slot.cardId, slot.level, JSON.stringify(slot.stats));
|
||||
this.db.prepare("INSERT INTO expedition_slots(expedition_id, position, role, player_id, edition_id, card_id, level, stats_json, powers_json) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)")
|
||||
.run(expeditionId, position, ROLE_BY_STAT[slot.role], playerId, slot.editionId, slot.cardId, slot.level, JSON.stringify(slot.stats), JSON.stringify(slot.powers || []));
|
||||
},
|
||||
|
||||
formingRow(expeditionId) {
|
||||
|
|
@ -190,7 +191,7 @@ export const groupMethods = {
|
|||
launchInTx(row, at, settings) {
|
||||
const setup = JSON.parse(row.setup_json);
|
||||
const members = this.memberSlots(row.id);
|
||||
const { evaluation, cohesion, synergy } = this.evaluateGroup(setup, members, settings);
|
||||
const { evaluation, cohesion, synergy, powers, destination } = this.evaluateGroup(setup, members, settings);
|
||||
this.discoverResonancesInTx(members.map((member) => member.playerId), synergy);
|
||||
const keeper = guildKeeperSlot(settings);
|
||||
const taken = new Set(members.map((slot) => slot.position));
|
||||
|
|
@ -198,12 +199,13 @@ export const groupMethods = {
|
|||
const insertKeeper = this.db.prepare("INSERT INTO expedition_slots(expedition_id, position, role, player_id, edition_id, card_id, level, stats_json) VALUES (?, ?, NULL, NULL, NULL, NULL, 0, ?)");
|
||||
for (const position of free) insertKeeper.run(row.id, position, JSON.stringify(keeper.stats));
|
||||
const multiplierPct = groupLootPct(members.length, settings);
|
||||
const expected = expectedLoot({ hours: setup.hours, stars: setup.stars, tier: evaluation.tier, fortune: evaluation.stats.fortune, slotCount: setup.roles.length, multiplierPct, bonusSlot: setup.bonusSlot ?? null }, settings);
|
||||
const expected = expectedLoot({ hours: setup.hours, stars: setup.stars, tier: evaluation.tier, fortune: evaluation.stats.fortune, slotCount: setup.roles.length, multiplierPct, bonusSlot: setup.bonusSlot ?? null, powers }, settings);
|
||||
const updateReward = this.db.prepare("UPDATE expedition_members SET reward_json = ? WHERE expedition_id = ? AND player_id = ?");
|
||||
for (const member of members) updateReward.run(JSON.stringify(this.rollReward(expected, settings, evaluation.stats.orientation / setup.roles.length)), row.id, member.playerId);
|
||||
const result = this.resultView(evaluation, { players: members.length, cohesionPct: cohesion, lootPct: multiplierPct }, synergy);
|
||||
this.db.prepare("UPDATE expeditions SET status = 'running', departs_at = ?, returns_at = ?, result_json = ? WHERE id = ?")
|
||||
.run(at, at + setup.hours * HOUR_MS, JSON.stringify(result), row.id);
|
||||
for (const member of members) updateReward.run(JSON.stringify(this.rollReward(expected, settings, { orientationPerSlot: evaluation.stats.orientation / setup.roles.length, powers, destination })), row.id, member.playerId);
|
||||
const result = this.resultView(evaluation, { players: members.length, cohesionPct: cohesion, lootPct: multiplierPct, powers }, synergy);
|
||||
const travel = Math.round(travelHours(setup.hours, powers, settings) * HOUR_MS);
|
||||
this.db.prepare("UPDATE expeditions SET status = 'running', departs_at = ?, returns_at = ?, duration_ms = ?, result_json = ? WHERE id = ?")
|
||||
.run(at, at + travel, travel, JSON.stringify(result), row.id);
|
||||
},
|
||||
|
||||
// Garde-fou : à la fin de la période d'inscription, un groupe part seul s'il a assez de joueurs, sinon il est dissous.
|
||||
|
|
@ -227,7 +229,7 @@ export const groupMethods = {
|
|||
return this.db.prepare("SELECT e.*, p.display_name AS creator_name FROM expeditions e JOIN players p ON p.id = e.creator_id WHERE e.status = 'forming' ORDER BY e.created_at").all().map((row) => {
|
||||
const setup = JSON.parse(row.setup_json);
|
||||
const members = this.memberSlots(row.id);
|
||||
const { evaluation, cohesion, synergy } = this.evaluateGroup(setup, members, settings);
|
||||
const { evaluation, cohesion, synergy, powers } = this.evaluateGroup(setup, members, settings);
|
||||
const isMember = members.some((slot) => slot.playerId === playerId);
|
||||
const freeRoles = setup.roles.filter((role) => !members.some((slot) => slot.role === role));
|
||||
return {
|
||||
|
|
@ -237,7 +239,8 @@ export const groupMethods = {
|
|||
canJoin: settings.enabled && !isMember && freeRoles.length > 0,
|
||||
canDepart: row.creator_id === playerId && members.length >= settings.group.minPlayers,
|
||||
requirements: requirementsFor({ stats: setup.destination.stats }, setup.stars, setup.roles, settings),
|
||||
projected: this.resultView(evaluation, { players: members.length, cohesionPct: cohesion, lootPct: groupLootPct(members.length, settings) }, synergy)
|
||||
projected: powers.includes("madCompass") ? { hiddenRequirements: true, powers, players: members.length, cohesionPct: cohesion, lootPct: groupLootPct(members.length, settings) }
|
||||
: this.resultView(evaluation, { players: members.length, cohesionPct: cohesion, lootPct: groupLootPct(members.length, settings), powers }, synergy)
|
||||
};
|
||||
});
|
||||
},
|
||||
|
|
|
|||
|
|
@ -102,6 +102,43 @@ export const itemMethods = {
|
|||
return this.cards.getState(playerId);
|
||||
},
|
||||
|
||||
// Communes de pouvoir que l'atelier peut fabriquer : celles des collections des Expéditions déjà illustrées.
|
||||
powerCommons() {
|
||||
const expeditionCollections = new Set(this.cards.catalog.collections.filter((collection) => collection.packCategory === "expedition").map((collection) => collection.id));
|
||||
return this.cards.catalog.editions.filter((edition) => {
|
||||
const card = this.cards.index.cards.get(edition.cardId);
|
||||
return card?.image && card.expedition?.equipment?.power && !edition.promotional && expeditionCollections.has(card.collectionId);
|
||||
});
|
||||
},
|
||||
|
||||
atelierAvailable() {
|
||||
return this.powerCommons().length > 0;
|
||||
},
|
||||
|
||||
// Atelier : un plan et 3 doublons de communes donnent une commune de pouvoir des Carnets, au hasard.
|
||||
craft(playerId, { editionIds } = {}) {
|
||||
if (!Array.isArray(editionIds) || editionIds.length !== 3) fail(400, "ATELIER_INVALID", "Choisissez 3 doublons de communes.");
|
||||
let crafted;
|
||||
this.cards.database.transaction(() => {
|
||||
const recipes = this.powerCommons();
|
||||
if (!recipes.length) fail(409, "ATELIER_UNAVAILABLE", "L’atelier attend encore les illustrations des Carnets des Veilleurs.");
|
||||
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.");
|
||||
const needed = new Map();
|
||||
for (const editionId of editionIds) needed.set(editionId, (needed.get(editionId) || 0) + 1);
|
||||
const owned = new Map(this.cards.collectionOf(playerId).map((entry) => [entry.editionId, entry]));
|
||||
for (const [editionId, count] of needed) {
|
||||
if (!this.equipmentItem(editionId)) fail(400, "ATELIER_INVALID", "L’atelier n’utilise que des communes.");
|
||||
if ((owned.get(editionId)?.spare ?? 0) < count) fail(409, "NOT_A_DUPLICATE", "Il faut des doublons libres de ces communes.");
|
||||
}
|
||||
this.consumeItemInTx(playerId, "plan");
|
||||
for (const [editionId, count] of needed) this.cards.removeDuplicates(playerId, editionId, count);
|
||||
crafted = recipes[this.random(recipes.length)].id;
|
||||
this.cards.addCard(playerId, crafted);
|
||||
this.cards.audit(playerId, "item_used", "plan", { item: "plan", editionId: crafted, used: editionIds });
|
||||
});
|
||||
return { crafted, state: this.cards.getState(playerId) };
|
||||
},
|
||||
|
||||
forgetItemsInTx(playerId) {
|
||||
for (const table of ["player_items", "equipment_engravings", "player_bonus_destinations"]) this.db.prepare(`DELETE FROM ${table} WHERE player_id = ?`).run(playerId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -138,7 +138,8 @@ export function tierFor(scorePct, settings) {
|
|||
}
|
||||
|
||||
// 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) {
|
||||
// `scoreFactor` : multiplicateur d'un pouvoir (la Carte au trésor coûte une part du score).
|
||||
export function scoreExpedition({ requirements, stats, conditionMet: met = null, synergyPct = 0, scoreFactor = 1 }, settings) {
|
||||
let weighted = 0;
|
||||
let weights = 0;
|
||||
const perRequirement = requirements.map((requirement) => {
|
||||
|
|
@ -150,20 +151,23 @@ export function scoreExpedition({ requirements, stats, conditionMet: met = null,
|
|||
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 raw = (weights ? weighted / weights : 0) * 100 * conditionFactor * (1 + synergyPct / 100) * scoreFactor;
|
||||
const scorePct = Math.min(settings.score.capPct, raw);
|
||||
return { perRequirement, conditionFactor, scorePct, tier: tierFor(scorePct, settings) };
|
||||
}
|
||||
|
||||
function evaluateAt({ destination, entry, stars, durationIndex, slots, synergyPct = 0 }, base, settings) {
|
||||
function evaluateAt({ destination, entry, stars, durationIndex, slots, synergyPct = 0, powers = [] }, 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);
|
||||
// Filet à étoiles filantes : l'équipe perd un peu de Fortune.
|
||||
if (powers.includes("starNet")) hazards.stats.fortune = Math.max(0, hazards.stats.fortune - settings.powers.starNetFortune);
|
||||
const met = condition ? conditionMet(slots, condition) : null;
|
||||
const synergy = Math.min(settings.score.synergyCapPct, synergyPct);
|
||||
const score = scoreExpedition({ requirements, stats: hazards.stats, conditionMet: met, synergyPct: synergy }, settings);
|
||||
const scoreFactor = powers.includes("treasureMap") ? 1 - settings.powers.treasureMapScorePct / 100 : 1;
|
||||
const score = scoreExpedition({ requirements, stats: hazards.stats, conditionMet: met, synergyPct: synergy, scoreFactor }, settings);
|
||||
return { synergyPct: synergy, requirements, baseStats: base, stats: hazards.stats, durationFactor: hazards.durationFactor, dangers: hazards.dangers, condition, conditionMet: met, ...score };
|
||||
}
|
||||
|
||||
|
|
@ -183,7 +187,9 @@ export function evaluateTeam(input, settings) {
|
|||
limitedByStars = stars;
|
||||
}
|
||||
}
|
||||
return { ...result, scorePct, limitedByStars, tier: tierFor(scorePct, settings) };
|
||||
// Talisman de la Lune Pâle : ni Retour difficile ni Triomphe, toujours une Réussite.
|
||||
const tier = (input.powers || []).includes("talisman") ? "success" : tierFor(scorePct, settings);
|
||||
return { ...result, scorePct, limitedByStars, tier };
|
||||
}
|
||||
|
||||
// Butin espéré (valeurs fractionnaires) : il est proportionnel à la durée choisie, donc identique par heure.
|
||||
|
|
@ -196,16 +202,18 @@ export function bonusLootPct(bonusSlot, settings) {
|
|||
}
|
||||
|
||||
// `multiplierPct` : multiplicateur propre au joueur (butin de groupe selon le nombre de joueurs).
|
||||
export function expectedLoot({ hours, stars, tier, fortune, slotCount, bonusSlot = null, multiplierPct = 100 }, settings) {
|
||||
export function expectedLoot({ hours, stars, tier, fortune, slotCount, bonusSlot = null, multiplierPct = 100, powers = [] }, settings) {
|
||||
const { loot } = settings;
|
||||
const bonus = (bonusLootPct(bonusSlot, settings) / 100) * (multiplierPct / 100);
|
||||
const bonus = (bonusLootPct(bonusSlot, settings) / 100) * (multiplierPct / 100) * powerLootFactor(powers, settings);
|
||||
const packFactor = powers.includes("longsight") ? 1 + settings.powers.longsightPackPct / 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)),
|
||||
packs: Math.min(loot.maxPacks, base * (loot.packPerHourPermille / 1000) * (1 + fortuneBonusPct / 100) * packFactor),
|
||||
objects: Math.min(settings.items.maxPerExpedition, base * (settings.items.chancePerHourPermille / 1000)),
|
||||
cards: Math.min(settings.carnets.maxCards, base * (settings.carnets.cardPerHourPermille / 1000)),
|
||||
fortuneBonusPct
|
||||
};
|
||||
}
|
||||
|
|
@ -394,3 +402,25 @@ export function pickItems(count, { orientationPerSlot, excluded = [] }, settings
|
|||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
export const POWER_IDS = Object.freeze(["longsight", "rations", "treasureMap", "talisman", "madCompass", "starNet"]);
|
||||
|
||||
// Pouvoirs d'une équipe : chacun ne compte qu'une fois, quel que soit le nombre de cartes qui le portent.
|
||||
export function teamPowers(slots) {
|
||||
return [...new Set(slots.flatMap((slot) => slot.powers || []))].filter((power) => POWER_IDS.includes(power));
|
||||
}
|
||||
|
||||
// Multiplicateur de butin des pouvoirs : les Provisions en retirent une part, la Boussole folle en ajoute.
|
||||
export function powerLootFactor(powers, settings) {
|
||||
let factor = 1;
|
||||
if (powers.includes("rations")) factor *= 1 - settings.powers.rationsLootPct / 100;
|
||||
if (powers.includes("madCompass")) factor *= 1 + settings.powers.madCompassLootPct / 100;
|
||||
return factor;
|
||||
}
|
||||
|
||||
// Temps de trajet réel : la Longue-vue l'allonge, les Provisions le raccourcissent ; le butin reste calculé sur la durée choisie.
|
||||
export function travelHours(hours, powers, settings) {
|
||||
let actual = hours + (powers.includes("longsight") ? settings.powers.longsightExtraHours : 0);
|
||||
if (powers.includes("rations")) actual *= 1 - settings.powers.rationsTimePct / 100;
|
||||
return Math.max(0.25, actual);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import { randomInt, randomUUID } from "node:crypto";
|
|||
import { dailyDayKey, nextDailyAt, shiftDayKey } from "./daily.js";
|
||||
import {
|
||||
dangerCount, drawExpeditionDay, editionExpeditionData, evaluateTeam, expectedLoot, hasCondition, MAX_STARS, requirementsFor, resolveDayEntry,
|
||||
pickItems, ROLE_BY_STAT, rollLoot, roundStochastic, soloRoles, STAT_BY_ROLE, teamSynergy
|
||||
HIDDEN_ITEMS, ITEM_IDS, pickItems, ROLE_BY_STAT, rollLoot, roundStochastic, soloRoles, STAT_BY_ROLE, teamPowers, teamSynergy, travelHours
|
||||
} from "./expedition-rules.js";
|
||||
import {
|
||||
DEFAULT_EXPEDITION_SETTINGS, diffExpeditionSettings, EXPEDITION_SETTINGS_SCHEMA, mergeExpeditionSettings, validateExpeditionSettings
|
||||
|
|
@ -171,8 +171,9 @@ export class ExpeditionService {
|
|||
return card;
|
||||
}
|
||||
|
||||
// Butin tiré au départ : arrondi au hasard, collection de chaque paquet, puis objets (la partie cachée demande de l'Orientation).
|
||||
rollReward(expected, settings, orientationPerSlot = 0) {
|
||||
// Butin tiré au départ : arrondi au hasard, collection de chaque paquet, objets (la partie cachée demande de l'Orientation),
|
||||
// cartes des Carnets de la destination, puis ce qu'ajoutent les pouvoirs (Carte au trésor, Filet à étoiles filantes).
|
||||
rollReward(expected, settings, { orientationPerSlot = 0, powers = [], destination = null } = {}) {
|
||||
const random = (max) => this.random(max);
|
||||
const loot = rollLoot(expected, settings, random);
|
||||
const packs = [];
|
||||
|
|
@ -181,7 +182,32 @@ export class ExpeditionService {
|
|||
if (collectionId) packs.push(collectionId);
|
||||
}
|
||||
const items = pickItems(roundStochastic(expected.objects, random), { orientationPerSlot, excluded: this.excludedItems() }, settings, random);
|
||||
return { eclats: loot.eclats, stardust: loot.stardust, packs, items };
|
||||
if (powers.includes("treasureMap")) {
|
||||
const notHidden = ITEM_IDS.filter((id) => !HIDDEN_ITEMS.includes(id));
|
||||
items.push(...pickItems(1, { orientationPerSlot: Infinity, excluded: [...notHidden, ...this.excludedItems()] }, settings, random));
|
||||
}
|
||||
const cards = [];
|
||||
const fromDestination = this.logbookEditions(destination?.logbookCards || []);
|
||||
for (let index = roundStochastic(expected.cards, random); index > 0 && fromDestination.length; index -= 1) cards.push(this.pickLogbookEdition(fromDestination, random));
|
||||
const anyLogbook = this.logbookEditions();
|
||||
if (powers.includes("starNet") && anyLogbook.length && random(100) < settings.powers.starNetCardPct) cards.push(this.pickLogbookEdition(anyLogbook, random));
|
||||
return { eclats: loot.eclats, stardust: loot.stardust, packs, items, cards };
|
||||
}
|
||||
|
||||
// Éditions standard des cartes des Carnets (rare ou mieux) déjà illustrées ; sans `cardIds`, toutes celles des collections des Expéditions.
|
||||
logbookEditions(cardIds = null) {
|
||||
const expeditionCollections = new Set(this.cards.catalog.collections.filter((collection) => collection.packCategory === "expedition").map((collection) => collection.id));
|
||||
return this.cards.catalog.editions.filter((edition) => {
|
||||
const card = this.cards.index.cards.get(edition.cardId);
|
||||
return card?.image && !edition.promotional && edition.rarity !== "mythic" && edition.rarity !== "common" && expeditionCollections.has(card.collectionId) && (!cardIds || cardIds.includes(card.id));
|
||||
});
|
||||
}
|
||||
|
||||
// Tirage pondéré par les poids recommandés des raretés : une légendaire reste rare.
|
||||
pickLogbookEdition(editions, random) {
|
||||
const weight = (edition) => this.cards.catalog.rarities.find((rarity) => rarity.id === edition.rarity)?.recommendedWeight || 1;
|
||||
let cursor = random(editions.reduce((sum, edition) => sum + weight(edition), 0));
|
||||
return (editions.find((edition) => (cursor -= weight(edition)) < 0) || editions.at(-1)).id;
|
||||
}
|
||||
|
||||
// Objets qui ne peuvent pas encore être rapportés : le plan d'atelier attend des communes de pouvoir illustrées.
|
||||
|
|
@ -203,9 +229,10 @@ export class ExpeditionService {
|
|||
const slots = editionIds.map((editionId, position) => ({ ...this.ownedCard(playerId, editionId, settings, owned), role: roles[position], position }));
|
||||
if (new Set(slots.map((slot) => slot.cardId)).size !== slots.length) fail(400, "EXPEDITION_CARD_INVALID", "Une même carte ne peut occuper qu’une place.");
|
||||
const synergy = teamSynergy({ destination: resolved.destination, slots }, settings);
|
||||
const evaluation = evaluateTeam({ destination: resolved.destination, entry: resolved.entry, stars, durationIndex, slots, synergyPct: synergy.totalPct }, settings);
|
||||
const expected = expectedLoot({ hours, stars, tier: evaluation.tier, fortune: evaluation.stats.fortune, slotCount: slots.length, bonusSlot: resolved.bonusSlot ?? null }, settings);
|
||||
return { day, resolved, stars, durationIndex, hours, slots, synergy, evaluation, expected };
|
||||
const powers = teamPowers(slots);
|
||||
const evaluation = evaluateTeam({ destination: resolved.destination, entry: resolved.entry, stars, durationIndex, slots, synergyPct: synergy.totalPct, powers }, settings);
|
||||
const expected = expectedLoot({ hours, stars, tier: evaluation.tier, fortune: evaluation.stats.fortune, slotCount: slots.length, bonusSlot: resolved.bonusSlot ?? null, powers }, settings);
|
||||
return { day, resolved, stars, durationIndex, hours, slots, synergy, powers, evaluation, expected };
|
||||
}
|
||||
|
||||
// `synergy` : Affinité, Résonances et cohésion qui ont donné le bonus de score.
|
||||
|
|
@ -213,6 +240,7 @@ export class ExpeditionService {
|
|||
return {
|
||||
...extra,
|
||||
affinity: synergy?.affinity ?? null,
|
||||
powers: extra.powers ?? [],
|
||||
resonances: synergy?.resonances ?? [],
|
||||
scorePct: round1(evaluation.scorePct),
|
||||
synergyPct: evaluation.synergyPct,
|
||||
|
|
@ -236,7 +264,10 @@ export class ExpeditionService {
|
|||
if (!settings.enabled) fail(409, "EXPEDITIONS_CLOSED", "Les Expéditions sont fermées pour le moment.");
|
||||
const today = this.today(settings, playerId);
|
||||
const plan = body?.mode === "group" ? this.prepareGroup(playerId, body, settings, today) : this.prepareSolo(playerId, body, settings, today);
|
||||
return { preview: { ...this.resultView(plan.evaluation, plan.cohesion != null ? { cohesionPct: plan.cohesion } : {}, plan.synergy), expected: this.expectedView(plan.expected) } };
|
||||
const travel = travelHours(plan.hours, plan.powers, settings);
|
||||
// Boussole folle : les exigences et le résultat restent inconnus jusqu'au retour.
|
||||
if (plan.powers.includes("madCompass")) return { preview: { hiddenRequirements: true, powers: plan.powers, travelHours: travel, expected: this.expectedView(plan.expected) } };
|
||||
return { preview: { ...this.resultView(plan.evaluation, { ...(plan.cohesion != null ? { cohesionPct: plan.cohesion } : {}), powers: plan.powers }, plan.synergy), travelHours: travel, expected: this.expectedView(plan.expected) } };
|
||||
}
|
||||
|
||||
// Collection d'un paquet rapporté : une collection permanente ouverte, au hasard.
|
||||
|
|
@ -262,7 +293,8 @@ export class ExpeditionService {
|
|||
if (busy) fail(409, "EXPEDITION_CARD_BUSY", "Cette carte est déjà en expédition.");
|
||||
if (this.activeCount(playerId, "solo") >= settings.solo.maxConcurrent) fail(409, "EXPEDITION_LIMIT", "Récupérez d’abord le butin de votre expédition en cours.");
|
||||
const now = this.now();
|
||||
const reward = this.rollReward(plan.expected, settings, plan.evaluation.stats.orientation / plan.slots.length);
|
||||
const reward = this.rollReward(plan.expected, settings, { orientationPerSlot: plan.evaluation.stats.orientation / plan.slots.length, powers: plan.powers, destination: plan.resolved.destination });
|
||||
const travel = travelHours(plan.hours, plan.powers, settings);
|
||||
const { destination } = plan.resolved;
|
||||
const setup = {
|
||||
destination: { id: destination.id, name: destination.name, description: destination.description, coverCardId: destination.coverCardId ?? null, stats: destination.stats },
|
||||
|
|
@ -270,16 +302,18 @@ export class ExpeditionService {
|
|||
stars: plan.stars,
|
||||
hours: plan.hours,
|
||||
bonusSlot: plan.resolved.bonusSlot ?? null,
|
||||
roles: plan.slots.map((slot) => slot.role)
|
||||
roles: plan.slots.map((slot) => slot.role),
|
||||
powers: plan.powers,
|
||||
travelHours: travel
|
||||
};
|
||||
expeditionId = randomUUID();
|
||||
this.db.prepare(`INSERT INTO expeditions(id, mode, day, destination_id, difficulty, duration_ms, creator_id, status, setup_json, result_json, created_at, departs_at, returns_at)
|
||||
VALUES (?, 'solo', ?, ?, ?, ?, ?, 'running', ?, ?, ?, ?, ?)`)
|
||||
.run(expeditionId, plan.day, destination.id, plan.stars, plan.hours * HOUR_MS, playerId, JSON.stringify(setup), JSON.stringify(this.resultView(plan.evaluation, {}, plan.synergy)), now, now, now + plan.hours * HOUR_MS);
|
||||
.run(expeditionId, plan.day, destination.id, plan.stars, Math.round(travel * HOUR_MS), playerId, JSON.stringify(setup), JSON.stringify(this.resultView(plan.evaluation, { powers: plan.powers }, plan.synergy)), now, now, now + Math.round(travel * HOUR_MS));
|
||||
this.db.prepare("INSERT INTO expedition_members(expedition_id, player_id, reward_json, joined_at) VALUES (?, ?, ?, ?)")
|
||||
.run(expeditionId, playerId, JSON.stringify(reward), now);
|
||||
const insertSlot = this.db.prepare("INSERT INTO expedition_slots(expedition_id, position, role, player_id, edition_id, card_id, level, stats_json) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
for (const slot of plan.slots) insertSlot.run(expeditionId, slot.position, ROLE_BY_STAT[slot.role] ?? null, playerId, slot.editionId, slot.cardId, slot.level, JSON.stringify(slot.stats));
|
||||
const insertSlot = this.db.prepare("INSERT INTO expedition_slots(expedition_id, position, role, player_id, edition_id, card_id, level, stats_json, powers_json) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
for (const slot of plan.slots) insertSlot.run(expeditionId, slot.position, ROLE_BY_STAT[slot.role] ?? null, playerId, slot.editionId, slot.cardId, slot.level, JSON.stringify(slot.stats), JSON.stringify(slot.powers || []));
|
||||
this.discoverResonancesInTx([playerId], plan.synergy);
|
||||
this.db.prepare("INSERT INTO idempotency(player_id, scope, request_key, response_json, created_at) VALUES (?, 'expedition-start', ?, ?, ?)")
|
||||
.run(playerId, requestKey, JSON.stringify({ expeditionId }), now);
|
||||
|
|
@ -339,7 +373,8 @@ export class ExpeditionService {
|
|||
groups: this.boardView(playerId, settings),
|
||||
grimoire: this.grimoireOf(playerId),
|
||||
items: this.itemsOf(playerId),
|
||||
fragmentsForMap: settings.items.fragmentsForMap
|
||||
fragmentsForMap: settings.items.fragmentsForMap,
|
||||
atelierAvailable: this.atelierAvailable()
|
||||
};
|
||||
// Fermées : le joueur peut encore récupérer le butin de ses expéditions, mais aucune destination n'est tirée.
|
||||
if (!settings.enabled) return { ...base, day: dailyDayKey(now), destinations: [], cards: [] };
|
||||
|
|
@ -363,6 +398,7 @@ export class ExpeditionService {
|
|||
const insertPack = this.db.prepare("INSERT INTO gift_packs(id, player_id, source, expedition_id, collection_id, options_json, created_at) VALUES (?, ?, 'expedition', ?, ?, ?, ?)");
|
||||
for (const collectionId of reward.packs) insertPack.run(randomUUID(), playerId, row.id, collectionId, JSON.stringify({ rarityWeights: null, guarantee: null }), now);
|
||||
this.addItemsInTx(playerId, reward.items || []);
|
||||
for (const editionId of reward.cards || []) if (this.cards.index.editions.has(editionId)) this.cards.addCard(playerId, editionId);
|
||||
this.db.prepare("UPDATE expedition_members SET claimed_at = ? WHERE expedition_id = ? AND player_id = ?").run(now, row.id, playerId);
|
||||
const waiting = this.db.prepare("SELECT COUNT(*) AS count FROM expedition_members WHERE expedition_id = ? AND claimed_at IS NULL").get(row.id).count;
|
||||
if (!waiting) this.db.prepare("UPDATE expeditions SET status = 'completed', completed_at = ? WHERE id = ?").run(now, row.id);
|
||||
|
|
@ -370,7 +406,7 @@ export class ExpeditionService {
|
|||
this.gainFieldXpInTx(playerId, editionIds, this.settings);
|
||||
this.cards.audit(playerId, "expedition_completed", row.id, {
|
||||
destinationId: setup.destination.id, destinationName: setup.destination.name, difficulty: row.difficulty, hours: setup.hours,
|
||||
mode: row.mode, players: result.players ?? 1, tier: result.tier, scorePct: result.scorePct, eclats: reward.eclats, stardust: reward.stardust, packs: reward.packs.length, items: reward.items || [], editionIds
|
||||
mode: row.mode, players: result.players ?? 1, tier: result.tier, scorePct: result.scorePct, eclats: reward.eclats, stardust: reward.stardust, packs: reward.packs.length, items: reward.items || [], cards: reward.cards || [], editionIds
|
||||
});
|
||||
});
|
||||
return { expedition: this.expeditionView(expeditionId, playerId), expeditions: this.getExpeditions(playerId), state: this.cards.getState(playerId) };
|
||||
|
|
|
|||
|
|
@ -23,6 +23,10 @@ export const DEFAULT_EXPEDITION_SETTINGS = Object.freeze({
|
|||
synergy: { affinityPct: 10, resonancePct: 10, maxResonances: 2, sistersCount: 2 },
|
||||
// Objets : chance par heure d'en rapporter un (‰, multipliée comme le butin), au plus par expédition, Orientation moyenne par place
|
||||
// qui ouvre la partie cachée (fragments, burins, plans), fragments pour une carte au trésor, butin des destinations cachées et poids de tirage.
|
||||
// Pouvoirs des communes des Carnets : avantage et contrepartie de chacun (le Talisman n'a pas de valeur : ni échec ni triomphe).
|
||||
powers: { longsightPackPct: 25, longsightExtraHours: 2, rationsTimePct: 25, rationsLootPct: 15, treasureMapScorePct: 10, madCompassLootPct: 30, starNetCardPct: 20, starNetFortune: 2 },
|
||||
// Cartes des Carnets des Veilleurs rapportées d'expédition (chance par heure, multipliée comme le butin) et au plus par expédition.
|
||||
carnets: { cardPerHourPermille: 20, maxCards: 1 },
|
||||
items: {
|
||||
chancePerHourPermille: 50, maxPerExpedition: 2, orientationPerSlot: 15, fragmentsForMap: 4, hiddenLootPct: 150,
|
||||
weights: { fragment: 30, engraving: 10, plan: 10, anchor: 15, guideStar: 20, skyChart: 5 }
|
||||
|
|
@ -94,6 +98,16 @@ export const EXPEDITION_SETTINGS_SCHEMA = Object.freeze([
|
|||
int("synergy.resonancePct", 0, 100),
|
||||
int("synergy.maxResonances", 0, 3),
|
||||
int("synergy.sistersCount", 2, 4),
|
||||
int("powers.longsightPackPct", 0, 500),
|
||||
int("powers.longsightExtraHours", 0, 24),
|
||||
int("powers.rationsTimePct", 0, 90),
|
||||
int("powers.rationsLootPct", 0, 90),
|
||||
int("powers.treasureMapScorePct", 0, 90),
|
||||
int("powers.madCompassLootPct", 0, 500),
|
||||
int("powers.starNetCardPct", 0, 100),
|
||||
int("powers.starNetFortune", 0, 100),
|
||||
int("carnets.cardPerHourPermille", 0, 1000),
|
||||
int("carnets.maxCards", 0, 3),
|
||||
int("items.chancePerHourPermille", 0, 1000),
|
||||
int("items.maxPerExpedition", 0, 5),
|
||||
int("items.orientationPerSlot", 0, 1000),
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ function normalizeItem(reward, catalog) {
|
|||
if (!collection) invalid("Choisissez une collection.");
|
||||
const cardIds = new Set(catalog.cards.filter((card) => card.collectionId === collection.id).map((card) => card.id));
|
||||
if (collection.packCategory === "shop") invalid("Ce paquet ne s’obtient que dans la boutique.");
|
||||
if (collection.packCategory === "expedition") invalid("Cette collection ne s’obtient qu’en expédition.");
|
||||
const drawable = catalog.editions.filter((edition) => cardIds.has(edition.cardId) && isDrawableEdition(edition));
|
||||
const rarityIds = new Set(catalog.rarities.map((rarity) => rarity.id));
|
||||
|
||||
|
|
|
|||
|
|
@ -231,6 +231,7 @@ export class CardsService {
|
|||
this.requireAdmin(playerId);
|
||||
this.requireCollection(collectionId);
|
||||
if (typeof active !== "boolean") fail(400, "COLLECTION_STATE_INVALID", "État du paquet invalide.");
|
||||
if (this.index.collections.get(collectionId)?.packCategory === "expedition") fail(409, "EXPEDITION_COLLECTION", "Cette collection ne s’obtient qu’en expédition : elle n’a pas de paquet.");
|
||||
if (active && !this.index.collections.get(collectionId)?.dropWeights) fail(409, "DROP_RATES_REQUIRED", "Définissez d’abord les taux de tirage de ce paquet.");
|
||||
this.database.transaction(() => {
|
||||
this.db.prepare(`INSERT INTO collection_states(collection_id, active, updated_at, updated_by) VALUES (?, ?, ?, ?)
|
||||
|
|
@ -603,7 +604,9 @@ export class CardsService {
|
|||
// `purchased` : consomme une ouverture achetée en boutique au lieu de la réserve rechargeable.
|
||||
openPack(playerId, collectionId, requestKey, { purchased = false } = {}) {
|
||||
return this.idempotentOpening(playerId, purchased ? "open-purchased" : "open-pack", requestKey, () => {
|
||||
if (this.catalog.collections.find((item) => item.id === collectionId)?.packCategory === "shop") fail(409, "SHOP_PACK_ONLY", "Ce paquet ne s’obtient que dans la boutique.");
|
||||
const category = this.catalog.collections.find((item) => item.id === collectionId)?.packCategory;
|
||||
if (category === "shop") fail(409, "SHOP_PACK_ONLY", "Ce paquet ne s’obtient que dans la boutique.");
|
||||
if (category === "expedition") fail(409, "EXPEDITION_COLLECTION", "Cette collection ne s’obtient qu’en expédition.");
|
||||
if (purchased) {
|
||||
const spent = this.db.prepare("UPDATE players SET purchased_openings = purchased_openings - 1 WHERE id = ? AND purchased_openings > 0").run(playerId);
|
||||
if (!spent.changes) fail(409, "NO_PURCHASED_OPENING", "Vous n’avez aucune ouverture achetée.");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue