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,117 @@
|
||||
/**
|
||||
* Dataset: stock training missions and their first-completion rewards from char.vromfs.bin:
|
||||
* - config/mislist.blk ("training" block): chapter/mission full names accepted for progress;
|
||||
* - config/pve_awards.blk ("training" block): per-mission decal, shared first-completion unlock,
|
||||
* and per-difficulty Silver Lions rewards (`wpEarnedWinDiff0..2`);
|
||||
* - config/unlocks.blk: decal unlock verification and `oneTimeAwardUnlock` Golden Eagles amount
|
||||
* and mutually exclusive `char_unlocked` conditions.
|
||||
*/
|
||||
import { findParam, type BlkBlock } from '@wto/blk';
|
||||
import { blockAt, boolField, stringField, stringList } from './blk-fields.ts';
|
||||
import type { Dataset, DatasetSource } from './dataset.ts';
|
||||
|
||||
const CHAR_PACK = 'char.vromfs.bin';
|
||||
const MISLIST = 'config/mislist.blk';
|
||||
const PVE_AWARDS = 'config/pve_awards.blk';
|
||||
const UNLOCKS = 'config/unlocks.blk';
|
||||
const TRAINING_SECTION = 'training';
|
||||
|
||||
export interface TrainingFirstCompletionAward {
|
||||
readonly id: string;
|
||||
readonly goldenEagles: number;
|
||||
readonly blockedBy: readonly string[];
|
||||
}
|
||||
|
||||
export interface TrainingMissionEntry {
|
||||
readonly fullName: string;
|
||||
readonly decal?: string;
|
||||
readonly firstCompletion?: TrainingFirstCompletionAward;
|
||||
/** First-win Silver Lions rewards (`wpEarnedWinDiff0..2`) for arcade, realistic, simulator. */
|
||||
readonly silverLionsByDifficulty: readonly [number, number, number];
|
||||
}
|
||||
|
||||
export interface TrainingMissionsData {
|
||||
readonly missions: readonly TrainingMissionEntry[];
|
||||
}
|
||||
|
||||
export const trainingMissions: Dataset<TrainingMissionsData> = {
|
||||
id: 'training-missions',
|
||||
version: 1,
|
||||
extract(source: DatasetSource): TrainingMissionsData {
|
||||
const misSection = blockAt(source.readBlk(CHAR_PACK, MISLIST), TRAINING_SECTION);
|
||||
if (!misSection) throw new Error(`${MISLIST} has no "${TRAINING_SECTION}" block`);
|
||||
const awardSection = blockAt(source.readBlk(CHAR_PACK, PVE_AWARDS), TRAINING_SECTION);
|
||||
if (!awardSection) throw new Error(`${PVE_AWARDS} has no "${TRAINING_SECTION}" block`);
|
||||
|
||||
const awardsByMission = new Map<string, BlkBlock>(awardSection.blocks.map((entry) => [entry.name, entry]));
|
||||
const unlocksById = new Map<string, BlkBlock>();
|
||||
for (const entry of source.readBlk(CHAR_PACK, UNLOCKS).blocks) {
|
||||
const id = stringField(entry, 'id');
|
||||
if (id) unlocksById.set(id, entry);
|
||||
}
|
||||
|
||||
const seen = new Set<string>();
|
||||
const missions: TrainingMissionEntry[] = [];
|
||||
for (const chapter of misSection.blocks) {
|
||||
for (const mission of stringList(chapter, 'm')) {
|
||||
const fullName = `${chapter.name}/${mission}`;
|
||||
if (seen.has(fullName)) continue;
|
||||
seen.add(fullName);
|
||||
missions.push(buildMissionEntry(fullName, mission, awardsByMission.get(mission), unlocksById));
|
||||
}
|
||||
}
|
||||
return { missions };
|
||||
},
|
||||
};
|
||||
|
||||
function buildMissionEntry(
|
||||
fullName: string,
|
||||
mission: string,
|
||||
award: BlkBlock | undefined,
|
||||
unlocks: ReadonlyMap<string, BlkBlock>,
|
||||
): TrainingMissionEntry {
|
||||
const decalId = stringField(award, 'decal');
|
||||
const decal = decalId && stringField(unlocks.get(decalId), 'type') === 'decal' ? decalId : undefined;
|
||||
const firstCompletion = award ? readFirstCompletionAward(award, mission, unlocks) : undefined;
|
||||
return {
|
||||
fullName,
|
||||
...(decal ? { decal } : {}),
|
||||
...(firstCompletion ? { firstCompletion } : {}),
|
||||
silverLionsByDifficulty: [
|
||||
readWinSilverLions(award, 0),
|
||||
readWinSilverLions(award, 1),
|
||||
readWinSilverLions(award, 2),
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
function readFirstCompletionAward(
|
||||
award: BlkBlock,
|
||||
mission: string,
|
||||
unlocks: ReadonlyMap<string, BlkBlock>,
|
||||
): TrainingFirstCompletionAward | undefined {
|
||||
const id = stringField(award, 'oneTimeAwardUnlock');
|
||||
if (!id) return undefined;
|
||||
const unlock = unlocks.get(id);
|
||||
if (stringField(unlock, 'type') !== 'award') return undefined;
|
||||
const amount = unlock && findParam(unlock, 'amount_gold')?.value;
|
||||
const mode = blockAt(unlock, 'mode');
|
||||
if (amount?.type !== 'int' || amount.value <= 0
|
||||
|| stringField(mode, 'type') !== 'char_mission_list'
|
||||
|| !stringList(mode, 'name').includes(mission)) return undefined;
|
||||
|
||||
const blocked = mode?.blocks.flatMap((condition) =>
|
||||
condition.name === 'condition'
|
||||
&& stringField(condition, 'type') === 'char_unlocked'
|
||||
&& boolField(condition, 'positive') === false
|
||||
? stringList(condition, 'unlock')
|
||||
: []) ?? [];
|
||||
const hideIfEarned = stringField(award, 'hideOneTimeAwardIfUnlockIsOpen');
|
||||
if (hideIfEarned) blocked.push(hideIfEarned);
|
||||
return { id, goldenEagles: amount.value, blockedBy: [...new Set(blocked)] };
|
||||
}
|
||||
|
||||
function readWinSilverLions(award: BlkBlock | undefined, difficulty: 0 | 1 | 2): number {
|
||||
const value = award && findParam(award, `wpEarnedWinDiff${difficulty}`)?.value;
|
||||
return value?.type === 'int' && value.value > 0 ? value.value : 0;
|
||||
}
|
||||
Reference in new issue
Block a user