Settlement already added an expert crew's battle RP to expertToAceProgress but capped
it at train3Cost_exp and left the crew at expert. The stock tooltip says ace is
"obtained for free when the crew gets {expAmount} with the current vehicle"
(crew/qualification/specDescriptionPart), and the client's discount stages end at
75 % (wp_get_specialization_cost_gold -> aces.exe 2.61.0.37 0x9165f0). The crew now
becomes ace once the RP reaches the target and its progress entry is dropped, as
the client drops an empty expertToAceProgress block (0x93b4eb). The ace price no
longer has its own "free at 100 %" case, so it matches the price the client shows.
Checked: typecheck.
131 lines
5.6 KiB
TypeScript
131 lines
5.6 KiB
TypeScript
/**
|
|
* Crew skill upgrades, skill point packs and specializations:
|
|
*
|
|
* cln_upgrade_crew raise skills: <page>{ <skill>:i=levels to add } id:i
|
|
* cost = sum of the per-level costs of the new levels
|
|
* (crew_skills.blk skill_level_exp), paid in skill points
|
|
* cln_purchase_skill_points id:i pack:t: warpoints.blk crewSkillPointsCost, golden eagles
|
|
* cln_specialize_crew id:i aircraft:t: one step up for a trained vehicle,
|
|
* expert (wpcost.blk train2Cost, silver lions) then
|
|
* ace (train3Cost_gold discounted by expert_to_ace_cost_reduce)
|
|
*/
|
|
import type { BlkBlock } from '@wto/blk';
|
|
import type { AceDiscountStage, CrewSkillData, CrewTrainingPrices, SkillFacts, SkillPointPack } from '../game-data/datasets/crew-skills.ts';
|
|
import { canAfford, pay, type Price } from '../profile/profile-currency.ts';
|
|
import {
|
|
addSkillPoints,
|
|
expertToAceRp,
|
|
isTrainedFor,
|
|
setSkillLevel,
|
|
setSpecialization,
|
|
skillLevel,
|
|
skillPoints,
|
|
specializationOf,
|
|
} from '../profile/profile-crew-skills.ts';
|
|
import { crewOf } from '../profile/profile-crews.ts';
|
|
import { ACCEPTED, refused, type RuleOutcome } from '../research/rule-outcome.ts';
|
|
|
|
const ACE = 2;
|
|
|
|
export class CrewSkillCatalogue {
|
|
readonly #skills = new Map<string, SkillFacts>();
|
|
readonly #packs: ReadonlyMap<string, SkillPointPack>;
|
|
readonly #training: ReadonlyMap<string, CrewTrainingPrices>;
|
|
readonly #aceDiscountStages: readonly AceDiscountStage[];
|
|
|
|
constructor(data: CrewSkillData) {
|
|
for (const page of data.pages) for (const skill of page.skills) this.#skills.set(`${page.name}/${skill.name}`, skill);
|
|
this.#packs = new Map(data.packs.map((pack) => [pack.name, pack]));
|
|
this.#training = new Map(data.training.map((prices) => [prices.vehicle, prices]));
|
|
this.#aceDiscountStages = data.aceDiscountStages;
|
|
}
|
|
|
|
skill(page: string, skill: string): SkillFacts | undefined {
|
|
return this.#skills.get(`${page}/${skill}`);
|
|
}
|
|
|
|
pack(name: string): SkillPointPack | undefined {
|
|
return this.#packs.get(name);
|
|
}
|
|
|
|
packs(): Iterable<SkillPointPack> {
|
|
return this.#packs.values();
|
|
}
|
|
|
|
training(vehicle: string): CrewTrainingPrices | undefined {
|
|
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;
|
|
const progressPercent = Math.floor((earnedAceRp * 100) / targetRp);
|
|
let discount = 0;
|
|
for (const stage of this.#aceDiscountStages) {
|
|
if (progressPercent >= stage.percent && stage.discount > discount) discount = stage.discount;
|
|
}
|
|
return Math.max(0, baseGold - Math.floor((baseGold * discount) / 100));
|
|
}
|
|
}
|
|
|
|
export interface SkillRaise {
|
|
readonly page: string;
|
|
readonly skill: string;
|
|
readonly levels: number;
|
|
}
|
|
|
|
export function upgradeCrewSkills(profile: BlkBlock, catalogue: CrewSkillCatalogue, crewId: number, raises: readonly SkillRaise[]): RuleOutcome {
|
|
const crew = crewOf(profile, crewId);
|
|
if (!crew || raises.length === 0) return refused('BAD_PARAMS');
|
|
let cost = 0;
|
|
const changes: { raise: SkillRaise; level: number }[] = [];
|
|
for (const raise of raises) {
|
|
const facts = catalogue.skill(raise.page, raise.skill);
|
|
if (!facts || raise.levels < 1) return refused('BAD_PARAMS');
|
|
const current = skillLevel(crew, raise.page, raise.skill);
|
|
const level = current + raise.levels;
|
|
if (level > facts.levelCosts.length) return refused('NOT_AVAILABLE');
|
|
for (let next = current + 1; next <= level; next++) cost += facts.levelCosts[next - 1] ?? 0;
|
|
changes.push({ raise, level });
|
|
}
|
|
if (cost > skillPoints(crew)) return refused('NOT_ENOUGH_SKILL_POINTS');
|
|
for (const { raise, level } of changes) setSkillLevel(crew, raise.page, raise.skill, level);
|
|
addSkillPoints(crew, -cost);
|
|
return ACCEPTED;
|
|
}
|
|
|
|
export function buySkillPoints(profile: BlkBlock, catalogue: CrewSkillCatalogue, crewId: number, packName: string): RuleOutcome {
|
|
const crew = crewOf(profile, crewId);
|
|
const pack = catalogue.pack(packName);
|
|
if (!crew || !pack) return refused('BAD_PARAMS');
|
|
const price: Price = { silverLions: 0, goldenEagles: pack.goldenEagles };
|
|
if (!canAfford(profile, price)) return refused('NOT_ENOUGH_MONEY');
|
|
pay(profile, price);
|
|
addSkillPoints(crew, pack.points);
|
|
return ACCEPTED;
|
|
}
|
|
|
|
export function specializeCrew(profile: BlkBlock, catalogue: CrewSkillCatalogue, crewId: number, vehicle: string): RuleOutcome {
|
|
const crew = crewOf(profile, crewId);
|
|
const prices = catalogue.training(vehicle);
|
|
if (!crew || !prices || !isTrainedFor(crew, vehicle)) return refused('BAD_PARAMS');
|
|
const spec = specializationOf(crew, vehicle);
|
|
if (spec >= ACE) return refused('NOT_AVAILABLE');
|
|
const price: Price = spec === 0
|
|
? { silverLions: prices.expert, goldenEagles: 0 }
|
|
: { silverLions: 0, goldenEagles: catalogue.aceGoldenEaglesPrice(vehicle, expertToAceRp(crew, vehicle)) };
|
|
if (!canAfford(profile, price)) return refused('NOT_ENOUGH_MONEY');
|
|
pay(profile, price);
|
|
setSpecialization(crew, vehicle, spec + 1);
|
|
return ACCEPTED;
|
|
}
|