feat(cosmetics): support cosmetic purchases
Handle cln_buy_resource, persist ownership in resourcesInfo, and expose the prices of skins, decals, and attachments.
This commit is contained in:
1 parent
6d8a3af37a
commit
28909cf1e9
8 files changed
+178
-6
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 { buyResourceAction } from './decor-actions.ts';
|
||||
import { saveDecorLayoutsAction } from './decor-layout-actions.ts';
|
||||
import { entitlementsFull, initialMeta, legacyUserData } from './online-init-actions.ts';
|
||||
import { priceEx } from './price-actions.ts';
|
||||
@@ -38,6 +39,7 @@ 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_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')],
|
||||
]);
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Buying decorations. cln_buy_resource is sent with char_send_blk (job
|
||||
* type 13), so the answer is the whole profile.
|
||||
*
|
||||
* cln_buy_resource (scripts customization/decoratorAcquire.nut buyResourceImpl):
|
||||
* name:t the skin, decal or attachable
|
||||
* type:t skin | decal | attachable
|
||||
* unitName:t the vehicle (skins)
|
||||
* cost:i costGold:i
|
||||
*/
|
||||
import type { AccountStore } from '../../accounts/account-store.ts';
|
||||
import { buyDecoration, decorKey, isDecorKind } from '../../decor/decor-purchase.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 buyResourceAction(profiles: PlayerProfiles, accounts: AccountStore, rules: ResearchRules): CharActionHandler {
|
||||
return ruleAction(profiles, accounts, (payload) => {
|
||||
const name = stringParam(payload, 'name');
|
||||
const type = stringParam(payload, 'type');
|
||||
if (name === undefined || type === undefined || !isDecorKind(type)) return undefined;
|
||||
const key = decorKey(type, name, stringParam(payload, 'unitName') ?? '');
|
||||
const offered = { silverLions: intParam(payload, 'cost') ?? 0, goldenEagles: intParam(payload, 'costGold') ?? 0 };
|
||||
return (profile) => buyDecoration(profile, rules.decor, type, key, offered);
|
||||
});
|
||||
}
|
||||
@@ -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);
|
||||
const table = priceTable(rules.techTree, rules.equipment, rules.decor);
|
||||
return () => ({ kind: 'data', blk: table });
|
||||
}
|
||||
Reference in new issue
Block a user