Files
WT-Offline/packages/local-service/src/game-data/datasets/battle-streaks.ts
T
N0VAN0M4LY 8febf2d94e Judge LocalMP battle awards in the local service
The battle awards (streaks) of unlocks.blk are now judged by the local
service from the battle's facts: the player's combat events, each life
and whether it ended in death, the HUD kill log and the final
scoreboard. The record patch also sends each fact live over the
matching connection (wto_battle.fact); the awards it completes come
back and are shown with the stock award banner and kill log entry.

After the battle the awards become EULT_NEW_STREAK logs, which the
stock debriefing lists on its left, and their Silver Lions are paid and
shown in the Unlocks row. Modes whose facts are not reported, and
best-player awards limited by battle rating, are never given.
2026-11-28 08:32:35 +08:00

121 lines
4.6 KiB
TypeScript

/**
* Dataset: the battle awards ("streaks") of char.vromfs.bin config/unlocks.blk (implementation notes "3e").
*
* unlockable{ id:t type:t="streak" hidden:b isAfterFlight:b isMultiStage:b
* amount_warpoints:i|ip3 amount_exp:i|ip3 reward of a single-stage award
* wpA:p3 wpB:p3 expA:p3 expB:p3 reward terms of a multi-stage award
* stage{ param:i amount_warpoints amount_exp } first stage of a multi-stage award
* mode{ type:t <mode parameters> condition{ type:t <condition parameters> } ... }
* }
*
* Three-value parameters (p3 / ip3) are per difficulty: arcade, realistic, simulator. Hidden
* awards are left out: the stock client does not show them (scripts/unlocks isUnlockVisible).
* Online the battle server evaluates these definitions; battle/battle-streaks.ts does it offline.
*/
import type { BlkBlock, BlkValue } from '@wto/blk';
import type { Dataset } from './dataset.ts';
export type StreakValue = string | number | boolean;
/** Every parameter of a block by name, repeated names in order; three-value parameters spread. */
export type StreakParams = Readonly<Record<string, readonly StreakValue[]>>;
export interface StreakCondition {
readonly type: string;
readonly params: StreakParams;
}
export interface StreakMode {
readonly type: string;
readonly params: StreakParams;
readonly conditions: readonly StreakCondition[];
}
export type PerDifficulty = readonly [number, number, number];
export interface StreakDefinition {
readonly id: string;
readonly afterFlight: boolean;
readonly multiStage: boolean;
readonly wp: PerDifficulty;
readonly exp: PerDifficulty;
readonly stage?: { readonly param: number; readonly wp: PerDifficulty; readonly exp: PerDifficulty };
readonly wpA: PerDifficulty;
readonly wpB: PerDifficulty;
readonly expA: PerDifficulty;
readonly expB: PerDifficulty;
readonly mode?: StreakMode;
}
export const battleStreaks: Dataset<readonly StreakDefinition[]> = {
id: 'battle-streaks',
version: 1,
extract: (source) => source.readBlk('char.vromfs.bin', 'config/unlocks.blk').blocks
.filter((block) => block.name === 'unlockable')
.flatMap((block): StreakDefinition[] => {
const params = paramsOf(block);
const id = params.id?.[0];
if (params.type?.[0] !== 'streak' || typeof id !== 'string' || params.hidden?.[0] === true) return [];
const stage = block.blocks.find((child) => child.name === 'stage');
const stageParams = stage && paramsOf(stage);
const stageParam = stageParams?.param?.[0];
const mode = block.blocks.find((child) => child.name === 'mode');
return [{
id,
afterFlight: params.isAfterFlight?.[0] === true,
multiStage: params.isMultiStage?.[0] === true,
wp: perDifficulty(params.amount_warpoints),
exp: perDifficulty(params.amount_exp),
...(stageParams && typeof stageParam === 'number'
? { stage: { param: stageParam, wp: perDifficulty(stageParams.amount_warpoints), exp: perDifficulty(stageParams.amount_exp) } }
: {}),
wpA: perDifficulty(params.wpA),
wpB: perDifficulty(params.wpB),
expA: perDifficulty(params.expA),
expB: perDifficulty(params.expB),
...(mode ? { mode: modeOf(mode) } : {}),
}];
}),
};
function modeOf(block: BlkBlock): StreakMode {
const params = paramsOf(block);
return {
type: String(params.type?.[0] ?? ''),
params,
conditions: block.blocks.filter((child) => child.name === 'condition').map((condition) => {
const conditionParams = paramsOf(condition);
return { type: String(conditionParams.type?.[0] ?? ''), params: conditionParams };
}),
};
}
function paramsOf(block: BlkBlock): Record<string, StreakValue[]> {
const out: Record<string, StreakValue[]> = {};
for (const param of block.params) (out[param.name] ??= []).push(...valuesOf(param.value));
return out;
}
function valuesOf(value: BlkValue): StreakValue[] {
switch (value.type) {
case 'string':
case 'int':
case 'real':
case 'bool':
return [value.value];
case 'point3':
case 'ipoint3':
return [...value.value];
default:
return [];
}
}
/** An int applies to every difficulty; a three-value parameter is per difficulty; missing is 0. */
function perDifficulty(values: readonly StreakValue[] | undefined): PerDifficulty {
const numbers = (values ?? []).filter((value): value is number => typeof value === 'number');
if (numbers.length >= 3) return [numbers[0]!, numbers[1]!, numbers[2]!];
const single = numbers[0] ?? 0;
return [single, single, single];
}