fix(modifications): grant custom-slot weapon containers and support unit weapons
This commit is contained in:
1 parent
62da2e3038
commit
388dc9d9d7
4 files changed
+97
-37
No files matched your search
@@ -54,6 +54,10 @@ export interface WeaponFacts {
|
||||
readonly requires: readonly string[];
|
||||
/** maxCount; 0 when the preset is not bought by the piece. */
|
||||
readonly maxCount: number;
|
||||
/** True for `isWeaponForCustomSlot` single-weapon containers referenced by `sum_weapons`. */
|
||||
readonly forCustomSlot?: boolean;
|
||||
/** `sum_weapons` container names referenced by a selectable preset. */
|
||||
readonly sumWeapons?: readonly string[];
|
||||
}
|
||||
|
||||
export interface VehicleEquipment {
|
||||
@@ -74,7 +78,7 @@ interface GlobalModificationMeta {
|
||||
|
||||
export const vehicleEquipment: Dataset<readonly VehicleEquipment[]> = {
|
||||
id: 'vehicle-equipment',
|
||||
version: 3,
|
||||
version: 4,
|
||||
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));
|
||||
@@ -141,14 +145,17 @@ function weaponsOf(weaponsBlock: BlkBlock | undefined): WeaponFacts[] {
|
||||
containerRequires.set(entry.name, stringList(entry, 'reqModification'));
|
||||
}
|
||||
}
|
||||
return weaponsBlock.blocks
|
||||
.filter((entry) => boolField(entry, 'isWeaponForCustomSlot') !== true)
|
||||
.map((entry) => weaponOf(entry, containerRequires));
|
||||
// Keep `isWeaponForCustomSlot` container blocks too: native `shop_is_weapon_purchased`
|
||||
// (aces.exe 0x15562f0 -> 0x913570) checks every `sum_weapons` container against `profile.weapons{}`.
|
||||
return weaponsBlock.blocks.map((entry) => weaponOf(entry, containerRequires));
|
||||
}
|
||||
|
||||
function weaponOf(entry: BlkBlock, containerRequires: ReadonlyMap<string, readonly string[]>): WeaponFacts {
|
||||
const forCustomSlot = boolField(entry, 'isWeaponForCustomSlot') === true;
|
||||
const requires = [...stringList(entry, 'reqModification')];
|
||||
const sumWeapons: string[] = [];
|
||||
for (const param of findBlock(entry, 'sum_weapons')?.params ?? []) {
|
||||
if (!sumWeapons.includes(param.name)) sumWeapons.push(param.name);
|
||||
for (const req of containerRequires.get(param.name) ?? []) {
|
||||
if (!requires.includes(req)) requires.push(req);
|
||||
}
|
||||
@@ -159,5 +166,7 @@ function weaponOf(entry: BlkBlock, containerRequires: ReadonlyMap<string, readon
|
||||
goldenEagles: numberField(entry, 'costGold') ?? 0,
|
||||
requires,
|
||||
maxCount: numberField(entry, 'maxCount') ?? 0,
|
||||
...(forCustomSlot ? { forCustomSlot: true } : {}),
|
||||
...(sumWeapons.length > 0 ? { sumWeapons } : {}),
|
||||
};
|
||||
}
|
||||
@@ -69,7 +69,7 @@ function grantUnlockedFreeWeapons(index: ProfileEquipmentIndex, vehicle: string,
|
||||
for (const weapon of weapons) {
|
||||
if (!isFreeWeapon(weapon) || index.weaponRecord(vehicle, weapon.name)) continue;
|
||||
if (!prerequisitesOwned(index, vehicle, weapon.requires)) continue;
|
||||
index.writeWeaponRecord(vehicle, weapon.name, { silverLionsSpent: 0, goldenEaglesSpent: 0, count: 1 });
|
||||
index.writeWeaponRecord(vehicle, weapon.name, { silverLionsSpent: 0, goldenEaglesSpent: 0, count: Math.max(1, weapon.maxCount) });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,9 +31,9 @@ export class EquipmentCatalogue {
|
||||
}
|
||||
}
|
||||
|
||||
/** Bought by the piece (bombs, rockets): has a price and a maxCount. */
|
||||
/** Bought by the piece (bombs, rockets): has a price and a maxCount, excluding custom-slot containers. */
|
||||
export function isPaidWeapon(weapon: WeaponFacts): boolean {
|
||||
return (weapon.silverLions > 0 || weapon.goldenEagles > 0) && weapon.maxCount > 0;
|
||||
return !weapon.forCustomSlot && (weapon.silverLions > 0 || weapon.goldenEagles > 0) && weapon.maxCount > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
/**
|
||||
* The modifications the mission support planes' forced presets need (gameplay.blk
|
||||
* missionSupportPlane <country>{ unitName weapon }, e.g. f_16a_block_15_adf_killstreak with
|
||||
* f_16a_block_15_adf_killstreak_b61_30kt_nt, whose bombguns_us_b61_30kt has reqModification
|
||||
* us_500lb_mk82 in wpcost.blk), kept in every profile as owned.
|
||||
* Modifications and weapon records required by unowned battle support units (nuclear carriers in
|
||||
* `gameplay.blk` `missionSupportPlane` and strike UCAVs `ucav_*_killstreak` in `wpcost.blk`).
|
||||
*
|
||||
* The respawn screen lists a preset only when shop_is_weapon_available passes (aces.exe 2.61.0.37
|
||||
* 0x17a38a0 -> 0x912d20 -> 0x90f2c0 / 0x9662f0): every reqModification of the preset and of the
|
||||
* weapons in its sum_weapons must be a bought modification of the unit in the profile; the unit's
|
||||
* killStreak flag adds a condition but does not lift this one. Without the records the support
|
||||
* plane's loadout box is empty. The player never owns these units, so online the server has to
|
||||
* provide the records (inferred; not observed).
|
||||
* The respawn screen lists a preset only when both `shop_is_weapon_available` (aces.exe 2.61.0.37
|
||||
* 0x17a38a0 -> 0x912d20 -> 0x90f2c0 / 0x9662f0) and `shop_is_weapon_purchased` (0x15562f0 ->
|
||||
* 0x913570) pass: every `reqModification` must exist in `profile.modifications{}`, and both the
|
||||
* preset and every `isWeaponForCustomSlot` container in its `sum_weapons` must exist in
|
||||
* `profile.weapons{}`. Because the player does not own these killstreak units in `hangar{}`,
|
||||
* the local server keeps their required modification and weapon records in every profile.
|
||||
*/
|
||||
import { ensureBlock, findBlock, type BlkBlock } from '@wto/blk';
|
||||
import type { BattleSpawnRulesData } from '../game-data/datasets/battle-spawn-rules.ts';
|
||||
@@ -21,36 +19,89 @@ export interface SupportPlaneModification {
|
||||
readonly modification: string;
|
||||
}
|
||||
|
||||
export interface SupportPlaneWeapon {
|
||||
readonly vehicle: string;
|
||||
readonly weapon: string;
|
||||
readonly count: number;
|
||||
}
|
||||
|
||||
export interface SupportUnitEquipmentGrants {
|
||||
readonly modifications: readonly SupportPlaneModification[];
|
||||
readonly weapons: readonly SupportPlaneWeapon[];
|
||||
}
|
||||
|
||||
export function supportPlaneModifications(
|
||||
rules: Pick<BattleSpawnRulesData, 'supportPlanes'>,
|
||||
rules: Pick<BattleSpawnRulesData, 'supportPlanes' | 'strikeUcavs'>,
|
||||
catalogue: EquipmentCatalogue,
|
||||
): readonly SupportPlaneModification[] {
|
||||
const seen = new Set<string>();
|
||||
const out: SupportPlaneModification[] = [];
|
||||
): SupportUnitEquipmentGrants {
|
||||
const seenMods = new Set<string>();
|
||||
const seenWeapons = new Set<string>();
|
||||
const modifications: SupportPlaneModification[] = [];
|
||||
const weapons: SupportPlaneWeapon[] = [];
|
||||
|
||||
const addMod = (vehicle: string, modification: string): void => {
|
||||
const key = `${vehicle}/${modification}`;
|
||||
if (seenMods.has(key)) return;
|
||||
seenMods.add(key);
|
||||
modifications.push({ vehicle, modification });
|
||||
};
|
||||
|
||||
const addWeapon = (vehicle: string, weapon: string, count: number): void => {
|
||||
const key = `${vehicle}/${weapon}`;
|
||||
if (seenWeapons.has(key)) return;
|
||||
seenWeapons.add(key);
|
||||
weapons.push({ vehicle, weapon, count: Math.max(1, count) });
|
||||
};
|
||||
|
||||
for (const presets of Object.values(rules.supportPlanes)) {
|
||||
for (const preset of presets) {
|
||||
for (const { unitName, weapon } of Object.values(preset.units)) {
|
||||
for (const modification of catalogue.weapon(unitName, weapon)?.requires ?? []) {
|
||||
const key = `${unitName}/${modification}`;
|
||||
if (seen.has(key)) continue;
|
||||
seen.add(key);
|
||||
out.push({ vehicle: unitName, modification });
|
||||
const facts = catalogue.weapon(unitName, weapon);
|
||||
addWeapon(unitName, weapon, facts?.maxCount ?? 1);
|
||||
for (const modification of facts?.requires ?? []) addMod(unitName, modification);
|
||||
for (const container of facts?.sumWeapons ?? []) {
|
||||
const containerFacts = catalogue.weapon(unitName, container);
|
||||
addWeapon(unitName, container, containerFacts?.maxCount ?? 1);
|
||||
for (const modification of containerFacts?.requires ?? []) addMod(unitName, modification);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
|
||||
for (const ucav of rules.strikeUcavs) {
|
||||
const vehicle = catalogue.vehicle(ucav.unitName);
|
||||
if (!vehicle) continue;
|
||||
for (const weapon of vehicle.weapons) {
|
||||
addWeapon(ucav.unitName, weapon.name, weapon.maxCount);
|
||||
for (const modification of weapon.requires) addMod(ucav.unitName, modification);
|
||||
}
|
||||
}
|
||||
|
||||
return { modifications, weapons };
|
||||
}
|
||||
|
||||
export function grantSupportPlaneModifications(profile: BlkBlock, grants: readonly SupportPlaneModification[]): void {
|
||||
if (grants.length === 0) return;
|
||||
let modsBlock = findBlock(profile, 'modifications');
|
||||
const existing = new Set((modsBlock?.blocks ?? []).map((entry) => entry.name));
|
||||
for (const { vehicle, modification } of grants) {
|
||||
const key = recordName(vehicle, modification);
|
||||
if (existing.has(key)) continue;
|
||||
modsBlock ??= ensureBlock(profile, 'modifications');
|
||||
modsBlock.blocks.push({ name: key, params: [{ name: 'count', value: { type: 'int64', value: 1n } }], blocks: [] });
|
||||
existing.add(key);
|
||||
export function grantSupportPlaneModifications(profile: BlkBlock, grants: SupportUnitEquipmentGrants): void {
|
||||
if (grants.modifications.length > 0) {
|
||||
let modsBlock = findBlock(profile, 'modifications');
|
||||
const existing = new Set((modsBlock?.blocks ?? []).map((entry) => entry.name));
|
||||
for (const { vehicle, modification } of grants.modifications) {
|
||||
const key = recordName(vehicle, modification);
|
||||
if (existing.has(key)) continue;
|
||||
modsBlock ??= ensureBlock(profile, 'modifications');
|
||||
modsBlock.blocks.push({ name: key, params: [{ name: 'count', value: { type: 'int64', value: 1n } }], blocks: [] });
|
||||
existing.add(key);
|
||||
}
|
||||
}
|
||||
|
||||
if (grants.weapons.length > 0) {
|
||||
let weaponsBlock = findBlock(profile, 'weapons');
|
||||
const existing = new Set((weaponsBlock?.blocks ?? []).map((entry) => entry.name));
|
||||
for (const { vehicle, weapon, count } of grants.weapons) {
|
||||
const key = `${vehicle}_${weapon}`;
|
||||
if (existing.has(key)) continue;
|
||||
weaponsBlock ??= ensureBlock(profile, 'weapons');
|
||||
weaponsBlock.blocks.push({ name: key, params: [{ name: 'count', value: { type: 'int64', value: BigInt(count) } }], blocks: [] });
|
||||
existing.add(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user