Grant reserve vehicles and support crew presets
Derive reserve vehicles from the stock economy data. Grant all reserves and mark the basic takeoff and landing tutorials complete in new saves. Apply the same grants through the format 2 migration. Use shared crew slot rules for first-run selection, presets, training, assignment, and removal.
This commit is contained in:
1 parent
40af06edad
commit
2fc28dd7a5
16 files changed
+366
-57
No files matched your search
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* Putting vehicles into crew slots: the first choice (cln_set_starting_info) and applying a
|
||||
* slotbar preset (cln_bulk_train_aircraft) send a list of crew slot -> vehicle (gui.vromfs.bin
|
||||
* scripts/crew/crewTrain.nut createBatchTrainCrewRequestBlk); taking a vehicle into one slot
|
||||
* or clearing it (cln_train_aircraft) sends a single one. An empty vehicle name leaves the
|
||||
* slot empty.
|
||||
*
|
||||
* A slot can only take a vehicle the player owns, as online. Training a crew for a vehicle
|
||||
* costs nothing yet: the economy rules do not exist so far.
|
||||
*/
|
||||
import type { BlkBlock } from '@wto/blk';
|
||||
import { crewOf, emptyCrewSlot, putVehicleInCrew, trainCrewFor } from './profile-crews.ts';
|
||||
import { ownsVehicle } from './profile-hangar.ts';
|
||||
|
||||
export interface CrewSlotAssignment {
|
||||
readonly crewId: number;
|
||||
/** Empty: leave the slot empty. */
|
||||
readonly vehicle: string;
|
||||
}
|
||||
|
||||
/** Every crew exists and every vehicle is owned. */
|
||||
export function canAssignCrewSlots(profile: BlkBlock, assignments: readonly CrewSlotAssignment[]): boolean {
|
||||
return assignments.every(({ crewId, vehicle }) => crewOf(profile, crewId) !== undefined && (vehicle === '' || ownsVehicle(profile, vehicle)));
|
||||
}
|
||||
|
||||
/** Apply assignments that canAssignCrewSlots accepted. */
|
||||
export function assignCrewSlots(profile: BlkBlock, assignments: readonly CrewSlotAssignment[]): void {
|
||||
for (const { crewId, vehicle } of assignments) {
|
||||
const crew = crewOf(profile, crewId)!;
|
||||
if (vehicle === '') emptyCrewSlot(crew);
|
||||
else putVehicleInCrew(crew, vehicle);
|
||||
}
|
||||
}
|
||||
|
||||
/** Train one crew for a vehicle without changing its slot; the assignment must have passed canAssignCrewSlots. */
|
||||
export function trainCrewKeepingSlot(profile: BlkBlock, { crewId, vehicle }: CrewSlotAssignment): void {
|
||||
if (vehicle !== '') trainCrewFor(crewOf(profile, crewId)!, vehicle);
|
||||
}
|
||||
@@ -1,9 +1,12 @@
|
||||
/**
|
||||
* A new account's profile. The starting content is Gaijin's own new-account template from
|
||||
* the player's game files (config/default_user.blk), copied as it is.
|
||||
* A new account's profile: Gaijin's own new-account template from the player's game files
|
||||
* (config/default_user.blk), plus the offline starting content (starting-content.ts).
|
||||
*/
|
||||
import type { BlkBlock } from '@wto/blk';
|
||||
import { applyStartingContent, type StartingContent } from './starting-content.ts';
|
||||
|
||||
export function newProfile(template: BlkBlock): BlkBlock {
|
||||
return structuredClone(template);
|
||||
export function newProfile(template: BlkBlock, content: StartingContent): BlkBlock {
|
||||
const profile = structuredClone(template);
|
||||
applyStartingContent(profile, content);
|
||||
return profile;
|
||||
}
|
||||
@@ -6,20 +6,23 @@ import type { BlkBlock } from '@wto/blk';
|
||||
import type { GameFiles } from '../game-data/game-files.ts';
|
||||
import type { SaveStore } from '../saves/save-store.ts';
|
||||
import { newProfile } from './new-profile.ts';
|
||||
import type { StartingContent } from './starting-content.ts';
|
||||
|
||||
export class PlayerProfiles {
|
||||
readonly #saves: SaveStore;
|
||||
readonly #gameFiles: GameFiles;
|
||||
readonly #startingContent: StartingContent;
|
||||
|
||||
constructor(saves: SaveStore, gameFiles: GameFiles) {
|
||||
constructor(saves: SaveStore, gameFiles: GameFiles, startingContent: StartingContent) {
|
||||
this.#saves = saves;
|
||||
this.#gameFiles = gameFiles;
|
||||
this.#startingContent = startingContent;
|
||||
}
|
||||
|
||||
profileOf(userId: string): BlkBlock {
|
||||
const saved = this.#saves.loadProfile(userId);
|
||||
if (saved) return saved;
|
||||
const created = newProfile(this.#gameFiles.newAccountTemplate());
|
||||
const created = newProfile(this.#gameFiles.newAccountTemplate(), this.#startingContent);
|
||||
this.#saves.saveProfile(userId, created);
|
||||
return created;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
* "trained" lists the vehicles the crew is trained for (repeated), "current" is the vehicle
|
||||
* in its slot.
|
||||
*/
|
||||
import { ensureBlock, setParam, type BlkBlock } from '@wto/blk';
|
||||
import { ensureBlock, type BlkBlock } from '@wto/blk';
|
||||
|
||||
const CREWS = 'crews';
|
||||
const VEHICLES = 'aircrafts';
|
||||
@@ -22,10 +22,24 @@ export function crewOf(profile: BlkBlock, crewId: number): BlkBlock | undefined
|
||||
return profile.blocks.find((block) => block.name === CREWS)?.blocks.find((crew) => crew.name === `c${crewId}`);
|
||||
}
|
||||
|
||||
/** Train the crew for the vehicle (if it is not yet) and put the vehicle in its slot. */
|
||||
export function putVehicleInCrew(crew: BlkBlock, vehicle: string): void {
|
||||
/** Leave the crew's slot empty; the vehicles it is trained for stay trained. */
|
||||
export function emptyCrewSlot(crew: BlkBlock): void {
|
||||
const vehicles = crew.blocks.find((block) => block.name === VEHICLES);
|
||||
if (vehicles) vehicles.params = vehicles.params.filter((param) => param.name !== CURRENT);
|
||||
}
|
||||
|
||||
/** Train the crew for the vehicle, if it is not yet; the vehicle in its slot stays. "current" stays last, as in Gaijin's profiles. */
|
||||
export function trainCrewFor(crew: BlkBlock, vehicle: string): void {
|
||||
const vehicles = ensureBlock(crew, VEHICLES);
|
||||
const trained = vehicles.params.some((param) => param.name === TRAINED && param.value.type === 'string' && param.value.value === vehicle);
|
||||
if (!trained) vehicles.params.push({ name: TRAINED, value: { type: 'string', value: vehicle } });
|
||||
setParam(vehicles, CURRENT, { type: 'string', value: vehicle });
|
||||
if (trained) return;
|
||||
const current = vehicles.params.filter((param) => param.name === CURRENT);
|
||||
vehicles.params = [...vehicles.params.filter((param) => param.name !== CURRENT), { name: TRAINED, value: { type: 'string', value: vehicle } }, ...current];
|
||||
}
|
||||
|
||||
/** Train the crew for the vehicle (if it is not yet) and put the vehicle in its slot. */
|
||||
export function putVehicleInCrew(crew: BlkBlock, vehicle: string): void {
|
||||
emptyCrewSlot(crew);
|
||||
trainCrewFor(crew, vehicle);
|
||||
ensureBlock(crew, VEHICLES).params.push({ name: CURRENT, value: { type: 'string', value: vehicle } });
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Owned vehicles in the profile, as in Gaijin's
|
||||
* config/default_user.blk: one empty sub-block per vehicle the player owns.
|
||||
*
|
||||
* hangar{
|
||||
* bf2c_1{
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
import { ensureBlock, findBlock, type BlkBlock } from '@wto/blk';
|
||||
|
||||
const HANGAR = 'hangar';
|
||||
|
||||
export function ownsVehicle(profile: BlkBlock, vehicle: string): boolean {
|
||||
const hangar = findBlock(profile, HANGAR);
|
||||
return hangar !== undefined && findBlock(hangar, vehicle) !== undefined;
|
||||
}
|
||||
|
||||
/** Add the vehicle to the owned vehicles; nothing changes when the player owns it already. */
|
||||
export function addOwnedVehicle(profile: BlkBlock, vehicle: string): void {
|
||||
const hangar = ensureBlock(profile, HANGAR);
|
||||
if (!hangar.blocks.some((owned) => owned.name === vehicle)) hangar.blocks.push({ name: vehicle, params: [], blocks: [] });
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Mission completion in the profile: which difficulties the player has completed a mission
|
||||
* on (tutorials and other single-player missions).
|
||||
*
|
||||
* pveProgress{
|
||||
* missions{
|
||||
* "tutorial/tutorialB_takeoff_and_landing"{ diff_0:b=yes diff_1:b=yes diff_2:b=yes }
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* Read by the client's profile serializer (aces.exe 2.61.0.37 0x92bd40: "pveProgress" ->
|
||||
* "missions", one sub-block per mission, 0x92f090), each entry by 0x92f7d0:
|
||||
* onlineDiff:i, singleDiff:i optional, -1 when missing
|
||||
* timesCompleted:i, timesPlayed:i optional, 0 when missing
|
||||
* diff_0:b, diff_1:b, diff_2:b completed on arcade, historical, simulator
|
||||
* The entry's name is the mission's full name, "<chapter>/<mission>", the key that the
|
||||
* script function get_mission_progress (0x179c900 -> 0xebad60) looks up. It returns the
|
||||
* highest difficulty completed (0, 1, 2), or 3 or more when there is none.
|
||||
*/
|
||||
import { ensureBlock, setParam, type BlkBlock } from '@wto/blk';
|
||||
|
||||
const PVE_PROGRESS = 'pveProgress';
|
||||
const MISSIONS = 'missions';
|
||||
const DIFFICULTIES = [0, 1, 2] as const;
|
||||
|
||||
/** Record the mission as completed on every difficulty up to and including `highest` (0, 1 or 2). */
|
||||
export function recordMissionCompleted(profile: BlkBlock, fullMissionName: string, highest: 0 | 1 | 2): void {
|
||||
const entry = ensureBlock(ensureBlock(ensureBlock(profile, PVE_PROGRESS), MISSIONS), fullMissionName);
|
||||
for (const difficulty of DIFFICULTIES) {
|
||||
if (difficulty <= highest) setParam(entry, `diff_${difficulty}`, { type: 'bool', value: true });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* The save format's upgrade steps (saves/save-upgrades.ts), in version order. A step is
|
||||
* never changed once released; a later change to saves adds a new step.
|
||||
*/
|
||||
import { SaveUpgrades } from '../saves/save-upgrades.ts';
|
||||
import { applyStartingContent, type StartingContent } from './starting-content.ts';
|
||||
|
||||
export function profileUpgrades(content: StartingContent): SaveUpgrades {
|
||||
return new SaveUpgrades([
|
||||
// 1 -> 2: the starting content (reserve vehicles of every branch, completed
|
||||
// difficulty-gating tutorials) for saves made before new accounts had it.
|
||||
(profile) => applyStartingContent(profile, content),
|
||||
]);
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* What every account starts with besides Gaijin's new-account template
|
||||
* (config/default_user.blk), which owns only reserve aircraft.
|
||||
*
|
||||
* - Every reserve vehicle of every country and branch (aircraft, ground vehicles, boats,
|
||||
* ships), as accounts have them online. The stock first-choice window and the slotbar
|
||||
* only offer reserve vehicles the player owns (scripts/slotbar/slotbarStateData.nut
|
||||
* checkReserveUnit: isBought), so without them a new player only has aircraft.
|
||||
* - The base tutorials that gate a difficulty count as completed on every difficulty, so no
|
||||
* game mode asks for a tutorial first (user quotes 87, 92; the tutorials stay playable).
|
||||
* The stock rule (gui.vromfs.bin scripts/tutorials/tutorialsState.nut isDiffUnlocked)
|
||||
* locks historical and simulator battles for a vehicle type until the player has either
|
||||
* played 60 s in one of them or completed the type's required tutorial on that difficulty;
|
||||
* the required tutorials are the table reqTutorial there (2.61.0.37: aircraft only,
|
||||
* tutorialB_takeoff_and_landing, chapter "tutorial" in char.vromfs.bin config/mislist.blk
|
||||
* block "training").
|
||||
*
|
||||
* Applying it again changes nothing, so it also brings older saves up to date
|
||||
* (profile-upgrades.ts).
|
||||
*/
|
||||
import type { BlkBlock } from '@wto/blk';
|
||||
import type { ReserveVehicle } from '../game-data/datasets/reserve-vehicles.ts';
|
||||
import { addOwnedVehicle } from './profile-hangar.ts';
|
||||
import { recordMissionCompleted } from './profile-mission-progress.ts';
|
||||
|
||||
const DIFFICULTY_GATING_TUTORIALS = ['tutorial/tutorialB_takeoff_and_landing'] as const;
|
||||
const HIGHEST_DIFFICULTY = 2;
|
||||
|
||||
export interface StartingContent {
|
||||
readonly reserveVehicles: readonly ReserveVehicle[];
|
||||
}
|
||||
|
||||
export function applyStartingContent(profile: BlkBlock, content: StartingContent): void {
|
||||
for (const vehicle of content.reserveVehicles) addOwnedVehicle(profile, vehicle.name);
|
||||
for (const tutorial of DIFFICULTY_GATING_TUTORIALS) recordMissionCompleted(profile, tutorial, HIGHEST_DIFFICULTY);
|
||||
}
|
||||
Reference in new issue
Block a user