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:
1 parent
9196dc2a4d
commit
c448ed94a7
18 files changed
+742
-23
No files matched your search
@@ -0,0 +1,71 @@
|
||||
/**
|
||||
* Bought modifications in the profile:
|
||||
*
|
||||
* modifications{
|
||||
* us_m22_locust_tank_tool_kit{ count:i64=1 }
|
||||
* us_m22_locust_37mm_usa_m3_APC{ wpSpent:i=450 count:i64=150 }
|
||||
* us_m22_locust_new_tank_tracks{ enabled:b=no count:i64=1 }
|
||||
* }
|
||||
*
|
||||
* One block per bought modification, named <vehicle>_<modification>; having a block means the
|
||||
* modification is owned. The client reads a block's params strictly in this order and stops at
|
||||
* the first one that does not match (aces.exe 0x942740), so a record is always rewritten whole:
|
||||
* wpSpent:i goldSpent:i lastWpCost:i lastGoldCost:i persist:b rpEarned:i enabled:b count:i64 modLevel:i
|
||||
* Absent values are left out; enabled is only written when false (the default is enabled).
|
||||
*/
|
||||
import { ensureBlock, findBlock, type BlkBlock, type BlkParam } from '@wto/blk';
|
||||
|
||||
const MODIFICATIONS = 'modifications';
|
||||
|
||||
export interface ModificationRecord {
|
||||
readonly silverLionsSpent: number;
|
||||
readonly goldenEaglesSpent: number;
|
||||
readonly enabled: boolean;
|
||||
/** How many the player has: 1 for a plain modification, the number of rounds or uses for counted ones. */
|
||||
readonly count: number;
|
||||
}
|
||||
|
||||
export function recordName(vehicle: string, modification: string): string {
|
||||
return `${vehicle}_${modification}`;
|
||||
}
|
||||
|
||||
export function modificationRecord(profile: BlkBlock, vehicle: string, modification: string): ModificationRecord | undefined {
|
||||
const block = findBlock(profile, MODIFICATIONS);
|
||||
const record = block && findBlock(block, recordName(vehicle, modification));
|
||||
if (!record) return undefined;
|
||||
return {
|
||||
silverLionsSpent: intOf(record, 'wpSpent'),
|
||||
goldenEaglesSpent: intOf(record, 'goldSpent'),
|
||||
enabled: boolOf(record, 'enabled') ?? true,
|
||||
count: intOf(record, 'count'),
|
||||
};
|
||||
}
|
||||
|
||||
export function ownsModification(profile: BlkBlock, vehicle: string, modification: string): boolean {
|
||||
return modificationRecord(profile, vehicle, modification) !== undefined;
|
||||
}
|
||||
|
||||
export function writeModificationRecord(profile: BlkBlock, vehicle: string, modification: string, record: ModificationRecord): void {
|
||||
const block = ensureBlock(ensureBlock(profile, MODIFICATIONS), recordName(vehicle, modification));
|
||||
block.params = orderedParams(record);
|
||||
}
|
||||
|
||||
function orderedParams(record: ModificationRecord): BlkParam[] {
|
||||
const params: BlkParam[] = [];
|
||||
if (record.silverLionsSpent) params.push({ name: 'wpSpent', value: { type: 'int', value: record.silverLionsSpent } });
|
||||
if (record.goldenEaglesSpent) params.push({ name: 'goldSpent', value: { type: 'int', value: record.goldenEaglesSpent } });
|
||||
if (!record.enabled) params.push({ name: 'enabled', value: { type: 'bool', value: false } });
|
||||
if (record.count) params.push({ name: 'count', value: { type: 'int64', value: BigInt(record.count) } });
|
||||
return params;
|
||||
}
|
||||
|
||||
function intOf(block: BlkBlock, name: string): number {
|
||||
const value = block.params.find((param) => param.name === name)?.value;
|
||||
if (value?.type === 'int64') return Number(value.value);
|
||||
return value?.type === 'int' ? value.value : 0;
|
||||
}
|
||||
|
||||
function boolOf(block: BlkBlock, name: string): boolean | undefined {
|
||||
const value = block.params.find((param) => param.name === name)?.value;
|
||||
return value?.type === 'bool' ? value.value : undefined;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* Modification research in the profile:
|
||||
*
|
||||
* modsResearch{ us_m22_locust_new_tank_tracks{ unitStatus:i=2 exp:i64=120 } }
|
||||
*
|
||||
* One block per modification of an owned vehicle that is not bought yet, named
|
||||
* <vehicle>_<modification>; each block has the layout of a unitResearch entry (the client reads
|
||||
* both with aces.exe 0x943990): unitStatus is the status the server works out,
|
||||
* exp the research points already put into it.
|
||||
*/
|
||||
import { ensureBlock, findBlock, findParam, setParam, type BlkBlock } from '@wto/blk';
|
||||
import { recordName } from './profile-modifications.ts';
|
||||
|
||||
const MODS_RESEARCH = 'modsResearch';
|
||||
const STATUS = 'unitStatus';
|
||||
const RESEARCH_POINTS = 'exp';
|
||||
|
||||
export function moduleResearchPoints(profile: BlkBlock, vehicle: string, modification: string): number {
|
||||
const entry = entryOf(profile, vehicle, modification);
|
||||
const value = entry && findParam(entry, RESEARCH_POINTS)?.value;
|
||||
if (value?.type === 'int64') return Number(value.value);
|
||||
return value?.type === 'int' ? value.value : 0;
|
||||
}
|
||||
|
||||
export function setModuleResearchPoints(profile: BlkBlock, vehicle: string, modification: string, amount: number): void {
|
||||
setParam(ensureEntry(profile, vehicle, modification), RESEARCH_POINTS, { type: 'int64', value: BigInt(amount) });
|
||||
}
|
||||
|
||||
export function setModuleStatus(profile: BlkBlock, vehicle: string, modification: string, status: number): void {
|
||||
setParam(ensureEntry(profile, vehicle, modification), STATUS, { type: 'int', value: status });
|
||||
}
|
||||
|
||||
export function removeModuleResearch(profile: BlkBlock, vehicle: string, modification: string): void {
|
||||
const block = findBlock(profile, MODS_RESEARCH);
|
||||
const name = recordName(vehicle, modification);
|
||||
if (block) block.blocks = block.blocks.filter((entry) => entry.name !== name);
|
||||
}
|
||||
|
||||
function entryOf(profile: BlkBlock, vehicle: string, modification: string): BlkBlock | undefined {
|
||||
const block = findBlock(profile, MODS_RESEARCH);
|
||||
return block && findBlock(block, recordName(vehicle, modification));
|
||||
}
|
||||
|
||||
function ensureEntry(profile: BlkBlock, vehicle: string, modification: string): BlkBlock {
|
||||
return ensureBlock(ensureBlock(profile, MODS_RESEARCH), recordName(vehicle, modification));
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* Per-vehicle fields of owned vehicles: hangar{ <vehicle>{ ... } },
|
||||
* read by name by AircraftInfo::serialize (aces.exe 0x940510). Only the fields the local
|
||||
* service maintains are handled here:
|
||||
* investMode:t the modification being researched (empty = none)
|
||||
* tierNumber:i the highest open modification tier (script is_tier_available)
|
||||
* spareAircraftsCount:i spares the player has for this vehicle
|
||||
*/
|
||||
import { findBlock, findParam, setParam, type BlkBlock } from '@wto/blk';
|
||||
|
||||
const HANGAR = 'hangar';
|
||||
const RESEARCH_TARGET = 'investMode';
|
||||
const OPEN_TIER = 'tierNumber';
|
||||
const SPARES = 'spareAircraftsCount';
|
||||
|
||||
export function moduleResearchTarget(profile: BlkBlock, vehicle: string): string {
|
||||
const value = fieldOf(profile, vehicle, RESEARCH_TARGET);
|
||||
return value?.type === 'string' ? value.value : '';
|
||||
}
|
||||
|
||||
export function setModuleResearchTarget(profile: BlkBlock, vehicle: string, modification: string): void {
|
||||
const entry = vehicleEntry(profile, vehicle);
|
||||
if (entry) setParam(entry, RESEARCH_TARGET, { type: 'string', value: modification });
|
||||
}
|
||||
|
||||
export function setOpenTier(profile: BlkBlock, vehicle: string, tier: number): void {
|
||||
const entry = vehicleEntry(profile, vehicle);
|
||||
if (entry) setParam(entry, OPEN_TIER, { type: 'int', value: tier });
|
||||
}
|
||||
|
||||
export function spareCount(profile: BlkBlock, vehicle: string): number {
|
||||
const value = fieldOf(profile, vehicle, SPARES);
|
||||
return value?.type === 'int' ? value.value : 0;
|
||||
}
|
||||
|
||||
export function setSpareCount(profile: BlkBlock, vehicle: string, count: number): void {
|
||||
const entry = vehicleEntry(profile, vehicle);
|
||||
if (entry) setParam(entry, SPARES, { type: 'int', value: count });
|
||||
}
|
||||
|
||||
function fieldOf(profile: BlkBlock, vehicle: string, name: string) {
|
||||
const entry = vehicleEntry(profile, vehicle);
|
||||
return entry && findParam(entry, name)?.value;
|
||||
}
|
||||
|
||||
function vehicleEntry(profile: BlkBlock, vehicle: string): BlkBlock | undefined {
|
||||
const hangar = findBlock(profile, HANGAR);
|
||||
return hangar && findBlock(hangar, vehicle);
|
||||
}
|
||||
Reference in new issue
Block a user