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.
22 lines
1.0 KiB
TypeScript
22 lines
1.0 KiB
TypeScript
import type { BlkBlock } from '@wto/blk';
|
|
import { ownsVehicle, setVehicleMrankDelta } from '../profile/profile-hangar.ts';
|
|
import { modificationRecord } from '../profile/profile-modifications.ts';
|
|
import { ACCEPTED, refused, type RuleOutcome } from '../research/rule-outcome.ts';
|
|
import type { EquipmentCatalogue } from './equipment-catalogue.ts';
|
|
|
|
export function selectVehicleMrankDelta(
|
|
profile: BlkBlock, catalogue: EquipmentCatalogue, vehicle: string, delta: number,
|
|
): RuleOutcome {
|
|
const equipment = catalogue.vehicle(vehicle);
|
|
if (!equipment || !ownsVehicle(profile, vehicle) || !Number.isInteger(delta) || delta < 0) return refused('BAD_PARAMS');
|
|
|
|
// Stock getSelectableAddMranks offers zero and each positive addMrank on an owned modification.
|
|
if (delta > 0 && !equipment.modifications.some((modification) =>
|
|
modification.addMrank === delta && (modificationRecord(profile, vehicle, modification.name)?.count ?? 0) > 0)) {
|
|
return refused('NOT_AVAILABLE');
|
|
}
|
|
|
|
setVehicleMrankDelta(profile, vehicle, delta);
|
|
return ACCEPTED;
|
|
}
|