Recompute unlocked ranks, prerequisites, and unit states before serving profiles. Add research target selection, research conversion, vehicle and slot purchases, and the price table. Support editing convertible RP and restrict hidden vehicle visibility to eligible entries. The client still displays zero purchase prices pending price table integration.
52 lines
2.1 KiB
TypeScript
52 lines
2.1 KiB
TypeScript
/**
|
|
* Free research points in the profile.
|
|
*
|
|
* The client shows shop_get_free_exp (aces.exe 2.61.0.37 0x17a4f40): the total of the
|
|
* experience counters (0x933190) minus "converted". The counters are top-level i64
|
|
* parameters read and written by 0x9331b0: experience, experienceOffline, valUnlocks,
|
|
* presented and valTrophy count into the total; Gaijin's new-account template has
|
|
* experience:i64=0. Free research points are earned into "experience" and spending them
|
|
* raises "converted".
|
|
*/
|
|
import { findParam, setParam, type BlkBlock } from '@wto/blk';
|
|
|
|
const EARNED = 'experience';
|
|
const OTHER_EARNED = ['experienceOffline', 'valUnlocks', 'presented', 'valTrophy'] as const;
|
|
const SPENT = 'converted';
|
|
|
|
export function freeResearchPoints(profile: BlkBlock): number {
|
|
return earnedTotal(profile) - counter(profile, SPENT);
|
|
}
|
|
|
|
/** Spend free research points the player has (callers check freeResearchPoints first). */
|
|
export function spendFreeResearchPoints(profile: BlkBlock, amount: number): void {
|
|
setCounter(profile, SPENT, counter(profile, SPENT) + amount);
|
|
}
|
|
|
|
/** Make the free research points this amount (the save editor). */
|
|
export function setFreeResearchPoints(profile: BlkBlock, amount: number): void {
|
|
if (!Number.isSafeInteger(amount) || amount < 0) throw new RangeError(`amount out of range: ${amount}`);
|
|
const others = earnedTotal(profile) - counter(profile, EARNED);
|
|
const earned = amount + counter(profile, SPENT) - others;
|
|
if (earned >= 0) {
|
|
setCounter(profile, EARNED, earned);
|
|
} else {
|
|
setCounter(profile, EARNED, 0);
|
|
setCounter(profile, SPENT, counter(profile, SPENT) - earned);
|
|
}
|
|
}
|
|
|
|
function earnedTotal(profile: BlkBlock): number {
|
|
return [EARNED, ...OTHER_EARNED].reduce((sum, name) => sum + counter(profile, name), 0);
|
|
}
|
|
|
|
function counter(profile: BlkBlock, name: string): number {
|
|
const value = findParam(profile, name)?.value;
|
|
if (value?.type === 'int64') return Number(value.value);
|
|
return value?.type === 'int' ? value.value : 0;
|
|
}
|
|
|
|
function setCounter(profile: BlkBlock, name: string, amount: number): void {
|
|
setParam(profile, name, { type: 'int64', value: BigInt(amount) });
|
|
}
|