diff --git a/packages/local-service/src/battle/battle-rp-investment.ts b/packages/local-service/src/battle/battle-rp-investment.ts index 110bffa..76df35b 100644 --- a/packages/local-service/src/battle/battle-rp-investment.ts +++ b/packages/local-service/src/battle/battle-rp-investment.ts @@ -22,6 +22,11 @@ * against the helicopter target like any other (inferred). Once the destination branch has * nothing left to research the RP goes to the vehicle's own branch again (inferred; the option * cannot be switched on then, shop.nut onMoveExpToHelicoptersChange). + * - Crews: an expert crew's RP with the vehicle adds up in expertToAceProgress (the stock tooltip: + * "Crew experience with selected vehicle"; the battle's total RP is used, inferred) and lowers + * the ace price by the expert_to_ace_cost_reduce stages; at train3Cost_exp the crew becomes ace + * ("...or obtained for free when the crew gets {expAmount} with the current vehicle", + * crew/qualification/specDescriptionPart; promoted at once, inferred). * * Each vehicle's breakdown is returned in the shape of the `EULT_SESSION_RESULT` * `container.researchPoints.unit` entries the stock debriefing explains RP with @@ -34,7 +39,7 @@ import type { UnitClass } from '../game-modes/catalogue/game-mode-declaration.ts import { isResearchable, type EquipmentCatalogue } from '../modifications/equipment-catalogue.ts'; import { pickDefaultResearchableModule } from '../modifications/module-state.ts'; import { isModuleResearched, ModuleStatus, vehicleModuleState } from '../modifications/module-status.ts'; -import { addExpertToAceRp, specializationOf } from '../profile/profile-crew-skills.ts'; +import { addExpertToAceRp, clearExpertToAceRp, expertToAceRp, setSpecialization, specializationOf } from '../profile/profile-crew-skills.ts'; import { crewForVehicleInCountry } from '../profile/profile-crews.ts'; import { destinationRpDomain, type VehicleDomain } from '../profile/profile-dest-rp.ts'; import { ownedVehicles } from '../profile/profile-hangar.ts'; @@ -65,6 +70,9 @@ import type { TreeVehicle } from '../research/tech-tree.ts'; import { VehicleStatus } from '../research/vehicle-status.ts'; import type { EarnedRpItem } from './battle-result-log.ts'; +const EXPERT = 1; +const ACE = 2; + export interface BattleRpDeps { readonly research: ResearchRules; readonly efficiency: ResearchEfficiency; @@ -406,7 +414,10 @@ function investAceCrewRp( const targetRp = catalogue.training(vehicleName)?.aceResearchPoints ?? 0; if (targetRp <= 0) return; const crew = crewForVehicleInCountry(profile, country, vehicleName); - if (crew && specializationOf(crew, vehicleName) === 1) { - addExpertToAceRp(crew, vehicleName, amount, targetRp); + if (!crew || specializationOf(crew, vehicleName) !== EXPERT) return; + addExpertToAceRp(crew, vehicleName, amount, targetRp); + if (expertToAceRp(crew, vehicleName) >= targetRp) { + setSpecialization(crew, vehicleName, ACE); + clearExpertToAceRp(crew, vehicleName); } } diff --git a/packages/local-service/src/crew/crew-skill-rules.ts b/packages/local-service/src/crew/crew-skill-rules.ts index 72de651..292fc58 100644 --- a/packages/local-service/src/crew/crew-skill-rules.ts +++ b/packages/local-service/src/crew/crew-skill-rules.ts @@ -56,13 +56,18 @@ export class CrewSkillCatalogue { return this.#training.get(vehicle); } + /** + * The price the client shows (wp_get_specialization_cost_gold -> aces.exe 2.61.0.37 0x9165f0): + * train3Cost_gold less the discount of the last expert_to_ace_cost_reduce stage whose percent + * the crew's RP with the vehicle has reached. A crew that reaches train3Cost_exp becomes ace + * without buying (battle/battle-rp-investment.ts). + */ aceGoldenEaglesPrice(vehicle: string, earnedAceRp: number): number { const prices = this.#training.get(vehicle); if (!prices) return 0; const baseGold = Math.max(0, prices.aceGoldenEagles); const targetRp = prices.aceResearchPoints; if (baseGold === 0 || targetRp <= 0 || earnedAceRp <= 0) return baseGold; - if (earnedAceRp >= targetRp) return 0; const progressPercent = Math.floor((earnedAceRp * 100) / targetRp); let discount = 0; for (const stage of this.#aceDiscountStages) { diff --git a/packages/local-service/src/profile/profile-crew-skills.ts b/packages/local-service/src/profile/profile-crew-skills.ts index 52f4bc9..d83e144 100644 --- a/packages/local-service/src/profile/profile-crew-skills.ts +++ b/packages/local-service/src/profile/profile-crew-skills.ts @@ -98,6 +98,14 @@ export function addExpertToAceRp(crew: BlkBlock, vehicle: string, deltaRp: numbe if (next !== current) setParam(ensureBlock(crew, ACE_PROGRESS), vehicle, { type: 'int', value: next }); } +/** Drop the vehicle's Expert-to-Ace RP, and the block when it is empty (as the client does, 0x93b4eb). */ +export function clearExpertToAceRp(crew: BlkBlock, vehicle: string): void { + const progress = findBlock(crew, ACE_PROGRESS); + if (!progress) return; + progress.params = progress.params.filter((param) => param.name !== vehicle); + if (progress.params.length === 0 && progress.blocks.length === 0) crew.blocks = crew.blocks.filter((block) => block !== progress); +} + function intOf(block: BlkBlock, name: string): number { const value = findParam(block, name)?.value; if (value?.type === 'int64') return Number(value.value);