fix(training): persist tutorial completions and grant first-time rewards
On returning from a stock training mission, the client reports the outcome in cln_update under missionAwards while sending an empty pveProgress block. Because the local server did not record this completion, the hangar repeated tutorial prompts after restart and never credited first-completion rewards. Add a cached training-missions dataset (config/mislist.blk, config/pve_awards.blk, config/unlocks.blk), pure completion rules in TrainingCatalogue, and missionAwards parsing in clientUpdateAction. Completed tutorials now persist pveProgress/missions and grant per-mission decals, the shared first-basic-tutorial Golden Eagles unlock, and per-difficulty first-win Silver Lions once per account during cln_update before replying. Credit to duduyagame for identifying the cln_update missionAwards reporting flow and stock reward definitions (PR #6). Checks: root `npm run typecheck` passed; verified training-missions dataset extraction/caching and TrainingCatalogue idempotency against read-only stock 2.61.0.37 files in a temporary data folder. In-game acceptance pending on an isolated client copy. Co-authored-by: duduyagame <[email protected]>
This commit is contained in:
1 parent
42b8275151
commit
4e99d2c484
6 files changed
+240
-8
No files matched your search
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* Rules for completing stock training missions reported by `cln_update` (`missionAwards`):
|
||||
* persists `pveProgress/missions` completion flags and grants first-completion rewards
|
||||
* (decal unlock/resource, shared first-basic-tutorial Golden Eagles unlock, and per-difficulty
|
||||
* first-win Silver Lions) once per account.
|
||||
*/
|
||||
import type { BlkBlock } from '@wto/blk';
|
||||
import type { TrainingMissionEntry, TrainingMissionsData } from '../game-data/datasets/training-missions.ts';
|
||||
import { addGoldenEagles, addSilverLions } from '../profile/profile-currency.ts';
|
||||
import { hasCompletedMissionDifficulty, recordMissionCompleted } from '../profile/profile-mission-progress.ts';
|
||||
import { addResource, ownsResource } from '../profile/profile-resources.ts';
|
||||
import { addUnlock, earnedUnlocks } from '../profile/profile-unlocks.ts';
|
||||
|
||||
export type TrainingDifficulty = 0 | 1 | 2;
|
||||
|
||||
export interface TrainingCompletionReport {
|
||||
readonly chapter: string;
|
||||
readonly mission: string;
|
||||
readonly difficulty: TrainingDifficulty;
|
||||
}
|
||||
|
||||
const DIFFICULTIES: readonly TrainingDifficulty[] = [0, 1, 2];
|
||||
|
||||
export class TrainingCatalogue {
|
||||
readonly #byFullName: ReadonlyMap<string, TrainingMissionEntry>;
|
||||
|
||||
constructor(data: TrainingMissionsData) {
|
||||
this.#byFullName = new Map(data.missions.map((entry) => [entry.fullName, entry]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Persist a completed training mission and grant its one-time rewards. Repeated reports keep
|
||||
* existing completion flags intact without paying any reward twice.
|
||||
*/
|
||||
applyCompletion(profile: BlkBlock, report: TrainingCompletionReport): void {
|
||||
const entry = this.#byFullName.get(`${report.chapter}/${report.mission}`);
|
||||
if (!entry) return;
|
||||
|
||||
let silverLions = 0;
|
||||
for (const difficulty of DIFFICULTIES) {
|
||||
if (difficulty <= report.difficulty && !hasCompletedMissionDifficulty(profile, entry.fullName, difficulty)) {
|
||||
silverLions += entry.silverLionsByDifficulty[difficulty];
|
||||
}
|
||||
}
|
||||
|
||||
recordMissionCompleted(profile, entry.fullName, report.difficulty);
|
||||
if (silverLions > 0) addSilverLions(profile, silverLions);
|
||||
grantMissionUnlocks(profile, entry);
|
||||
}
|
||||
}
|
||||
|
||||
function grantMissionUnlocks(profile: BlkBlock, entry: TrainingMissionEntry): void {
|
||||
if (!entry.decal && !entry.firstCompletion) return;
|
||||
const earned = earnedUnlocks(profile);
|
||||
const grantUnlock = (id: string): void => {
|
||||
if (earned.has(id)) return;
|
||||
addUnlock(profile, id);
|
||||
earned.add(id);
|
||||
};
|
||||
|
||||
if (entry.decal) {
|
||||
grantUnlock(entry.decal);
|
||||
if (!ownsResource(profile, entry.decal)) {
|
||||
addResource(profile, entry.decal, { silverLions: 0, goldenEagles: 0 });
|
||||
}
|
||||
}
|
||||
|
||||
const first = entry.firstCompletion;
|
||||
if (first && !earned.has(first.id) && !first.blockedBy.some((id) => earned.has(id))) {
|
||||
addGoldenEagles(profile, first.goldenEagles);
|
||||
grantUnlock(first.id);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user