Everything sat in packages/: two programs next to the small libraries
they use, and the patch data loose at the root. The programs now live in
apps/ and the shared libraries in packages/:
apps/server the local server (was packages/local-service),
package @wto/server
packages/patcher builds the game copy (was packages/build),
package @wto/patcher
patches/exe exe patch definitions (was exe-patches)
patches/gui GUI script patches (was gui-patches)
Inside the server, the network layer folder becomes transport/ so it is
not server/server/, the entry module is server.ts, and startLocalService
and its types become startServer, ServerOptions and RunningServer. The
health answer names the app wto-server, and the TLS files in the data
folder are server.key and server.crt (made again on the next start).
Comments, logs and tool texts say "local server".
The patcher no longer reaches into the server's folder. It read the
default tuning/store.jsonc by a relative path to register bundle GUIDs
for the multi-vehicle packs, which also ignored the player's overrides
in <data>/tuning/. It now takes the pack ids from its caller; the
server exports multiVehiclePackIds(dataFolder), which reads them the way
the running server does. rebuildGuiPack takes the patch folder from its
caller as well.
The development build moves out of the patcher to
scripts/build-game-copy.ts, since it uses both the server and the
patcher. It needs --data (the folder the server will run with) and
defaults the patch folders and the hook library to this repository.
Checked with the root typecheck, check-patches, check-gui,
check-offsets, the native build, a run of build-game-copy.ts into a
scratch folder (12 exe patches, 35 GUI patches, 496 bundle GUIDs as
before) and a server start from apps/server answering wto-server.
BREAKING CHANGE: Use @wto/server and @wto/patcher from the new workspace paths. Run the development build with scripts/build-game-copy.ts and pass --data.
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;
|
|
}
|