Files
WT-Offline/apps/server/src/research/tech-tree.ts
T
N0VAN0M4LY 930ea07630 refactor(repo)!: move apps, shared packages, and patch definitions
Everything sat in packages/: two programs next to the small libraries
they use, and the patch data loose at the root. The programs now live in
apps/ and the shared libraries in packages/:

  apps/server        the local server (was packages/local-service),
                     package @wto/server
  packages/patcher   builds the game copy (was packages/build),
                     package @wto/patcher
  patches/exe        exe patch definitions (was exe-patches)
  patches/gui        GUI script patches (was gui-patches)

Inside the server, the network layer folder becomes transport/ so it is
not server/server/, the entry module is server.ts, and startLocalService
and its types become startServer, ServerOptions and RunningServer. The
health answer names the app wto-server, and the TLS files in the data
folder are server.key and server.crt (made again on the next start).
Comments, logs and tool texts say "local server".

The patcher no longer reaches into the server's folder. It read the
default tuning/store.jsonc by a relative path to register bundle GUIDs
for the multi-vehicle packs, which also ignored the player's overrides
in <data>/tuning/. It now takes the pack ids from its caller; the
server exports multiVehiclePackIds(dataFolder), which reads them the way
the running server does. rebuildGuiPack takes the patch folder from its
caller as well.

The development build moves out of the patcher to
scripts/build-game-copy.ts, since it uses both the server and the
patcher. It needs --data (the folder the server will run with) and
defaults the patch folders and the hook library to this repository.


Checked with the root typecheck, check-patches, check-gui,
check-offsets, the native build, a run of build-game-copy.ts into a
scratch folder (12 exe patches, 35 GUI patches, 496 bundle GUIDs as
before) and a server start from apps/server answering wto-server.

BREAKING CHANGE: Use @wto/server and @wto/patcher from the new workspace paths. Run the development build with scripts/build-game-copy.ts and pass --data.
2026-11-29 03:20:54 +08:00

90 lines
4.2 KiB
TypeScript

/**
* The vehicles as research and purchase see them: the catalogue (game-data vehicle-catalogue)
* with each vehicle's type and how it is obtained.
*
* Kinds, checked in this order:
* part the separate part of a split vehicle; comes with its main vehicle
* hidden shop.blk showOnlyWhenBought: event and promotion prizes, mission copies,
* drones, ship floatplanes; the stock UI only shows them to players who own
* them, so they are not offered
* squadron researchType clanVehicle: researched with squadron research points or bought
* early for golden eagles (feature-inventory I, later); no rank requirement
* gift gift:t: packs and marketplace vehicles; the stock scripts never offer them
* for silver lions or golden eagles (scripts/unit/unitShopInfo.nut
* canBuyUnitEvenNotInShop); the local shop gives them (feature-inventory G, later)
* event event:t (feature-inventory G, later)
* premium costGold > 0 or premPackAir (the scripts' isUnitSpecial): bought for golden
* eagles without research, rank or previous vehicle
* research reqExp > 0: researched, then bought
* purchase no reqExp: bought without research (helicopters that start a branch, free
* vehicles unlocked by an achievement, reserve vehicles)
*/
import type { CatalogueVehicle } from '../game-data/datasets/vehicle-catalogue.ts';
import { vehicleTypeOfClass, type VehicleType } from './vehicle-types.ts';
export type VehicleKind = 'part' | 'hidden' | 'squadron' | 'gift' | 'event' | 'premium' | 'research' | 'purchase';
export interface TreeVehicle extends CatalogueVehicle {
readonly type: VehicleType;
readonly kind: VehicleKind;
}
const SQUADRON_RESEARCH = 'clanVehicle';
export class TechTree {
readonly #vehicles: ReadonlyMap<string, TreeVehicle>;
constructor(catalogue: readonly CatalogueVehicle[]) {
const parts = new Set(catalogue.filter((vehicle) => vehicle.inTechTree).flatMap((vehicle) => vehicle.parts));
const vehicles = new Map<string, TreeVehicle>();
for (const vehicle of catalogue) {
const type = vehicleTypeOfClass(vehicle.unitClass);
// Without a type or country the client's status function locks the vehicle (0x911750, 0x961dd0).
if (type && vehicle.country) vehicles.set(vehicle.name, { ...vehicle, type, kind: kindOf(vehicle, parts) });
}
this.#vehicles = vehicles;
}
vehicle(name: string): TreeVehicle | undefined {
return this.#vehicles.get(name);
}
/** Every vehicle with a type and country, in the tech tree or not. */
all(): Iterable<TreeVehicle> {
return this.#vehicles.values();
}
/** The countries and vehicle types that have vehicles in the tech tree, with their highest rank. */
branches(): { country: string; type: VehicleType; highestRank: number }[] {
const highest = new Map<string, { country: string; type: VehicleType; highestRank: number }>();
for (const vehicle of this.#vehicles.values()) {
if (!vehicle.inTechTree) continue;
const key = `${vehicle.country}/${vehicle.type}`;
const known = highest.get(key);
if (!known) highest.set(key, { country: vehicle.country, type: vehicle.type, highestRank: vehicle.rank });
else known.highestRank = Math.max(known.highestRank, vehicle.rank);
}
return [...highest.values()];
}
hasCountry(country: string): boolean {
for (const vehicle of this.#vehicles.values()) if (vehicle.inTechTree && vehicle.country === country) return true;
return false;
}
}
function kindOf(vehicle: CatalogueVehicle, parts: ReadonlySet<string>): VehicleKind {
if (parts.has(vehicle.name)) return 'part';
if (vehicle.onlyShownWhenOwned) return 'hidden';
if (vehicle.researchType === SQUADRON_RESEARCH) return 'squadron';
if (vehicle.gift) return 'gift';
if (vehicle.event) return 'event';
if (vehicle.goldenEagles > 0 || vehicle.premiumPack) return 'premium';
return vehicle.researchPoints > 0 ? 'research' : 'purchase';
}
/** Premium-like vehicles for unlock conditions that count "premium" vehicles separately (unlocks.blk premium:b). */
export function isPremiumKind(kind: VehicleKind): boolean {
return kind === 'premium' || kind === 'gift' || kind === 'event';
}