Add the daily team administration, recruitment retouches, the Watchers' balm and a new Guild layout
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
7ed63fff49
commit
b179a40a04
36 changed files with 799 additions and 298 deletions
|
|
@ -346,6 +346,15 @@ export function createCardsApiHandler({
|
|||
json(res, 200, service.team.startRecruitment(session.player.id, { day: (await readBody(req)).day }));
|
||||
return true;
|
||||
}
|
||||
if (req.method === "POST" && url.pathname === "/api/cards/team/reset") {
|
||||
json(res, 200, service.team.resetForTests(session.player.id));
|
||||
return true;
|
||||
}
|
||||
if (req.method === "POST" && url.pathname === "/api/cards/team/reroll") {
|
||||
rateLimit(req, "team-reroll", 60);
|
||||
json(res, 200, service.team.rerollOffer(session.player.id, { offer: (await readBody(req)).offer }));
|
||||
return true;
|
||||
}
|
||||
if (req.method === "POST" && url.pathname === "/api/cards/team/choose") {
|
||||
rateLimit(req, "team-choose", 60);
|
||||
json(res, 200, service.team.chooseCharacter(session.player.id, { cardId: (await readBody(req)).cardId }));
|
||||
|
|
@ -356,6 +365,11 @@ export function createCardsApiHandler({
|
|||
json(res, 200, service.team.revealStar(session.player.id, { index: (await readBody(req)).index }));
|
||||
return true;
|
||||
}
|
||||
if (req.method === "POST" && url.pathname === "/api/cards/team/heal") {
|
||||
rateLimit(req, "team-heal", 60);
|
||||
json(res, 200, service.team.healCompanion(session.player.id, { cardId: (await readBody(req)).cardId }));
|
||||
return true;
|
||||
}
|
||||
if (req.method === "POST" && url.pathname === "/api/cards/team/keep") {
|
||||
rateLimit(req, "team-keep", 60);
|
||||
json(res, 200, service.team.keepCompanion(session.player.id, { cardId: (await readBody(req)).cardId }));
|
||||
|
|
|
|||
|
|
@ -626,8 +626,8 @@ export function teamSynergy({ destination, slots, cohesionPct: cohesion = 0 }, s
|
|||
}
|
||||
|
||||
// Le Parchemin d'oubli (oblivion) s'achète en boutique : sans poids de tirage, il ne sort jamais du butin. La Rose des vents
|
||||
// (windRose) s'achète aussi, et sort rarement du butin.
|
||||
export const ITEM_IDS = Object.freeze(["fragment", "engraving", "plan", "anchor", "guideStar", "skyChart", "oblivion", "windRose"]);
|
||||
// (windRose) s'achète aussi, et sort rarement du butin. Le Baume des Veilleurs (balm) ne vient que du butin et sert à l'Équipe du jour.
|
||||
export const ITEM_IDS = Object.freeze(["fragment", "engraving", "plan", "anchor", "guideStar", "skyChart", "oblivion", "windRose", "balm"]);
|
||||
// Objets vendus en boutique, et le réglage de leur prix en poussière.
|
||||
export const SHOP_ITEM_PRICES = Object.freeze({ oblivion: "oblivionPrice", windRose: "windRosePrice" });
|
||||
// Partie cachée du butin : elle ne s'ouvre qu'avec assez d'Orientation moyenne par place.
|
||||
|
|
|
|||
|
|
@ -341,9 +341,10 @@ export class ExpeditionService {
|
|||
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.
|
||||
// Objets qui ne peuvent pas être rapportés : le plan d'atelier attend des communes de pouvoir illustrées, et le Baume ne sert que si
|
||||
// l'Équipe du jour est ouverte.
|
||||
excludedItems() {
|
||||
return this.atelierAvailable?.() ? [] : ["plan"];
|
||||
return [...(this.atelierAvailable?.() ? [] : ["plan"]), ...(this.cards.team.settings.enabled ? [] : ["balm"])];
|
||||
}
|
||||
|
||||
// `synergy` : Affinité, Résonances et cohésion qui ont donné le bonus de score.
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ export const DEFAULT_EXPEDITION_SETTINGS = Object.freeze({
|
|||
rewardCards: { linkedCollectionPct: 75, missingWeightPct: 200 },
|
||||
items: {
|
||||
chancePerHourPermille: 50, maxPerExpedition: 2, orientationPerSlot: 15, fragmentsForMap: 4, hiddenLootPct: 150,
|
||||
weights: { fragment: 30, engraving: 10, plan: 10, anchor: 15, guideStar: 20, skyChart: 5, windRose: 5, oblivion: 5 }
|
||||
weights: { fragment: 30, engraving: 10, plan: 10, anchor: 15, guideStar: 20, skyChart: 5, windRose: 5, oblivion: 5, balm: 15 }
|
||||
},
|
||||
// Exigence d'une stat, par place, pour chaque nombre d'étoiles : stat principale, puis seconde, troisième et quatrième.
|
||||
// Hausse de l'exigence par place pour chaque joueur en plus d'un groupe (`extraPlayerPct`). Sans équipement, une carte au plafond
|
||||
|
|
@ -188,6 +188,7 @@ export const EXPEDITION_SETTINGS_SCHEMA = Object.freeze([
|
|||
int("items.weights.guideStar", 0, 100),
|
||||
int("items.weights.skyChart", 0, 100),
|
||||
int("items.weights.windRose", 0, 100),
|
||||
int("items.weights.balm", 0, 100),
|
||||
int("items.weights.oblivion", 0, 100),
|
||||
ints("requirements.star1", 1, 1, 1000),
|
||||
ints("requirements.star2", 2, 1, 1000),
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ export const STAR_KINDS = Object.freeze(["gold", "black", "dust"]);
|
|||
|
||||
export const DEFAULT_TEAM_SETTINGS = Object.freeze({
|
||||
goldStars: 8, blackStars: 3, dustStars: 2, dustValue: 3,
|
||||
// Fois où le joueur peut redemander trois personnages, par recrutement.
|
||||
rerolls: 2,
|
||||
// Puissance à l'arrivée, puis après chaque étoile dorée ; `fallPower` après une étoile noire.
|
||||
powers: Object.freeze([50, 60, 75, 95]), fallPower: 30
|
||||
});
|
||||
|
|
@ -40,6 +42,7 @@ export function teamSettingsError(settings) {
|
|||
if (!integer(settings.blackStars, 0, 15)) return "Étoiles noires : un entier entre 0 et 15.";
|
||||
if (!integer(settings.dustStars, 0, 10)) return "Étoiles de poussière : un entier entre 0 et 10.";
|
||||
if (!integer(settings.dustValue, 0, 1_000)) return "Poussière par étoile : un entier entre 0 et 1 000.";
|
||||
if (!integer(settings.rerolls, 0, 10)) return "Nouvelles propositions : un entier entre 0 et 10.";
|
||||
const { powers, fallPower } = settings;
|
||||
if (!Array.isArray(powers) || powers.length < 2 || powers.length > 6 || powers.some((power) => !integer(power, 1, 100))) return "Paliers de Puissance : de 2 à 6 entiers entre 1 et 100.";
|
||||
if (powers.some((power, index) => index > 0 && power <= powers[index - 1])) return "Chaque palier de Puissance doit dépasser le précédent.";
|
||||
|
|
@ -87,16 +90,17 @@ export function lentCharacters(characters, ownedIds, random = defaultRandom) {
|
|||
return lent.map((character) => character.id);
|
||||
}
|
||||
|
||||
// Trois personnages de profils différents : d'abord ceux du joueur et ses prêtés, complétés au besoin par le reste des collections
|
||||
// ouvertes. Un profil porté par beaucoup de personnages n'est pas proposé plus souvent qu'un autre.
|
||||
export function drawOffer(characters, { poolIds, seenIds }, random = defaultRandom) {
|
||||
// Trois personnages de profils différents : d'abord ceux du joueur et ses prêtés pas encore proposés, puis ceux déjà proposés
|
||||
// (`excludedIds` : l'équipe et les trois derniers), enfin le reste des collections ouvertes. Un profil porté par beaucoup de
|
||||
// personnages n'est pas proposé plus souvent qu'un autre.
|
||||
export function drawOffer(characters, { poolIds, seenIds, excludedIds = seenIds }, random = defaultRandom) {
|
||||
const offer = [];
|
||||
const used = new Set();
|
||||
const take = (candidates) => {
|
||||
const take = (candidates, hiddenIds) => {
|
||||
const byProfile = new Map();
|
||||
for (const character of candidates) {
|
||||
const key = profileKey(character.profile);
|
||||
if (seenIds.has(character.id) || used.has(key)) continue;
|
||||
if (hiddenIds.has(character.id) || used.has(key)) continue;
|
||||
byProfile.set(key, [...(byProfile.get(key) || []), character.id]);
|
||||
}
|
||||
for (const [key, ids] of shuffle([...byProfile], random).slice(0, OFFER_SIZE - offer.length)) {
|
||||
|
|
@ -104,8 +108,10 @@ export function drawOffer(characters, { poolIds, seenIds }, random = defaultRand
|
|||
offer.push(ids[random(ids.length)]);
|
||||
}
|
||||
};
|
||||
take(characters.filter((character) => poolIds.has(character.id)));
|
||||
if (offer.length < OFFER_SIZE) take(characters.filter((character) => character.active && !poolIds.has(character.id)));
|
||||
const pool = characters.filter((character) => poolIds.has(character.id));
|
||||
take(pool, seenIds);
|
||||
if (offer.length < OFFER_SIZE) take(pool, new Set([...excludedIds, ...offer]));
|
||||
if (offer.length < OFFER_SIZE) take(characters.filter((character) => character.active && !poolIds.has(character.id)), seenIds);
|
||||
return offer;
|
||||
}
|
||||
|
||||
|
|
@ -119,13 +125,14 @@ export function startRecruitment(characters, { ownedIds, goldReserve = 0, settin
|
|||
...Array(settings.blackStars).fill("black"),
|
||||
...Array(settings.dustStars).fill("dust")
|
||||
], random);
|
||||
const state = { settings, extraGold: extra, sky, revealed: [], lentIds: lentCharacters(characters, ownedIds, random), seenIds: [], offer: [], current: null, team: [], dust: 0 };
|
||||
const state = { settings, extraGold: extra, sky, revealed: [], lentIds: lentCharacters(characters, ownedIds, random), seenIds: [], offer: [], current: null, team: [], dust: 0, rerolls: settings.rerolls };
|
||||
return nextOffer(characters, ownedIds, state, random);
|
||||
}
|
||||
|
||||
function nextOffer(characters, ownedIds, state, random) {
|
||||
const poolIds = new Set([...ownedIds, ...state.lentIds]);
|
||||
const offer = drawOffer(characters, { poolIds, seenIds: new Set(state.seenIds) }, random);
|
||||
const excludedIds = new Set([...state.team.map((companion) => companion.cardId), ...state.offer]);
|
||||
const offer = drawOffer(characters, { poolIds, seenIds: new Set(state.seenIds), excludedIds }, random);
|
||||
return { ...state, offer, seenIds: [...state.seenIds, ...offer], current: null };
|
||||
}
|
||||
|
||||
|
|
@ -140,6 +147,12 @@ export function repairRecruitment(characters, ownedIds, state, random = defaultR
|
|||
|
||||
export const recruitmentFinished = (state) => state.team.length >= TEAM_SIZE;
|
||||
|
||||
// Remplace les trois personnages proposés, tant qu'il reste de nouvelles propositions.
|
||||
export function rerollOffer(characters, ownedIds, state, random = defaultRandom) {
|
||||
if (state.current || recruitmentFinished(state) || !(state.rerolls > 0)) return null;
|
||||
return { ...nextOffer(characters, ownedIds, state, random), rerolls: state.rerolls - 1 };
|
||||
}
|
||||
|
||||
export function chooseCharacter(state, cardId) {
|
||||
if (state.current || recruitmentFinished(state) || !state.offer.includes(cardId)) return null;
|
||||
return { ...state, current: { cardId, step: 0, power: state.settings.powers[0], fallen: false } };
|
||||
|
|
@ -163,14 +176,21 @@ export function revealStar(state, index) {
|
|||
return { star, state: { ...state, revealed, current: { ...current, step, power: settings.powers[step] } } };
|
||||
}
|
||||
|
||||
// Soin d'un compagnon affaibli, avant de le garder : il retrouve sa Puissance de départ, sans nouvel essai.
|
||||
export function healCompanion(state) {
|
||||
const { current, settings } = state;
|
||||
if (!current?.fallen || current.healed) return null;
|
||||
return { ...state, current: { ...current, power: settings.powers[0], healed: true } };
|
||||
}
|
||||
|
||||
// Garde le compagnon en cours et propose les suivants, sauf si l'équipe est complète. Son profil est figé avec lui : un changement du
|
||||
// catalogue ne modifie pas une équipe déjà recrutée. `null` sans compagnon en cours, ou s'il n'est plus au catalogue.
|
||||
export function keepCompanion(characters, ownedIds, state, random = defaultRandom) {
|
||||
const profile = characters.find((character) => character.id === state.current?.cardId)?.profile;
|
||||
if (!profile) return null;
|
||||
const { cardId, step, power, fallen } = state.current;
|
||||
const next = { ...state, team: [...state.team, { cardId, profile, power, step, fallen, lent: !ownedIds.has(cardId) }], current: null, offer: [] };
|
||||
return recruitmentFinished(next) ? next : nextOffer(characters, ownedIds, next, random);
|
||||
const { cardId, step, power, fallen, healed = false } = state.current;
|
||||
const next = { ...state, team: [...state.team, { cardId, profile, power, step, fallen, healed, lent: !ownedIds.has(cardId) }], current: null };
|
||||
return recruitmentFinished(next) ? { ...next, offer: [] } : nextOffer(characters, ownedIds, next, random);
|
||||
}
|
||||
|
||||
// Étoiles encore cachées, par sorte.
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
// Rôle : applique les règles de l'Équipe du jour avec la base (parcours du jour, recrutement, étoiles en réserve, réglages).
|
||||
// Branché sur CardsService (`service.team`) : il réutilise sa base, son horloge, son hasard, son audit et sa collection.
|
||||
import { dailyDayKey, isDayKey, nextDailyAt } from "./daily.js";
|
||||
import { dailyDayKey, isDayKey, nextDailyAt, shiftDayKey } from "./daily.js";
|
||||
import { drawZones } from "./race-rules.js";
|
||||
import {
|
||||
canRevealStar, chooseCharacter, companionStats, hiddenStars, keepCompanion, MAX_GOLD_RESERVE, recruitmentFinished, repairRecruitment, revealStar, specialtiesOf,
|
||||
canRevealStar, chooseCharacter, companionStats, healCompanion, hiddenStars, keepCompanion, MAX_GOLD_RESERVE, recruitmentFinished, repairRecruitment, rerollOffer, revealStar, specialtiesOf,
|
||||
startRecruitment, TEAM_DAYS, TEAM_SIZE, teamCharacters, teamDay, visibleSky
|
||||
} from "./team-rules.js";
|
||||
import { raceMethods } from "./team-race.js";
|
||||
|
|
@ -31,8 +31,19 @@ export class TeamService {
|
|||
return readDailyTeamSettings(JSON.parse(row?.settings_json || "{}"), (error) => console.error(`Invalid stored team settings, using defaults: ${error}`));
|
||||
}
|
||||
|
||||
// Activité du jour : équipes utilisables, courses lancées et étoiles dorées choisies à la Carte du jour.
|
||||
adminSummary() {
|
||||
const day = this.today;
|
||||
const count = (sql, ...values) => this.db.prepare(sql).get(...values).count;
|
||||
return {
|
||||
teams: count("SELECT COUNT(*) AS count FROM player_teams WHERE ready_day BETWEEN ? AND ?", shiftDayKey(day, 1 - TEAM_DAYS), day),
|
||||
races: count("SELECT COUNT(*) AS count FROM team_races WHERE day = ?", day),
|
||||
stars: count("SELECT COUNT(*) AS count FROM daily_attempts WHERE day = ? AND reward_choice = 'star'", day)
|
||||
};
|
||||
}
|
||||
|
||||
adminSettings() {
|
||||
return { settings: this.settings, defaults: normalizeDailyTeamSettings(DEFAULT_DAILY_TEAM_SETTINGS), updatedAt: this.db.prepare("SELECT updated_at FROM team_settings WHERE id = 1").get()?.updated_at ?? 0 };
|
||||
return { today: this.adminSummary(), settings: this.settings, defaults: normalizeDailyTeamSettings(DEFAULT_DAILY_TEAM_SETTINGS), updatedAt: this.db.prepare("SELECT updated_at FROM team_settings WHERE id = 1").get()?.updated_at ?? 0 };
|
||||
}
|
||||
|
||||
// Un recrutement commencé garde les réglages de son début (voir startRecruitment).
|
||||
|
|
@ -98,16 +109,16 @@ export class TeamService {
|
|||
return rank ? { day: rank, companions: row.state.team } : null;
|
||||
}
|
||||
|
||||
companionView({ cardId, profile, power, step = 0, fallen = false, lent = false }) {
|
||||
return { cardId, power, step, fallen, lent, stats: companionStats(profile, power), specialties: specialtiesOf(profile) };
|
||||
companionView({ cardId, profile, power, step = 0, fallen = false, healed = false, lent = false }) {
|
||||
return { cardId, power, step, fallen, healed, lent, stats: companionStats(profile, power), specialties: specialtiesOf(profile) };
|
||||
}
|
||||
|
||||
// Le client ne reçoit ni la place des étoiles cachées, ni les personnages suivants.
|
||||
recruitmentView(state, characters, owned) {
|
||||
recruitmentView(playerId, state, characters, owned) {
|
||||
const byId = new Map(characters.map((character) => [character.id, character]));
|
||||
const preview = (cardId) => this.companionView({ cardId, profile: byId.get(cardId).profile, power: state.settings.powers[0], lent: !owned.has(cardId) });
|
||||
return {
|
||||
size: TEAM_SIZE, powers: state.settings.powers, fallPower: state.settings.fallPower, dustValue: state.settings.dustValue, extraGold: state.extraGold, dust: state.dust,
|
||||
size: TEAM_SIZE, powers: state.settings.powers, fallPower: state.settings.fallPower, dustValue: state.settings.dustValue, extraGold: state.extraGold, dust: state.dust, rerolls: state.rerolls ?? 0, balms: this.cards.expeditions.itemsOf(playerId).balm,
|
||||
offer: state.current ? [] : state.offer.map(preview),
|
||||
current: state.current ? this.companionView({ ...state.current, profile: byId.get(state.current.cardId).profile, lent: !owned.has(state.current.cardId) }) : null,
|
||||
// Stats du compagnon en cours à chaque palier de Puissance.
|
||||
|
|
@ -132,11 +143,13 @@ export class TeamService {
|
|||
// Un recrutement par jour, et jamais deux à la fois.
|
||||
canRecruit: settings.enabled && !recruiting && row?.startedDay !== day,
|
||||
status: recruiting ? "recruiting" : rank ? "ready" : row ? "expired" : "none",
|
||||
// Serveur Vite local : remise à zéro pour les essais.
|
||||
devReset: Boolean(this.cards.devPerks),
|
||||
teamDay: rank, companions: row ? row.state.team.map((companion) => this.companionView(companion)) : [], recruitment: null,
|
||||
race: this.raceView(playerId)
|
||||
};
|
||||
if (!recruiting) return { ...base, lastSky: row ? visibleSky(row.state) : null, lastDust: row?.state.dust ?? 0 };
|
||||
return { ...base, recruitment: this.recruitmentView(row.state, recruitable.characters, recruitable.owned) };
|
||||
return { ...base, recruitment: this.recruitmentView(playerId, row.state, recruitable.characters, recruitable.owned) };
|
||||
}
|
||||
|
||||
// Résumé pour le tableau de bord et la Guilde, sans rien tirer.
|
||||
|
|
@ -171,6 +184,14 @@ export class TeamService {
|
|||
return this.result(playerId);
|
||||
}
|
||||
|
||||
// `offer` : les personnages que le client affiche, pour qu'un double clic ne consomme pas deux nouvelles propositions.
|
||||
rerollOffer(playerId, { offer } = {}) {
|
||||
return this.change(playerId, (state, characters, owned) => {
|
||||
if (!Array.isArray(offer) || offer.join() !== state.offer.join()) return state;
|
||||
return rerollOffer(characters, owned, state, this.random) ?? fail(409, "TEAM_REROLL_UNAVAILABLE", "Vous ne pouvez plus redemander de personnages.");
|
||||
});
|
||||
}
|
||||
|
||||
chooseCharacter(playerId, { cardId } = {}) {
|
||||
return this.change(playerId, (state) => {
|
||||
// Choisir deux fois le même personnage (double clic, deux onglets) ne change rien.
|
||||
|
|
@ -189,6 +210,18 @@ export class TeamService {
|
|||
});
|
||||
}
|
||||
|
||||
// Baume des Veilleurs : soigne le compagnon que le client croit affaibli. Le soigner deux fois n'en consomme pas deux.
|
||||
healCompanion(playerId, { cardId } = {}) {
|
||||
return this.change(playerId, (state) => {
|
||||
if (state.current?.cardId !== cardId) fail(409, "TEAM_CHOICE_INVALID", "Ce compagnon n’est plus en cours de recrutement.");
|
||||
if (state.current.healed) return state;
|
||||
const next = healCompanion(state) ?? fail(409, "TEAM_HEAL_INVALID", "Ce compagnon n’est pas affaibli.");
|
||||
this.cards.expeditions.consumeItemInTx(playerId, "balm");
|
||||
this.cards.audit(playerId, "item_used", "balm", { item: "balm", cardId });
|
||||
return next;
|
||||
});
|
||||
}
|
||||
|
||||
// `cardId` : le compagnon que le client croit garder, pour qu'un double clic ne garde pas le suivant.
|
||||
keepCompanion(playerId, { cardId } = {}) {
|
||||
return this.change(playerId, (state, characters, owned) => {
|
||||
|
|
@ -219,6 +252,15 @@ export class TeamService {
|
|||
return { team: this.view(playerId), state: this.cards.getState(playerId) };
|
||||
}
|
||||
|
||||
// Serveur Vite local (`devPerks`) : efface l'équipe et les courses du joueur, pour recruter et courir à nouveau le même jour.
|
||||
resetForTests(playerId) {
|
||||
if (!this.cards.devPerks) fail(404, "NOT_FOUND", "Remise à zéro indisponible.");
|
||||
this.cards.database.transaction(() => {
|
||||
for (const table of ["player_teams", "team_races"]) this.db.prepare(`DELETE FROM ${table} WHERE player_id = ?`).run(playerId);
|
||||
});
|
||||
return this.result(playerId);
|
||||
}
|
||||
|
||||
// Suppression de compte : l'équipe disparaît, la réserve est remise à zéro avec le reste des possessions.
|
||||
forgetPlayer(playerId) {
|
||||
for (const table of ["player_teams", "team_races"]) this.db.prepare(`DELETE FROM ${table} WHERE player_id = ?`).run(playerId);
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ export function dailyTeamSettingsError(settings) {
|
|||
return teamSettingsError(settings.recruitment);
|
||||
}
|
||||
|
||||
const pickRecruitment = ({ goldStars, blackStars, dustStars, dustValue, powers, fallPower }) => ({ goldStars, blackStars, dustStars, dustValue, powers: [...powers], fallPower });
|
||||
const pickRecruitment = ({ goldStars, blackStars, dustStars, dustValue, rerolls, powers, fallPower }) => ({ goldStars, blackStars, dustStars, dustValue, rerolls, powers: [...powers], fallPower });
|
||||
|
||||
// Garde seulement les champs connus.
|
||||
export const normalizeDailyTeamSettings = ({ enabled, starStardust, raceRewards, recruitment }) => ({ enabled, starStardust, raceRewards: [...raceRewards], recruitment: pickRecruitment(recruitment) });
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue