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.
114 lines
5.1 KiB
TypeScript
114 lines
5.1 KiB
TypeScript
/**
|
|
* Bringing the research state of a profile up to date. The char
|
|
* server keeps it current online; the local server does it whenever a profile is handed out
|
|
* or changed (profile/player-profiles.ts), so the state always follows from the facts:
|
|
* owned vehicles, research points, earned unlocks, banked excess research points.
|
|
*
|
|
* 1. Open ranks and earn unlocks until neither changes anything (an unlock can give a vehicle,
|
|
* a vehicle can open a rank, a rank can earn an unlock).
|
|
* 2. Write every vehicle's status into unitResearch: owned vehicles have no entry, locked
|
|
* vehicles only keep one while they hold research points.
|
|
* 3. Keep every branch researching while it can: a target that is no
|
|
* longer researchable (bought, researched, ...) is cleared, and a new one is picked by
|
|
* auto-research-target.ts when the branch has just finished a vehicle (prevUnit set: the
|
|
* stock scripts then open the "choose the next research" window, ShopCheckResearch, from
|
|
* scripts/researches/researchActions.nut checkNonApprovedResearches) or has no banked
|
|
* exp<Branch>. With banked RP and nothing just finished it stays empty, so the player chooses
|
|
* where the RP goes (cln_move_exp_to_unit). A branch with nothing left to research has its
|
|
* banked RP cleared.
|
|
*/
|
|
import type { BlkBlock } from '@wto/blk';
|
|
import { ownedVehicles } from '../profile/profile-hangar.ts';
|
|
import {
|
|
branchExcessRp,
|
|
finishedResearch,
|
|
researchTarget,
|
|
setBranchExcessRp,
|
|
setResearchTarget,
|
|
} from '../profile/profile-research-targets.ts';
|
|
import { earnedUnlocks } from '../profile/profile-unlocks.ts';
|
|
import { removeVehicleResearch, researchPointsOf, setVehicleStatus } from '../profile/profile-vehicle-research.ts';
|
|
import { pickResearchTarget } from './auto-research-target.ts';
|
|
import { openEarnedRanks } from './era-progress.ts';
|
|
import type { ResearchRules } from './research-rules.ts';
|
|
import type { TreeVehicle } from './tech-tree.ts';
|
|
import { VehicleStatus, vehicleStatuses } from './vehicle-status.ts';
|
|
import { earnVehicleUnlocks } from './vehicle-unlock-rules.ts';
|
|
|
|
const MAX_ROUNDS = 16;
|
|
|
|
export function refreshResearchState(profile: BlkBlock, rules: ResearchRules): void {
|
|
const owned = ownedVehicles(profile);
|
|
const earned = earnedUnlocks(profile);
|
|
for (let round = 0; round < MAX_ROUNDS; round++) {
|
|
const ranksChanged = openEarnedRanks(profile, owned, rules.techTree, rules.eraRequirements);
|
|
const unlocksChanged = earnVehicleUnlocks(profile, { earned, owned }, rules.vehicleUnlocks, rules.techTree);
|
|
if (!ranksChanged && !unlocksChanged) break;
|
|
}
|
|
|
|
const statuses = vehicleStatuses({ profile, owned, earnedUnlocks: earned, techTree: rules.techTree });
|
|
for (const vehicle of rules.techTree.all()) {
|
|
const status = statuses.get(vehicle.name);
|
|
if (status === undefined || (status === VehicleStatus.LOCKED && researchPointsOf(profile, vehicle.name) === 0)) {
|
|
removeVehicleResearch(profile, vehicle.name);
|
|
} else {
|
|
setVehicleStatus(profile, vehicle.name, status);
|
|
}
|
|
}
|
|
|
|
const candidates = researchCandidates(rules, statuses);
|
|
const unresearchedBranches = branchesWithUnresearchedTreeVehicles(rules, statuses);
|
|
for (const { country, type } of rules.techTree.branches()) {
|
|
const key = `${country}/${type}`;
|
|
if (!unresearchedBranches.has(key)) {
|
|
setBranchExcessRp(profile, country, type, 0);
|
|
}
|
|
const target = researchTarget(profile, country, type);
|
|
if (target && statuses.get(target) === VehicleStatus.CAN_RESEARCH) continue;
|
|
if (target) setResearchTarget(profile, country, type, '');
|
|
|
|
const prev = finishedResearch(profile, country, type);
|
|
const excess = branchExcessRp(profile, country, type);
|
|
if (prev !== '' || excess === 0) {
|
|
const next = pickResearchTarget(candidates.get(key) ?? [], rules.researchTuning, target || prev);
|
|
setResearchTarget(profile, country, type, next?.name ?? '');
|
|
}
|
|
}
|
|
}
|
|
|
|
function researchCandidates(rules: ResearchRules, statuses: ReadonlyMap<string, VehicleStatus>): Map<string, TreeVehicle[]> {
|
|
const byBranch = new Map<string, TreeVehicle[]>();
|
|
for (const vehicle of rules.techTree.all()) {
|
|
if (vehicle.kind !== 'research' || statuses.get(vehicle.name) !== VehicleStatus.CAN_RESEARCH) continue;
|
|
const key = `${vehicle.country}/${vehicle.type}`;
|
|
const list = byBranch.get(key);
|
|
if (list) list.push(vehicle);
|
|
else byBranch.set(key, [vehicle]);
|
|
}
|
|
return byBranch;
|
|
}
|
|
|
|
function branchesWithUnresearchedTreeVehicles(
|
|
rules: ResearchRules,
|
|
statuses: ReadonlyMap<string, VehicleStatus>,
|
|
): Set<string> {
|
|
const branches = new Set<string>();
|
|
for (const vehicle of rules.techTree.all()) {
|
|
if (vehicle.kind !== 'research') continue;
|
|
const status = statuses.get(vehicle.name);
|
|
if (status === VehicleStatus.CAN_RESEARCH || status === VehicleStatus.LOCKED) {
|
|
branches.add(`${vehicle.country}/${vehicle.type}`);
|
|
}
|
|
}
|
|
return branches;
|
|
}
|
|
|
|
export function currentStatus(profile: BlkBlock, rules: ResearchRules, vehicle: string): VehicleStatus | undefined {
|
|
return vehicleStatuses({
|
|
profile,
|
|
owned: ownedVehicles(profile),
|
|
earnedUnlocks: earnedUnlocks(profile),
|
|
techTree: rules.techTree,
|
|
}).get(vehicle);
|
|
}
|