Files
WT-Offline/packages/local-service/src/research/price-table.ts
T
N0VAN0M4LY 415f78e761 feat(inventory): add external inventory, marketplace, and supply chests
Define external inventory items and support GJN purchases, recycling,
and supply chest drops.
2026-11-25 07:19:07 +08:00

139 lines
6.6 KiB
TypeScript

/**
* The price table the char server sends for cln_get_price_ex (implementation notes,
* implementation notes).
*
* The client keeps the answer whole as its price table (aces.exe 2.61.0.37 0xeb7a88, job type
* 0x21; stored in the save-data object at +0x3f5c0, which warpoints::init makes the price
* source, 0x105bb4d..0x105bb67). Every price reader goes through one lookup (0x908a20 ->
* 0x908d10): it first takes a top-level block named after a client-side string (default
* "English"), else the top-level block "Common", else finds nothing; the path is looked up
* inside that block. So the whole table sits in Common:
*
* Common{
* aircrafts{
* <vehicle>{
* cost:i costGold:i the vehicle
* mods{ <modification>{ cost:i costGold:i openCostGold:i } }
* weapons{ <preset>{ cost:i costGold:i } }
* spare{ cost:i costGold:i }
* }
* }
* skins{ "<vehicle>/<skin>"{ cost:i costGold:i } } decorations (get_skin_cost_*, 0x17a8910...)
* decals{ <decal>{ ... } }
* attachable{ <attachable>{ ... } }
* skills{ <pack>{ costGold:i } } skill point packs (0x916380)
* unlocks{ <unlock>{ cost:i costGold:i } } unlocks for sale (0x9170c0)
* items{ <item>{ cost:i costGold:i } } classic items for sale, price per piece
* (wp_get_item_cost, 0x10531e0; implementation notes)
* }
*
* Every entry is read as cost:i (silver lions), costGold:i (golden eagles), discount:i (percent
* off, not sent: no discounts), each 0 when missing (so zero prices are left out); openCostGold
* is the outright price of a modification before research progress (0xec0910). Anything the
* lookup does not find costs 0 for the client, which then offers it at 0 (lab round 20). The
* prices are config/wpcost.blk value and costGold (decorations: config/skins.blk, decals.blk,
* attachable.blk; unlocks: config/unlocks.blk), the same the purchase rules charge.
*/
import type { BlkBlock, BlkParam } from '@wto/blk';
import type { CrewSkillCatalogue } from '../crew/crew-skill-rules.ts';
import type { DecorShop } from '../decor/decor-purchase.ts';
import type { TrophyCatalogue } from '../inventory/trophy-catalogue.ts';
import type { ItemCatalogue } from '../items/item-catalogue.ts';
import type { EquipmentCatalogue } from '../modifications/equipment-catalogue.ts';
import type { UnlockShop } from '../unlocks/unlock-purchase.ts';
import type { ResearchRules } from './research-rules.ts';
import type { TechTree } from './tech-tree.ts';
/** The top-level block every client lookup falls back to (0x908e28). */
const COMMON_SECTION = 'Common';
export function priceTable(rules: ResearchRules): BlkBlock {
return {
name: '',
params: [],
blocks: [
{
name: COMMON_SECTION,
params: [],
blocks: [
vehicleSection(rules.techTree, rules.equipment),
...decorSections(rules.decor),
skillPackSection(rules.crew),
unlockSection(rules.unlocks),
itemSection(rules.items),
trophyPriceSection(rules.trophies),
],
},
rules.trophies.definitionsBlk(),
],
};
}
function vehicleSection(techTree: TechTree, equipment: EquipmentCatalogue): BlkBlock {
const vehicles: BlkBlock[] = [];
for (const vehicle of techTree.all()) {
const entry: BlkBlock = { name: vehicle.name, params: priceParams(vehicle.silverLions, vehicle.goldenEagles), blocks: [] };
const fitted = equipment.vehicle(vehicle.name);
if (fitted) {
const mods = fitted.modifications.filter((mod) => mod.silverLions > 0 || mod.goldenEagles > 0 || mod.openGoldenEagles > 0).map((mod) => ({
name: mod.name,
params: [...priceParams(mod.silverLions, mod.goldenEagles), ...(mod.openGoldenEagles > 0 ? [intParam('openCostGold', mod.openGoldenEagles)] : [])],
blocks: [],
}));
const weapons = fitted.weapons.filter((weapon) => weapon.silverLions > 0 || weapon.goldenEagles > 0)
.map((weapon) => ({ name: weapon.name, params: priceParams(weapon.silverLions, weapon.goldenEagles), blocks: [] }));
if (mods.length) entry.blocks.push({ name: 'mods', params: [], blocks: mods });
if (weapons.length) entry.blocks.push({ name: 'weapons', params: [], blocks: weapons });
if (fitted.spare) entry.blocks.push({ name: 'spare', params: priceParams(fitted.spare.silverLions, fitted.spare.goldenEagles), blocks: [] });
}
if (entry.blocks.length || vehicle.silverLions > 0 || vehicle.goldenEagles > 0) vehicles.push(entry);
}
return { name: 'aircrafts', params: [], blocks: vehicles };
}
/** Zero prices are left out: the client reads a missing value as 0, and the table stays small. */
function priceParams(silverLions: number, goldenEagles: number): BlkParam[] {
return [
...(silverLions ? [intParam('cost', silverLions)] : []),
...(goldenEagles ? [intParam('costGold', goldenEagles)] : []),
];
}
function intParam(name: string, value: number): BlkParam {
return { name, value: { type: 'int', value } };
}
/** The price-table section each decoration kind is looked up in. */
const DECOR_SECTIONS = { skin: 'skins', decal: 'decals', attachable: 'attachable' } as const;
function decorSections(decor: DecorShop): BlkBlock[] {
const sections = new Map<string, BlkBlock>();
for (const price of decor.all()) {
const name = DECOR_SECTIONS[price.kind];
let section = sections.get(name);
if (!section) sections.set(name, section = { name, params: [], blocks: [] });
section.blocks.push({ name: price.key, params: priceParams(price.silverLions, price.goldenEagles), blocks: [] });
}
return [...sections.values()];
}
function skillPackSection(crew: CrewSkillCatalogue): BlkBlock {
return { name: 'skills', params: [], blocks: [...crew.packs()].map((pack) => ({ name: pack.name, params: priceParams(0, pack.goldenEagles), blocks: [] })) };
}
function unlockSection(unlocks: UnlockShop): BlkBlock {
return { name: 'unlocks', params: [], blocks: [...unlocks.all()].map((price) => ({ name: price.id, params: priceParams(price.silverLions, price.goldenEagles), blocks: [] })) };
}
function itemSection(items: ItemCatalogue): BlkBlock {
return { name: 'items', params: [], blocks: items.forSale().map((item) => ({ name: item.name, params: priceParams(item.silverLions, item.goldenEagles), blocks: [] })) };
}
function trophyPriceSection(trophies: TrophyCatalogue): BlkBlock {
return {
name: 'trophy',
params: [],
blocks: trophies.all().map((trophy) => ({ name: trophy.id, params: priceParams(trophy.silverLions, trophy.goldenEagles), blocks: [] })),
};
}