Files
WT-Offline/packages/local-service/src/profile/profile-module-research.ts
T
N0VAN0M4LY 1e7dc2447f fix(equipment): correct modification status and persist weapon presets
Write modStatus in modsResearch so the client recognizes purchasable
modifications. Persist ownership and initial equipment state for free
modifications and quantities for free weapon presets.

Persist preset inventory in the weapon records and handle cln_buy_weapon
using the maximum quantity extracted from the game data.
2026-11-25 02:44:16 +08:00

59 lines
2.8 KiB
TypeScript

/**
* Modification research in the profile:
*
* modsResearch{ us_m22_locust_new_tank_tracks{ exp:i64=120 modStatus:i=2 } }
*
* One block per modification of an owned vehicle that is not bought yet, named
* <vehicle>_<modification>. The client reads each block with aces.exe 0x9403b0, by name:
* exp:i64 research points already put into it
* modStatus:i the status the server works out; 1 (locked) when absent
* (it also reads goldSpent:i, which the offline service never sets). An entry is always
* rewritten whole, so it holds nothing else.
*/
import { ensureBlock, findBlock, findParam, type BlkBlock, type BlkParam } from '@wto/blk';
import { recordName } from './profile-modifications.ts';
const MODS_RESEARCH = 'modsResearch';
const STATUS = 'modStatus';
const RESEARCH_POINTS = 'exp';
const LOCKED = 1;
export function moduleResearchPoints(profile: BlkBlock, vehicle: string, modification: string): number {
const entry = entryOf(profile, vehicle, modification);
const value = entry && findParam(entry, RESEARCH_POINTS)?.value;
if (value?.type === 'int64') return Number(value.value);
return value?.type === 'int' ? value.value : 0;
}
export function setModuleResearchPoints(profile: BlkBlock, vehicle: string, modification: string, amount: number): void {
writeEntry(profile, vehicle, modification, amount, moduleStatusOf(profile, vehicle, modification));
}
export function setModuleStatus(profile: BlkBlock, vehicle: string, modification: string, status: number): void {
writeEntry(profile, vehicle, modification, moduleResearchPoints(profile, vehicle, modification), status);
}
export function removeModuleResearch(profile: BlkBlock, vehicle: string, modification: string): void {
const block = findBlock(profile, MODS_RESEARCH);
const name = recordName(vehicle, modification);
if (block) block.blocks = block.blocks.filter((entry) => entry.name !== name);
}
function moduleStatusOf(profile: BlkBlock, vehicle: string, modification: string): number {
const entry = entryOf(profile, vehicle, modification);
const value = entry && findParam(entry, STATUS)?.value;
return value?.type === 'int' ? value.value : LOCKED;
}
function writeEntry(profile: BlkBlock, vehicle: string, modification: string, researchPoints: number, status: number): void {
const params: BlkParam[] = [];
if (researchPoints) params.push({ name: RESEARCH_POINTS, value: { type: 'int64', value: BigInt(researchPoints) } });
params.push({ name: STATUS, value: { type: 'int', value: status } });
ensureBlock(ensureBlock(profile, MODS_RESEARCH), recordName(vehicle, modification)).params = params;
}
function entryOf(profile: BlkBlock, vehicle: string, modification: string): BlkBlock | undefined {
const block = findBlock(profile, MODS_RESEARCH);
return block && findBlock(block, recordName(vehicle, modification));
}