Add store and marketplace deep links and coupon resale
Register bundle GUIDs at build time and return local store item URLs. Route marketplace item links to the requested coupon. Update vehicle and cosmetic prices from the marketplace snapshot and support selling coupons back to the system at the configured fee. Type checking, an isolated build, and local service checks passed. In-game acceptance is pending.
This commit is contained in:
1 parent
b6964658d7
commit
c01ee8ae5a
16 files changed
+588
-250
No files matched your search
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Offline store bundle GUIDs for config/gui.blk `bundles/guid`.
|
||||
*
|
||||
* The game opens a gift vehicle's own store page only when `getBundleId(<entitlement>)` finds a
|
||||
* GUID for it (scripts/onlineShop/onlineShopModel.nut showUnitGoods → doBrowserPurchaseByGuid);
|
||||
* the URL then comes from the local service's item_info.php `url` field. Every vehicle carrying
|
||||
* `gift` in char.vromfs.bin config/wpcost.blk gets `stableGuid(wto_pack_<vehicle>)`, and every
|
||||
* multi-vehicle pack listed in the local service's tuning/store.jsonc gets `stableGuid(<pack id>)`;
|
||||
* entries the store does not sell are never looked up, so registering extra ones is harmless.
|
||||
*/
|
||||
import { existsSync, readFileSync } from 'node:fs';
|
||||
import { singleVehiclePackId, stableGuid, type BlkBlock } from '@wto/blk';
|
||||
import { readPackBlk } from '../pack-edit.ts';
|
||||
|
||||
export const WPCOST_PATH = 'config/wpcost.blk';
|
||||
|
||||
export function offlinePackBundleGuids(charPack: Uint8Array, storeTuningPath: string): Array<readonly [string, string]> {
|
||||
const ids = new Set<string>();
|
||||
for (const vehicle of giftVehicles(readPackBlk(charPack, WPCOST_PATH))) ids.add(singleVehiclePackId(vehicle));
|
||||
for (const id of multiVehiclePackIds(storeTuningPath)) ids.add(id);
|
||||
return [...ids].sort().map((id) => [id, stableGuid(id)] as const);
|
||||
}
|
||||
|
||||
function giftVehicles(wpcost: BlkBlock): string[] {
|
||||
return wpcost.blocks.filter((unit) => unit.params.some((param) => param.name === 'gift')).map((unit) => unit.name);
|
||||
}
|
||||
|
||||
/** Pack ids of `multiVehiclePacks` in tuning/store.jsonc (a plain scan; the file is JSON with comments). */
|
||||
function multiVehiclePackIds(storeTuningPath: string): string[] {
|
||||
if (!existsSync(storeTuningPath)) return [];
|
||||
const text = readFileSync(storeTuningPath, 'utf8');
|
||||
const start = text.indexOf('"multiVehiclePacks"');
|
||||
if (start < 0) return [];
|
||||
return [...text.slice(start).matchAll(/"id"\s*:\s*"([^"]+)"/g)].map((match) => match[1]!);
|
||||
}
|
||||
Reference in new issue
Block a user