/** * The price table the char server sends for cln_get_price_ex. * * 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{ * { * cost:i costGold:i the vehicle * mods{ { cost:i costGold:i openCostGold:i } } * weapons{ { cost:i costGold:i } } * spare{ cost:i costGold:i } * repair{ arcade{ cost:i } historical{ cost:i } simulation{ cost:i } } full repair cost per * mode before modifications (0x10517b0, 0x90e0b0) * specialization{ spec_expert{ cost:i } spec_ace{ costGold:i } } * } * } * skins{ "/"{ cost:i costGold:i } } decorations (get_skin_cost_*, 0x17a8910...) * decals{ { ... } } * attachable{ { ... } } * skills{ { costGold:i } } skill point packs (0x916380) * unlocks{ { cost:i costGold:i } } unlocks for sale (0x9170c0) * items{ { cost:i costGold:i } } classic items for sale, price per piece * (wp_get_item_cost, 0x10531e0) * trophy{ { cost:i costGold:i } } classic trophy prices * } * trophy{ { ... } } classic trophy definitions & drop weights * * 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, TrophyDefinition, TrophyPrize } from '../../inventory/trophy-catalogue.ts'; import type { ItemCatalogue } from '../../items/item-catalogue.ts'; import type { EquipmentCatalogue } from '../../modifications/equipment-catalogue.ts'; import { REPAIR_MODES } from '../../game-data/datasets/vehicle-repair.ts'; import type { RepairRules } from '../../repair/repair-rules.ts'; import type { TechTree } from '../../research/tech-tree.ts'; import type { UnlockShop } from '../../unlocks/unlock-purchase.ts'; /** The top-level block every client lookup falls back to (0x908e28). */ const COMMON_SECTION = 'Common'; export interface PriceTableSources { readonly techTree: TechTree; readonly equipment: EquipmentCatalogue; readonly decor: DecorShop; readonly crew: CrewSkillCatalogue; readonly unlocks: UnlockShop; readonly items: ItemCatalogue; readonly trophies: TrophyCatalogue; readonly repair: RepairRules; } export function priceTable(sources: PriceTableSources): BlkBlock { return { name: '', params: [], blocks: [ { name: COMMON_SECTION, params: [], blocks: [ vehicleSection(sources.techTree, sources.equipment, sources.crew, sources.repair), ...decorSections(sources.decor), skillPackSection(sources.crew), unlockSection(sources.unlocks), itemSection(sources.items), trophyPriceSection(sources.trophies), ], }, trophyDefinitionsSection(sources.trophies), ], }; } function vehicleSection(techTree: TechTree, equipment: EquipmentCatalogue, crew: CrewSkillCatalogue, repair: RepairRules): 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: [] }); } const repairCost = repair.vehicle(vehicle.name)?.cost; if (repairCost) { const modes = REPAIR_MODES.filter((mode) => repairCost[mode] > 0) .map((mode) => ({ name: mode.toLowerCase(), params: priceParams(repairCost[mode], 0), blocks: [] })); if (modes.length) entry.blocks.push({ name: 'repair', params: [], blocks: modes }); } const training = crew.training(vehicle.name); if (training && (training.expert > 0 || training.aceGoldenEagles > 0)) { const specBlocks: BlkBlock[] = []; if (training.expert > 0) specBlocks.push({ name: 'spec_expert', params: priceParams(training.expert, 0), blocks: [] }); if (training.aceGoldenEagles > 0) specBlocks.push({ name: 'spec_ace', params: priceParams(0, training.aceGoldenEagles), blocks: [] }); entry.blocks.push({ name: 'specialization', params: [], blocks: specBlocks }); } 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(); 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: [] })), }; } function trophyDefinitionsSection(trophies: TrophyCatalogue): BlkBlock { return { name: 'trophy', params: [], blocks: trophies.all().map(toTrophyDefinitionBlk), }; } function toTrophyDefinitionBlk(trophy: TrophyDefinition): BlkBlock { const params: BlkParam[] = [ { name: 'iconStyle', value: { type: 'string', value: trophy.iconStyle } }, { name: 'showChances', value: { type: 'bool', value: trophy.showChances } }, { name: 'repeatable', value: { type: 'bool', value: trophy.repeatable } }, { name: 'instantOpening', value: { type: 'bool', value: trophy.instantOpening } }, ]; if (trophy.numTotal > 0) params.push(intParam('numTotal', trophy.numTotal)); if (trophy.countryFlag) params.push({ name: 'showCountryFlag', value: { type: 'string', value: trophy.countryFlag } }); if (trophy.prizes.length === 1 && trophy.prizes[0]!.kind === 'unit') { params.push({ name: 'showTypeInName', value: { type: 'bool', value: true } }); } return { name: trophy.id, params, blocks: [{ name: 'prizes', params: [], blocks: trophy.prizes.map(prizeToBlk) }], }; } function prizeToBlk(prize: TrophyPrize): BlkBlock { // calculate_drop_chances (aces.exe 0x95a510 -> 0x95c27c..0x95c28f) checks paramType == TYPE_REAL (3) // on `weight` (defaulting to 1.0f when non-real) and writes normalized `percent:i` (0..10000). const params: BlkParam[] = [{ name: 'weight', value: { type: 'real', value: prize.weight } }]; if (prize.kind === 'warpoints') params.push(intParam('warpoints', prize.amount)); else if (prize.kind === 'gold') params.push(intParam('gold', prize.amount)); else if (prize.kind === 'item') { params.push({ name: 'item', value: { type: 'string', value: prize.itemName } }, intParam('count', prize.count)); } else { params.push({ name: 'unit', value: { type: 'string', value: prize.unitName } }); } return { name: 'i', params, blocks: [] }; }