feat(equipment): repair damaged vehicles for free over time
The client never raises a vehicle's hp by itself; the hangar shows (1 - hp) x the full repair time as what is left (shop_time_until_repair, aces.exe 2.61.0.37 0x17a5040). The local service now restores hp whenever it hands out or changes a profile: hp grows by the hours since it was last set over the full repair time, and the damage is cleared at 1. The full repair time follows the client (0x937330): repairTimeHrs<Mode> times the repair cost's modification factor (0x964750 -> 0x964900) times a crew multiplier when a crew has the vehicle as its current one, else repairTimeHrsNoCrew<Mode> (or repairTimeHrs x rTimeNoCrewMul, 0x964e30). The crew multiplier runs from 1 to 1/3 (hangarRepairSpeed default, 0x95cee0) over the groundService/repair level plus the specialization share of specialization<k>_add (0x95d200), and applies only when repair_ranks covers the vehicle's rank for the crew's repairRank level (0x95d7b0). The vehicle-repair dataset gains the repair times, rTimeNoCrewMul and these crew skill values; RepairRules is built with the profiles so the refresh can use it. Inferred: the skill fields the client divides are level and maximum level, the rank compared is the tech tree rank, linear growth at the current crew's pace. Checked: typecheck; full repair times for us_m1a1_abrams from the game data (no crew 678 h, untrained 171 h, maxed ace 57 h) and the hp growth over time.
This commit is contained in:
1 parent
2a89070f3e
commit
fa7c9071b7
6 files changed
+241
-34
No files matched your search
@@ -1,17 +1,24 @@
|
||||
/**
|
||||
* Dataset: what repairing each vehicle costs, char.vromfs.bin config/wpcost.blk:
|
||||
* Dataset: what repairing each vehicle costs and how long a free repair takes.
|
||||
*
|
||||
* <vehicle>{
|
||||
* repairCost<Mode>:i full repair cost (Mode = Arcade, Historical, Simulation)
|
||||
* repairCostPerMin<Mode>:i repair cost per minute of the vehicle's lifetime in a battle
|
||||
* modifications{ <mod>{ repairCostCoef:r repairCostCoef<Mode>:r } } added to the cost factor
|
||||
* }
|
||||
* char.vromfs.bin config/wpcost.blk, per vehicle:
|
||||
* repairCost<Mode>:i full repair cost (Mode = Arcade, Historical, Simulation)
|
||||
* repairCostPerMin<Mode>:i repair cost per minute of the vehicle's lifetime in a battle
|
||||
* repairTimeHrs<Mode>:r full repair time in hours with a crew
|
||||
* repairTimeHrsNoCrew<Mode>:r full repair time in hours when no crew has the vehicle
|
||||
* modifications{ <mod>{ repairCostCoef:r repairCostCoef<Mode>:r } } added to the cost factor
|
||||
* char.vromfs.bin config/warpoints.blk: rTimeNoCrewMul:r (no-crew time = repairTimeHrs x it when
|
||||
* repairTimeHrsNoCrew<Mode> is missing).
|
||||
* char.vromfs.bin config/crew_skills.blk: the crew's groundService skills that shorten the repair:
|
||||
* crew_skills{ groundService{ repair{ use_specializations:b skill_level_exp{ level1..levelN } } } }
|
||||
* specialization<k>_add:r (k = 1..4), repair_ranks{ rank<level>:i }.
|
||||
*
|
||||
* The client reads the same fields: the full cost from the price table (cln_get_price_ex,
|
||||
* aircrafts/<vehicle>/repair/<mode>/cost, aces.exe 2.61.0.37 0x10517b0), times 1 + the
|
||||
* repairCostCoef<Mode> (else repairCostCoef) of each modification the player has (0x964900).
|
||||
* repairCostCoef<Mode> (else repairCostCoef) of each modification the player has (0x964900); the
|
||||
* repair time in 0x937330 (repair/repair-rules.ts fullRepairHours).
|
||||
*/
|
||||
import type { BlkBlock } from '@wto/blk';
|
||||
import { findBlock, type BlkBlock } from '@wto/blk';
|
||||
import { blockAt, numberField } from './blk-fields.ts';
|
||||
import type { Dataset } from './dataset.ts';
|
||||
|
||||
@@ -23,26 +30,86 @@ export interface VehicleRepair {
|
||||
readonly name: string;
|
||||
readonly cost: PerRepairMode;
|
||||
readonly costPerMin: PerRepairMode;
|
||||
/** Hours; 0 when the data has none. */
|
||||
readonly timeHours: PerRepairMode;
|
||||
/** Hours; -1 when the data has none (the client's default, 0x964e30). */
|
||||
readonly noCrewTimeHours: PerRepairMode;
|
||||
/** Modifications with a repair cost coefficient. */
|
||||
readonly modCoefs: Readonly<Record<string, PerRepairMode>>;
|
||||
}
|
||||
|
||||
export const vehicleRepair: Dataset<readonly VehicleRepair[]> = {
|
||||
/** The crew skills that shorten a repair (crew_skills.blk). */
|
||||
export interface CrewRepairSkill {
|
||||
/** Levels of groundService/repair (the length of its skill_level_exp). */
|
||||
readonly maxLevel: number;
|
||||
readonly usesSpecializations: boolean;
|
||||
/** specialization1_add .. specialization4_add (0 when missing). */
|
||||
readonly specializationAdds: readonly number[];
|
||||
/** repair_ranks: the highest vehicle rank a groundService/repairRank level covers, index = level - 1. */
|
||||
readonly ranksByQualification: readonly number[];
|
||||
/** groundService/repairRank min_skill_level. */
|
||||
readonly minQualification: number;
|
||||
}
|
||||
|
||||
export interface VehicleRepairData {
|
||||
readonly vehicles: readonly VehicleRepair[];
|
||||
readonly noCrewTimeMul: number;
|
||||
readonly crewSkill: CrewRepairSkill;
|
||||
}
|
||||
|
||||
const SPECIALIZATION_ADDS = 4;
|
||||
|
||||
export const vehicleRepair: Dataset<VehicleRepairData> = {
|
||||
id: 'vehicle-repair',
|
||||
version: 1,
|
||||
extract: (source) => source.readBlk('char.vromfs.bin', 'config/wpcost.blk').blocks.flatMap((vehicle): VehicleRepair[] => {
|
||||
const cost = perMode(vehicle, 'repairCost');
|
||||
if (REPAIR_MODES.every((mode) => cost[mode] <= 0)) return [];
|
||||
const modCoefs: Record<string, PerRepairMode> = {};
|
||||
for (const mod of blockAt(vehicle, 'modifications')?.blocks ?? []) {
|
||||
const base = numberField(mod, 'repairCostCoef');
|
||||
const coefs = Object.fromEntries(REPAIR_MODES.map((mode) => [mode, numberField(mod, `repairCostCoef${mode}`) ?? base ?? 0])) as Record<RepairMode, number>;
|
||||
if (REPAIR_MODES.some((mode) => coefs[mode] !== 0)) modCoefs[mod.name] = coefs;
|
||||
}
|
||||
return [{ name: vehicle.name, cost, costPerMin: perMode(vehicle, 'repairCostPerMin'), modCoefs }];
|
||||
}),
|
||||
version: 2,
|
||||
extract: (source) => {
|
||||
const vehicles = source.readBlk('char.vromfs.bin', 'config/wpcost.blk').blocks.flatMap((vehicle): VehicleRepair[] => {
|
||||
const cost = perMode(vehicle, 'repairCost', 0);
|
||||
if (REPAIR_MODES.every((mode) => cost[mode] <= 0)) return [];
|
||||
const modCoefs: Record<string, PerRepairMode> = {};
|
||||
for (const mod of blockAt(vehicle, 'modifications')?.blocks ?? []) {
|
||||
const base = numberField(mod, 'repairCostCoef');
|
||||
const coefs = Object.fromEntries(REPAIR_MODES.map((mode) => [mode, numberField(mod, `repairCostCoef${mode}`) ?? base ?? 0])) as Record<RepairMode, number>;
|
||||
if (REPAIR_MODES.some((mode) => coefs[mode] !== 0)) modCoefs[mod.name] = coefs;
|
||||
}
|
||||
return [{
|
||||
name: vehicle.name,
|
||||
cost,
|
||||
costPerMin: perMode(vehicle, 'repairCostPerMin', 0),
|
||||
timeHours: perMode(vehicle, 'repairTimeHrs', 0),
|
||||
noCrewTimeHours: perMode(vehicle, 'repairTimeHrsNoCrew', -1),
|
||||
modCoefs,
|
||||
}];
|
||||
});
|
||||
const warpoints = source.readBlk('char.vromfs.bin', 'config/warpoints.blk');
|
||||
return {
|
||||
vehicles,
|
||||
noCrewTimeMul: numberField(warpoints, 'rTimeNoCrewMul') ?? 1,
|
||||
crewSkill: crewRepairSkill(source.readBlk('char.vromfs.bin', 'config/crew_skills.blk')),
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
function perMode(vehicle: BlkBlock, prefix: string): PerRepairMode {
|
||||
return Object.fromEntries(REPAIR_MODES.map((mode) => [mode, Math.max(0, numberField(vehicle, `${prefix}${mode}`) ?? 0)])) as Record<RepairMode, number>;
|
||||
function crewRepairSkill(crewSkills: BlkBlock): CrewRepairSkill {
|
||||
const groundService = findBlock(findBlock(crewSkills, 'crew_skills') ?? crewSkills, 'groundService');
|
||||
const repair = groundService && findBlock(groundService, 'repair');
|
||||
const qualification = groundService && findBlock(groundService, 'repairRank');
|
||||
const levels = repair && findBlock(repair, 'skill_level_exp');
|
||||
const ranks = findBlock(crewSkills, 'repair_ranks');
|
||||
const ranksByQualification: number[] = [];
|
||||
for (let level = 1; ranks && numberField(ranks, `rank${level}`) !== undefined; level++) ranksByQualification.push(numberField(ranks, `rank${level}`)!);
|
||||
return {
|
||||
maxLevel: levels?.params.length ?? numberField(crewSkills, 'max_skill_level') ?? 0,
|
||||
usesSpecializations: repair?.params.some((param) => param.name === 'use_specializations' && param.value.type === 'bool' && param.value.value) ?? false,
|
||||
specializationAdds: Array.from({ length: SPECIALIZATION_ADDS }, (_, index) => numberField(crewSkills, `specialization${index + 1}_add`) ?? 0),
|
||||
ranksByQualification,
|
||||
minQualification: (qualification && numberField(qualification, 'min_skill_level')) ?? 0,
|
||||
};
|
||||
}
|
||||
|
||||
function perMode(vehicle: BlkBlock, prefix: string, missing: number): PerRepairMode {
|
||||
return Object.fromEntries(REPAIR_MODES.map((mode) => {
|
||||
const value = numberField(vehicle, `${prefix}${mode}`);
|
||||
return [mode, value === undefined ? missing : Math.max(0, value)];
|
||||
})) as Record<RepairMode, number>;
|
||||
}
|
||||
@@ -27,7 +27,6 @@ import { DatasetCache } from './game-data/datasets/dataset-cache.ts';
|
||||
import { decorCatalogue } from './game-data/datasets/decor-catalogue.ts';
|
||||
import { externalItemSources } from './game-data/datasets/external-item-sources.ts';
|
||||
import { itemCatalogue } from './game-data/datasets/item-catalogue.ts';
|
||||
import { vehicleRepair } from './game-data/datasets/vehicle-repair.ts';
|
||||
import { multiplayerMissions } from './game-data/datasets/multiplayer-missions.ts';
|
||||
import { shopCountries } from './game-data/datasets/shop-countries.ts';
|
||||
import { storeBundles } from './game-data/datasets/store-bundles.ts';
|
||||
@@ -43,7 +42,6 @@ import { InventoryCatalogue } from './inventory/itemdef-catalogue.ts';
|
||||
import { MarketplaceService } from './inventory/marketplace-service.ts';
|
||||
import { TrophyCatalogue } from './inventory/trophy-catalogue.ts';
|
||||
import { ItemCatalogue } from './items/item-catalogue.ts';
|
||||
import { RepairRules } from './repair/repair-rules.ts';
|
||||
import { LoginService } from './login/login-service.ts';
|
||||
import { matchingRequests } from './matching/matching-requests.ts';
|
||||
import type { MatchingService } from './matching/matching-service.ts';
|
||||
@@ -92,7 +90,7 @@ export async function startLocalService(options: LocalServiceOptions): Promise<R
|
||||
const efficiencyData = datasets.load(researchEfficiency);
|
||||
const streakDefinitions = datasets.load(battleStreaks);
|
||||
const labels = datasets.load(uiLabels);
|
||||
const { profiles, research, equipment } = setUpProfiles(options.dataFolder, gameFiles, datasets, tuning, { accounts, clans }, vehicles);
|
||||
const { profiles, research, equipment, repair } = setUpProfiles(options.dataFolder, gameFiles, datasets, tuning, { accounts, clans }, vehicles);
|
||||
const { clanEconomy: squadronEconomy, ...catalogues } = loadDomainCatalogues(datasets, tuning, vehicles, labels);
|
||||
const storeProducts = catalogues.store.allProducts();
|
||||
const artwork = new GameArtwork(options.gameFolder, {
|
||||
@@ -127,6 +125,7 @@ export async function startLocalService(options: LocalServiceOptions): Promise<R
|
||||
accounts,
|
||||
research,
|
||||
equipment,
|
||||
repair,
|
||||
...catalogues,
|
||||
clans: { store: clans, economy: squadronEconomy },
|
||||
cloudSettings,
|
||||
@@ -173,7 +172,6 @@ function loadDomainCatalogues(datasets: DatasetCache, tuning: Tuning, vehicles:
|
||||
decor: new DecorShop(datasets.load(decorCatalogue)),
|
||||
unlocks: new UnlockShop(datasets.load(unlockPrices)),
|
||||
items: new ItemCatalogue(classicItemDefs, tuning.limits.itemPiecesPerPurchase),
|
||||
repair: new RepairRules(datasets.load(vehicleRepair)),
|
||||
store: new StoreCatalogue(vehicles, datasets.load(storeBundles), localizedUnitNames, labels, tuning.store),
|
||||
inventory: new InventoryCatalogue(vehicles, localizedUnitNames, datasets.load(externalItemSources), classicItemDefs, tuning),
|
||||
trophies: new TrophyCatalogue(vehicles, classicItemDefs, tuning.trophies),
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
* 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
|
||||
* (here: when hp was last set, server time, which the free repair counts from:
|
||||
* repair/repair-over-time.ts; the client does not read it for the repair timer); 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).
|
||||
*/
|
||||
@@ -32,6 +33,17 @@ export function vehicleCondition(profile: BlkBlock, vehicle: string): VehicleCon
|
||||
};
|
||||
}
|
||||
|
||||
/** The damaged vehicles of the hangar. */
|
||||
export function damagedVehicles(profile: BlkBlock): string[] {
|
||||
return (findBlock(profile, HANGAR)?.blocks ?? []).map((entry) => entry.name).filter((vehicle) => isDamaged(profile, vehicle));
|
||||
}
|
||||
|
||||
/** When the vehicle's hp was last set; undefined when the entry has no time. */
|
||||
export function damageTime(profile: BlkBlock, vehicle: string): ServerTime | undefined {
|
||||
const time = hangarEntry(profile, vehicle) && findParam(hangarEntry(profile, vehicle)!, 'time')?.value;
|
||||
return time?.type === 'int64' ? time.value : undefined;
|
||||
}
|
||||
|
||||
export function isDamaged(profile: BlkBlock, vehicle: string): boolean {
|
||||
const condition = vehicleCondition(profile, vehicle);
|
||||
return condition !== undefined && condition.hp < 1;
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
* Assemble the players' profiles with the rules they depend on, the same way for the local
|
||||
* service and for the save editor (save-cli.ts): static data from the dataset cache, the
|
||||
* save store with its format upgrades, and clan membership, research, and modification state
|
||||
* kept up to date and persisted on every read or write.
|
||||
* and the free repair over time (repair/repair-over-time.ts) kept up to date and persisted on
|
||||
* every read or write.
|
||||
*/
|
||||
import type { AccountStore } from './accounts/account-store.ts';
|
||||
import type { ClanStore } from './clans/clan-store.ts';
|
||||
@@ -11,6 +12,7 @@ import { reserveVehicles } from './game-data/datasets/reserve-vehicles.ts';
|
||||
import { shopBranches } from './game-data/datasets/shop-branches.ts';
|
||||
import { vehicleCatalogue, type CatalogueVehicle } from './game-data/datasets/vehicle-catalogue.ts';
|
||||
import { vehicleEquipment } from './game-data/datasets/vehicle-equipment.ts';
|
||||
import { vehicleRepair } from './game-data/datasets/vehicle-repair.ts';
|
||||
import type { GameFiles } from './game-data/game-files.ts';
|
||||
import { removeExpiredItems } from './items/item-expiry.ts';
|
||||
import { EquipmentCatalogue } from './modifications/equipment-catalogue.ts';
|
||||
@@ -20,6 +22,8 @@ import { PlayerProfiles } from './profile/player-profiles.ts';
|
||||
import { profileUpgrades } from './profile/profile-upgrades.ts';
|
||||
import { serverTimeNow } from './profile/server-time.ts';
|
||||
import type { StartingContent } from './profile/starting-content.ts';
|
||||
import { repairVehiclesOverTime } from './repair/repair-over-time.ts';
|
||||
import { RepairRules } from './repair/repair-rules.ts';
|
||||
import { loadResearchRules, type ResearchRules } from './research/research-rules.ts';
|
||||
import { refreshResearchState } from './research/research-state.ts';
|
||||
import { SaveStore } from './saves/save-store.ts';
|
||||
@@ -29,6 +33,7 @@ export interface ProfileServices {
|
||||
readonly profiles: PlayerProfiles;
|
||||
readonly research: ResearchRules;
|
||||
readonly equipment: EquipmentCatalogue;
|
||||
readonly repair: RepairRules;
|
||||
}
|
||||
|
||||
export interface ProfileSyncContext {
|
||||
@@ -51,6 +56,7 @@ export function setUpProfiles(
|
||||
};
|
||||
const research = loadResearchRules(datasets, tuning.research, vehicles);
|
||||
const equipment = new EquipmentCatalogue(datasets.load(vehicleEquipment));
|
||||
const repair = new RepairRules(datasets.load(vehicleRepair), research.techTree);
|
||||
const saves = new SaveStore(dataFolder, profileUpgrades(startingContent));
|
||||
const profiles = new PlayerProfiles(saves, gameFiles, startingContent, (profile, userId) => {
|
||||
const account = sync?.accounts.byUserId(userId);
|
||||
@@ -58,7 +64,8 @@ export function setUpProfiles(
|
||||
refreshResearchState(profile, research);
|
||||
refreshModuleState(profile, equipment);
|
||||
removeExpiredItems(profile, serverTimeNow());
|
||||
repairVehiclesOverTime(profile, repair, serverTimeNow());
|
||||
trimUserLogs(profile, tuning.limits.userLogsKept);
|
||||
});
|
||||
return { profiles, research, equipment };
|
||||
return { profiles, research, equipment, repair };
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* Free repair over time: a damaged vehicle that is not repaired for silver lions becomes intact
|
||||
* again after its full repair time (the stat card's "full repair time", repair-rules.ts
|
||||
* fullRepairHours), part by part: the hangar shows (1 - hp) x the full time as what is left
|
||||
* (shop_time_until_repair, aces.exe 2.61.0.37 0x17a5040).
|
||||
*
|
||||
* The client never raises hp itself, so the local service does it whenever it hands out or
|
||||
* changes a profile: hp grows by the hours since it was last set / the full repair time (with the
|
||||
* crew the vehicle has now), and the damage is cleared once hp reaches 1. The pace following the
|
||||
* current crew and the linear growth are inferred from the client's timer formula; whether a
|
||||
* vehicle keeps repairing while it is in a battle was not looked into (it does here).
|
||||
*/
|
||||
import type { BlkBlock } from '@wto/blk';
|
||||
import {
|
||||
clearVehicleDamage,
|
||||
damagedVehicles,
|
||||
damageTime,
|
||||
setVehicleDamage,
|
||||
vehicleCondition,
|
||||
} from '../profile/profile-vehicle-condition.ts';
|
||||
import { TICKS_PER_HOUR, type ServerTime } from '../profile/server-time.ts';
|
||||
import type { RepairRules } from './repair-rules.ts';
|
||||
|
||||
export function repairVehiclesOverTime(profile: BlkBlock, rules: RepairRules, now: ServerTime): void {
|
||||
for (const vehicle of damagedVehicles(profile)) {
|
||||
const condition = vehicleCondition(profile, vehicle)!;
|
||||
const since = damageTime(profile, vehicle);
|
||||
const fullHours = rules.fullRepairHours(profile, vehicle);
|
||||
if (fullHours <= 0) {
|
||||
clearVehicleDamage(profile, vehicle);
|
||||
continue;
|
||||
}
|
||||
if (since === undefined || since > now) {
|
||||
setVehicleDamage(profile, vehicle, condition.hp, condition.lastGameMode, now);
|
||||
continue;
|
||||
}
|
||||
const hours = Number(now - since) / Number(TICKS_PER_HOUR);
|
||||
const hp = condition.hp + hours / fullHours;
|
||||
if (hp >= 1) clearVehicleDamage(profile, vehicle);
|
||||
else if (hp > condition.hp) setVehicleDamage(profile, vehicle, hp, condition.lastGameMode, now);
|
||||
}
|
||||
}
|
||||
@@ -12,11 +12,42 @@
|
||||
* at repairCostPerMin x a play time of its own (feature repairCostUsesPlayTime, a per-vehicle
|
||||
* table at EconomicState+0xe838 whose source was not found; the local service never fills it),
|
||||
* so the battle settlement puts the lifetime rule into hp instead (battle/battle-repair.ts).
|
||||
* - Full repair time (shop_get_full_repair_time_by_mode; 0x937330 with the mode it was damaged in),
|
||||
* in hours; the hangar shows (1 - hp) x it as the time until the free repair is done
|
||||
* (shop_time_until_repair 0x17a5040) and never counts down by itself (repair/repair-over-time.ts):
|
||||
* - A crew has the vehicle as its current one: repairTimeHrs<Mode> x the cost's modification
|
||||
* factor (0x964750 multiplies by 0x964900 when the time is positive) x a crew multiplier.
|
||||
* The multiplier is 1 unless the vehicle's rank is at most repair_ranks/rank<q> of the crew's
|
||||
* groundService/repairRank level q (0x95d7b0). Otherwise it runs from 1/low to 1/high of
|
||||
* crew_parameters/mechanic/hangarRepairSpeed (no data file has it: the client default (1, 3),
|
||||
* 0x95cee0) over f = groundService/repair level / its maximum, plus, when the skill uses
|
||||
* specializations, the share of specialization<k>_add up to the crew's specialization with the
|
||||
* vehicle (0x95d200); f spans 0..2 then, else 0..1 (table at 0x72b6e00).
|
||||
* - No crew has it: repairTimeHrsNoCrew<Mode> x the factor, or repairTimeHrs<Mode> x the factor x
|
||||
* rTimeNoCrewMul when the vehicle has no no-crew time (0x964e30, warpoints.blk at 0x5c).
|
||||
* Inferred: the skill entry's two fields the client divides (+0xc / +0x10) are the level and the
|
||||
* maximum level, the rank compared is the vehicle's tech tree rank (0x9523b0), and a crew with
|
||||
* no repairRank level bought has the skill's min_skill_level.
|
||||
*/
|
||||
import type { BlkBlock } from '@wto/blk';
|
||||
import { REPAIR_MODES, type RepairMode, type VehicleRepair } from '../game-data/datasets/vehicle-repair.ts';
|
||||
import { findBlock, findParam, type BlkBlock } from '@wto/blk';
|
||||
import {
|
||||
REPAIR_MODES,
|
||||
type CrewRepairSkill,
|
||||
type RepairMode,
|
||||
type VehicleRepair,
|
||||
type VehicleRepairData,
|
||||
} from '../game-data/datasets/vehicle-repair.ts';
|
||||
import { skillLevel, specializationOf } from '../profile/profile-crew-skills.ts';
|
||||
import { allCrews } from '../profile/profile-crews.ts';
|
||||
import { ownsModification } from '../profile/profile-modifications.ts';
|
||||
import { vehicleCondition } from '../profile/profile-vehicle-condition.ts';
|
||||
import type { TechTree } from '../research/tech-tree.ts';
|
||||
|
||||
/** crew_parameters/mechanic/hangarRepairSpeed default (aces.exe 2.61.0.37 0x95cee0). */
|
||||
const HANGAR_REPAIR_SPEED = { low: 1, high: 3 } as const;
|
||||
/** The smallest repair speed the client allows (0x937330, constant at 0x7296ba0). */
|
||||
const MIN_REPAIR_SPEED = 0.001;
|
||||
const CREW_SKILL_PAGE = 'groundService';
|
||||
|
||||
/** lastGameMode / the client's EGD index: 1 arcade, 2 historical, 3 simulation. */
|
||||
export function repairModeOf(lastGameMode: number): RepairMode {
|
||||
@@ -29,9 +60,15 @@ export function gameModeIndexOf(mode: RepairMode): number {
|
||||
|
||||
export class RepairRules {
|
||||
readonly #vehicles: ReadonlyMap<string, VehicleRepair>;
|
||||
readonly #noCrewTimeMul: number;
|
||||
readonly #crewSkill: CrewRepairSkill;
|
||||
readonly #techTree: TechTree;
|
||||
|
||||
constructor(data: readonly VehicleRepair[]) {
|
||||
this.#vehicles = new Map(data.map((vehicle) => [vehicle.name, vehicle]));
|
||||
constructor(data: VehicleRepairData, techTree: TechTree) {
|
||||
this.#vehicles = new Map(data.vehicles.map((vehicle) => [vehicle.name, vehicle]));
|
||||
this.#noCrewTimeMul = data.noCrewTimeMul;
|
||||
this.#crewSkill = data.crewSkill;
|
||||
this.#techTree = techTree;
|
||||
}
|
||||
|
||||
/** The vehicle's repair data; undefined for vehicles that repair for free. */
|
||||
@@ -60,6 +97,36 @@ export class RepairRules {
|
||||
return Math.max(1, Math.trunc((1 - condition.hp) * full));
|
||||
}
|
||||
|
||||
/** Hours a free repair from wreck to intact takes in the vehicle's damage mode; 0 when it has no time. */
|
||||
fullRepairHours(profile: BlkBlock, vehicle: string): number {
|
||||
const data = this.#vehicles.get(vehicle);
|
||||
const condition = vehicleCondition(profile, vehicle);
|
||||
if (!data || !condition) return 0;
|
||||
const mode = repairModeOf(condition.lastGameMode);
|
||||
const factor = this.#modFactor(profile, data, mode);
|
||||
const scaled = (hours: number) => (hours > 0 ? hours * factor : hours);
|
||||
const crew = allCrews(profile).find((candidate) => currentVehicleOf(candidate) === vehicle);
|
||||
if (crew) return Math.max(0, scaled(data.timeHours[mode]) * this.#crewTimeMultiplier(crew, vehicle));
|
||||
const noCrew = scaled(data.noCrewTimeHours[mode]);
|
||||
if (noCrew >= 0) return noCrew;
|
||||
return Math.max(0, scaled(data.timeHours[mode]) * Math.max(1, this.#noCrewTimeMul));
|
||||
}
|
||||
|
||||
#crewTimeMultiplier(crew: BlkBlock, vehicle: string): number {
|
||||
const skill = this.#crewSkill;
|
||||
const qualification = Math.max(skill.minQualification, skillLevel(crew, CREW_SKILL_PAGE, 'repairRank'));
|
||||
const coveredRank = (skill.ranksByQualification[qualification - 1] ?? 0) > 0 ? skill.ranksByQualification[qualification - 1]! : qualification;
|
||||
const rank = this.#techTree.vehicle(vehicle)?.rank ?? Number.POSITIVE_INFINITY;
|
||||
if (rank > coveredRank) return 1;
|
||||
const slow = 1 / HANGAR_REPAIR_SPEED.low;
|
||||
const fast = 1 / HANGAR_REPAIR_SPEED.high;
|
||||
const span = skill.usesSpecializations ? 2 : 1;
|
||||
const level = skill.maxLevel > 0 ? skillLevel(crew, CREW_SKILL_PAGE, 'repair') / skill.maxLevel : 0;
|
||||
const progress = (skill.usesSpecializations ? specializationShare(skill, specializationOf(crew, vehicle)) : 0) + level;
|
||||
const multiplier = progress <= 0 ? slow : progress < span ? slow + (progress * (fast - slow)) / span : fast;
|
||||
return 1 / Math.max(MIN_REPAIR_SPEED, 1 / multiplier);
|
||||
}
|
||||
|
||||
#modFactor(profile: BlkBlock, data: VehicleRepair, mode: RepairMode): number {
|
||||
let factor = 1;
|
||||
for (const [mod, coefs] of Object.entries(data.modCoefs)) {
|
||||
@@ -68,3 +135,17 @@ export class RepairRules {
|
||||
return factor;
|
||||
}
|
||||
}
|
||||
|
||||
/** Share of specialization<k>_add up to the crew's specialization (0 none, 1 expert, 2 ace; 0x95d200). */
|
||||
function specializationShare(skill: CrewRepairSkill, specialization: number): number {
|
||||
const adds = skill.specializationAdds;
|
||||
const total = adds.reduce((sum, add) => sum + add, 0);
|
||||
if (total === 0) return 0;
|
||||
const reached = adds.reduce((sum, add, index) => sum + (index <= specialization ? add : 0), 0);
|
||||
return reached / total;
|
||||
}
|
||||
|
||||
function currentVehicleOf(crew: BlkBlock): string | undefined {
|
||||
const current = findParam(findBlock(crew, 'aircrafts') ?? crew, 'current')?.value;
|
||||
return current?.type === 'string' && current.value.length > 0 ? current.value : undefined;
|
||||
}
|
||||
Reference in new issue
Block a user