Handle cln_buy_resource, persist ownership in resourcesInfo, and expose the prices of skins, decals, and attachments.
27 lines
1.3 KiB
TypeScript
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 });
|
|
}
|