feat(saves): edit account levels and avatars

Read rank thresholds and available avatar artwork from the selected copy. Persist avatar selections in the player profile and preserve free research points when a level changes.
This commit is contained in:
N0VAN0M4LY committed 2026-11-29 18:19:05 +08:00
1 parent d043a8f0f8
commit 5d1d7001b8
22 files changed
+337 -63

No files matched your search

@@ -10,12 +10,15 @@
*/
import { setParam, type BlkBlock } from '@wto/blk';
import type { Account } from '../accounts/account-store.ts';
import { appearance } from './profile-appearance.ts';
import { clearStoreCart } from './profile-store-cart.ts';
import { serverTimeNow } from './server-time.ts';
export function clientProfile(saved: BlkBlock, account: Account): BlkBlock {
const profile = structuredClone(saved);
clearStoreCart(profile);
const pilotIcon = appearance(profile).pilotIcon;
if (pilotIcon !== undefined) setParam(profile, 'pilotIcon', { type: 'string', value: pilotIcon });
setParam(profile, 'charDrivenNick', { type: 'string', value: account.nick });
setParam(profile, 'serverTime', { type: 'int64', value: serverTimeNow() });
return profile;
@@ -30,6 +30,10 @@ export function appearance(profile: BlkBlock): Partial<Record<AppearanceField, s
const value = block && findParam(block, field)?.value;
if (value?.type === 'string') result[field] = value.value;
}
if (result.pilotIcon === undefined) {
const legacy = findParam(profile, 'pilotIcon')?.value;
if (legacy?.type === 'string') result.pilotIcon = legacy.value;
}
return result;
}
@@ -1,57 +1,50 @@
/**
* 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".
* The client uses the total of the saved experience counters for its account rank.
* Free research points are that total minus the signed `converted` counter. Both
* values were observed in the 2.61.0.43 client's rank and free RP getters.
* Battle rewards increase `experience`, and spending free RP increases `converted`.
*/
import { findParam, setParam, type BlkBlock } from '@wto/blk';
import { setParam, type BlkBlock } from '@wto/blk';
import { int64Field } from './blk-fields.ts';
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);
return Number(playerExperience(profile) - int64Field(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);
setCounter(profile, SPENT, int64Field(profile, SPENT) + BigInt(amount));
}
/** Credit convertible (free) research points earned in battle (`experience:i64`). */
export function addFreeResearchPoints(profile: BlkBlock, amount: number): void {
if (!Number.isSafeInteger(amount) || amount < 0) throw new RangeError(`amount out of range: ${amount}`);
if (amount > 0) setCounter(profile, EARNED, counter(profile, EARNED) + amount);
if (amount > 0) setCounter(profile, EARNED, int64Field(profile, EARNED) + BigInt(amount));
}
/** Make the free research points this amount (the save editor). */
/** Set the free research balance while keeping the experience used for rank. */
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);
}
setCounter(profile, SPENT, playerExperience(profile) - BigInt(amount));
}
function earnedTotal(profile: BlkBlock): number {
return [EARNED, ...OTHER_EARNED].reduce((sum, name) => sum + counter(profile, name), 0);
export function playerExperience(profile: BlkBlock): bigint {
return [EARNED, ...OTHER_EARNED].reduce((sum, name) => sum + int64Field(profile, name), 0n);
}
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;
/** Set rank experience by applying the same adjustment to earned and converted RP. */
export function setPlayerExperience(profile: BlkBlock, amount: bigint): void {
const difference = amount - playerExperience(profile);
setCounter(profile, EARNED, int64Field(profile, EARNED) + difference);
setCounter(profile, SPENT, int64Field(profile, SPENT) + difference);
}
function setCounter(profile: BlkBlock, name: string, amount: number): void {
setParam(profile, name, { type: 'int64', value: BigInt(amount) });
function setCounter(profile: BlkBlock, name: string, amount: bigint): void {
setParam(profile, name, { type: 'int64', value: amount });
}