83 lines
3.9 KiB
TypeScript
83 lines
3.9 KiB
TypeScript
/**
|
|
* Dataset: how a battle's Research Points reach the researched vehicle.
|
|
*
|
|
* char.vromfs.bin config/rank.blk:
|
|
* expBonusPercentForChildForMode<N> bonus when the vehicle played precedes the researched one;
|
|
* the client reads N = the difficulty's diffCode
|
|
* (gui.vromfs.bin scripts/airinfo.nut)
|
|
* expPenaltyPercentForHigherRank<N> penalty when the researched vehicle is N ranks above the one played
|
|
* expPenaltyPercentForLowerRank<N> penalty when it is N ranks below
|
|
* ExpNewNationBonus{<type>{rank<N>}} "Vehicle Research Bonus" percent by the researched vehicle's rank
|
|
* expNewNationBonusDailyBattleCount battles per nation and branch per day that get it
|
|
* char.vromfs.bin config/shop.blk:
|
|
* country{ branch{ range{ vehicle | group{ vehicle... } } } }: the last entry of each range ends a
|
|
* research line; when it is a group, its first vehicle counts (official wiki "Research Points",
|
|
* "top" vehicle definition).
|
|
*/
|
|
import type { BlkBlock } from '@wto/blk';
|
|
import { numberField } from './blk-fields.ts';
|
|
import type { Dataset } from './dataset.ts';
|
|
import { SHOP } from './shop-tree.ts';
|
|
|
|
export interface ResearchEfficiencyData {
|
|
/** Indexed by mode number N of expBonusPercentForChildForMode<N>. */
|
|
readonly childBonusPercent: readonly number[];
|
|
/** Indexed by the rank difference. */
|
|
readonly higherRankPenaltyPercent: readonly number[];
|
|
readonly lowerRankPenaltyPercent: readonly number[];
|
|
/** Vehicle type (rank.blk spelling: Tank, Aircraft, Helicopter, Ship, Boat) -> rank -> percent. */
|
|
readonly nationBonusPercent: Readonly<Record<string, Readonly<Record<number, number>>>>;
|
|
readonly nationBonusDailyBattles: number;
|
|
/** The vehicle that ends each research line of shop.blk. */
|
|
readonly lineEnds: readonly string[];
|
|
}
|
|
|
|
const RANK = 'config/rank.blk';
|
|
|
|
export const researchEfficiency: Dataset<ResearchEfficiencyData> = {
|
|
id: 'research-efficiency',
|
|
version: 1,
|
|
extract: (source) => {
|
|
const rank = source.readBlk('char.vromfs.bin', RANK);
|
|
const nationBonus = rank.blocks.find((block) => block.name === 'ExpNewNationBonus');
|
|
const dailyBattles = numberField(rank, 'expNewNationBonusDailyBattleCount');
|
|
if (dailyBattles === undefined) throw new Error('rank.blk: expNewNationBonusDailyBattleCount is missing');
|
|
return {
|
|
childBonusPercent: indexedSeries(rank, 'expBonusPercentForChildForMode'),
|
|
higherRankPenaltyPercent: indexedSeries(rank, 'expPenaltyPercentForHigherRank'),
|
|
lowerRankPenaltyPercent: indexedSeries(rank, 'expPenaltyPercentForLowerRank'),
|
|
nationBonusPercent: Object.fromEntries((nationBonus?.blocks ?? []).map((type) => [
|
|
type.name,
|
|
Object.fromEntries(type.params.flatMap((param) => {
|
|
const rankNumber = /^rank(\d+)$/.exec(param.name)?.[1];
|
|
return rankNumber !== undefined && param.value.type === 'int' ? [[Number(rankNumber), param.value.value]] : [];
|
|
})),
|
|
])),
|
|
nationBonusDailyBattles: dailyBattles,
|
|
lineEnds: source.readBlk('char.vromfs.bin', SHOP).blocks.flatMap((country) =>
|
|
country.blocks.flatMap((branch) => branch.blocks.filter((range) => range.name === 'range').flatMap(lineEnd))),
|
|
};
|
|
},
|
|
};
|
|
|
|
/** <prefix>0, <prefix>1, ... up to the first missing index. */
|
|
function indexedSeries(block: BlkBlock, prefix: string): number[] {
|
|
const values: number[] = [];
|
|
for (let index = 0; ; index++) {
|
|
const value = numberField(block, `${prefix}${index}`);
|
|
if (value === undefined) break;
|
|
values.push(value);
|
|
}
|
|
if (values.length === 0) throw new Error(`rank.blk: ${prefix}0 is missing`);
|
|
return values;
|
|
}
|
|
|
|
/** A vehicle entry has no child blocks; a group holds its vehicles as child blocks. */
|
|
function lineEnd(range: BlkBlock): string[] {
|
|
const last = range.blocks.at(-1);
|
|
if (!last) return [];
|
|
if (last.blocks.length === 0) return [last.name];
|
|
const first = last.blocks[0];
|
|
return first ? [first.name] : [];
|
|
}
|