Files
WT-Offline/packages/local-service/src/items/item-purchase.ts
T
N0VAN0M4LY 9cf7df5299 feat(store): open store pages in-game and centralize economy tuning
Use the native embedded browser and pass the game language through
auto_local. Share web assets and extract vehicle icons, flags, and
localized names from the installed client.

Load and validate per-domain JSONC tuning and merge local overrides
by field. Use official store USD prices for GJN products, keep GJN
balances in integer cents, and split the native and web store
handlers by protocol. Multi-vehicle packs are still listed as single
vehicles at this point.

Type checking, patch checks, and configuration loading passed.
In-game acceptance is pending.
2026-11-25 11:01:05 +08:00

27 lines
1.5 KiB
TypeScript

/**
* Buying classic items (cln_buy_item, implementation notes; scripts items/itemsBase.nut
* _requestBuy): name:t count:i cost:i costGold:i.
*
* The client prices a purchase as the price-table price of one piece times the pieces it buys
* (getCost: wp_get_item_cost x sell_count_step; count is sell_count_step), so the offered price
* must be the piece price times count.
*/
import type { BlkBlock } from '@wto/blk';
import { canAfford, pay, type Price } from '../profile/profile-currency.ts';
import type { ServerTime } from '../profile/server-time.ts';
import { ACCEPTED, refused, type RuleOutcome } from '../research/rule-outcome.ts';
import { isForSale, type ItemCatalogue } from './item-catalogue.ts';
import { grantItem } from './item-grants.ts';
export function buyItem(profile: BlkBlock, catalogue: ItemCatalogue, name: string, pieces: number, offered: Price, now: ServerTime): RuleOutcome {
const item = catalogue.item(name);
if (!item || pieces < 1 || pieces > catalogue.maxPiecesPerPurchase) return refused('BAD_PARAMS');
if (!isForSale(item)) return refused('NOT_AVAILABLE');
const price: Price = { silverLions: item.silverLions * pieces, goldenEagles: item.goldenEagles * pieces };
if (price.silverLions !== offered.silverLions || price.goldenEagles !== offered.goldenEagles) return refused('PRICE_CHANGED');
if (!canAfford(profile, price)) return refused('NOT_ENOUGH_MONEY');
pay(profile, price);
grantItem(profile, item, pieces, now);
return ACCEPTED;
}