Add modification, ammunition, and spare vehicle actions

Include modification, weapon, and spare vehicle prices, omitting zero
prices. Recalculate modification research and ranks and handle research
target selection, purchases, bulk purchases, and equipment toggles.
This commit is contained in:
N0VAN0M4LY committed 2026-11-24 21:43:35 +08:00
1 parent 56731efa76
commit 8692a13577
18 files changed
+742 -23

No files matched your search

@@ -0,0 +1,74 @@
/**
* The status of each modification of an owned vehicle. The client
* works out "owned" and "mounted" from the modifications records and "in research" from
* investMode itself; the server supplies the rest through modsResearch:
*
* researchable modification (tier 1+, research points)
* tier not open LOCKED
* research points reached CAN_BUY
* otherwise CAN_RESEARCH
* other modification (ammunition, expendables, premium)
* every required modification bought CAN_BUY
* otherwise LOCKED
*
* Tiers: tier 1 is open; tier N+1 opens once tier N is open and at least
* needBuyToOpenNextInTier<N> of its counted modifications are researched (scripts
* weaponry/bulletsInfo.nut isWeaponTierAvailable, weaponry/modsTree.nut getNextTierModsCount).
*/
import type { BlkBlock } from '@wto/blk';
import type { ModificationFacts, VehicleEquipment } from '../game-data/datasets/vehicle-equipment.ts';
import { ownsModification } from '../profile/profile-modifications.ts';
import { moduleResearchPoints } from '../profile/profile-module-research.ts';
import { countsForTier, isResearchable } from './equipment-catalogue.ts';
/** shopItemConsts ES_ITEM_STATUS_*; the same values as the vehicle statuses. */
export const ModuleStatus = {
LOCKED: 1,
CAN_RESEARCH: 2,
CAN_BUY: 8,
} as const;
export type ModuleStatus = (typeof ModuleStatus)[keyof typeof ModuleStatus];
export interface VehicleModuleState {
/** The highest open tier (hangar tierNumber). */
readonly openTier: number;
/** Status of every modification the player does not own. */
readonly statuses: ReadonlyMap<string, ModuleStatus>;
}
export function vehicleModuleState(profile: BlkBlock, equipment: VehicleEquipment): VehicleModuleState {
const openTier = openTierOf(profile, equipment);
const statuses = new Map<string, ModuleStatus>();
for (const modification of equipment.modifications) {
if (ownsModification(profile, equipment.vehicle, modification.name)) continue;
statuses.set(modification.name, statusOf(profile, equipment.vehicle, modification, openTier));
}
return { openTier, statuses };
}
export function isModuleResearched(profile: BlkBlock, vehicle: string, modification: ModificationFacts): boolean {
return ownsModification(profile, vehicle, modification.name)
|| moduleResearchPoints(profile, vehicle, modification.name) >= modification.researchPoints;
}
function openTierOf(profile: BlkBlock, equipment: VehicleEquipment): number {
let tier = 1;
while (tier <= equipment.tierRequirements.length) {
const needed = equipment.tierRequirements[tier - 1] ?? 0;
const tierModifications = equipment.modifications.filter((modification) => modification.tier === tier && countsForTier(modification));
if (tierModifications.length === 0) break;
const researched = tierModifications.filter((modification) => isModuleResearched(profile, equipment.vehicle, modification)).length;
if (researched < needed) break;
tier++;
}
return tier;
}
function statusOf(profile: BlkBlock, vehicle: string, modification: ModificationFacts, openTier: number): ModuleStatus {
if (isResearchable(modification)) {
if (modification.tier > openTier) return ModuleStatus.LOCKED;
return isModuleResearched(profile, vehicle, modification) ? ModuleStatus.CAN_BUY : ModuleStatus.CAN_RESEARCH;
}
return modification.requires.every((required) => ownsModification(profile, vehicle, required)) ? ModuleStatus.CAN_BUY : ModuleStatus.LOCKED;
}