/** * 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): * { :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 { 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)); } function offeredPrice(payload: BlkBlock) { return { silverLions: intParam(payload, 'cost') ?? 0, goldenEagles: intParam(payload, 'costGold') ?? 0 }; }