Support first-run selection and optional tutorials
Save the selected country, starting crew, and unlocks when the client submits its first-run selection. Use the stock unlock and crew formats. Enable the existing option to skip the basic tutorial. The client reached the hangar. Tutorial verification is pending.
This commit is contained in:
1 parent
c3c5f583ad
commit
6ed498e4d0
8 files changed
+227
-10
No files matched your search
@@ -4,6 +4,7 @@ import type { PlayerProfiles } from '../../profile/player-profiles.ts';
|
||||
import type { CharActionHandler } from '../char-action.ts';
|
||||
import { acceptEula } from './agreement-actions.ts';
|
||||
import { entitlementsFull, initialMeta, legacyUserData } from './online-init-actions.ts';
|
||||
import { setStartingInfo } from './starting-info-actions.ts';
|
||||
|
||||
export interface ActionDependencies {
|
||||
readonly profiles: PlayerProfiles;
|
||||
@@ -16,5 +17,6 @@ export function actionTable(deps: ActionDependencies): ReadonlyMap<string, CharA
|
||||
['cln_upd_entitlements_full', entitlementsFull(deps.profiles, deps.accounts)],
|
||||
['cln_legacy_get_userdata', legacyUserData(deps.profiles, deps.accounts)],
|
||||
['cln_accept_eula', acceptEula(deps.profiles, deps.accounts)],
|
||||
['cln_set_starting_info', setStartingInfo(deps.profiles, deps.accounts)],
|
||||
]);
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* The new player's first choice (implementation notes, step 6).
|
||||
*
|
||||
* The stock "first choice" window (gui.vromfs.bin scripts/firstChoice/unitTypeChoiceHandler.nut,
|
||||
* clnSetStartingInfo) sends cln_set_starting_info with:
|
||||
* country:t the country picked
|
||||
* unitType:i the vehicle type picked
|
||||
* unlock:t repeated: every country, and "chosen_unit_type_<type>" for the type picked
|
||||
* batchTrainCrew{ trainCrew{ crewId:i unitName:t } ... } the vehicle for every crew slot
|
||||
* ("" leaves the slot empty)
|
||||
* The login script waits until the vehicle type counts as chosen, which the client reads as
|
||||
* the unlock "chosen_unit_type_<type>" being earned (scripts/unit/unitTypesList.nut
|
||||
* isFirstChosen). The client applies the answer as a profile update
|
||||
* (GameSaveData::onAsyncEconTransComplete -> onUpdateProfile, job type 13), so the answer is
|
||||
* the whole updated profile.
|
||||
*
|
||||
* The country picked is also recorded as chosen ("chosen_country_<country>", defined in
|
||||
* config/unlocks.blk). The stock scripts start the base tutorial by force for a player who
|
||||
* has a chosen vehicle type but no chosen country (scripts/tutorials.nut checkTutorialOnStart:
|
||||
* needAutoStartTutorial = !hasRunTutorialDialog(), which is false while
|
||||
* scripts/user/newbieTutorialDisplay.nut reqFirstCountryChoice() holds). With the country
|
||||
* chosen, they offer the tutorial instead, which the player may skip (local verification; the
|
||||
* skip itself is the feature AllowedToSkipBaseTutorials, set by the build).
|
||||
*/
|
||||
import { findBlock, findParam, type BlkBlock } from '@wto/blk';
|
||||
import type { AccountStore } from '../../accounts/account-store.ts';
|
||||
import { clientProfile } from '../../profile/client-profile.ts';
|
||||
import { crewOf, putVehicleInCrew } from '../../profile/profile-crews.ts';
|
||||
import { addUnlock } from '../../profile/profile-unlocks.ts';
|
||||
import type { PlayerProfiles } from '../../profile/player-profiles.ts';
|
||||
import type { CharActionHandler } from '../char-action.ts';
|
||||
import { withAccount } from './account-context.ts';
|
||||
|
||||
interface CrewVehicle {
|
||||
readonly crewId: number;
|
||||
readonly vehicle: string;
|
||||
}
|
||||
|
||||
export function setStartingInfo(profiles: PlayerProfiles, accounts: AccountStore): CharActionHandler {
|
||||
return (context) => withAccount(context, accounts, (account) => {
|
||||
const payload = context.payload;
|
||||
if (!payload) return { kind: 'error', code: 'BAD_PARAMS' };
|
||||
const unlocks = payload.params.flatMap((param) => (param.name === 'unlock' && param.value.type === 'string' ? [param.value.value] : []));
|
||||
const country = findParam(payload, 'country')?.value;
|
||||
const crews = crewVehicles(findBlock(payload, 'batchTrainCrew'));
|
||||
if (unlocks.length === 0 || crews === undefined || country?.type !== 'string' || !country.value.startsWith('country_')) {
|
||||
return { kind: 'error', code: 'BAD_PARAMS' };
|
||||
}
|
||||
unlocks.push(`chosen_${country.value}`);
|
||||
|
||||
const current = profiles.profileOf(account.userId);
|
||||
if (crews.some(({ crewId }) => crewOf(current, crewId) === undefined)) return { kind: 'error', code: 'BAD_PARAMS' };
|
||||
|
||||
const profile = profiles.update(account.userId, (saved) => {
|
||||
for (const unlock of unlocks) addUnlock(saved, unlock);
|
||||
for (const { crewId, vehicle } of crews) {
|
||||
if (vehicle !== '') putVehicleInCrew(crewOf(saved, crewId)!, vehicle);
|
||||
}
|
||||
});
|
||||
return { kind: 'data', blk: clientProfile(profile, account) };
|
||||
});
|
||||
}
|
||||
|
||||
/** The crew slots of batchTrainCrew, or undefined when an entry is malformed. */
|
||||
function crewVehicles(batch: BlkBlock | undefined): CrewVehicle[] | undefined {
|
||||
if (!batch) return [];
|
||||
const result: CrewVehicle[] = [];
|
||||
for (const entry of batch.blocks) {
|
||||
if (entry.name !== 'trainCrew') continue;
|
||||
const crewId = findParam(entry, 'crewId')?.value;
|
||||
const vehicle = findParam(entry, 'unitName')?.value;
|
||||
if (crewId?.type !== 'int' || vehicle?.type !== 'string') return undefined;
|
||||
result.push({ crewId: crewId.value, vehicle: vehicle.value });
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Crews in the profile, as in Gaijin's config/default_user.blk:
|
||||
*
|
||||
* crews{
|
||||
* c0{
|
||||
* country:t="country_usa"
|
||||
* aircrafts{ trained:t="bf2c_1" trained:t="p-26a_34_m2" current:t="bf2c_1" }
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* "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';
|
||||
|
||||
const CREWS = 'crews';
|
||||
const VEHICLES = 'aircrafts';
|
||||
const TRAINED = 'trained';
|
||||
const CURRENT = 'current';
|
||||
|
||||
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 {
|
||||
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 });
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* Earned unlocks in the profile.
|
||||
*
|
||||
* unlocks{
|
||||
* unlock{ item:t="country_usa" cachedIndex:i=-1 expired:b=no earned:b=yes }
|
||||
* }
|
||||
*
|
||||
* The client's profile reader (aces.exe 2.61.0.37 0x919060, from 0x91bad2) walks the
|
||||
* sub-blocks of "unlocks" named "unlock" and reads each one's parameters in this order,
|
||||
* matching every position by name:
|
||||
* item:t the unlock's id from config/unlocks.blk; must come first
|
||||
* ("TROPHY: Bad DataBlock for unlock - NO id param" otherwise)
|
||||
* cachedIndex:i optional; the unlock's position in the client's table, only a
|
||||
* lookup hint: a negative value makes the client look it up by name
|
||||
* (0x91c052)
|
||||
* expired:b optional
|
||||
* removeTimeMinutes:i optional
|
||||
* earned:b only "earned:b=yes" marks the unlock earned (0x91c289..0x91c2b7
|
||||
* sets the flag that the script function is_unlocked, 0x179eae0,
|
||||
* reads); without it the unlock is registered but not earned
|
||||
* The client's own profile writer (0x91cd6f..) emits the same head: item, cachedIndex,
|
||||
* expired, then removeTimeMinutes when set, then earned.
|
||||
*/
|
||||
import { ensureBlock, findParam, type BlkBlock, type BlkParam } from '@wto/blk';
|
||||
|
||||
const UNLOCKS = 'unlocks';
|
||||
const UNLOCK = 'unlock';
|
||||
const ITEM = 'item';
|
||||
|
||||
/** Record the unlock as earned, rewriting an existing entry for it. */
|
||||
export function addUnlock(profile: BlkBlock, name: string): void {
|
||||
const unlocks = ensureBlock(profile, UNLOCKS);
|
||||
const existing = unlocks.blocks.find((unlock) => unlockName(unlock) === name);
|
||||
if (existing) existing.params = earnedUnlockParams(name);
|
||||
else unlocks.blocks.push({ name: UNLOCK, params: earnedUnlockParams(name), blocks: [] });
|
||||
}
|
||||
|
||||
function earnedUnlockParams(name: string): BlkParam[] {
|
||||
return [
|
||||
{ name: ITEM, value: { type: 'string', value: name } },
|
||||
{ name: 'cachedIndex', value: { type: 'int', value: -1 } },
|
||||
{ name: 'expired', value: { type: 'bool', value: false } },
|
||||
{ name: 'earned', value: { type: 'bool', value: true } },
|
||||
];
|
||||
}
|
||||
|
||||
function unlockName(unlock: BlkBlock): string | undefined {
|
||||
if (unlock.name !== UNLOCK) return undefined;
|
||||
const item = findParam(unlock, ITEM)?.value;
|
||||
return item?.type === 'string' ? item.value : undefined;
|
||||
}
|
||||
Reference in new issue
Block a user