fix(server): persist selectable battle ratings
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.
This commit is contained in:
1 parent
3f0e08c5b7
commit
899fb5d91b
8 files changed
+82
-17
No files matched your search
@@ -0,0 +1,21 @@
|
||||
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;
|
||||
}
|
||||
Reference in new issue
Block a user