Implement crew 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
391082278f
commit
81d33f3048
11 files changed
+370
-11
No files matched your search
@@ -6,6 +6,7 @@ import type { CharActionHandler } from '../char-action.ts';
|
||||
import { acceptEula } from './agreement-actions.ts';
|
||||
import { bulkTrainCrews, trainCrew } from './crew-actions.ts';
|
||||
import { buyAllModificationsAction, buyModificationAction, buySparesAction, enableModificationsAction } from './modification-actions.ts';
|
||||
import { purchaseSkillPointsAction, specializeCrewAction, upgradeCrewAction } from './crew-skill-actions.ts';
|
||||
import { buyResourceAction } from './decor-actions.ts';
|
||||
import { saveDecorLayoutsAction } from './decor-layout-actions.ts';
|
||||
import { entitlementsFull, initialMeta, legacyUserData } from './online-init-actions.ts';
|
||||
@@ -27,8 +28,8 @@ 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)],
|
||||
['cln_bulk_train_aircraft', bulkTrainCrews(deps.profiles, deps.accounts, deps.research)],
|
||||
['cln_train_aircraft', trainCrew(deps.profiles, deps.accounts, deps.research)],
|
||||
['cln_set_researchable', setResearchable(deps.profiles, deps.accounts, deps.research)],
|
||||
['cln_reset_researchable', resetResearchable(deps.profiles, deps.accounts, deps.research)],
|
||||
['cln_convert_exp', convertExp(deps.profiles, deps.accounts, deps.research)],
|
||||
@@ -39,6 +40,9 @@ export function actionTable(deps: ActionDependencies): ReadonlyMap<string, CharA
|
||||
['cln_buy_all_modification', buyAllModificationsAction(deps.profiles, deps.accounts, deps.research)],
|
||||
['cln_buy_spare_aircrafts', buySparesAction(deps.profiles, deps.accounts, deps.research)],
|
||||
['cln_enable_modifications', enableModificationsAction(deps.profiles, deps.accounts)],
|
||||
['cln_upgrade_crew', upgradeCrewAction(deps.profiles, deps.accounts, deps.research)],
|
||||
['cln_purchase_skill_points', purchaseSkillPointsAction(deps.profiles, deps.accounts, deps.research)],
|
||||
['cln_specialize_crew', specializeCrewAction(deps.profiles, deps.accounts, deps.research)],
|
||||
['cln_buy_resource', buyResourceAction(deps.profiles, deps.accounts, deps.research)],
|
||||
['cln_save_decals', saveDecorLayoutsAction(deps.profiles, deps.accounts, 'decals')],
|
||||
['cln_save_attachables', saveDecorLayoutsAction(deps.profiles, deps.accounts, 'attachables')],
|
||||
|
||||
@@ -21,26 +21,39 @@ 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 { trainingFee } from '../../crew/crew-training.ts';
|
||||
import { canAfford, pay } from '../../profile/profile-currency.ts';
|
||||
import type { ResearchRules } from '../../research/research-rules.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 {
|
||||
export function bulkTrainCrews(profiles: PlayerProfiles, accounts: AccountStore, rules: ResearchRules): 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));
|
||||
const current = profiles.profileOf(account.userId);
|
||||
if (!assignments || !canAssignCrewSlots(current, assignments)) return { kind: 'error', code: 'BAD_PARAMS' };
|
||||
const fee = trainingFee(current, rules.crew, assignments);
|
||||
if (!canAfford(current, fee)) return { kind: 'error', code: 'NOT_ENOUGH_MONEY' };
|
||||
const profile = profiles.update(account.userId, (saved) => {
|
||||
pay(saved, fee);
|
||||
assignCrewSlots(saved, assignments);
|
||||
});
|
||||
return { kind: 'data', blk: clientProfile(profile, account) };
|
||||
});
|
||||
}
|
||||
|
||||
export function trainCrew(profiles: PlayerProfiles, accounts: AccountStore): CharActionHandler {
|
||||
export function trainCrew(profiles: PlayerProfiles, accounts: AccountStore, rules: ResearchRules): 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 current = profiles.profileOf(account.userId);
|
||||
if (!canAssignCrewSlots(current, [assignment])) return { kind: 'error', code: 'BAD_PARAMS' };
|
||||
const fee = trainingFee(current, rules.crew, [assignment]);
|
||||
if (!canAfford(current, fee)) return { kind: 'error', code: 'NOT_ENOUGH_MONEY' };
|
||||
const profile = profiles.update(account.userId, (saved) => {
|
||||
pay(saved, fee);
|
||||
if (keepCurrent) trainCrewKeepingSlot(saved, assignment);
|
||||
else assignCrewSlots(saved, [assignment]);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Crew skill actions. All three are sent by native functions with job
|
||||
* type 1, a profile update, so each answers the whole profile. The crew is id:i (crews/c<id>).
|
||||
*
|
||||
* cln_upgrade_crew (shop_upgrade_crew, aces.exe 0x29aad0): <page>{ <skill>:i=levels to add } ... id:i
|
||||
* cln_purchase_skill_points (shop_purchase_skillpoints, 0x29e220): id:i pack:t
|
||||
* cln_specialize_crew (shop_specialize_crew, 0x29ad40): id:i aircraft:t
|
||||
*/
|
||||
import type { AccountStore } from '../../accounts/account-store.ts';
|
||||
import { buySkillPoints, specializeCrew, upgradeCrewSkills, type SkillRaise } from '../../crew/crew-skill-rules.ts';
|
||||
import type { PlayerProfiles } from '../../profile/player-profiles.ts';
|
||||
import type { ResearchRules } from '../../research/research-rules.ts';
|
||||
import type { CharActionHandler } from '../char-action.ts';
|
||||
import { intParam, stringParam } from './payload-params.ts';
|
||||
import { ruleAction } from './rule-answer.ts';
|
||||
|
||||
export function upgradeCrewAction(profiles: PlayerProfiles, accounts: AccountStore, rules: ResearchRules): CharActionHandler {
|
||||
return ruleAction(profiles, accounts, (payload) => {
|
||||
const crewId = intParam(payload, 'id');
|
||||
if (crewId === undefined) return undefined;
|
||||
const raises: SkillRaise[] = payload.blocks.flatMap((page) => page.params.flatMap((param) =>
|
||||
param.value.type === 'int' && param.value.value > 0 ? [{ page: page.name, skill: param.name, levels: param.value.value }] : []));
|
||||
return (profile) => upgradeCrewSkills(profile, rules.crew, crewId, raises);
|
||||
});
|
||||
}
|
||||
|
||||
export function purchaseSkillPointsAction(profiles: PlayerProfiles, accounts: AccountStore, rules: ResearchRules): CharActionHandler {
|
||||
return ruleAction(profiles, accounts, (payload) => {
|
||||
const crewId = intParam(payload, 'id');
|
||||
const pack = stringParam(payload, 'pack');
|
||||
if (crewId === undefined || pack === undefined) return undefined;
|
||||
return (profile) => buySkillPoints(profile, rules.crew, crewId, pack);
|
||||
});
|
||||
}
|
||||
|
||||
export function specializeCrewAction(profiles: PlayerProfiles, accounts: AccountStore, rules: ResearchRules): CharActionHandler {
|
||||
return ruleAction(profiles, accounts, (payload) => {
|
||||
const crewId = intParam(payload, 'id');
|
||||
const vehicle = stringParam(payload, 'aircraft');
|
||||
if (crewId === undefined || vehicle === undefined) return undefined;
|
||||
return (profile) => specializeCrew(profile, rules.crew, crewId, vehicle);
|
||||
});
|
||||
}
|
||||
@@ -9,6 +9,6 @@ import { priceTable } from '../../research/price-table.ts';
|
||||
import type { ResearchRules } from '../../research/research-rules.ts';
|
||||
|
||||
export function priceEx(rules: ResearchRules): CharActionHandler {
|
||||
const table = priceTable(rules.techTree, rules.equipment, rules.decor);
|
||||
const table = priceTable(rules.techTree, rules.equipment, rules.decor, rules.crew);
|
||||
return () => ({ kind: 'data', blk: table });
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/**
|
||||
* Crew skill upgrades, skill point packs and specializations.
|
||||
*
|
||||
* cln_upgrade_crew raise skills: <page>{ <skill>:i=levels to add } id:i
|
||||
* cost = sum of the per-level costs of the new levels
|
||||
* (crew_skills.blk skill_level_exp), paid in skill points
|
||||
* cln_purchase_skill_points id:i pack:t: warpoints.blk crewSkillPointsCost, golden eagles
|
||||
* cln_specialize_crew id:i aircraft:t: one step up for a trained vehicle,
|
||||
* expert (wpcost.blk train2Cost, silver lions) then
|
||||
* ace (train3Cost_gold, golden eagles)
|
||||
*/
|
||||
import type { BlkBlock } from '@wto/blk';
|
||||
import type { CrewSkillData, CrewTrainingPrices, SkillFacts, SkillPointPack } from '../game-data/datasets/crew-skills.ts';
|
||||
import { canAfford, pay, type Price } from '../profile/profile-currency.ts';
|
||||
import { addSkillPoints, isTrainedFor, setSkillLevel, setSpecialization, skillLevel, skillPoints, specializationOf } from '../profile/profile-crew-skills.ts';
|
||||
import { crewOf } from '../profile/profile-crews.ts';
|
||||
import { ACCEPTED, refused, type RuleOutcome } from '../research/rule-outcome.ts';
|
||||
|
||||
const ACE = 2;
|
||||
|
||||
export class CrewSkillCatalogue {
|
||||
readonly #skills = new Map<string, SkillFacts>();
|
||||
readonly #packs: ReadonlyMap<string, SkillPointPack>;
|
||||
readonly #training: ReadonlyMap<string, CrewTrainingPrices>;
|
||||
|
||||
constructor(data: CrewSkillData) {
|
||||
for (const page of data.pages) for (const skill of page.skills) this.#skills.set(`${page.name}/${skill.name}`, skill);
|
||||
this.#packs = new Map(data.packs.map((pack) => [pack.name, pack]));
|
||||
this.#training = new Map(data.training.map((prices) => [prices.vehicle, prices]));
|
||||
}
|
||||
|
||||
skill(page: string, skill: string): SkillFacts | undefined {
|
||||
return this.#skills.get(`${page}/${skill}`);
|
||||
}
|
||||
|
||||
pack(name: string): SkillPointPack | undefined {
|
||||
return this.#packs.get(name);
|
||||
}
|
||||
|
||||
packs(): Iterable<SkillPointPack> {
|
||||
return this.#packs.values();
|
||||
}
|
||||
|
||||
training(vehicle: string): CrewTrainingPrices | undefined {
|
||||
return this.#training.get(vehicle);
|
||||
}
|
||||
}
|
||||
|
||||
export interface SkillRaise {
|
||||
readonly page: string;
|
||||
readonly skill: string;
|
||||
readonly levels: number;
|
||||
}
|
||||
|
||||
export function upgradeCrewSkills(profile: BlkBlock, catalogue: CrewSkillCatalogue, crewId: number, raises: readonly SkillRaise[]): RuleOutcome {
|
||||
const crew = crewOf(profile, crewId);
|
||||
if (!crew || raises.length === 0) return refused('BAD_PARAMS');
|
||||
let cost = 0;
|
||||
const changes: { raise: SkillRaise; level: number }[] = [];
|
||||
for (const raise of raises) {
|
||||
const facts = catalogue.skill(raise.page, raise.skill);
|
||||
if (!facts || raise.levels < 1) return refused('BAD_PARAMS');
|
||||
const current = skillLevel(crew, raise.page, raise.skill);
|
||||
const level = current + raise.levels;
|
||||
if (level > facts.levelCosts.length) return refused('NOT_AVAILABLE');
|
||||
for (let next = current + 1; next <= level; next++) cost += facts.levelCosts[next - 1] ?? 0;
|
||||
changes.push({ raise, level });
|
||||
}
|
||||
if (cost > skillPoints(crew)) return refused('NOT_ENOUGH_SKILL_POINTS');
|
||||
for (const { raise, level } of changes) setSkillLevel(crew, raise.page, raise.skill, level);
|
||||
addSkillPoints(crew, -cost);
|
||||
return ACCEPTED;
|
||||
}
|
||||
|
||||
export function buySkillPoints(profile: BlkBlock, catalogue: CrewSkillCatalogue, crewId: number, packName: string): RuleOutcome {
|
||||
const crew = crewOf(profile, crewId);
|
||||
const pack = catalogue.pack(packName);
|
||||
if (!crew || !pack) return refused('BAD_PARAMS');
|
||||
const price: Price = { silverLions: 0, goldenEagles: pack.goldenEagles };
|
||||
if (!canAfford(profile, price)) return refused('NOT_ENOUGH_MONEY');
|
||||
pay(profile, price);
|
||||
addSkillPoints(crew, pack.points);
|
||||
return ACCEPTED;
|
||||
}
|
||||
|
||||
export function specializeCrew(profile: BlkBlock, catalogue: CrewSkillCatalogue, crewId: number, vehicle: string): RuleOutcome {
|
||||
const crew = crewOf(profile, crewId);
|
||||
const prices = catalogue.training(vehicle);
|
||||
if (!crew || !prices || !isTrainedFor(crew, vehicle)) return refused('BAD_PARAMS');
|
||||
const spec = specializationOf(crew, vehicle);
|
||||
if (spec >= ACE) return refused('NOT_AVAILABLE');
|
||||
const price: Price = spec === 0 ? { silverLions: prices.expert, goldenEagles: 0 } : { silverLions: 0, goldenEagles: prices.aceGoldenEagles };
|
||||
if (!canAfford(profile, price)) return refused('NOT_ENOUGH_MONEY');
|
||||
pay(profile, price);
|
||||
setSpecialization(crew, vehicle, spec + 1);
|
||||
return ACCEPTED;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Crew training fee: putting a vehicle into a crew that is not trained
|
||||
* for it yet costs the vehicle's wpcost.blk trainCost in silver lions (scripts crew/crew.nut
|
||||
* getCrewTrainCost; reserve vehicles cost 0). Charged by cln_train_aircraft and
|
||||
* cln_bulk_train_aircraft for every new crew/vehicle pair.
|
||||
*/
|
||||
import type { BlkBlock } from '@wto/blk';
|
||||
import type { Price } from '../profile/profile-currency.ts';
|
||||
import { isTrainedFor } from '../profile/profile-crew-skills.ts';
|
||||
import { crewOf } from '../profile/profile-crews.ts';
|
||||
import type { CrewSlotAssignment } from '../profile/crew-slots.ts';
|
||||
import type { CrewSkillCatalogue } from './crew-skill-rules.ts';
|
||||
|
||||
export function trainingFee(profile: BlkBlock, catalogue: CrewSkillCatalogue, assignments: readonly CrewSlotAssignment[]): Price {
|
||||
const counted = new Set<string>();
|
||||
let silverLions = 0;
|
||||
for (const { crewId, vehicle } of assignments) {
|
||||
const crew = crewOf(profile, crewId);
|
||||
const key = `${crewId}/${vehicle}`;
|
||||
if (vehicle === '' || !crew || isTrainedFor(crew, vehicle) || counted.has(key)) continue;
|
||||
counted.add(key);
|
||||
silverLions += catalogue.training(vehicle)?.training ?? 0;
|
||||
}
|
||||
return { silverLions, goldenEagles: 0 };
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/**
|
||||
* Dataset: crew skills, skill point packs and per-vehicle crew training prices
|
||||
*.
|
||||
*
|
||||
* char.vromfs.bin config/crew_skills.blk
|
||||
* crew_skills{ <page>{ type:t <skill>{ skill_level_exp{ level1:i ... levelN:i } } } }
|
||||
* levelN is the skill point cost of level N (the scripts add them up into costTbl).
|
||||
* char.vromfs.bin config/warpoints.blk
|
||||
* crewSkillPointsCost{ <pack>{ costGold:i crewExp:i } }
|
||||
* char.vromfs.bin config/wpcost.blk, per vehicle
|
||||
* trainCost:i (training a crew, silver lions), train2Cost:i (expert, silver lions),
|
||||
* train3Cost_gold:i (ace, golden eagles)
|
||||
*/
|
||||
import type { BlkBlock } from '@wto/blk';
|
||||
import { findBlock } from '@wto/blk';
|
||||
import { numberField, stringField } from './blk-fields.ts';
|
||||
import type { Dataset } from './dataset.ts';
|
||||
|
||||
export interface SkillFacts {
|
||||
readonly name: string;
|
||||
/** Cost of each level, index 0 = level 1; the length is the maximum level. */
|
||||
readonly levelCosts: readonly number[];
|
||||
}
|
||||
|
||||
export interface SkillPage {
|
||||
readonly name: string;
|
||||
readonly type: string;
|
||||
readonly skills: readonly SkillFacts[];
|
||||
}
|
||||
|
||||
export interface SkillPointPack {
|
||||
readonly name: string;
|
||||
readonly goldenEagles: number;
|
||||
readonly points: number;
|
||||
}
|
||||
|
||||
export interface CrewTrainingPrices {
|
||||
readonly vehicle: string;
|
||||
readonly training: number;
|
||||
readonly expert: number;
|
||||
readonly aceGoldenEagles: number;
|
||||
}
|
||||
|
||||
export interface CrewSkillData {
|
||||
readonly pages: readonly SkillPage[];
|
||||
readonly packs: readonly SkillPointPack[];
|
||||
readonly training: readonly CrewTrainingPrices[];
|
||||
}
|
||||
|
||||
export const crewSkillData: Dataset<CrewSkillData> = {
|
||||
id: 'crew-skills',
|
||||
version: 1,
|
||||
extract: (source) => {
|
||||
const skills = findBlock(source.readBlk('char.vromfs.bin', 'config/crew_skills.blk'), 'crew_skills');
|
||||
const packs = findBlock(source.readBlk('char.vromfs.bin', 'config/warpoints.blk'), 'crewSkillPointsCost');
|
||||
return {
|
||||
pages: (skills?.blocks ?? []).map(pageOf),
|
||||
packs: (packs?.blocks ?? []).map((pack) => ({ name: pack.name, goldenEagles: numberField(pack, 'costGold') ?? 0, points: numberField(pack, 'crewExp') ?? 0 })),
|
||||
training: source.readBlk('char.vromfs.bin', 'config/wpcost.blk').blocks.map((vehicle) => ({
|
||||
vehicle: vehicle.name,
|
||||
training: numberField(vehicle, 'trainCost') ?? 0,
|
||||
expert: numberField(vehicle, 'train2Cost') ?? 0,
|
||||
aceGoldenEagles: numberField(vehicle, 'train3Cost_gold') ?? 0,
|
||||
})),
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
function pageOf(page: BlkBlock): SkillPage {
|
||||
return {
|
||||
name: page.name,
|
||||
type: stringField(page, 'type') ?? '',
|
||||
skills: page.blocks.map((skill) => {
|
||||
const levels = findBlock(skill, 'skill_level_exp');
|
||||
const levelCosts: number[] = [];
|
||||
for (let level = 1; levels && numberField(levels, `level${level}`) !== undefined; level++) levelCosts.push(numberField(levels, `level${level}`)!);
|
||||
return { name: skill.name, levelCosts };
|
||||
}),
|
||||
};
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -21,6 +21,7 @@
|
||||
* skins{ "<vehicle>/<skin>"{ cost:i costGold:i } } decorations (get_skin_cost_*, 0x17a8910...)
|
||||
* decals{ <decal>{ ... } }
|
||||
* attachable{ <attachable>{ ... } }
|
||||
* skills{ <pack>{ costGold:i } } skill point packs (0x916380)
|
||||
* }
|
||||
*
|
||||
* Every entry is read as cost:i (silver lions), costGold:i (golden eagles), discount:i (percent
|
||||
@@ -31,6 +32,7 @@
|
||||
* attachable.blk), the same the purchase rules charge.
|
||||
*/
|
||||
import type { BlkBlock, BlkParam } from '@wto/blk';
|
||||
import type { CrewSkillCatalogue } from '../crew/crew-skill-rules.ts';
|
||||
import type { DecorShop } from '../decor/decor-purchase.ts';
|
||||
import type { EquipmentCatalogue } from '../modifications/equipment-catalogue.ts';
|
||||
import type { TechTree } from './tech-tree.ts';
|
||||
@@ -38,7 +40,7 @@ import type { TechTree } from './tech-tree.ts';
|
||||
/** The top-level block every client lookup falls back to (0x908e28). */
|
||||
const COMMON_SECTION = 'Common';
|
||||
|
||||
export function priceTable(techTree: TechTree, equipment: EquipmentCatalogue, decor: DecorShop): BlkBlock {
|
||||
export function priceTable(techTree: TechTree, equipment: EquipmentCatalogue, decor: DecorShop, crew: CrewSkillCatalogue): BlkBlock {
|
||||
const vehicles: BlkBlock[] = [];
|
||||
for (const vehicle of techTree.all()) {
|
||||
const entry: BlkBlock = { name: vehicle.name, params: priceParams(vehicle.silverLions, vehicle.goldenEagles), blocks: [] };
|
||||
@@ -57,7 +59,7 @@ export function priceTable(techTree: TechTree, equipment: EquipmentCatalogue, de
|
||||
}
|
||||
if (entry.blocks.length || vehicle.silverLions > 0 || vehicle.goldenEagles > 0) vehicles.push(entry);
|
||||
}
|
||||
const common: BlkBlock = { name: COMMON_SECTION, params: [], blocks: [{ name: 'aircrafts', params: [], blocks: vehicles }, ...decorSections(decor)] };
|
||||
const common: BlkBlock = { name: COMMON_SECTION, params: [], blocks: [{ name: 'aircrafts', params: [], blocks: vehicles }, ...decorSections(decor), skillPackSection(crew)] };
|
||||
return { name: '', params: [], blocks: [common] };
|
||||
}
|
||||
|
||||
@@ -86,3 +88,7 @@ function decorSections(decor: DecorShop): BlkBlock[] {
|
||||
}
|
||||
return [...sections.values()];
|
||||
}
|
||||
|
||||
function skillPackSection(crew: CrewSkillCatalogue): BlkBlock {
|
||||
return { name: 'skills', params: [], blocks: [...crew.packs()].map((pack) => ({ name: pack.name, params: priceParams(0, pack.goldenEagles), blocks: [] })) };
|
||||
}
|
||||
@@ -7,6 +7,8 @@ import { crewSlotPrices, eraRequirements, type CrewSlotPrices, type EraRequireme
|
||||
import { researchPointsPerGoldenEagle } from '../game-data/datasets/research-point-rate.ts';
|
||||
import { vehicleCatalogue } from '../game-data/datasets/vehicle-catalogue.ts';
|
||||
import { decorCatalogue } from '../game-data/datasets/decor-catalogue.ts';
|
||||
import { crewSkillData } from '../game-data/datasets/crew-skills.ts';
|
||||
import { CrewSkillCatalogue } from '../crew/crew-skill-rules.ts';
|
||||
import { vehicleEquipment } from '../game-data/datasets/vehicle-equipment.ts';
|
||||
import { DecorShop } from '../decor/decor-purchase.ts';
|
||||
import { vehicleUnlocks, type UnlockDefinition } from '../game-data/datasets/vehicle-unlocks.ts';
|
||||
@@ -23,6 +25,8 @@ export interface ResearchRules {
|
||||
readonly equipment: EquipmentCatalogue;
|
||||
/** Decorations for sale. */
|
||||
readonly decor: DecorShop;
|
||||
/** Crew skills, skill point packs, training prices. */
|
||||
readonly crew: CrewSkillCatalogue;
|
||||
}
|
||||
|
||||
export function loadResearchRules(datasets: DatasetCache): ResearchRules {
|
||||
@@ -34,5 +38,6 @@ export function loadResearchRules(datasets: DatasetCache): ResearchRules {
|
||||
researchPointsPerGoldenEagle: datasets.load(researchPointsPerGoldenEagle),
|
||||
equipment: new EquipmentCatalogue(datasets.load(vehicleEquipment)),
|
||||
decor: new DecorShop(datasets.load(decorCatalogue)),
|
||||
crew: new CrewSkillCatalogue(datasets.load(crewSkillData)),
|
||||
};
|
||||
}
|
||||
@@ -8,7 +8,9 @@ export type Refusal =
|
||||
/** The price the client offered is not the current price. */
|
||||
| 'PRICE_CHANGED'
|
||||
| 'NOT_ENOUGH_MONEY'
|
||||
| 'NOT_ENOUGH_RESEARCH_POINTS';
|
||||
| 'NOT_ENOUGH_RESEARCH_POINTS'
|
||||
/** A crew does not have the skill points the upgrade costs. */
|
||||
| 'NOT_ENOUGH_SKILL_POINTS';
|
||||
|
||||
export type RuleOutcome = { readonly ok: true } | { readonly ok: false; readonly refusal: Refusal };
|
||||
|
||||
|
||||
Reference in new issue
Block a user