feat(equipment): add modification, ammunition, and spare actions

Include modification, weapon, and spare vehicle prices, omitting zero
prices. Recalculate modification research and ranks and handle research
target selection, purchases, bulk purchases, and equipment toggles.
This commit is contained in:
N0VAN0M4LY committed 2026-11-24 21:43:35 +08:00
1 parent 9196dc2a4d
commit c448ed94a7
18 files changed
+742 -23

No files matched your search

@@ -5,6 +5,7 @@ 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 { buyAllModificationsAction, buyModificationAction, buySparesAction, enableModificationsAction } from './modification-actions.ts';
import { entitlementsFull, initialMeta, legacyUserData } from './online-init-actions.ts';
import { priceEx } from './price-actions.ts';
import { buyAircraft, buySlot } from './purchase-actions.ts';
@@ -32,5 +33,9 @@ export function actionTable(deps: ActionDependencies): ReadonlyMap<string, CharA
['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)],
['cln_buy_modification', buyModificationAction(deps.profiles, deps.accounts, deps.research)],
['cln_buy_all_modification', buyAllModificationsAction(deps.profiles, deps.accounts, deps.research)],
['cln_buy_spare_aircrafts', buySparesAction(deps.profiles, deps.accounts, deps.research)],
['cln_enable_modifications', enableModificationsAction(deps.profiles, deps.accounts)],
]);
}
@@ -0,0 +1,69 @@
/**
* Modification, ammunition and spare actions. The first three are sent
* with char_send_blk (job type 13); cln_enable_modifications by a native function with job type
* 0x17 (aces.exe 0x29aa21). Both types are profile updates, so each answers the whole profile.
*
* cln_buy_modification (scripts weaponry/weaponsPurchase.nut):
* aircraft:t modification:t open:b count:i cost:i costGold:i
* cln_buy_all_modification: unit:t forceOpen:b cost:i costGold:i
* cln_buy_spare_aircrafts: aircraft:t count:i cost:i costGold:i
* cln_enable_modifications (shop_enable_modifications, 0x17a5020 -> 0x29a890; lab round 18):
* <vehicle>{ <modification>:b=yes ... } ...
*/
import type { BlkBlock } from '@wto/blk';
import type { AccountStore } from '../../accounts/account-store.ts';
import { buyAllModifications, buyModification, enableModifications } from '../../modifications/modification-purchase.ts';
import { buySpares } from '../../modifications/spare-purchase.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 { boolParam, intParam, stringParam } from './payload-params.ts';
import { ruleAction } from './rule-answer.ts';
export function buyModificationAction(profiles: PlayerProfiles, accounts: AccountStore, rules: ResearchRules): CharActionHandler {
return ruleAction(profiles, accounts, (payload) => {
const vehicle = stringParam(payload, 'aircraft');
const modification = stringParam(payload, 'modification');
if (vehicle === undefined || modification === undefined) return undefined;
const order = {
vehicle,
modification,
outright: boolParam(payload, 'open') ?? false,
amount: intParam(payload, 'count') ?? 1,
offered: offeredPrice(payload),
};
return (profile) => buyModification(profile, rules.equipment, order);
});
}
export function buyAllModificationsAction(profiles: PlayerProfiles, accounts: AccountStore, rules: ResearchRules): CharActionHandler {
return ruleAction(profiles, accounts, (payload) => {
const vehicle = stringParam(payload, 'unit');
if (vehicle === undefined) return undefined;
const outright = boolParam(payload, 'forceOpen') ?? false;
const offered = offeredPrice(payload);
return (profile) => buyAllModifications(profile, rules.equipment, vehicle, outright, offered);
});
}
export function buySparesAction(profiles: PlayerProfiles, accounts: AccountStore, rules: ResearchRules): CharActionHandler {
return ruleAction(profiles, accounts, (payload) => {
const vehicle = stringParam(payload, 'aircraft');
if (vehicle === undefined) return undefined;
const amount = intParam(payload, 'count') ?? 1;
const offered = offeredPrice(payload);
return (profile) => buySpares(profile, rules.equipment, vehicle, amount, offered);
});
}
export function enableModificationsAction(profiles: PlayerProfiles, accounts: AccountStore): CharActionHandler {
return ruleAction(profiles, accounts, (payload) => {
const switches = payload.blocks.flatMap((vehicle) => vehicle.params.flatMap((param) =>
param.value.type === 'bool' ? [{ vehicle: vehicle.name, modification: param.name, enabled: param.value.value }] : []));
return (profile) => enableModifications(profile, switches);
});
}
function offeredPrice(payload: BlkBlock) {
return { silverLions: intParam(payload, 'cost') ?? 0, goldenEagles: intParam(payload, 'costGold') ?? 0 };
}
@@ -10,3 +10,8 @@ export function intParam(payload: BlkBlock, name: string): number | undefined {
const value = findParam(payload, name)?.value;
return value?.type === 'int' ? value.value : undefined;
}
export function boolParam(payload: BlkBlock, name: string): boolean | undefined {
const value = findParam(payload, name)?.value;
return value?.type === 'bool' ? value.value : undefined;
}
@@ -9,6 +9,6 @@ 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);
const table = priceTable(rules.techTree, rules.equipment);
return () => ({ kind: 'data', blk: table });
}
@@ -5,6 +5,9 @@
* 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
* or, for a modification (shop_set_researchable_unit_module, 0x17a3e00; implementation notes):
* unit:t the owned vehicle
* mod:t the modification to research
* cln_reset_researchable (shop_reset_researchable_unit, 0x17a3f00): the player closed the
* "research finished" prompt without choosing.
* country:t, type:i
@@ -14,6 +17,7 @@
*/
import type { AccountStore } from '../../accounts/account-store.ts';
import type { PlayerProfiles } from '../../profile/player-profiles.ts';
import { chooseModuleResearch } from '../../modifications/module-research-target.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';
@@ -23,6 +27,8 @@ 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 modification = stringParam(payload, 'mod');
if (vehicle !== undefined && modification !== undefined) return (profile) => chooseModuleResearch(profile, rules.equipment, vehicle, modification);
const type = intParam(payload, 'type');
if (vehicle === undefined || type === undefined) return undefined;
return (profile) => chooseResearchTarget(profile, rules, vehicle, type);