Rework the daily team screens, share its team block and give the race its admin tab
The daily team page now opens on a welcome screen with the three steps, and the recruitment keeps the same look: golden steps, the choice in a golden panel with the hidden stars, a team summary of colored mini cards and its strengths, and a reroll badge. One "Your team" block is shared by the Guild, the recruitment and the ready team. The header shows the extra golden stars and the balms; the tips button is gone. On the Guild, team quests carry a "En groupe" sign until the team is ready and the streak badge stays readable. The race gets its own admin tab: its own opening, the day's circuit and results, rewards by place and the watchers' skill. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
327337075b
commit
52b35880f2
23 changed files with 570 additions and 253 deletions
|
|
@ -1,7 +1,7 @@
|
|||
// Rôle : Course des courants avec la base (adversaires, départ, élans, arrivée, récompense). Méthodes ajoutées à TeamService.
|
||||
import { dailyDayKey, isDayKey, shiftDayKey } from "./daily.js";
|
||||
import { autoRun, bestRunner, boostsError, MAX_RACE_MS, placeOf, RACERS, replayRun } from "./race-rules.js";
|
||||
import { companionStats, inventTeam, shuffle, TEAM_DAYS, teamCharacters, WATCHER_TEAM_LEVELS } from "./team-rules.js";
|
||||
import { companionStats, inventTeam, shuffle, TEAM_DAYS, teamCharacters } from "./team-rules.js";
|
||||
|
||||
// Délai laissé après la plus longue course possible : au-delà, une course quittée se termine avec les élans déjà donnés.
|
||||
const ABANDON_MS = MAX_RACE_MS + 60_000;
|
||||
|
|
@ -19,6 +19,21 @@ function entrantOf(companions, runnerIndex) {
|
|||
const statsOf = ({ runner, helpers }) => ({ runner: runner.stats, helpers: helpers.map((helper) => helper.stats) });
|
||||
|
||||
export const raceMethods = {
|
||||
// Suivi d'un jour pour l'administration : parcours, courses lancées et finies, places, poussière versée et adversaires.
|
||||
raceAdminSummary(day = this.today) {
|
||||
const zonesRow = this.db.prepare("SELECT zones_json FROM team_days WHERE day = ?").get(day);
|
||||
const rows = this.db.prepare("SELECT status, race_json, place, reward FROM team_races WHERE day = ?").all(day);
|
||||
const finished = rows.filter((row) => row.status === "finished");
|
||||
const opponents = rows.flatMap((row) => JSON.parse(row.race_json).opponents);
|
||||
return {
|
||||
zones: zonesRow ? JSON.parse(zonesRow.zones_json) : null,
|
||||
started: rows.length, finished: finished.length,
|
||||
places: Array.from({ length: RACERS }, (_, index) => finished.filter((row) => row.place === index + 1).length),
|
||||
stardust: finished.reduce((sum, row) => sum + row.reward, 0),
|
||||
opponents: { players: opponents.filter((opponent) => opponent.playerId).length, watchers: opponents.filter((opponent) => !opponent.playerId).length }
|
||||
};
|
||||
},
|
||||
|
||||
raceRow(playerId, day) {
|
||||
const row = this.db.prepare("SELECT day, status, started_at, race_json, boosts_json, place, reward FROM team_races WHERE player_id = ? AND day = ?").get(playerId, day);
|
||||
return row ? { day: row.day, status: row.status, startedAt: row.started_at, race: JSON.parse(row.race_json), boosts: JSON.parse(row.boosts_json), place: row.place, reward: row.reward } : null;
|
||||
|
|
@ -37,7 +52,7 @@ export const raceMethods = {
|
|||
WHERE t.player_id != ? AND t.ready_day BETWEEN ? AND ? AND p.deleted_at IS NULL ORDER BY t.player_id`).all(playerId, shiftDayKey(day, 1 - TEAM_DAYS), day);
|
||||
const opponents = shuffle(rows, this.random).slice(0, RACERS - 1).map((row) => ({ playerId: row.player_id, companions: JSON.parse(row.state_json).team, skilled: this.random(2) === 0 }));
|
||||
const characters = teamCharacters(this.cards.catalog);
|
||||
const levels = shuffle(Object.entries(WATCHER_TEAM_LEVELS), this.random);
|
||||
const levels = shuffle(Object.entries(this.settings.watcherSkill), this.random);
|
||||
while (opponents.length < RACERS - 1) {
|
||||
const [level, skill] = levels.pop();
|
||||
opponents.push({ playerId: null, companions: inventTeam(characters, zones, skill, this.random, this.settings.recruitment), skilled: level === "strong" });
|
||||
|
|
@ -52,6 +67,7 @@ export const raceMethods = {
|
|||
startRace(playerId, { day, cardId } = {}) {
|
||||
if (!isDayKey(day) || typeof cardId !== "string") fail(400, "RACE_INVALID", "Demande invalide.");
|
||||
this.requireOpen();
|
||||
if (!this.settings.raceEnabled) fail(409, "RACE_CLOSED", "La Course des courants est fermée pour le moment.");
|
||||
this.cards.database.transaction(() => {
|
||||
const today = this.today;
|
||||
if (day !== today) fail(409, "TEAM_EXPIRED", "Un nouveau jour a commencé : rechargez la page.");
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ export class TeamService {
|
|||
}
|
||||
|
||||
adminSettings() {
|
||||
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 };
|
||||
return { today: this.adminSummary(), race: this.raceAdminSummary(), 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).
|
||||
|
|
@ -139,7 +139,9 @@ export class TeamService {
|
|||
const recruiting = Boolean(row && !row.readyDay);
|
||||
const rank = row?.readyDay ? teamDay(row.readyDay, day) : 0;
|
||||
const base = {
|
||||
enabled: settings.enabled, day, nextAt: nextDailyAt(this.cards.now()), zones, goldStars: this.goldStars(playerId), maxGoldStars: MAX_GOLD_RESERVE, maxDays: TEAM_DAYS,
|
||||
enabled: settings.enabled, raceEnabled: settings.enabled && settings.raceEnabled, day, nextAt: nextDailyAt(this.cards.now()), zones, goldStars: this.goldStars(playerId), maxGoldStars: MAX_GOLD_RESERVE, maxDays: TEAM_DAYS,
|
||||
// Baumes du Sac : ils soignent un compagnon affaibli pendant le recrutement.
|
||||
balms: this.cards.expeditions.itemsOf(playerId).balm,
|
||||
// Un recrutement par jour, et jamais deux à la fois.
|
||||
canRecruit: settings.enabled && !recruiting && row?.startedDay !== day,
|
||||
status: recruiting ? "recruiting" : rank ? "ready" : row ? "expired" : "none",
|
||||
|
|
@ -157,7 +159,7 @@ export class TeamService {
|
|||
const row = this.teamRow(playerId);
|
||||
const rank = row?.readyDay ? teamDay(row.readyDay, this.today) : 0;
|
||||
const race = this.runningRace(playerId) || this.raceRow(playerId, this.today);
|
||||
return { enabled: this.settings.enabled, race: race?.status ?? "none", status: row && !row.readyDay ? "recruiting" : rank ? "ready" : row ? "expired" : "none", teamDay: rank, maxDays: TEAM_DAYS, goldStars: this.goldStars(playerId), maxGoldStars: MAX_GOLD_RESERVE,
|
||||
return { enabled: this.settings.enabled, raceEnabled: this.settings.enabled && this.settings.raceEnabled, race: race?.status ?? "none", status: row && !row.readyDay ? "recruiting" : rank ? "ready" : row ? "expired" : "none", teamDay: rank, maxDays: TEAM_DAYS, goldStars: this.goldStars(playerId), maxGoldStars: MAX_GOLD_RESERVE,
|
||||
// Compagnons d'une équipe utilisable ou en cours de recrutement, pour la Guilde.
|
||||
companions: rank || (row && !row.readyDay) ? row.state.team.map((companion) => this.companionView(companion)) : [] };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,17 @@
|
|||
// Rôle : réglages de l'Équipe du jour (ouverture, étoiles, récompenses) : valeurs par défaut, validation et lecture tolérante.
|
||||
// Rôle : réglages de l'Équipe du jour et de la Course des courants (ouvertures, étoiles, récompenses, Veilleurs) : valeurs par
|
||||
// défaut, validation et lecture tolérante.
|
||||
import { RACE_REWARDS, RACERS } from "./race-rules.js";
|
||||
import { DEFAULT_TEAM_SETTINGS, teamSettingsError } from "./team-rules.js";
|
||||
import { DEFAULT_TEAM_SETTINGS, teamSettingsError, WATCHER_TEAM_LEVELS } from "./team-rules.js";
|
||||
|
||||
const MAX_REWARD = 100_000;
|
||||
|
||||
const WATCHER_LEVELS = Object.keys(WATCHER_TEAM_LEVELS);
|
||||
|
||||
// `starStardust` : poussière reçue avec une étoile dorée quand le joueur choisit cette récompense pour la Carte du jour.
|
||||
// `raceEnabled` : la Course s'ouvre et se ferme seule, mais ne se court qu'avec l'Équipe du jour ouverte (il faut une équipe).
|
||||
// `watcherSkill` : habileté des Équipes des Veilleurs qui complètent une course, en % de bons choix au recrutement.
|
||||
export const DEFAULT_DAILY_TEAM_SETTINGS = Object.freeze({
|
||||
enabled: false, starStardust: 10, raceRewards: RACE_REWARDS, recruitment: DEFAULT_TEAM_SETTINGS
|
||||
enabled: false, starStardust: 10, raceEnabled: true, raceRewards: RACE_REWARDS, watcherSkill: WATCHER_TEAM_LEVELS, recruitment: DEFAULT_TEAM_SETTINGS
|
||||
});
|
||||
|
||||
export function dailyTeamSettingsError(settings) {
|
||||
|
|
@ -14,18 +19,23 @@ export function dailyTeamSettingsError(settings) {
|
|||
if (!settings || typeof settings !== "object" || Array.isArray(settings)) return "Réglages de l’Équipe du jour invalides.";
|
||||
if (typeof settings.enabled !== "boolean") return "L’ouverture de l’Équipe du jour doit être vraie ou fausse.";
|
||||
if (!reward(settings.starStardust)) return `Poussière reçue avec une étoile : un entier entre 0 et ${MAX_REWARD.toLocaleString("fr-FR")}.`;
|
||||
if (typeof settings.raceEnabled !== "boolean") return "L’ouverture de la Course doit être vraie ou fausse.";
|
||||
if (!Array.isArray(settings.raceRewards) || settings.raceRewards.length !== RACERS || !settings.raceRewards.every(reward)) return `Récompenses de la Course : ${RACERS} entiers entre 0 et ${MAX_REWARD.toLocaleString("fr-FR")}.`;
|
||||
const skill = settings.watcherSkill;
|
||||
if (!skill || typeof skill !== "object" || !WATCHER_LEVELS.every((level) => Number.isInteger(skill[level]) && skill[level] >= 0 && skill[level] <= 100)) return "Habileté des Équipes des Veilleurs : des entiers entre 0 et 100.";
|
||||
return teamSettingsError(settings.recruitment);
|
||||
}
|
||||
|
||||
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) });
|
||||
export const normalizeDailyTeamSettings = ({ enabled, starStardust, raceEnabled, raceRewards, watcherSkill, recruitment }) => ({
|
||||
enabled, starStardust, raceEnabled, raceRewards: [...raceRewards], watcherSkill: Object.fromEntries(WATCHER_LEVELS.map((level) => [level, watcherSkill[level]])), recruitment: pickRecruitment(recruitment)
|
||||
});
|
||||
|
||||
// Réglages enregistrés : des valeurs invalides laissent la place aux valeurs par défaut, pour que le jeu reste jouable.
|
||||
export function readDailyTeamSettings(stored, onInvalid = () => {}) {
|
||||
const merged = { ...DEFAULT_DAILY_TEAM_SETTINGS, ...stored, recruitment: { ...DEFAULT_TEAM_SETTINGS, ...stored?.recruitment } };
|
||||
const merged = { ...DEFAULT_DAILY_TEAM_SETTINGS, ...stored, watcherSkill: { ...WATCHER_TEAM_LEVELS, ...stored?.watcherSkill }, recruitment: { ...DEFAULT_TEAM_SETTINGS, ...stored?.recruitment } };
|
||||
const error = dailyTeamSettingsError(merged);
|
||||
if (!error) return normalizeDailyTeamSettings(merged);
|
||||
onInvalid(error);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue