feat(equipment): add modification, ammunition, and spare actions

Include modification, weapon, and spare vehicle prices, omitting zero
prices. Recalculate modification research and ranks and handle research
target selection, purchases, bulk purchases, and equipment toggles.
This commit is contained in:
N0VAN0M4LY committed 2026-11-24 21:43:35 +08:00
1 parent 9196dc2a4d
commit c448ed94a7
18 files changed
+742 -23

No files matched your search

@@ -0,0 +1,92 @@
/**
* Dataset: every vehicle's modifications, ammunition, weapon presets and spare, with their
* research and purchase facts.
*
* char.vromfs.bin config/wpcost.blk, per vehicle:
* needBuyToOpenNextInTier<N>:i researched modifications of tier N needed to open tier N+1
* modifications{ <name>{ tier:i reqExp:i value:i costGold:i openCostGold:i
* reqModification:t (repeated) maxCount:i ammoCount:i ... } }
* Ammunition and expendables are modifications too (tier 0, maxCount, ammoCount).
* weapons{ <preset>{ value:i costGold:i maxCount:i reqModification:t ... } }
* spare{ value:i costGold:i }
*
* Only what the file says is recorded; what it means is the rules layer's (modifications/).
*/
import type { BlkBlock } from '@wto/blk';
import { findBlock } from '@wto/blk';
import { numberField, stringList } from './blk-fields.ts';
import type { Dataset } from './dataset.ts';
const VEHICLE_ECONOMY = 'config/wpcost.blk';
/** wpcost.blk has needBuyToOpenNextInTier1..4; the modification tree has tiers 1..5 at most. */
const TIER_REQUIREMENT_COUNT = 4;
export interface ModificationFacts {
readonly name: string;
readonly tier: number;
/** reqExp; 0 when the modification is not researched (ammunition, expendables, premium). */
readonly researchPoints: number;
readonly silverLions: number;
readonly goldenEagles: number;
/** openCostGold: golden eagles to get it without the research (scaled by progress, implementation notes). */
readonly openGoldenEagles: number;
/** reqModification, repeated: modifications that must be bought first. */
readonly requires: readonly string[];
/** maxCount; 0 when the modification is not counted (bought once). */
readonly maxCount: number;
/** ammoCount present: an ammunition belt or shell type. */
readonly ammunition: boolean;
}
export interface PriceFacts {
readonly name: string;
readonly silverLions: number;
readonly goldenEagles: number;
}
export interface VehicleEquipment {
readonly vehicle: string;
/** needBuyToOpenNextInTier1..4 (index 0 = tier 1). */
readonly tierRequirements: readonly number[];
readonly modifications: readonly ModificationFacts[];
readonly weapons: readonly PriceFacts[];
/** spare; absent when the vehicle has no spare price. */
readonly spare?: { readonly silverLions: number; readonly goldenEagles: number };
}
export const vehicleEquipment: Dataset<readonly VehicleEquipment[]> = {
id: 'vehicle-equipment',
version: 1,
extract: (source) => source.readBlk('char.vromfs.bin', VEHICLE_ECONOMY).blocks.map(equipmentOf),
};
function equipmentOf(vehicle: BlkBlock): VehicleEquipment {
const tierRequirements: number[] = [];
for (let tier = 1; tier <= TIER_REQUIREMENT_COUNT; tier++) tierRequirements.push(numberField(vehicle, `needBuyToOpenNextInTier${tier}`) ?? 0);
const spare = findBlock(vehicle, 'spare');
return {
vehicle: vehicle.name,
tierRequirements,
modifications: (findBlock(vehicle, 'modifications')?.blocks ?? []).map(modificationOf),
weapons: (findBlock(vehicle, 'weapons')?.blocks ?? []).map(priceOf),
...(spare ? { spare: { silverLions: numberField(spare, 'value') ?? 0, goldenEagles: numberField(spare, 'costGold') ?? 0 } } : {}),
};
}
function modificationOf(modification: BlkBlock): ModificationFacts {
return {
name: modification.name,
tier: numberField(modification, 'tier') ?? 0,
researchPoints: numberField(modification, 'reqExp') ?? 0,
silverLions: numberField(modification, 'value') ?? 0,
goldenEagles: numberField(modification, 'costGold') ?? 0,
openGoldenEagles: numberField(modification, 'openCostGold') ?? 0,
requires: stringList(modification, 'reqModification'),
maxCount: numberField(modification, 'maxCount') ?? 0,
ammunition: numberField(modification, 'ammoCount') !== undefined,
};
}
function priceOf(entry: BlkBlock): PriceFacts {
return { name: entry.name, silverLions: numberField(entry, 'value') ?? 0, goldenEagles: numberField(entry, 'costGold') ?? 0 };
}