feat(battle): settle vehicle damage, repairs, and compensation
The local service now settles vehicle repair after a battle and charges hangar repairs at the price the client shows. - New dataset vehicle-repair (wpcost.blk repairCost<Mode>, repairCostPerMin<Mode>, modifications' repairCostCoef<Mode>) and RepairRules, which follow the client's own formulas: full cost = repairCost<Mode> x (1 + coefficients of the owned modifications) (aces.exe 2.61.0.37 0x10517b0, 0x964900); current cost = max(1, (1 - hp) x full cost) in the vehicle's lastGameMode (getAircraftRepairCost 0x90e0b0). - The price table now carries aircrafts/<vehicle>/repair/<mode>/cost, where the client looks the full repair cost up; it read 0 before. - After a battle each life costs the official lifetime share: destroyed = repairCostPerMin x minutes started, at most the full cost; leaving the vehicle (or the battle) early = full cost; surviving = nothing; destroyed by an ally = nothing. The cost is written as hp, lastGameMode and time on the hangar entry, so the client's own repair cost matches it. - Automatic repair (autoRepairAircrafts, on by default) pays for the damaged vehicles the player can afford; premium accounts with automatic repair and ammunition purchase get the expenses beyond the battle's earnings back. The battle log gets aircrafts hp, autoRepairWasOn, container.aircraftsRepaired and wpExpensesCompensation; the debriefing gets the ExpensesCompensation row. - cln_prepare_aircraft, cln_repair_all and cln_repair_all_in_slots carry no price; they now charge the current repair cost instead of repairing for free. Not yet verified in game.
This commit is contained in:
1 parent
15779e805d
commit
8e4d4b6ea3
14 files changed
+400
-44
No files matched your search
@@ -32,6 +32,12 @@ export function isAutoRefillWeaponsEnabled(profile: BlkBlock): boolean {
|
||||
return param?.type === 'bool' ? param.value : true;
|
||||
}
|
||||
|
||||
/** Whether vehicles are repaired automatically after a battle (`EconomicState` +0xe978); `true` when absent (0x90b6a0). */
|
||||
export function isAutoRepairEnabled(profile: BlkBlock): boolean {
|
||||
const param = findParam(profile, 'autoRepairAircrafts')?.value;
|
||||
return param?.type === 'bool' ? param.value : true;
|
||||
}
|
||||
|
||||
export function applyClientProfileUpdate(profile: BlkBlock, request: BlkBlock): void {
|
||||
for (const name of BOOL_SETTINGS) {
|
||||
const param = findParam(request, name)?.value;
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* A vehicle's damage in the profile: fields of its hangar entry (AircraftInfo::serialize,
|
||||
* aces.exe 2.61.0.37 0x940510):
|
||||
*
|
||||
* hangar{ <vehicle>{ hp:r time:i64 lastGameMode:i } }
|
||||
*
|
||||
* hp is the vehicle's condition (1 = intact, the default; 0x9406a2); time is stored with it
|
||||
* (here: when the damage happened, server time); lastGameMode is the mode the damage was taken
|
||||
* in, 1 arcade / 2 historical / 3 simulation (default 1, 0x9415b1), which picks the repair
|
||||
* cost (getAircraftRepairCost 0x90e0b0 reads it at AircraftInfo+0xcc).
|
||||
*/
|
||||
import { findBlock, findParam, setParam, type BlkBlock } from '@wto/blk';
|
||||
import { removeParam } from './blk-fields.ts';
|
||||
import type { ServerTime } from './server-time.ts';
|
||||
|
||||
const HANGAR = 'hangar';
|
||||
|
||||
export interface VehicleCondition {
|
||||
readonly hp: number;
|
||||
/** 1 arcade, 2 historical, 3 simulation. */
|
||||
readonly lastGameMode: number;
|
||||
}
|
||||
|
||||
export function vehicleCondition(profile: BlkBlock, vehicle: string): VehicleCondition | undefined {
|
||||
const entry = hangarEntry(profile, vehicle);
|
||||
if (!entry) return undefined;
|
||||
const hp = findParam(entry, 'hp')?.value;
|
||||
const mode = findParam(entry, 'lastGameMode')?.value;
|
||||
return {
|
||||
hp: hp?.type === 'real' ? Math.min(1, Math.max(0, hp.value)) : 1,
|
||||
lastGameMode: mode?.type === 'int' && mode.value >= 1 && mode.value <= 3 ? mode.value : 1,
|
||||
};
|
||||
}
|
||||
|
||||
export function isDamaged(profile: BlkBlock, vehicle: string): boolean {
|
||||
const condition = vehicleCondition(profile, vehicle);
|
||||
return condition !== undefined && condition.hp < 1;
|
||||
}
|
||||
|
||||
export function setVehicleDamage(profile: BlkBlock, vehicle: string, hp: number, lastGameMode: number, time: ServerTime): void {
|
||||
const entry = hangarEntry(profile, vehicle);
|
||||
if (!entry) return;
|
||||
setParam(entry, 'hp', { type: 'real', value: hp });
|
||||
setParam(entry, 'time', { type: 'int64', value: time });
|
||||
setParam(entry, 'lastGameMode', { type: 'int', value: lastGameMode });
|
||||
}
|
||||
|
||||
export function clearVehicleDamage(profile: BlkBlock, vehicle: string): void {
|
||||
const entry = hangarEntry(profile, vehicle);
|
||||
if (!entry) return;
|
||||
removeParam(entry, 'hp');
|
||||
removeParam(entry, 'time');
|
||||
}
|
||||
|
||||
function hangarEntry(profile: BlkBlock, vehicle: string): BlkBlock | undefined {
|
||||
const hangar = findBlock(profile, HANGAR);
|
||||
return hangar && findBlock(hangar, vehicle);
|
||||
}
|
||||
Reference in new issue
Block a user