Files
WT-Offline/packages/local-service/src/profile/profile-resources.ts
T
N0VAN0M4LY 28909cf1e9 feat(cosmetics): support cosmetic purchases
Handle cln_buy_resource, persist ownership in resourcesInfo, and expose
the prices of skins, decals, and attachments.
2026-11-24 21:56:00 +08:00

27 lines
1.3 KiB
TypeScript

/**
* Bought decorations in the profile:
*
* resourcesInfo{ core{ "us_m22_locust/us_camo_olive"{ spendGold:i=200 } cow_skull{ spendGold:i=500 } } }
*
* A generic name-keyed storage (FastStrMapStorageBase, aces.exe 0x93da88): one block per bought
* decoration under core, named by the client's key; having a block means owned (player_have_skin,
* player_have_decal, player_have_attachable -> 0x95dfc0). Each entry's params are read by name
* (0x95eaa0): flags:i, spendWP:i, spendGold:i, exteriorInfoParams.
*/
import { ensureBlock, findBlock, setParam, type BlkBlock } from '@wto/blk';
const RESOURCES = 'resourcesInfo';
const CORE = 'core';
export function ownsResource(profile: BlkBlock, key: string): boolean {
const resources = findBlock(profile, RESOURCES);
const core = resources && findBlock(resources, CORE);
return core !== undefined && findBlock(core, key) !== undefined;
}
export function addResource(profile: BlkBlock, key: string, spent: { silverLions: number; goldenEagles: number }): void {
const entry = ensureBlock(ensureBlock(ensureBlock(profile, RESOURCES), CORE), key);
if (spent.silverLions) setParam(entry, 'spendWP', { type: 'int', value: spent.silverLions });
if (spent.goldenEagles) setParam(entry, 'spendGold', { type: 'int', value: spent.goldenEagles });
}