feat(research): add vehicle research and purchases

Recompute unlocked ranks, prerequisites, and unit states before serving
profiles. Add research target selection, research conversion, vehicle
and slot purchases, and the price table. Support editing convertible RP
and restrict hidden vehicle visibility to eligible entries.

The client still displays zero purchase prices pending price table
integration.
This commit is contained in:
N0VAN0M4LY committed 2026-11-24 21:04:19 +08:00
1 parent e5452e925f
commit 08b5c1e51c
37 files changed
+1336 -75

No files matched your search

@@ -1,15 +1,20 @@
/** Char action names mapped to their handlers (full list of names: research-data/char_actions_37.json). */
import type { AccountStore } from '../../accounts/account-store.ts';
import type { PlayerProfiles } from '../../profile/player-profiles.ts';
import type { ResearchRules } from '../../research/research-rules.ts';
import type { CharActionHandler } from '../char-action.ts';
import { acceptEula } from './agreement-actions.ts';
import { bulkTrainCrews, trainCrew } from './crew-actions.ts';
import { entitlementsFull, initialMeta, legacyUserData } from './online-init-actions.ts';
import { priceEx } from './price-actions.ts';
import { buyAircraft, buySlot } from './purchase-actions.ts';
import { convertExp, resetResearchable, setResearchable } from './research-actions.ts';
import { setStartingInfo } from './starting-info-actions.ts';
export interface ActionDependencies {
readonly profiles: PlayerProfiles;
readonly accounts: AccountStore;
readonly research: ResearchRules;
}
export function actionTable(deps: ActionDependencies): ReadonlyMap<string, CharActionHandler> {
@@ -21,5 +26,11 @@ export function actionTable(deps: ActionDependencies): ReadonlyMap<string, CharA
['cln_set_starting_info', setStartingInfo(deps.profiles, deps.accounts)],
['cln_bulk_train_aircraft', bulkTrainCrews(deps.profiles, deps.accounts)],
['cln_train_aircraft', trainCrew(deps.profiles, deps.accounts)],
['cln_set_researchable', setResearchable(deps.profiles, deps.accounts, deps.research)],
['cln_reset_researchable', resetResearchable(deps.profiles, deps.accounts, deps.research)],
['cln_convert_exp', convertExp(deps.profiles, deps.accounts, deps.research)],
['cln_buy_aircraft', buyAircraft(deps.profiles, deps.accounts, deps.research)],
['cln_buy_slot', buySlot(deps.profiles, deps.accounts, deps.research)],
['cln_get_price_ex', priceEx(deps.research)],
]);
}
@@ -0,0 +1,12 @@
/** Typed reads of a char request's BLK parameters; a missing or differently typed parameter reads as undefined. */
import { findParam, type BlkBlock } from '@wto/blk';
export function stringParam(payload: BlkBlock, name: string): string | undefined {
const value = findParam(payload, name)?.value;
return value?.type === 'string' ? value.value : undefined;
}
export function intParam(payload: BlkBlock, name: string): number | undefined {
const value = findParam(payload, name)?.value;
return value?.type === 'int' ? value.value : undefined;
}
@@ -0,0 +1,14 @@
/**
* cln_get_price_ex: the price table (implementation notes; src/research/price-table.ts).
* Sent at sign-in with an empty body and again by the stock scripts when a purchase fails
* (scripts/unit/unitActions.nut impl_buyUnit: PRICE.update). The table only depends on the
* game files, so it is built once.
*/
import type { CharActionHandler } from '../char-action.ts';
import { priceTable } from '../../research/price-table.ts';
import type { ResearchRules } from '../../research/research-rules.ts';
export function priceEx(rules: ResearchRules): CharActionHandler {
const table = priceTable(rules.techTree);
return () => ({ kind: 'data', blk: table });
}
@@ -0,0 +1,38 @@
/**
* Purchase actions; the client applies each answer as a profile
* update, so each answers the whole profile.
*
* cln_buy_aircraft (char_send_blk, job type 13; gui.vromfs.bin scripts/unit/unitActions.nut
* impl_buyUnit):
* name:t the vehicle
* cost:i the silver lion price the client showed
* costGold:i the golden eagle price the client showed
* cln_buy_slot (purchase_crew_slot, aces.exe 2.61.0.37 0x1555a90 -> 0x2998f0, job type 10):
* country:t the country that gets one more crew slot
*/
import type { AccountStore } from '../../accounts/account-store.ts';
import type { PlayerProfiles } from '../../profile/player-profiles.ts';
import { buyCrewSlot } from '../../research/crew-slot-purchase.ts';
import type { ResearchRules } from '../../research/research-rules.ts';
import { buyVehicle } from '../../research/vehicle-purchase.ts';
import type { CharActionHandler } from '../char-action.ts';
import { intParam, stringParam } from './payload-params.ts';
import { ruleAction } from './rule-answer.ts';
export function buyAircraft(profiles: PlayerProfiles, accounts: AccountStore, rules: ResearchRules): CharActionHandler {
return ruleAction(profiles, accounts, (payload) => {
const vehicle = stringParam(payload, 'name');
const silverLions = intParam(payload, 'cost') ?? 0;
const goldenEagles = intParam(payload, 'costGold') ?? 0;
if (vehicle === undefined) return undefined;
return (profile) => buyVehicle(profile, rules, vehicle, { silverLions, goldenEagles });
});
}
export function buySlot(profiles: PlayerProfiles, accounts: AccountStore, rules: ResearchRules): CharActionHandler {
return ruleAction(profiles, accounts, (payload) => {
const country = stringParam(payload, 'country');
if (country === undefined) return undefined;
return (profile) => buyCrewSlot(profile, rules, country);
});
}
@@ -0,0 +1,48 @@
/**
* Research actions. All are sent with char_send_blk (job type 13),
* so the client applies each answer as a profile update and each answers the whole profile.
*
* cln_set_researchable (shop_set_researchable_unit, aces.exe 2.61.0.37 0x17a3e80):
* unit:t the vehicle to research
* type:i its vehicle type number
* cln_reset_researchable (shop_reset_researchable_unit, 0x17a3f00): the player closed the
* "research finished" prompt without choosing.
* country:t, type:i
* cln_convert_exp (shop_convert_free_exp_for_unit, 0x17a4ec0): free research points into a
* vehicle, paid with golden eagles.
* unit:t, amount:i research points
*/
import type { AccountStore } from '../../accounts/account-store.ts';
import type { PlayerProfiles } from '../../profile/player-profiles.ts';
import { chooseResearchTarget, convertFreeResearchPoints, dismissFinishedResearch } from '../../research/research-progress.ts';
import type { ResearchRules } from '../../research/research-rules.ts';
import type { CharActionHandler } from '../char-action.ts';
import { intParam, stringParam } from './payload-params.ts';
import { ruleAction } from './rule-answer.ts';
export function setResearchable(profiles: PlayerProfiles, accounts: AccountStore, rules: ResearchRules): CharActionHandler {
return ruleAction(profiles, accounts, (payload) => {
const vehicle = stringParam(payload, 'unit');
const type = intParam(payload, 'type');
if (vehicle === undefined || type === undefined) return undefined;
return (profile) => chooseResearchTarget(profile, rules, vehicle, type);
});
}
export function resetResearchable(profiles: PlayerProfiles, accounts: AccountStore, rules: ResearchRules): CharActionHandler {
return ruleAction(profiles, accounts, (payload) => {
const country = stringParam(payload, 'country');
const type = intParam(payload, 'type');
if (country === undefined || type === undefined) return undefined;
return (profile) => dismissFinishedResearch(profile, rules, country, type);
});
}
export function convertExp(profiles: PlayerProfiles, accounts: AccountStore, rules: ResearchRules): CharActionHandler {
return ruleAction(profiles, accounts, (payload) => {
const vehicle = stringParam(payload, 'unit');
const amount = intParam(payload, 'amount');
if (vehicle === undefined || amount === undefined) return undefined;
return (profile) => convertFreeResearchPoints(profile, rules, vehicle, amount);
});
}
@@ -0,0 +1,28 @@
/**
* Actions that run one rule on the player's profile and answer the whole updated profile
* (job types the client applies as profile updates, implementation notes). A refused
* rule changes nothing and answers "!ERROR:<refusal>".
*/
import type { BlkBlock } from '@wto/blk';
import type { AccountStore } from '../../accounts/account-store.ts';
import { clientProfile } from '../../profile/client-profile.ts';
import type { PlayerProfiles } from '../../profile/player-profiles.ts';
import type { RuleOutcome } from '../../research/rule-outcome.ts';
import type { CharActionHandler } from '../char-action.ts';
import { withAccount } from './account-context.ts';
/** Read the request into a rule (undefined: malformed request), run it, answer the outcome. */
export function ruleAction(profiles: PlayerProfiles, accounts: AccountStore,
readRequest: (payload: BlkBlock) => ((profile: BlkBlock) => RuleOutcome) | undefined): CharActionHandler {
return (context) => withAccount(context, accounts, (account) => {
const rule = context.payload && readRequest(context.payload);
if (!rule) return { kind: 'error', code: 'BAD_PARAMS' };
let outcome: RuleOutcome = { ok: false, refusal: 'BAD_PARAMS' };
const profile = profiles.updateWhen(account.userId, (saved) => {
outcome = rule(saved);
return outcome.ok;
});
if (profile) return { kind: 'data', blk: clientProfile(profile, account) };
return { kind: 'error', code: outcome.ok ? 'BAD_PARAMS' : outcome.refusal };
});
}