Extract weapon prerequisites, default equipment states, and exclusive groups. Grant eligible zero-cost modifications in dependency order and initialize newly unlocked consumables and weapon presets at capacity. When automatic restocking is enabled, replenish existing stock subject to the Silver Lions balance. Enforce purchase prerequisites and exclusive equipment groups. Type checking, patch checks, and local data extraction and restocking checks passed. In-game acceptance is pending.
82 lines
4.2 KiB
TypeScript
82 lines
4.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_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 { 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);
|
|
});
|
|
}
|
|
|
|
function offeredPrice(payload: BlkBlock) {
|
|
return { silverLions: intParam(payload, 'cost') ?? 0, goldenEagles: intParam(payload, 'costGold') ?? 0 };
|
|
}
|