Files
WT-Offline/packages/local-service/src/modifications/module-status.ts
T
N0VAN0M4LY 885966aa7e Stock newly unlocked ammunition and crew replenishment
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.
2026-11-26 02:14:00 +08:00

79 lines
3.7 KiB
TypeScript

/**
* 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;
}
export function arePrerequisitesOwned(profile: BlkBlock, vehicle: string, requires: readonly string[]): boolean {
return requires.every((required) => ownsModification(profile, vehicle, required));
}
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 arePrerequisitesOwned(profile, vehicle, modification.requires) ? ModuleStatus.CAN_BUY : ModuleStatus.LOCKED;
}