feat(crew): add crew presets and grant reserve vehicles
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
1d9c92a9d0
commit
ed0136f5fc
16 files changed
+366
-57
No files matched your search
@@ -3,6 +3,7 @@ import type { AccountStore } from '../../accounts/account-store.ts';
|
||||
import type { PlayerProfiles } from '../../profile/player-profiles.ts';
|
||||
import type { CharActionHandler } from '../char-action.ts';
|
||||
import { acceptEula } from './agreement-actions.ts';
|
||||
import { bulkTrainCrews, trainCrew } from './crew-actions.ts';
|
||||
import { entitlementsFull, initialMeta, legacyUserData } from './online-init-actions.ts';
|
||||
import { setStartingInfo } from './starting-info-actions.ts';
|
||||
|
||||
@@ -18,5 +19,7 @@ export function actionTable(deps: ActionDependencies): ReadonlyMap<string, CharA
|
||||
['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)],
|
||||
['cln_bulk_train_aircraft', bulkTrainCrews(deps.profiles, deps.accounts)],
|
||||
['cln_train_aircraft', trainCrew(deps.profiles, deps.accounts)],
|
||||
]);
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* Crew actions. The client applies the answer to each as a profile update (aces.exe
|
||||
* 2.61.0.37 GameSaveData::onAsyncEconTransComplete 0xeb5f60: job types 11 and 13 are both in
|
||||
* the profile set, mask 0x301800822fbf at 0xeb61c4), so each answers the whole updated profile.
|
||||
*
|
||||
* cln_bulk_train_aircraft (job type 13, sent with char_send_blk, 0x2991f0): put vehicles into
|
||||
* several crew slots at once; the stock slotbar sends it when the player applies a slotbar
|
||||
* preset (gui.vromfs.bin scripts/crew/crewTrain.nut batchTrainCrew). Body: the crew slot list
|
||||
* (crew-slots-payload.ts).
|
||||
*
|
||||
* cln_train_aircraft (job type 11, sent by the native chard.trainCrewAircraft, 0x299b40):
|
||||
* take a vehicle into one crew slot, or clear the slot (scripts/crew/crewTakeUnitProcess.nut),
|
||||
* or only train the crew for it (scripts/crew/crewActionsWithMsgBox.nut
|
||||
* trainCrewUnitWithoutSwitchCurrUnit). Body:
|
||||
* aircraft:t the vehicle; "" clears the slot
|
||||
* idx:i the crew id
|
||||
* keep_curr:b yes: train the crew for the vehicle, leave the slot as it is
|
||||
*/
|
||||
import { findParam, type BlkBlock } from '@wto/blk';
|
||||
import type { AccountStore } from '../../accounts/account-store.ts';
|
||||
import { clientProfile } from '../../profile/client-profile.ts';
|
||||
import { assignCrewSlots, canAssignCrewSlots, trainCrewKeepingSlot, type CrewSlotAssignment } from '../../profile/crew-slots.ts';
|
||||
import type { PlayerProfiles } from '../../profile/player-profiles.ts';
|
||||
import type { CharActionHandler } from '../char-action.ts';
|
||||
import { withAccount } from './account-context.ts';
|
||||
import { readCrewSlots } from './crew-slots-payload.ts';
|
||||
|
||||
export function bulkTrainCrews(profiles: PlayerProfiles, accounts: AccountStore): CharActionHandler {
|
||||
return (context) => withAccount(context, accounts, (account) => {
|
||||
const assignments = context.payload && readCrewSlots(context.payload);
|
||||
if (!assignments || !canAssignCrewSlots(profiles.profileOf(account.userId), assignments)) return { kind: 'error', code: 'BAD_PARAMS' };
|
||||
const profile = profiles.update(account.userId, (saved) => assignCrewSlots(saved, assignments));
|
||||
return { kind: 'data', blk: clientProfile(profile, account) };
|
||||
});
|
||||
}
|
||||
|
||||
export function trainCrew(profiles: PlayerProfiles, accounts: AccountStore): CharActionHandler {
|
||||
return (context) => withAccount(context, accounts, (account) => {
|
||||
const request = context.payload && readTrainCrew(context.payload);
|
||||
if (!request || (request.keepCurrent && request.vehicle === '')) return { kind: 'error', code: 'BAD_PARAMS' };
|
||||
const { keepCurrent, ...assignment } = request;
|
||||
if (!canAssignCrewSlots(profiles.profileOf(account.userId), [assignment])) return { kind: 'error', code: 'BAD_PARAMS' };
|
||||
const profile = profiles.update(account.userId, (saved) => {
|
||||
if (keepCurrent) trainCrewKeepingSlot(saved, assignment);
|
||||
else assignCrewSlots(saved, [assignment]);
|
||||
});
|
||||
return { kind: 'data', blk: clientProfile(profile, account) };
|
||||
});
|
||||
}
|
||||
|
||||
function readTrainCrew(payload: BlkBlock): (CrewSlotAssignment & { readonly keepCurrent: boolean }) | undefined {
|
||||
const vehicle = findParam(payload, 'aircraft')?.value;
|
||||
const crewId = findParam(payload, 'idx')?.value;
|
||||
const keepCurrent = findParam(payload, 'keep_curr')?.value;
|
||||
if (vehicle?.type !== 'string' || crewId?.type !== 'int') return undefined;
|
||||
return { crewId: crewId.value, vehicle: vehicle.value, keepCurrent: keepCurrent?.type === 'bool' && keepCurrent.value };
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* The crew slot list in a char request body, written by the stock scripts
|
||||
* (gui.vromfs.bin scripts/crew/crewTrain.nut createBatchTrainCrewRequestBlk):
|
||||
*
|
||||
* batchTrainCrew{
|
||||
* trainCrew{ crewId:i=10 unitName:t="cr_32" }
|
||||
* trainCrew{ crewId:i=11 unitName:t="" } empty: leave the slot empty
|
||||
* }
|
||||
*/
|
||||
import { findBlock, findParam, type BlkBlock } from '@wto/blk';
|
||||
import type { CrewSlotAssignment } from '../../profile/crew-slots.ts';
|
||||
|
||||
/** The list, empty when the body has none, or undefined when an entry is malformed. */
|
||||
export function readCrewSlots(payload: BlkBlock): CrewSlotAssignment[] | undefined {
|
||||
const batch = findBlock(payload, 'batchTrainCrew');
|
||||
if (!batch) return [];
|
||||
const result: CrewSlotAssignment[] = [];
|
||||
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;
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
* 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)
|
||||
* (crew-slots-payload.ts; "" 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
|
||||
@@ -22,19 +22,15 @@
|
||||
* 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 { findParam } 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 { assignCrewSlots, canAssignCrewSlots } from '../../profile/crew-slots.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;
|
||||
}
|
||||
import { readCrewSlots } from './crew-slots-payload.ts';
|
||||
|
||||
export function setStartingInfo(profiles: PlayerProfiles, accounts: AccountStore): CharActionHandler {
|
||||
return (context) => withAccount(context, accounts, (account) => {
|
||||
@@ -42,35 +38,17 @@ export function setStartingInfo(profiles: PlayerProfiles, accounts: AccountStore
|
||||
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_')) {
|
||||
const assignments = readCrewSlots(payload);
|
||||
if (unlocks.length === 0 || assignments === 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' };
|
||||
if (!canAssignCrewSlots(profiles.profileOf(account.userId), assignments)) 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);
|
||||
}
|
||||
assignCrewSlots(saved, assignments);
|
||||
});
|
||||
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;
|
||||
}
|
||||
Reference in new issue
Block a user