feat(crew): add skills, qualifications, and training fees
Support spending crew skill points, buying skill point packs, and purchasing expert and ace qualifications. Charge for training a crew on an unfamiliar vehicle and expose the skill pack prices.
This commit is contained in:
1 parent
28909cf1e9
commit
40f088a912
11 files changed
+370
-11
No files matched your search
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
* Crew skills, skill points and specializations inside a crew block:
|
||||
*
|
||||
* crews{
|
||||
* c0{
|
||||
* country:t="country_usa"
|
||||
* aircrafts{ trained:t="us_m2a4" spec:i=1 trained:t="us_m22_locust" spec:i=0 current:t="us_m2a4" }
|
||||
* commander{ crewMember_0{ eyesight:i64=5 field_repair:i64=2 } }
|
||||
* skillPointsStat:i64=0
|
||||
* skillPointsManualChanges:i64=150000
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* Skill levels sit in <page>/crewMember_0 as i64 (aces.exe 0x939b40..0x939c62). Skill points are
|
||||
* kept times 100: the client shows (skillPointsStat + skillPointsManualChanges) / 100
|
||||
* (get_crew_info, 0x179dbac); the local service books what the player buys and spends in
|
||||
* skillPointsManualChanges. Every trained vehicle is followed by its spec (0 none, 1 expert,
|
||||
* 2 ace), as the client writes them (0x939ed0..0x939f55).
|
||||
*/
|
||||
import { ensureBlock, findBlock, findParam, setParam, type BlkBlock, type BlkParam } from '@wto/blk';
|
||||
|
||||
const MEMBER = 'crewMember_0';
|
||||
const EARNED_POINTS = 'skillPointsStat';
|
||||
const BOOKED_POINTS = 'skillPointsManualChanges';
|
||||
const POINTS_SCALE = 100;
|
||||
const VEHICLES = 'aircrafts';
|
||||
const TRAINED = 'trained';
|
||||
const SPEC = 'spec';
|
||||
|
||||
export function skillLevel(crew: BlkBlock, page: string, skill: string): number {
|
||||
const pageBlock = findBlock(crew, page);
|
||||
const member = pageBlock && findBlock(pageBlock, MEMBER);
|
||||
return member ? intOf(member, skill) : 0;
|
||||
}
|
||||
|
||||
export function setSkillLevel(crew: BlkBlock, page: string, skill: string, level: number): void {
|
||||
setParam(ensureBlock(ensureBlock(crew, page), MEMBER), skill, { type: 'int64', value: BigInt(level) });
|
||||
}
|
||||
|
||||
/** Skill points as the player sees them. */
|
||||
export function skillPoints(crew: BlkBlock): number {
|
||||
return Math.floor((intOf(crew, EARNED_POINTS) + intOf(crew, BOOKED_POINTS)) / POINTS_SCALE);
|
||||
}
|
||||
|
||||
export function addSkillPoints(crew: BlkBlock, points: number): void {
|
||||
setParam(crew, BOOKED_POINTS, { type: 'int64', value: BigInt(intOf(crew, BOOKED_POINTS) + points * POINTS_SCALE) });
|
||||
}
|
||||
|
||||
export function isTrainedFor(crew: BlkBlock, vehicle: string): boolean {
|
||||
return (findBlock(crew, VEHICLES)?.params ?? []).some((param) => param.name === TRAINED && param.value.type === 'string' && param.value.value === vehicle);
|
||||
}
|
||||
|
||||
export function specializationOf(crew: BlkBlock, vehicle: string): number {
|
||||
return trainedPairs(crew).find((pair) => pair.vehicle === vehicle)?.spec ?? 0;
|
||||
}
|
||||
|
||||
export function setSpecialization(crew: BlkBlock, vehicle: string, spec: number): void {
|
||||
const vehicles = ensureBlock(crew, VEHICLES);
|
||||
const pairs = trainedPairs(crew).map((pair) => pair.vehicle === vehicle ? { ...pair, spec } : pair);
|
||||
const rest = vehicles.params.filter((param) => param.name !== TRAINED && param.name !== SPEC);
|
||||
vehicles.params = [
|
||||
...pairs.flatMap((pair): BlkParam[] => [
|
||||
{ name: TRAINED, value: { type: 'string', value: pair.vehicle } },
|
||||
{ name: SPEC, value: { type: 'int', value: pair.spec } },
|
||||
]),
|
||||
...rest,
|
||||
];
|
||||
}
|
||||
|
||||
/** trained/spec pairs in order; a trained vehicle without a following spec has spec 0. */
|
||||
function trainedPairs(crew: BlkBlock): { vehicle: string; spec: number }[] {
|
||||
const pairs: { vehicle: string; spec: number }[] = [];
|
||||
for (const param of findBlock(crew, VEHICLES)?.params ?? []) {
|
||||
if (param.name === TRAINED && param.value.type === 'string') pairs.push({ vehicle: param.value.value, spec: 0 });
|
||||
else if (param.name === SPEC && param.value.type === 'int' && pairs.length) pairs[pairs.length - 1]!.spec = param.value.value;
|
||||
}
|
||||
return pairs;
|
||||
}
|
||||
|
||||
function intOf(block: BlkBlock, name: string): number {
|
||||
const value = findParam(block, name)?.value;
|
||||
if (value?.type === 'int64') return Number(value.value);
|
||||
return value?.type === 'int' ? value.value : 0;
|
||||
}
|
||||
Reference in new issue
Block a user