Validate the selected rank against owned modifications and return the saved profile. Use the saved rank delta for mode eligibility and room matchmaking. Verified with typecheck and a local 2.61.0.58 server run using temporary data. In-game acceptance is pending.
98 lines
5.2 KiB
TypeScript
98 lines
5.2 KiB
TypeScript
/**
|
|
* Modification, ammunition, weapon preset and spare actions. The
|
|
* purchases 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_buy_weapon: aircraft:t weapon:t count:i cost:i costGold:i
|
|
* cln_set_unit_selected_mrank (scripts/unit/unitmrankselectionstate.nut): unit:t addMrank: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 type { EquipmentCatalogue } from '../../modifications/equipment-catalogue.ts';
|
|
import { buyAllModifications, buyModification, enableModifications } from '../../modifications/modification-purchase.ts';
|
|
import { buySpares } from '../../modifications/spare-purchase.ts';
|
|
import { selectVehicleMrankDelta } from '../../modifications/vehicle-mrank-selection.ts';
|
|
import { saveWeaponPresets } from '../../modifications/weapon-presets.ts';
|
|
import { buyWeapons } from '../../modifications/weapon-purchase.ts';
|
|
import type { PlayerProfiles } from '../../profile/player-profiles.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, equipment: EquipmentCatalogue): 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, equipment, order);
|
|
});
|
|
}
|
|
|
|
export function buyAllModificationsAction(profiles: PlayerProfiles, accounts: AccountStore, equipment: EquipmentCatalogue): 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, equipment, vehicle, outright, offered);
|
|
});
|
|
}
|
|
|
|
export function buySparesAction(profiles: PlayerProfiles, accounts: AccountStore, equipment: EquipmentCatalogue): 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, equipment, vehicle, amount, offered);
|
|
});
|
|
}
|
|
|
|
export function buyWeaponsAction(profiles: PlayerProfiles, accounts: AccountStore, equipment: EquipmentCatalogue): CharActionHandler {
|
|
return ruleAction(profiles, accounts, (payload) => {
|
|
const vehicle = stringParam(payload, 'aircraft');
|
|
const weapon = stringParam(payload, 'weapon');
|
|
if (vehicle === undefined || weapon === undefined) return undefined;
|
|
const order = { vehicle, weapon, amount: intParam(payload, 'count') ?? 1, offered: offeredPrice(payload) };
|
|
return (profile) => buyWeapons(profile, equipment, order);
|
|
});
|
|
}
|
|
|
|
export function enableModificationsAction(profiles: PlayerProfiles, accounts: AccountStore, equipment: EquipmentCatalogue): 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, equipment, switches);
|
|
});
|
|
}
|
|
|
|
export function saveWeaponPresetsAction(profiles: PlayerProfiles, accounts: AccountStore, equipment: EquipmentCatalogue): CharActionHandler {
|
|
return ruleAction(profiles, accounts, (payload) => (profile) => saveWeaponPresets(profile, equipment, payload));
|
|
}
|
|
|
|
export function setUnitSelectedMrankAction(profiles: PlayerProfiles, accounts: AccountStore, equipment: EquipmentCatalogue): CharActionHandler {
|
|
return ruleAction(profiles, accounts, (payload) => {
|
|
const vehicle = stringParam(payload, 'unit');
|
|
const delta = intParam(payload, 'addMrank');
|
|
if (!vehicle || delta === undefined) return undefined;
|
|
return (profile) => selectVehicleMrankDelta(profile, equipment, vehicle, delta);
|
|
});
|
|
}
|
|
|
|
function offeredPrice(payload: BlkBlock) {
|
|
return { silverLions: intParam(payload, 'cost') ?? 0, goldenEagles: intParam(payload, 'costGold') ?? 0 };
|
|
}
|