feat(cosmetics): support cosmetic purchases
Handle cln_buy_resource, persist ownership in resourcesInfo, and expose the prices of skins, decals, and attachments.
This commit is contained in:
1 parent
6d8a3af37a
commit
28909cf1e9
8 files changed
+178
-6
No files matched your search
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* Dataset: the decorations that can be bought.
|
||||
*
|
||||
* char.vromfs.bin config/skins.blk, config/decals.blk, config/attachable.blk: one block per
|
||||
* decoration, named like the client keys it (skins "<vehicle>/<skin>", decals and attachables by
|
||||
* name), with
|
||||
* cost:i silver lions (missing = -1)
|
||||
* costGold:i golden eagles (missing = -1; -1 means not for sale)
|
||||
* unlock:t an unlock that also gives it
|
||||
* Only decorations with a positive price are recorded: the others are either free (the client
|
||||
* counts them as owned, aces.exe 0x95e1c5) or not for sale.
|
||||
*/
|
||||
import type { BlkBlock } from '@wto/blk';
|
||||
import { numberField } from './blk-fields.ts';
|
||||
import type { Dataset } from './dataset.ts';
|
||||
|
||||
export type DecorKind = 'skin' | 'decal' | 'attachable';
|
||||
|
||||
export interface DecorPrice {
|
||||
readonly kind: DecorKind;
|
||||
/** The client's key: "<vehicle>/<skin>" for skins, the name otherwise. */
|
||||
readonly key: string;
|
||||
readonly silverLions: number;
|
||||
readonly goldenEagles: number;
|
||||
}
|
||||
|
||||
const SOURCES: readonly { kind: DecorKind; path: string }[] = [
|
||||
{ kind: 'skin', path: 'config/skins.blk' },
|
||||
{ kind: 'decal', path: 'config/decals.blk' },
|
||||
{ kind: 'attachable', path: 'config/attachable.blk' },
|
||||
];
|
||||
|
||||
export const decorCatalogue: Dataset<readonly DecorPrice[]> = {
|
||||
id: 'decor-catalogue',
|
||||
version: 1,
|
||||
extract: (source) => SOURCES.flatMap(({ kind, path }) =>
|
||||
source.readBlk('char.vromfs.bin', path).blocks.flatMap((entry) => priceOf(kind, entry))),
|
||||
};
|
||||
|
||||
function priceOf(kind: DecorKind, entry: BlkBlock): DecorPrice[] {
|
||||
const silverLions = Math.max(0, numberField(entry, 'cost') ?? 0);
|
||||
const goldenEagles = Math.max(0, numberField(entry, 'costGold') ?? 0);
|
||||
return silverLions > 0 || goldenEagles > 0 ? [{ kind, key: entry.name, silverLions, goldenEagles }] : [];
|
||||
}
|
||||
Reference in new issue
Block a user