Add classic items and fix initial showcase responses

Store and activate boosters, personal discounts, wagers, and universal
spares. Apply active personal discounts when pricing vehicle purchases.
Return the server time and default fields for every showcase type.

Add developer commands for inspecting game logs, strings, references,
callers, and disassembly.
This commit is contained in:
N0VAN0M4LY committed 2026-11-25 04:17:34 +08:00
1 parent 76670121a9
commit ae6958f291
21 files changed
+880 -35

No files matched your search

@@ -0,0 +1,155 @@
/**
* Dataset: the classic items, char.vromfs.bin config/items.blk.
* One block per item, named after the item:
*
* <item>{
* type:t rateBooster, personalDiscounts, wager, missionOrder, universalSpare
* cost:i costGold:i price of one piece; most items have none (prizes only)
* sell_count_step:i pieces per purchase
* purchase_feature:t sold only to players with that feature ("devItemShop")
* expiredTimeH:r lifetime in hours from when the player gets it
* expiredTimeHAfterActivation:r lifetime in hours from activation
* expiredAt:t absolute end, "YYYY-MM-DD hh:mm:ss" UTC
* canPacked:b the pieces stack under one uid
* universalSpareParams{ numSpares:i country:t... unitType:t... minRank:i maxRank:i }
* wagerParams{ minWager:i maxWager:i wagerStep:i goldWager:b ... }
* personalDiscountsParams{ purchasesMaxCount:i discountsDesc{ <category>{ <key>:i aircrafts{ <vehicle>:i } } } }
* }
*/
import type { BlkBlock } from '@wto/blk';
import { blockAt, boolField, numberField, stringField, stringList } from './blk-fields.ts';
import type { Dataset } from './dataset.ts';
const ITEMS = 'config/items.blk';
export interface SpareConditions {
readonly spares: number;
/** Empty: any country. */
readonly countries: readonly string[];
/** The client's lower-case unit type names (aircraft, tank, ship, helicopter, boat); empty: any. */
readonly unitTypes: readonly string[];
readonly minRank?: number;
readonly maxRank?: number;
}
export interface WagerLimits {
readonly minStake: number;
readonly maxStake: number;
readonly stakeStep: number;
readonly goldenEagles: boolean;
}
/** One category of a discount description: percentages by key, and by vehicle under "aircrafts". */
export interface DiscountCategory {
readonly name: string;
readonly keys: Readonly<Record<string, number>>;
readonly vehicles: Readonly<Record<string, number>>;
}
export interface DiscountDefinition {
readonly maxPurchases: number;
readonly categories: readonly DiscountCategory[];
}
export interface ItemDefinition {
readonly name: string;
readonly type: string;
readonly silverLions: number;
readonly goldenEagles: number;
readonly piecesPerPurchase: number;
readonly purchaseFeature?: string;
readonly lifetimeHours?: number;
readonly lifetimeHoursAfterActivation?: number;
/** Unix milliseconds. */
readonly expiresAt?: number;
readonly stacks: boolean;
readonly spare?: SpareConditions;
readonly wager?: WagerLimits;
readonly discount?: DiscountDefinition;
}
export const itemCatalogue: Dataset<readonly ItemDefinition[]> = {
id: 'item-catalogue',
version: 1,
extract: (source) => source.readBlk('char.vromfs.bin', ITEMS).blocks.flatMap(itemOf),
};
function itemOf(entry: BlkBlock): ItemDefinition[] {
const type = stringField(entry, 'type');
if (type === undefined) return [];
const lifetimeHours = positive(numberField(entry, 'expiredTimeH'));
const lifetimeHoursAfterActivation = positive(numberField(entry, 'expiredTimeHAfterActivation'));
const expiresAt = utcTime(stringField(entry, 'expiredAt'));
const purchaseFeature = stringField(entry, 'purchase_feature');
const spare = spareOf(blockAt(entry, 'universalSpareParams'));
const wager = wagerOf(blockAt(entry, 'wagerParams'));
const discount = discountOf(blockAt(entry, 'personalDiscountsParams'));
return [{
name: entry.name,
type,
silverLions: Math.max(0, numberField(entry, 'cost') ?? 0),
goldenEagles: Math.max(0, numberField(entry, 'costGold') ?? 0),
piecesPerPurchase: Math.max(1, numberField(entry, 'sell_count_step') ?? 1),
stacks: boolField(entry, 'canPacked') ?? false,
...(purchaseFeature ? { purchaseFeature } : {}),
...(lifetimeHours !== undefined ? { lifetimeHours } : {}),
...(lifetimeHoursAfterActivation !== undefined ? { lifetimeHoursAfterActivation } : {}),
...(expiresAt !== undefined ? { expiresAt } : {}),
...(spare ? { spare } : {}),
...(wager ? { wager } : {}),
...(discount ? { discount } : {}),
}];
}
function spareOf(params: BlkBlock | undefined): SpareConditions | undefined {
if (!params) return undefined;
const minRank = numberField(params, 'minRank');
const maxRank = numberField(params, 'maxRank');
return {
spares: Math.max(1, numberField(params, 'numSpares') ?? 1),
countries: stringList(params, 'country'),
unitTypes: stringList(params, 'unitType'),
...(minRank !== undefined ? { minRank } : {}),
...(maxRank !== undefined ? { maxRank } : {}),
};
}
function wagerOf(params: BlkBlock | undefined): WagerLimits | undefined {
if (!params) return undefined;
return {
minStake: Math.max(0, numberField(params, 'minWager') ?? 0),
maxStake: Math.max(0, numberField(params, 'maxWager') ?? 0),
stakeStep: Math.max(1, numberField(params, 'wagerStep') ?? 1),
goldenEagles: boolField(params, 'goldWager') ?? false,
};
}
function discountOf(params: BlkBlock | undefined): DiscountDefinition | undefined {
if (!params) return undefined;
const description = blockAt(params, 'discountsDesc');
return {
maxPurchases: numberField(params, 'purchasesMaxCount') ?? 0,
categories: (description?.blocks ?? []).map((category) => ({
name: category.name,
keys: intsOf(category),
vehicles: intsOf(blockAt(category, 'aircrafts')),
})),
};
}
function intsOf(block: BlkBlock | undefined): Record<string, number> {
if (!block) return {};
return Object.fromEntries(block.params.flatMap((param) => param.value.type === 'int' ? [[param.name, param.value.value]] : []));
}
function positive(value: number | undefined): number | undefined {
return value !== undefined && value > 0 ? value : undefined;
}
/** "YYYY-MM-DD hh:mm:ss" in UTC, as the scripts read it (getTimestampFromStringUtc). */
function utcTime(text: string | undefined): number | undefined {
const match = text && /^(\d{4})-(\d{2})-(\d{2})[ T](\d{2}):(\d{2}):(\d{2})$/.exec(text.trim());
if (!match) return undefined;
const [, year, month, day, hour, minute, second] = match.map(Number) as [number, number, number, number, number, number, number];
return Date.UTC(year, month - 1, day, hour, minute, second);
}