Implement vehicle research and purchases
Recompute unlocked ranks, prerequisites, and unit states before serving profiles. Add research target selection, research conversion, vehicle and slot purchases, and the price table. Support editing convertible RP and restrict hidden vehicle visibility to eligible entries. The client still displays zero purchase prices pending price table integration.
This commit is contained in:
1 parent
8b31277c58
commit
7a08fff85e
37 files changed
+1336
-75
No files matched your search
@@ -11,6 +11,11 @@ export function numberField(block: BlkBlock | undefined, name: string): number |
|
||||
return value?.type === 'int' || value?.type === 'real' ? value.value : undefined;
|
||||
}
|
||||
|
||||
export function boolField(block: BlkBlock | undefined, name: string): boolean | undefined {
|
||||
const value = block && findParam(block, name)?.value;
|
||||
return value?.type === 'bool' ? value.value : undefined;
|
||||
}
|
||||
|
||||
/** Every string value of a repeated parameter, in order. */
|
||||
export function stringList(block: BlkBlock | undefined, name: string): string[] {
|
||||
if (!block) return [];
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Datasets from char.vromfs.bin config/rank.blk.
|
||||
*
|
||||
* needBuyToOpenNextInEra{ <country>{ needBuyToOpenNextInEra<type><rank>:i=N } }
|
||||
* how many vehicles of a rank a country's branch must own before the next rank opens; the
|
||||
* stock scripts also look up the name without the type (gui.vromfs.bin
|
||||
* scripts/unit/unitInfo.nut getUnitsNeedBuyToOpenNextInEra).
|
||||
*
|
||||
* crew_slots{ slot<N>{ cost:i costGold:i } }
|
||||
* the price of a country's next crew slot when it has N crews (aces.exe 2.61.0.37
|
||||
* get_crew_slot_cost, 0x90eaa0).
|
||||
*/
|
||||
import { numberField } from './blk-fields.ts';
|
||||
import type { Dataset } from './dataset.ts';
|
||||
|
||||
const RANK = 'config/rank.blk';
|
||||
const SLOT = /^slot(\d+)$/;
|
||||
|
||||
/** country -> parameter name -> vehicles needed, as written. */
|
||||
export type EraRequirements = Readonly<Record<string, Readonly<Record<string, number>>>>;
|
||||
|
||||
export const eraRequirements: Dataset<EraRequirements> = {
|
||||
id: 'era-requirements',
|
||||
version: 1,
|
||||
extract: (source) => {
|
||||
const block = source.readBlk('char.vromfs.bin', RANK).blocks.find((child) => child.name === 'needBuyToOpenNextInEra');
|
||||
return Object.fromEntries((block?.blocks ?? []).map((country) => [
|
||||
country.name,
|
||||
Object.fromEntries(country.params.flatMap((param) => (param.value.type === 'int' ? [[param.name, param.value.value]] : []))),
|
||||
]));
|
||||
},
|
||||
};
|
||||
|
||||
export interface CrewSlotPrice {
|
||||
readonly silverLions: number;
|
||||
readonly goldenEagles: number;
|
||||
}
|
||||
|
||||
/** Indexed by the number of crews the country has; a missing index has no price (cannot be bought). */
|
||||
export type CrewSlotPrices = readonly (CrewSlotPrice | null)[];
|
||||
|
||||
export const crewSlotPrices: Dataset<CrewSlotPrices> = {
|
||||
id: 'crew-slot-prices',
|
||||
version: 1,
|
||||
extract: (source) => {
|
||||
const block = source.readBlk('char.vromfs.bin', RANK).blocks.find((child) => child.name === 'crew_slots');
|
||||
const prices: (CrewSlotPrice | null)[] = [];
|
||||
for (const slot of block?.blocks ?? []) {
|
||||
const index = SLOT.exec(slot.name)?.[1];
|
||||
if (index === undefined) continue;
|
||||
prices[Number(index)] = { silverLions: numberField(slot, 'cost') ?? 0, goldenEagles: numberField(slot, 'costGold') ?? 0 };
|
||||
}
|
||||
return Array.from(prices, (price) => price ?? null);
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Dataset: how many free research points one golden eagle converts into a vehicle's research
|
||||
* points (implementation notes, cln_convert_exp).
|
||||
*
|
||||
* char.vromfs.bin config/warpoints.blk playerExpToCountryFor1Gold:i (2.61.0.37: 45). The
|
||||
* client reads it in wp_get_exp_convert_exp_for_gold_rate (aces.exe 0x1052af0 -> 0x916eb0),
|
||||
* defaulting to 1; the price table can override it per country (exp_to_gold_rate), which the
|
||||
* local service does not send.
|
||||
*/
|
||||
import { numberField } from './blk-fields.ts';
|
||||
import type { Dataset } from './dataset.ts';
|
||||
|
||||
export const researchPointsPerGoldenEagle: Dataset<number> = {
|
||||
id: 'research-point-rate',
|
||||
version: 1,
|
||||
extract: (source) => numberField(source.readBlk('char.vromfs.bin', 'config/warpoints.blk'), 'playerExpToCountryFor1Gold') ?? 1,
|
||||
};
|
||||
@@ -0,0 +1,96 @@
|
||||
/**
|
||||
* Dataset: every vehicle's research and purchase facts.
|
||||
*
|
||||
* The client takes a vehicle's economy from char.vromfs.bin config/wpcost.blk (gui.vromfs.bin
|
||||
* scripts/unit/unit.nut initOnce; the native status function reads the same file,
|
||||
* implementation notes): one block per vehicle with
|
||||
* country:t the country whose tech tree and ranks it belongs to
|
||||
* unitClass:t exp_fighter, exp_tank, ... (the vehicle type, implementation notes)
|
||||
* rank:i
|
||||
* reqAir:t the vehicle that has to be researched before it
|
||||
* reqExp:i research points needed
|
||||
* value:i price in silver lions
|
||||
* costGold:i price in golden eagles
|
||||
* premPackAir:b, gift:t, event:t, researchType:t premium, gift, event and squadron vehicles
|
||||
* config/shop.blk places vehicles in the tech tree (country -> branch -> column -> vehicle,
|
||||
* grouped vehicles one level deeper) and adds per-vehicle entries that matter here:
|
||||
* reqUnlock:t an unlock from config/unlocks.blk the player must have earned first
|
||||
* slaveUnit:t the separate part of a split vehicle (a launcher), which comes with it
|
||||
* showOnlyWhenBought:b the stock UI only shows it to players who own it (kept by the build,
|
||||
* packages/build reveal-hidden-vehicles.ts)
|
||||
*
|
||||
* Only what the files say is recorded; what it means for research is the rules layer's
|
||||
* (research/tech-tree.ts).
|
||||
*/
|
||||
import type { BlkBlock } from '@wto/blk';
|
||||
import { boolField, numberField, stringField } from './blk-fields.ts';
|
||||
import type { Dataset } from './dataset.ts';
|
||||
|
||||
const VEHICLE_ECONOMY = 'config/wpcost.blk';
|
||||
const SHOP = 'config/shop.blk';
|
||||
|
||||
export interface CatalogueVehicle {
|
||||
readonly name: string;
|
||||
readonly country: string;
|
||||
readonly unitClass: string;
|
||||
readonly rank: number;
|
||||
/** wpcost.blk reqAir; absent when empty or missing. */
|
||||
readonly requires?: string;
|
||||
/** wpcost.blk reqExp; 0 when missing. */
|
||||
readonly researchPoints: number;
|
||||
readonly silverLions: number;
|
||||
readonly goldenEagles: number;
|
||||
readonly premiumPack: boolean;
|
||||
readonly gift: boolean;
|
||||
readonly event: boolean;
|
||||
readonly researchType?: string;
|
||||
/** Listed in config/shop.blk. */
|
||||
readonly inTechTree: boolean;
|
||||
/** shop.blk reqUnlock. */
|
||||
readonly requiredUnlock?: string;
|
||||
/** shop.blk slaveUnit, repeated. */
|
||||
readonly parts: readonly string[];
|
||||
/** shop.blk showOnlyWhenBought. */
|
||||
readonly onlyShownWhenOwned: boolean;
|
||||
}
|
||||
|
||||
export const vehicleCatalogue: Dataset<readonly CatalogueVehicle[]> = {
|
||||
id: 'vehicle-catalogue',
|
||||
version: 2,
|
||||
extract: (source) => {
|
||||
const shopEntries = new Map<string, BlkBlock>();
|
||||
for (const country of source.readBlk('char.vromfs.bin', SHOP).blocks) {
|
||||
for (const entry of entriesBelow(country)) if (!shopEntries.has(entry.name)) shopEntries.set(entry.name, entry);
|
||||
}
|
||||
return source.readBlk('char.vromfs.bin', VEHICLE_ECONOMY).blocks.map((vehicle) => catalogueVehicle(vehicle, shopEntries.get(vehicle.name)));
|
||||
},
|
||||
};
|
||||
|
||||
function catalogueVehicle(vehicle: BlkBlock, shopEntry: BlkBlock | undefined): CatalogueVehicle {
|
||||
const requires = stringField(vehicle, 'reqAir');
|
||||
const researchType = stringField(vehicle, 'researchType');
|
||||
const requiredUnlock = stringField(shopEntry, 'reqUnlock');
|
||||
return {
|
||||
name: vehicle.name,
|
||||
country: stringField(vehicle, 'country') ?? '',
|
||||
unitClass: stringField(vehicle, 'unitClass') ?? '',
|
||||
rank: numberField(vehicle, 'rank') ?? 0,
|
||||
...(requires ? { requires } : {}),
|
||||
researchPoints: numberField(vehicle, 'reqExp') ?? 0,
|
||||
silverLions: numberField(vehicle, 'value') ?? 0,
|
||||
goldenEagles: numberField(vehicle, 'costGold') ?? 0,
|
||||
premiumPack: boolField(vehicle, 'premPackAir') ?? false,
|
||||
gift: stringField(vehicle, 'gift') !== undefined,
|
||||
event: stringField(vehicle, 'event') !== undefined,
|
||||
...(researchType ? { researchType } : {}),
|
||||
inTechTree: shopEntry !== undefined,
|
||||
...(requiredUnlock ? { requiredUnlock } : {}),
|
||||
parts: shopEntry ? shopEntry.params.flatMap((param) => (param.name === 'slaveUnit' && param.value.type === 'string' && param.value.value ? [param.value.value] : [])) : [],
|
||||
onlyShownWhenOwned: boolField(shopEntry, 'showOnlyWhenBought') ?? false,
|
||||
};
|
||||
}
|
||||
|
||||
/** Every block below a country: branches, columns, groups and vehicles (non-vehicles have no wpcost entry and are never looked up). */
|
||||
function entriesBelow(block: BlkBlock): BlkBlock[] {
|
||||
return block.blocks.flatMap((child) => [child, ...entriesBelow(child)]);
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
/**
|
||||
* Dataset: the unlocks that vehicles depend on, with their conditions.
|
||||
*
|
||||
* char.vromfs.bin config/unlocks.blk: unlockable{ id:t type:t mode{ type:t ... } }. The
|
||||
* conditions of type char_* are checked by the char server, which then records the unlock in
|
||||
* the profile. Taken here: the unlocks config/shop.blk names as a vehicle's reqUnlock, every
|
||||
* unlock of type "aircraft" (earning one gives the vehicle of the same name), and every
|
||||
* unlock those name in their conditions, transitively (2.61.0.37: 73 roots, 131 in all).
|
||||
*
|
||||
* Mode parameters kept, as written:
|
||||
* char_unlocks num:i, unlock:t (repeated)
|
||||
* char_aircrafts_in_era country:t, era:i, num:i, unitClass:t (repeated), rankExactly:b,
|
||||
* premium:b, clanUnits:b
|
||||
* char_player_era country:t, era:i, unitClass:t
|
||||
* A mode with condition{} sub-blocks is marked: those conditions (first battle, login time
|
||||
* ...) belong to other features.
|
||||
*/
|
||||
import type { BlkBlock } from '@wto/blk';
|
||||
import { boolField, numberField, stringField, stringList } from './blk-fields.ts';
|
||||
import type { Dataset } from './dataset.ts';
|
||||
|
||||
const UNLOCKS = 'config/unlocks.blk';
|
||||
const SHOP = 'config/shop.blk';
|
||||
/** Unlocks of this type give the vehicle named by the unlock's id. */
|
||||
export const VEHICLE_UNLOCK_TYPE = 'aircraft';
|
||||
|
||||
export interface UnlockMode {
|
||||
readonly type: string;
|
||||
readonly num?: number;
|
||||
readonly unlocks: readonly string[];
|
||||
readonly country?: string;
|
||||
readonly era?: number;
|
||||
readonly unitClasses: readonly string[];
|
||||
readonly rankExactly?: boolean;
|
||||
readonly premium?: boolean;
|
||||
readonly clanUnits?: boolean;
|
||||
readonly hasOtherConditions: boolean;
|
||||
}
|
||||
|
||||
export interface UnlockDefinition {
|
||||
readonly id: string;
|
||||
readonly type: string;
|
||||
readonly modes: readonly UnlockMode[];
|
||||
}
|
||||
|
||||
export const vehicleUnlocks: Dataset<readonly UnlockDefinition[]> = {
|
||||
id: 'vehicle-unlocks',
|
||||
version: 1,
|
||||
extract: (source) => {
|
||||
const definitions = new Map<string, UnlockDefinition>();
|
||||
for (const block of source.readBlk('char.vromfs.bin', UNLOCKS).blocks) {
|
||||
if (block.name !== 'unlockable') continue;
|
||||
const id = stringField(block, 'id');
|
||||
if (id && !definitions.has(id)) definitions.set(id, unlockDefinition(id, block));
|
||||
}
|
||||
const roots = [
|
||||
...requiredUnlocks(source.readBlk('char.vromfs.bin', SHOP)),
|
||||
...[...definitions.values()].filter((definition) => definition.type === VEHICLE_UNLOCK_TYPE).map((definition) => definition.id),
|
||||
];
|
||||
const kept = new Map<string, UnlockDefinition>();
|
||||
const pending = [...roots];
|
||||
while (pending.length) {
|
||||
const definition = definitions.get(pending.pop()!);
|
||||
if (!definition || kept.has(definition.id)) continue;
|
||||
kept.set(definition.id, definition);
|
||||
for (const mode of definition.modes) pending.push(...mode.unlocks);
|
||||
}
|
||||
return [...kept.values()];
|
||||
},
|
||||
};
|
||||
|
||||
function unlockDefinition(id: string, block: BlkBlock): UnlockDefinition {
|
||||
return { id, type: stringField(block, 'type') ?? '', modes: block.blocks.filter((child) => child.name === 'mode').map(unlockMode) };
|
||||
}
|
||||
|
||||
function unlockMode(mode: BlkBlock): UnlockMode {
|
||||
const optional = {
|
||||
num: numberField(mode, 'num'),
|
||||
country: stringField(mode, 'country'),
|
||||
era: numberField(mode, 'era'),
|
||||
rankExactly: boolField(mode, 'rankExactly'),
|
||||
premium: boolField(mode, 'premium'),
|
||||
clanUnits: boolField(mode, 'clanUnits'),
|
||||
};
|
||||
return {
|
||||
type: stringField(mode, 'type') ?? '',
|
||||
unlocks: stringList(mode, 'unlock'),
|
||||
unitClasses: stringList(mode, 'unitClass'),
|
||||
hasOtherConditions: mode.blocks.some((child) => child.name === 'condition'),
|
||||
...Object.fromEntries(Object.entries(optional).filter(([, value]) => value !== undefined)),
|
||||
};
|
||||
}
|
||||
|
||||
function requiredUnlocks(shop: BlkBlock): string[] {
|
||||
const found: string[] = [];
|
||||
const walk = (block: BlkBlock): void => {
|
||||
const unlock = stringField(block, 'reqUnlock');
|
||||
if (unlock) found.push(unlock);
|
||||
block.blocks.forEach(walk);
|
||||
};
|
||||
shop.blocks.forEach(walk);
|
||||
return found;
|
||||
}
|
||||
Reference in new issue
Block a user