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
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue