feat(equipment): stock newly unlocked ammunition and consumables
Extract weapon prerequisites, default equipment states, and exclusive groups. Grant eligible zero-cost modifications in dependency order and initialize newly unlocked consumables and weapon presets at capacity. When automatic restocking is enabled, replenish existing stock subject to the Silver Lions balance. Enforce purchase prerequisites and exclusive equipment groups. Type checking, patch checks, and local data extraction and restocking checks passed. In-game acceptance is pending.
This commit is contained in:
1 parent
943d395748
commit
71ba962e75
10 files changed
+268
-49
No files matched your search
@@ -16,10 +16,11 @@
|
||||
*/
|
||||
import type { BlkBlock } from '@wto/blk';
|
||||
import { findBlock } from '@wto/blk';
|
||||
import { numberField, stringList } from './blk-fields.ts';
|
||||
import { boolField, numberField, stringField, stringList } from './blk-fields.ts';
|
||||
import type { Dataset } from './dataset.ts';
|
||||
|
||||
const VEHICLE_ECONOMY = 'config/wpcost.blk';
|
||||
const MODIFICATIONS_CONFIG = 'config/modifications.blk';
|
||||
/** wpcost.blk has needBuyToOpenNextInTier1..4; the modification tree has tiers 1..5 at most. */
|
||||
const TIER_REQUIREMENT_COUNT = 4;
|
||||
|
||||
@@ -38,6 +39,10 @@ export interface ModificationFacts {
|
||||
readonly maxCount: number;
|
||||
/** ammoCount present: an ammunition belt or shell type. */
|
||||
readonly ammunition: boolean;
|
||||
/** Initial enabled state when acquired (`turn_it_off` / `isEnabledByDefaultForAddMrank`). */
|
||||
readonly defaultEnabled: boolean;
|
||||
/** Non-bullet `group` name when modifications in the same group are mutually exclusive. */
|
||||
readonly exclusiveGroup?: string;
|
||||
}
|
||||
|
||||
export interface WeaponFacts {
|
||||
@@ -45,6 +50,8 @@ export interface WeaponFacts {
|
||||
/** value: silver lions per piece. */
|
||||
readonly silverLions: number;
|
||||
readonly goldenEagles: number;
|
||||
/** reqModification (direct + inherited from `sum_weapons` containers, initUnitWeapons.nut). */
|
||||
readonly requires: readonly string[];
|
||||
/** maxCount; 0 when the preset is not bought by the piece. */
|
||||
readonly maxCount: number;
|
||||
}
|
||||
@@ -59,26 +66,58 @@ export interface VehicleEquipment {
|
||||
readonly spare?: { readonly silverLions: number; readonly goldenEagles: number };
|
||||
}
|
||||
|
||||
interface GlobalModificationMeta {
|
||||
readonly turnOffByDefault: boolean;
|
||||
readonly bulletGroup: boolean;
|
||||
readonly group?: string;
|
||||
}
|
||||
|
||||
export const vehicleEquipment: Dataset<readonly VehicleEquipment[]> = {
|
||||
id: 'vehicle-equipment',
|
||||
version: 2,
|
||||
extract: (source) => source.readBlk('char.vromfs.bin', VEHICLE_ECONOMY).blocks.map(equipmentOf),
|
||||
version: 3,
|
||||
extract: (source) => {
|
||||
const modMeta = readGlobalModificationMeta(source.readBlk('char.vromfs.bin', MODIFICATIONS_CONFIG));
|
||||
return source.readBlk('char.vromfs.bin', VEHICLE_ECONOMY).blocks.map((vehicle) => equipmentOf(vehicle, modMeta));
|
||||
},
|
||||
};
|
||||
|
||||
function equipmentOf(vehicle: BlkBlock): VehicleEquipment {
|
||||
function readGlobalModificationMeta(configRoot: BlkBlock): ReadonlyMap<string, GlobalModificationMeta> {
|
||||
const modsBlock = findBlock(configRoot, 'modifications');
|
||||
const map = new Map<string, GlobalModificationMeta>();
|
||||
for (const entry of modsBlock?.blocks ?? []) {
|
||||
const effects = findBlock(entry, 'effects');
|
||||
const bulletGroup = Boolean(
|
||||
effects?.params.some((p) => p.name === 'bulletMod' || p.name === 'additiveBulletMod')
|
||||
|| effects?.blocks.some((b) => b.name === 'bulletMod' || b.name === 'additiveBulletMod'),
|
||||
);
|
||||
const group = stringField(entry, 'group');
|
||||
map.set(entry.name, {
|
||||
turnOffByDefault: boolField(entry, 'turn_it_off') === true,
|
||||
bulletGroup,
|
||||
...(group !== undefined ? { group } : {}),
|
||||
});
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
function equipmentOf(vehicle: BlkBlock, modMeta: ReadonlyMap<string, GlobalModificationMeta>): 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(weaponOf),
|
||||
modifications: (findBlock(vehicle, 'modifications')?.blocks ?? []).map((mod) => modificationOf(mod, modMeta.get(mod.name))),
|
||||
weapons: weaponsOf(findBlock(vehicle, 'weapons')),
|
||||
...(spare ? { spare: { silverLions: numberField(spare, 'value') ?? 0, goldenEagles: numberField(spare, 'costGold') ?? 0 } } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
function modificationOf(modification: BlkBlock): ModificationFacts {
|
||||
function modificationOf(modification: BlkBlock, meta: GlobalModificationMeta | undefined): ModificationFacts {
|
||||
const ammunition = numberField(modification, 'ammoCount') !== undefined;
|
||||
const defaultEnabled = !(meta?.turnOffByDefault ?? false) && (boolField(modification, 'isEnabledByDefaultForAddMrank') ?? true);
|
||||
const group = stringField(modification, 'group') ?? meta?.group;
|
||||
const exclusiveGroup = !ammunition && !(meta?.bulletGroup ?? false) ? group : undefined;
|
||||
return {
|
||||
name: modification.name,
|
||||
tier: numberField(modification, 'tier') ?? 0,
|
||||
@@ -88,15 +127,37 @@ function modificationOf(modification: BlkBlock): ModificationFacts {
|
||||
openGoldenEagles: numberField(modification, 'openCostGold') ?? 0,
|
||||
requires: stringList(modification, 'reqModification'),
|
||||
maxCount: numberField(modification, 'maxCount') ?? 0,
|
||||
ammunition: numberField(modification, 'ammoCount') !== undefined,
|
||||
ammunition,
|
||||
defaultEnabled,
|
||||
...(exclusiveGroup !== undefined ? { exclusiveGroup } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
function weaponOf(entry: BlkBlock): WeaponFacts {
|
||||
function weaponsOf(weaponsBlock: BlkBlock | undefined): WeaponFacts[] {
|
||||
if (!weaponsBlock) return [];
|
||||
const containerRequires = new Map<string, readonly string[]>();
|
||||
for (const entry of weaponsBlock.blocks) {
|
||||
if (boolField(entry, 'isWeaponForCustomSlot') === true) {
|
||||
containerRequires.set(entry.name, stringList(entry, 'reqModification'));
|
||||
}
|
||||
}
|
||||
return weaponsBlock.blocks
|
||||
.filter((entry) => boolField(entry, 'isWeaponForCustomSlot') !== true)
|
||||
.map((entry) => weaponOf(entry, containerRequires));
|
||||
}
|
||||
|
||||
function weaponOf(entry: BlkBlock, containerRequires: ReadonlyMap<string, readonly string[]>): WeaponFacts {
|
||||
const requires = [...stringList(entry, 'reqModification')];
|
||||
for (const param of findBlock(entry, 'sum_weapons')?.params ?? []) {
|
||||
for (const req of containerRequires.get(param.name) ?? []) {
|
||||
if (!requires.includes(req)) requires.push(req);
|
||||
}
|
||||
}
|
||||
return {
|
||||
name: entry.name,
|
||||
silverLions: numberField(entry, 'value') ?? 0,
|
||||
goldenEagles: numberField(entry, 'costGold') ?? 0,
|
||||
requires,
|
||||
maxCount: numberField(entry, 'maxCount') ?? 0,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user