From f4bb5ccf46ee63d8acf618605ec875042b280d1c Mon Sep 17 00:00:00 2001 From: N0VAN0M4LY <224130499+N0VAN0M4LY@users.noreply.github.com> Date: Wed, 25 Nov 2026 16:33:27 +0800 Subject: [PATCH] Separate research rules from character price encoding Keep ResearchRules focused on vehicle research and purchases. Move cln_get_price_ex encoding into the character protocol layer and inject its catalogue dependencies explicitly. Load only the catalogues needed by each service and save editing command. Type checking and isolated service and save CLI checks passed. In-game acceptance is pending. --- .../src/char/actions/action-table.ts | 127 +++++++++++------- .../src/char/actions/clan-actions.ts | 18 +-- .../src/char/actions/crew-actions.ts | 12 +- .../src/char/actions/crew-skill-actions.ts | 15 +-- .../src/char/actions/decor-actions.ts | 7 +- .../src/char/actions/inventory-actions.ts | 32 +++-- .../src/char/actions/item-actions.ts | 19 +-- .../src/char/actions/modification-actions.ts | 18 +-- .../src/char/actions/player-card-actions.ts | 9 +- .../src/char/actions/price-actions.ts | 11 +- .../{research => char/actions}/price-table.ts | 43 +++--- .../src/char/actions/research-actions.ts | 12 +- .../src/char/actions/store-actions.ts | 11 +- .../src/char/actions/unlock-actions.ts | 7 +- packages/local-service/src/local-service.ts | 61 +++++++-- packages/local-service/src/profiles-setup.ts | 14 +- .../src/research/research-rules.ts | 63 ++------- packages/local-service/src/save-cli.ts | 63 +++++++-- 18 files changed, 310 insertions(+), 232 deletions(-) rename packages/local-service/src/{research => char/actions}/price-table.ts (85%) diff --git a/packages/local-service/src/char/actions/action-table.ts b/packages/local-service/src/char/actions/action-table.ts index 4e93ea4..a5990dd 100644 --- a/packages/local-service/src/char/actions/action-table.ts +++ b/packages/local-service/src/char/actions/action-table.ts @@ -2,8 +2,17 @@ import type { AccountStore } from '../../accounts/account-store.ts'; import type { ClanStore } from '../../clans/clan-store.ts'; import type { CloudSettingsStore } from '../../cloud-settings/cloud-settings-store.ts'; +import type { CrewSkillCatalogue } from '../../crew/crew-skill-rules.ts'; +import type { DecorShop } from '../../decor/decor-purchase.ts'; +import type { ClanEconomy } from '../../game-data/datasets/clan-economy.ts'; +import type { InventoryCatalogue } from '../../inventory/itemdef-catalogue.ts'; +import type { TrophyCatalogue } from '../../inventory/trophy-catalogue.ts'; +import type { ItemCatalogue } from '../../items/item-catalogue.ts'; +import type { EquipmentCatalogue } from '../../modifications/equipment-catalogue.ts'; import type { PlayerProfiles } from '../../profile/player-profiles.ts'; import type { ResearchRules } from '../../research/research-rules.ts'; +import type { StoreCatalogue } from '../../store/store-catalogue.ts'; +import type { UnlockShop } from '../../unlocks/unlock-purchase.ts'; import type { CharActionHandler } from '../char-action.ts'; import { acceptEula } from './agreement-actions.ts'; import { @@ -55,11 +64,24 @@ import { setStartingInfo } from './starting-info-actions.ts'; import { buyEntitlementAction, entitlementsPriceEx } from './store-actions.ts'; import { buyUnlockAction } from './unlock-actions.ts'; +export interface ClanActionDependencies { + readonly store: ClanStore; + readonly economy: ClanEconomy; +} + export interface ActionDependencies { readonly profiles: PlayerProfiles; readonly accounts: AccountStore; readonly research: ResearchRules; - readonly clans?: ClanStore; + readonly equipment: EquipmentCatalogue; + readonly crew: CrewSkillCatalogue; + readonly decor: DecorShop; + readonly unlocks: UnlockShop; + readonly items: ItemCatalogue; + readonly store: StoreCatalogue; + readonly inventory: InventoryCatalogue; + readonly trophies: TrophyCatalogue; + readonly clans?: ClanActionDependencies; readonly cloudSettings?: CloudSettingsStore; readonly notifyInventoryChanged?: () => void; } @@ -75,78 +97,79 @@ export function actionTable(deps: ActionDependencies): ReadonlyMap { const notifyInventory = deps.notifyInventoryChanged ?? (() => {}); + const { techTree } = deps.research; return [ ['cln_get_initial_meta', initialMeta(deps.accounts, deps.cloudSettings)], ['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)], - ['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_bulk_train_aircraft', bulkTrainCrews(deps.profiles, deps.accounts, deps.crew)], + ['cln_train_aircraft', trainCrew(deps.profiles, deps.accounts, deps.crew)], + ['cln_set_researchable', setResearchable(deps.profiles, deps.accounts, deps.research, deps.equipment)], ['cln_reset_researchable', resetResearchable(deps.profiles, deps.accounts, deps.research)], ['cln_convert_exp', convertExp(deps.profiles, deps.accounts, deps.research)], ['cln_buy_aircraft', buyAircraft(deps.profiles, deps.accounts, deps.research)], ['cln_buy_slot', buySlot(deps.profiles, deps.accounts, deps.research)], - ['cln_get_price_ex', priceEx(deps.research)], - ['cln_buy_modification', buyModificationAction(deps.profiles, deps.accounts, deps.research)], - ['cln_buy_all_modification', buyAllModificationsAction(deps.profiles, deps.accounts, deps.research)], - ['cln_buy_spare_aircrafts', buySparesAction(deps.profiles, deps.accounts, deps.research)], - ['cln_buy_unlock', buyUnlockAction(deps.profiles, deps.accounts, deps.research)], - ['cln_buy_weapon', buyWeaponsAction(deps.profiles, deps.accounts, deps.research)], + ['cln_get_price_ex', priceEx({ techTree, equipment: deps.equipment, decor: deps.decor, crew: deps.crew, unlocks: deps.unlocks, items: deps.items, trophies: deps.trophies })], + ['cln_buy_modification', buyModificationAction(deps.profiles, deps.accounts, deps.equipment)], + ['cln_buy_all_modification', buyAllModificationsAction(deps.profiles, deps.accounts, deps.equipment)], + ['cln_buy_spare_aircrafts', buySparesAction(deps.profiles, deps.accounts, deps.equipment)], + ['cln_buy_unlock', buyUnlockAction(deps.profiles, deps.accounts, deps.unlocks)], + ['cln_buy_weapon', buyWeaponsAction(deps.profiles, deps.accounts, deps.equipment)], ['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_upgrade_crew', upgradeCrewAction(deps.profiles, deps.accounts, deps.crew)], + ['cln_purchase_skill_points', purchaseSkillPointsAction(deps.profiles, deps.accounts, deps.crew)], + ['cln_specialize_crew', specializeCrewAction(deps.profiles, deps.accounts, deps.crew)], ['cln_select_title', selectTitleAction(deps.profiles, deps.accounts)], ['cln_save_pilot_appearance', savePilotAppearanceAction(deps.profiles, deps.accounts)], - ['cln_get_users_terse_info', usersTerseInfoAction(deps.profiles, deps.accounts, deps.research, deps.clans)], + ['cln_get_users_terse_info', usersTerseInfoAction(deps.profiles, deps.accounts, techTree, deps.clans?.store)], ['cln_save_profile_showcase', saveShowcaseAction(deps.profiles, deps.accounts)], - ['cln_get_showcases', showcasesAction(deps.profiles, deps.accounts, deps.research)], - ['cln_buy_resource', buyResourceAction(deps.profiles, deps.accounts, deps.research)], + ['cln_get_showcases', showcasesAction(deps.profiles, deps.accounts, techTree)], + ['cln_buy_resource', buyResourceAction(deps.profiles, deps.accounts, deps.decor)], ['cln_save_decals', saveDecorLayoutsAction(deps.profiles, deps.accounts, 'decals')], ['cln_save_attachables', saveDecorLayoutsAction(deps.profiles, deps.accounts, 'attachables')], - ['cln_buy_item', buyItemAction(deps.profiles, deps.accounts, deps.research)], + ['cln_buy_item', buyItemAction(deps.profiles, deps.accounts, deps.items)], ['cln_set_current_booster', activateBoosterAction(deps.profiles, deps.accounts)], - ['cln_set_current_personal_discount', activateDiscountAction(deps.profiles, deps.accounts, deps.research)], - ['cln_set_current_wager', startWagerAction(deps.profiles, deps.accounts, deps.research)], - ['cln_apply_spare_item', applySpareItemAction(deps.profiles, deps.accounts, deps.research)], - ['cln_get_entitlements_price_ex', entitlementsPriceEx(deps.research)], - ['cln_buy_entitlement', buyEntitlementAction(deps.profiles, deps.accounts, deps.research)], - ['cln_consume_inventory_item', consumeInventoryItemAction(deps.profiles, deps.accounts, deps.research, notifyInventory)], - ['cln_multi_consume_inventory_item_json', multiConsumeInventoryItemsAction(deps.profiles, deps.accounts, deps.research, notifyInventory)], - ['cln_inventory_purchase_item', purchaseInventoryItemAction(deps.profiles, deps.accounts, deps.research, notifyInventory)], - ['cln_recycle_items', recycleItemsAction(deps.profiles, deps.accounts, deps.research, notifyInventory)], - ['cln_inventory_exchange_items', inventoryExchangeAction(deps.profiles, deps.accounts, deps.research)], - ['cln_buy_trophy', buyTrophyAction(deps.profiles, deps.accounts, deps.research)], + ['cln_set_current_personal_discount', activateDiscountAction(deps.profiles, deps.accounts, deps.items)], + ['cln_set_current_wager', startWagerAction(deps.profiles, deps.accounts, deps.items)], + ['cln_apply_spare_item', applySpareItemAction(deps.profiles, deps.accounts, deps.items, techTree)], + ['cln_get_entitlements_price_ex', entitlementsPriceEx(deps.store)], + ['cln_buy_entitlement', buyEntitlementAction(deps.profiles, deps.accounts, deps.store)], + ['cln_consume_inventory_item', consumeInventoryItemAction(deps.profiles, deps.accounts, deps.inventory, deps.items, notifyInventory)], + ['cln_multi_consume_inventory_item_json', multiConsumeInventoryItemsAction(deps.profiles, deps.accounts, deps.inventory, deps.items, notifyInventory)], + ['cln_inventory_purchase_item', purchaseInventoryItemAction(deps.profiles, deps.accounts, deps.inventory, notifyInventory)], + ['cln_recycle_items', recycleItemsAction(deps.profiles, deps.accounts, deps.items, notifyInventory)], + ['cln_inventory_exchange_items', inventoryExchangeAction(deps.profiles, deps.accounts, deps.inventory)], + ['cln_buy_trophy', buyTrophyAction(deps.profiles, deps.accounts, deps.trophies, deps.items)], ]; } -function clanActionEntries(deps: ActionDependencies, clans: ClanStore): Array<[string, CharActionHandler]> { +function clanActionEntries(deps: ActionDependencies, clans: ClanActionDependencies): Array<[string, CharActionHandler]> { return [ - ['cln_clan_get', clanGetAction(deps.accounts, clans)], - ['cln_clan_get_leaderboard', clanGetLeaderboardAction(clans)], - ['cln_clan_find_by_prefix', clanFindByPrefixAction(clans)], - ['cln_clans_list_get_short_info', clansListShortInfoAction(clans)], - ['cln_clan_get_log', clanGetLogAction(deps.accounts, clans)], - ['cln_clan_create', clanCreateAction(deps.profiles, deps.accounts, clans, deps.research)], - ['cln_clan_change_info', clanChangeInfoAction(deps.profiles, deps.accounts, clans, deps.research)], - ['cln_clan_upgrade', clanUpgradeAction(deps.profiles, deps.accounts, clans, deps.research)], - ['cln_clan_members_upgrade', clanMembersUpgradeAction(deps.profiles, deps.accounts, clans, deps.research)], - ['cln_clan_set_membership_requirements', clanSetMembershipReqAction(deps.accounts, clans)], - ['cln_clan_membership_request', clanMembershipRequestAction(deps.profiles, deps.accounts, clans)], - ['cln_clan_leave', clanLeaveAction(deps.profiles, deps.accounts, clans)], - ['cln_clan_disband', clanDisbandAction(deps.profiles, deps.accounts, clans)], - ['cln_clan_sync_profile_and_clan', clanSyncProfileAction(deps.profiles, deps.accounts, clans)], - ['ano_clan_accept_membership_request', clanAcceptCandidateAction(deps.profiles, deps.accounts, clans)], - ['ano_clan_reject_membership_request', clanRejectCandidateAction(deps.profiles, deps.accounts, clans)], - ['ano_clan_dismiss_member', clanDismissMemberAction(deps.profiles, deps.accounts, clans)], - ['ano_clan_change_member_role', clanChangeMemberRoleAction(deps.profiles, deps.accounts, clans)], - ['ano_clan_edit_blacklist', clanEditBlacklistAction(deps.accounts, clans)], - ['cln_set_clan_best_rewards', setClanBestRewardsAction(deps.accounts, clans)], - ['cln_set_research_clan_unit', setResearchClanUnitAction(deps.profiles, deps.accounts, clans, deps.research)], - ['cln_flush_clan_exp_to_unit', flushClanExpToUnitAction(deps.profiles, deps.accounts, clans, deps.research)], - ['cln_buy_not_researched_clans_unit', buyNotResearchedClanUnitAction(deps.profiles, deps.accounts, clans, deps.research)], + ['cln_clan_get', clanGetAction(deps.accounts, clans.store)], + ['cln_clan_get_leaderboard', clanGetLeaderboardAction(clans.store)], + ['cln_clan_find_by_prefix', clanFindByPrefixAction(clans.store)], + ['cln_clans_list_get_short_info', clansListShortInfoAction(clans.store)], + ['cln_clan_get_log', clanGetLogAction(deps.accounts, clans.store)], + ['cln_clan_create', clanCreateAction(deps.profiles, deps.accounts, clans.store, clans.economy)], + ['cln_clan_change_info', clanChangeInfoAction(deps.profiles, deps.accounts, clans.store, clans.economy)], + ['cln_clan_upgrade', clanUpgradeAction(deps.profiles, deps.accounts, clans.store, clans.economy)], + ['cln_clan_members_upgrade', clanMembersUpgradeAction(deps.profiles, deps.accounts, clans.store, clans.economy)], + ['cln_clan_set_membership_requirements', clanSetMembershipReqAction(deps.accounts, clans.store)], + ['cln_clan_membership_request', clanMembershipRequestAction(deps.profiles, deps.accounts, clans.store)], + ['cln_clan_leave', clanLeaveAction(deps.profiles, deps.accounts, clans.store)], + ['cln_clan_disband', clanDisbandAction(deps.profiles, deps.accounts, clans.store)], + ['cln_clan_sync_profile_and_clan', clanSyncProfileAction(deps.profiles, deps.accounts, clans.store)], + ['ano_clan_accept_membership_request', clanAcceptCandidateAction(deps.profiles, deps.accounts, clans.store)], + ['ano_clan_reject_membership_request', clanRejectCandidateAction(deps.profiles, deps.accounts, clans.store)], + ['ano_clan_dismiss_member', clanDismissMemberAction(deps.profiles, deps.accounts, clans.store)], + ['ano_clan_change_member_role', clanChangeMemberRoleAction(deps.profiles, deps.accounts, clans.store)], + ['ano_clan_edit_blacklist', clanEditBlacklistAction(deps.accounts, clans.store)], + ['cln_set_clan_best_rewards', setClanBestRewardsAction(deps.accounts, clans.store)], + ['cln_set_research_clan_unit', setResearchClanUnitAction(deps.profiles, deps.accounts, clans.store, deps.research)], + ['cln_flush_clan_exp_to_unit', flushClanExpToUnitAction(deps.profiles, deps.accounts, clans.store, deps.research)], + ['cln_buy_not_researched_clans_unit', buyNotResearchedClanUnitAction(deps.profiles, deps.accounts, clans.store, deps.research)], ]; } diff --git a/packages/local-service/src/char/actions/clan-actions.ts b/packages/local-service/src/char/actions/clan-actions.ts index d801a31..e72cca0 100644 --- a/packages/local-service/src/char/actions/clan-actions.ts +++ b/packages/local-service/src/char/actions/clan-actions.ts @@ -12,10 +12,10 @@ import { toClanShortInfoBlk, } from '../../clans/clan-blk.ts'; import type { ClanStore } from '../../clans/clan-store.ts'; +import type { ClanEconomy } from '../../game-data/datasets/clan-economy.ts'; import { clientProfile } from '../../profile/client-profile.ts'; import type { PlayerProfiles } from '../../profile/player-profiles.ts'; import type { Price } from '../../profile/profile-currency.ts'; -import type { ResearchRules } from '../../research/research-rules.ts'; import type { RuleOutcome } from '../../research/rule-outcome.ts'; import type { CharActionContext, CharActionHandler } from '../char-action.ts'; import { withAccount } from './account-context.ts'; @@ -123,7 +123,7 @@ export function clanGetLogAction(accounts: AccountStore, clans: ClanStore): Char }); } -export function clanCreateAction(profiles: PlayerProfiles, accounts: AccountStore, clans: ClanStore, rules: ResearchRules): CharActionHandler { +export function clanCreateAction(profiles: PlayerProfiles, accounts: AccountStore, clans: ClanStore, clanEconomy: ClanEconomy): CharActionHandler { return clanProfileRuleAction(profiles, accounts, clans, (context, profile, account) => { const payload = context.payload; const offered = payload && priceFromClanPayload(payload); @@ -131,7 +131,7 @@ export function clanCreateAction(profiles: PlayerProfiles, accounts: AccountStor if (!payload || !offered || (rawType !== 'normal' && rawType !== 'battalion')) { return { ok: false, refusal: 'BAD_PARAMS' }; } - return clans.createClan(profile, account, rules.clanEconomy, { + return clans.createClan(profile, account, clanEconomy, { name: stringParam(payload, 'name') ?? '', tag: stringParam(payload, 'tag') ?? '', slogan: stringParam(payload, 'slogan') ?? '', @@ -144,13 +144,13 @@ export function clanCreateAction(profiles: PlayerProfiles, accounts: AccountStor }); } -export function clanChangeInfoAction(profiles: PlayerProfiles, accounts: AccountStore, clans: ClanStore, rules: ResearchRules): CharActionHandler { +export function clanChangeInfoAction(profiles: PlayerProfiles, accounts: AccountStore, clans: ClanStore, clanEconomy: ClanEconomy): CharActionHandler { return clanProfileRuleAction(profiles, accounts, clans, (context, profile, account) => { const payload = context.payload; if (!payload) return { ok: false, refusal: 'BAD_PARAMS' }; const clanId = headerOrPayloadId(context, '_id') ?? '-1'; const rawStatus = stringParam(payload, 'status'); - return clans.editClanInfo(profile, account, rules.clanEconomy, clanId, { + return clans.editClanInfo(profile, account, clanEconomy, clanId, { name: stringParam(payload, 'name'), tag: stringParam(payload, 'tag'), desc: stringParam(payload, 'desc'), @@ -162,12 +162,12 @@ export function clanChangeInfoAction(profiles: PlayerProfiles, accounts: Account }); } -export function clanUpgradeAction(profiles: PlayerProfiles, accounts: AccountStore, clans: ClanStore, rules: ResearchRules): CharActionHandler { +export function clanUpgradeAction(profiles: PlayerProfiles, accounts: AccountStore, clans: ClanStore, clanEconomy: ClanEconomy): CharActionHandler { return clanProfileRuleAction(profiles, accounts, clans, (context, profile, account) => { const payload = context.payload; if (!payload) return { ok: false, refusal: 'BAD_PARAMS' }; const clanId = headerOrPayloadId(context, '_id') ?? '-1'; - return clans.upgradeClanToNormal(profile, account, rules.clanEconomy, clanId, { + return clans.upgradeClanToNormal(profile, account, clanEconomy, clanId, { tag: stringParam(payload, 'tag') ?? '', desc: stringParam(payload, 'desc') ?? '', announcement: stringParam(payload, 'announcement') ?? '', @@ -175,10 +175,10 @@ export function clanUpgradeAction(profiles: PlayerProfiles, accounts: AccountSto }); } -export function clanMembersUpgradeAction(profiles: PlayerProfiles, accounts: AccountStore, clans: ClanStore, rules: ResearchRules): CharActionHandler { +export function clanMembersUpgradeAction(profiles: PlayerProfiles, accounts: AccountStore, clans: ClanStore, clanEconomy: ClanEconomy): CharActionHandler { return clanProfileRuleAction(profiles, accounts, clans, (context, profile, account) => { const clanId = headerOrPayloadId(context, '_id') ?? '-1'; - return clans.upgradeMembersLimit(profile, account, rules.clanEconomy, clanId); + return clans.upgradeMembersLimit(profile, account, clanEconomy, clanId); }); } diff --git a/packages/local-service/src/char/actions/crew-actions.ts b/packages/local-service/src/char/actions/crew-actions.ts index f0f4c28..19ade70 100644 --- a/packages/local-service/src/char/actions/crew-actions.ts +++ b/packages/local-service/src/char/actions/crew-actions.ts @@ -18,22 +18,22 @@ */ import { findParam, type BlkBlock } from '@wto/blk'; import type { AccountStore } from '../../accounts/account-store.ts'; +import type { CrewSkillCatalogue } from '../../crew/crew-skill-rules.ts'; +import { trainingFee } from '../../crew/crew-training.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, rules: ResearchRules): CharActionHandler { +export function bulkTrainCrews(profiles: PlayerProfiles, accounts: AccountStore, crew: CrewSkillCatalogue): CharActionHandler { return (context) => withAccount(context, accounts, (account) => { const assignments = context.payload && readCrewSlots(context.payload); const current = profiles.profileOf(account.userId); if (!assignments || !canAssignCrewSlots(current, assignments)) return { kind: 'error', code: 'BAD_PARAMS' }; - const fee = trainingFee(current, rules.crew, assignments); + const fee = trainingFee(current, crew, assignments); if (!canAfford(current, fee)) return { kind: 'error', code: 'NOT_ENOUGH_MONEY' }; const profile = profiles.update(account.userId, (saved) => { pay(saved, fee); @@ -43,14 +43,14 @@ export function bulkTrainCrews(profiles: PlayerProfiles, accounts: AccountStore, }); } -export function trainCrew(profiles: PlayerProfiles, accounts: AccountStore, rules: ResearchRules): CharActionHandler { +export function trainCrew(profiles: PlayerProfiles, accounts: AccountStore, crew: CrewSkillCatalogue): 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; const current = profiles.profileOf(account.userId); if (!canAssignCrewSlots(current, [assignment])) return { kind: 'error', code: 'BAD_PARAMS' }; - const fee = trainingFee(current, rules.crew, [assignment]); + const fee = trainingFee(current, crew, [assignment]); if (!canAfford(current, fee)) return { kind: 'error', code: 'NOT_ENOUGH_MONEY' }; const profile = profiles.update(account.userId, (saved) => { pay(saved, fee); diff --git a/packages/local-service/src/char/actions/crew-skill-actions.ts b/packages/local-service/src/char/actions/crew-skill-actions.ts index 761243c..57adf81 100644 --- a/packages/local-service/src/char/actions/crew-skill-actions.ts +++ b/packages/local-service/src/char/actions/crew-skill-actions.ts @@ -7,37 +7,36 @@ * 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 { buySkillPoints, specializeCrew, upgradeCrewSkills, type CrewSkillCatalogue, 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 { +export function upgradeCrewAction(profiles: PlayerProfiles, accounts: AccountStore, crew: CrewSkillCatalogue): 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); + return (profile) => upgradeCrewSkills(profile, crew, crewId, raises); }); } -export function purchaseSkillPointsAction(profiles: PlayerProfiles, accounts: AccountStore, rules: ResearchRules): CharActionHandler { +export function purchaseSkillPointsAction(profiles: PlayerProfiles, accounts: AccountStore, crew: CrewSkillCatalogue): 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); + return (profile) => buySkillPoints(profile, crew, crewId, pack); }); } -export function specializeCrewAction(profiles: PlayerProfiles, accounts: AccountStore, rules: ResearchRules): CharActionHandler { +export function specializeCrewAction(profiles: PlayerProfiles, accounts: AccountStore, crew: CrewSkillCatalogue): 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); + return (profile) => specializeCrew(profile, crew, crewId, vehicle); }); } diff --git a/packages/local-service/src/char/actions/decor-actions.ts b/packages/local-service/src/char/actions/decor-actions.ts index 84f108c..bc793b2 100644 --- a/packages/local-service/src/char/actions/decor-actions.ts +++ b/packages/local-service/src/char/actions/decor-actions.ts @@ -9,20 +9,19 @@ * cost:i costGold:i */ import type { AccountStore } from '../../accounts/account-store.ts'; -import { buyDecoration, decorKey, isDecorKind } from '../../decor/decor-purchase.ts'; +import { buyDecoration, decorKey, isDecorKind, type DecorShop } 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 { +export function buyResourceAction(profiles: PlayerProfiles, accounts: AccountStore, decor: DecorShop): 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); + return (profile) => buyDecoration(profile, decor, type, key, offered); }); } diff --git a/packages/local-service/src/char/actions/inventory-actions.ts b/packages/local-service/src/char/actions/inventory-actions.ts index 1517e13..eb9c170 100644 --- a/packages/local-service/src/char/actions/inventory-actions.ts +++ b/packages/local-service/src/char/actions/inventory-actions.ts @@ -19,11 +19,12 @@ import { type ExchangeItemDelta, } from '../../inventory/inventory-rules.ts'; import { deltaToInventoryJson, parseExchangeItemsRequest } from '../../inventory/inventory-wire.ts'; -import { buyTrophy } from '../../inventory/trophy-catalogue.ts'; +import type { InventoryCatalogue } from '../../inventory/itemdef-catalogue.ts'; +import { buyTrophy, type TrophyCatalogue } from '../../inventory/trophy-catalogue.ts'; +import type { ItemCatalogue } from '../../items/item-catalogue.ts'; import { clientProfile } from '../../profile/client-profile.ts'; import type { PlayerProfiles } from '../../profile/player-profiles.ts'; import { serverTimeNow } from '../../profile/server-time.ts'; -import type { ResearchRules } from '../../research/research-rules.ts'; import type { RuleOutcome } from '../../research/rule-outcome.ts'; import type { CharActionHandler } from '../char-action.ts'; import { withAccount } from './account-context.ts'; @@ -53,21 +54,22 @@ function profileRuleWithNotify( export function consumeInventoryItemAction( profiles: PlayerProfiles, accounts: AccountStore, - rules: ResearchRules, + inventory: InventoryCatalogue, + items: ItemCatalogue, notifyInventoryChanged: () => void, ): CharActionHandler { return profileRuleWithNotify(profiles, accounts, notifyInventoryChanged, (payload) => { const itemId = intParam(payload, 'itemId'); const quantity = intParam(payload, 'quantity') ?? 1; if (itemId === undefined) return undefined; - return (profile) => consumeInventoryCoupon(profile, rules.inventory, rules.items, String(itemId), quantity, serverTimeNow()); + return (profile) => consumeInventoryCoupon(profile, inventory, items, String(itemId), quantity, serverTimeNow()); }); } export function purchaseInventoryItemAction( profiles: PlayerProfiles, accounts: AccountStore, - rules: ResearchRules, + inventory: InventoryCatalogue, notifyInventoryChanged: () => void, ): CharActionHandler { return profileRuleWithNotify(profiles, accounts, notifyInventoryChanged, (payload) => { @@ -76,14 +78,14 @@ export function purchaseInventoryItemAction( const amount = intParam(payload, 'amount') ?? 1; const wpCost = intParam(payload, 'wpCost') ?? 0; const goldCost = intParam(payload, 'goldCost') ?? 0; - return (profile) => purchaseExternalInventoryItem(profile, rules.inventory, itemDefId, amount, wpCost, goldCost); + return (profile) => purchaseExternalInventoryItem(profile, inventory, itemDefId, amount, wpCost, goldCost); }); } export function recycleItemsAction( profiles: PlayerProfiles, accounts: AccountStore, - rules: ResearchRules, + items: ItemCatalogue, notifyInventoryChanged: () => void, ): CharActionHandler { return profileRuleWithNotify(profiles, accounts, notifyInventoryChanged, (payload) => { @@ -96,14 +98,15 @@ export function recycleItemsAction( count: intParam(b, 'count') ?? 1, })); if (requests.length === 0) return undefined; - return (profile) => recycleClassicItems(profile, rules.items, requests); + return (profile) => recycleClassicItems(profile, items, requests); }); } export function multiConsumeInventoryItemsAction( profiles: PlayerProfiles, accounts: AccountStore, - rules: ResearchRules, + inventory: InventoryCatalogue, + items: ItemCatalogue, notifyInventoryChanged: () => void, ): CharActionHandler { return (context) => withAccount(context, accounts, (account) => { @@ -112,7 +115,7 @@ export function multiConsumeInventoryItemsAction( let revertedItems: number[] = []; profiles.update(account.userId, (saved) => { - const res = multiConsumeInventoryItems(saved, rules.inventory, rules.items, requests, serverTimeNow()); + const res = multiConsumeInventoryItems(saved, inventory, items, requests, serverTimeNow()); revertedItems = res.revertedItems; }); notifyInventoryChanged(); @@ -123,7 +126,7 @@ export function multiConsumeInventoryItemsAction( export function inventoryExchangeAction( profiles: PlayerProfiles, accounts: AccountStore, - rules: ResearchRules, + inventory: InventoryCatalogue, ): CharActionHandler { return (context) => withAccount(context, accounts, (account) => { const parsed = parseExchangeItemsRequest(context.rawText); @@ -134,7 +137,7 @@ export function inventoryExchangeAction( profiles.updateWhen(account.userId, (saved) => { const res = exchangeInventoryItems( saved, - rules.inventory, + inventory, parsed.outputItemDefId, parsed.quantity, parsed.materials, @@ -154,14 +157,15 @@ export function inventoryExchangeAction( export function buyTrophyAction( profiles: PlayerProfiles, accounts: AccountStore, - rules: ResearchRules, + trophies: TrophyCatalogue, + items: ItemCatalogue, ): CharActionHandler { return ruleAction(profiles, accounts, (payload) => { const name = stringParam(payload, 'name'); if (!name) return undefined; const cost = intParam(payload, 'cost') ?? 0; const costGold = intParam(payload, 'costGold') ?? 0; - return (profile) => buyTrophy(profile, rules.trophies, rules.items, name, cost, costGold, serverTimeNow()); + return (profile) => buyTrophy(profile, trophies, items, name, cost, costGold, serverTimeNow()); }); } diff --git a/packages/local-service/src/char/actions/item-actions.ts b/packages/local-service/src/char/actions/item-actions.ts index c4daa5d..0f81ad8 100644 --- a/packages/local-service/src/char/actions/item-actions.ts +++ b/packages/local-service/src/char/actions/item-actions.ts @@ -10,22 +10,23 @@ */ import type { AccountStore } from '../../accounts/account-store.ts'; import { activateBooster, activateDiscount, startWager } from '../../items/item-activation.ts'; +import type { ItemCatalogue } from '../../items/item-catalogue.ts'; import { buyItem } from '../../items/item-purchase.ts'; import { applyUniversalSpares } from '../../items/universal-spares.ts'; import type { PlayerProfiles } from '../../profile/player-profiles.ts'; import { serverTimeNow } from '../../profile/server-time.ts'; -import type { ResearchRules } from '../../research/research-rules.ts'; +import type { TechTree } from '../../research/tech-tree.ts'; import type { CharActionHandler } from '../char-action.ts'; import { intParam, stringParam } from './payload-params.ts'; import { ruleAction } from './rule-answer.ts'; -export function buyItemAction(profiles: PlayerProfiles, accounts: AccountStore, rules: ResearchRules): CharActionHandler { +export function buyItemAction(profiles: PlayerProfiles, accounts: AccountStore, items: ItemCatalogue): CharActionHandler { return ruleAction(profiles, accounts, (payload) => { const name = stringParam(payload, 'name'); const pieces = intParam(payload, 'count'); if (name === undefined || pieces === undefined) return undefined; const offered = { silverLions: intParam(payload, 'cost') ?? 0, goldenEagles: intParam(payload, 'costGold') ?? 0 }; - return (profile) => buyItem(profile, rules.items, name, pieces, offered, serverTimeNow()); + return (profile) => buyItem(profile, items, name, pieces, offered, serverTimeNow()); }); } @@ -37,29 +38,29 @@ export function activateBoosterAction(profiles: PlayerProfiles, accounts: Accoun }); } -export function activateDiscountAction(profiles: PlayerProfiles, accounts: AccountStore, rules: ResearchRules): CharActionHandler { +export function activateDiscountAction(profiles: PlayerProfiles, accounts: AccountStore, items: ItemCatalogue): CharActionHandler { return ruleAction(profiles, accounts, (payload) => { const uid = stringParam(payload, 'name'); if (uid === undefined) return undefined; - return (profile) => activateDiscount(profile, rules.items, uid, serverTimeNow()); + return (profile) => activateDiscount(profile, items, uid, serverTimeNow()); }); } -export function startWagerAction(profiles: PlayerProfiles, accounts: AccountStore, rules: ResearchRules): CharActionHandler { +export function startWagerAction(profiles: PlayerProfiles, accounts: AccountStore, items: ItemCatalogue): CharActionHandler { return ruleAction(profiles, accounts, (payload) => { const uid = stringParam(payload, 'name'); const stake = intParam(payload, 'wager'); if (uid === undefined || stake === undefined) return undefined; - return (profile) => startWager(profile, rules.items, uid, stake); + return (profile) => startWager(profile, items, uid, stake); }); } -export function applySpareItemAction(profiles: PlayerProfiles, accounts: AccountStore, rules: ResearchRules): CharActionHandler { +export function applySpareItemAction(profiles: PlayerProfiles, accounts: AccountStore, items: ItemCatalogue, techTree: TechTree): CharActionHandler { return ruleAction(profiles, accounts, (payload) => { const uid = stringParam(payload, 'uid'); const vehicle = stringParam(payload, 'unit'); const pieces = intParam(payload, 'useItemsCount'); if (uid === undefined || vehicle === undefined || pieces === undefined) return undefined; - return (profile) => applyUniversalSpares(profile, rules.items, rules.techTree, uid, vehicle, pieces); + return (profile) => applyUniversalSpares(profile, items, techTree, uid, vehicle, pieces); }); } diff --git a/packages/local-service/src/char/actions/modification-actions.ts b/packages/local-service/src/char/actions/modification-actions.ts index 6f2cab7..3cb4ebd 100644 --- a/packages/local-service/src/char/actions/modification-actions.ts +++ b/packages/local-service/src/char/actions/modification-actions.ts @@ -13,16 +13,16 @@ */ import type { BlkBlock } from '@wto/blk'; import type { AccountStore } from '../../accounts/account-store.ts'; +import type { EquipmentCatalogue } from '../../modifications/equipment-catalogue.ts'; import { buyAllModifications, buyModification, enableModifications } from '../../modifications/modification-purchase.ts'; import { buySpares } from '../../modifications/spare-purchase.ts'; import { buyWeapons } from '../../modifications/weapon-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 { boolParam, intParam, stringParam } from './payload-params.ts'; import { ruleAction } from './rule-answer.ts'; -export function buyModificationAction(profiles: PlayerProfiles, accounts: AccountStore, rules: ResearchRules): CharActionHandler { +export function buyModificationAction(profiles: PlayerProfiles, accounts: AccountStore, equipment: EquipmentCatalogue): CharActionHandler { return ruleAction(profiles, accounts, (payload) => { const vehicle = stringParam(payload, 'aircraft'); const modification = stringParam(payload, 'modification'); @@ -34,37 +34,37 @@ export function buyModificationAction(profiles: PlayerProfiles, accounts: Accoun amount: intParam(payload, 'count') ?? 1, offered: offeredPrice(payload), }; - return (profile) => buyModification(profile, rules.equipment, order); + return (profile) => buyModification(profile, equipment, order); }); } -export function buyAllModificationsAction(profiles: PlayerProfiles, accounts: AccountStore, rules: ResearchRules): CharActionHandler { +export function buyAllModificationsAction(profiles: PlayerProfiles, accounts: AccountStore, equipment: EquipmentCatalogue): CharActionHandler { return ruleAction(profiles, accounts, (payload) => { const vehicle = stringParam(payload, 'unit'); if (vehicle === undefined) return undefined; const outright = boolParam(payload, 'forceOpen') ?? false; const offered = offeredPrice(payload); - return (profile) => buyAllModifications(profile, rules.equipment, vehicle, outright, offered); + return (profile) => buyAllModifications(profile, equipment, vehicle, outright, offered); }); } -export function buySparesAction(profiles: PlayerProfiles, accounts: AccountStore, rules: ResearchRules): CharActionHandler { +export function buySparesAction(profiles: PlayerProfiles, accounts: AccountStore, equipment: EquipmentCatalogue): CharActionHandler { return ruleAction(profiles, accounts, (payload) => { const vehicle = stringParam(payload, 'aircraft'); if (vehicle === undefined) return undefined; const amount = intParam(payload, 'count') ?? 1; const offered = offeredPrice(payload); - return (profile) => buySpares(profile, rules.equipment, vehicle, amount, offered); + return (profile) => buySpares(profile, equipment, vehicle, amount, offered); }); } -export function buyWeaponsAction(profiles: PlayerProfiles, accounts: AccountStore, rules: ResearchRules): CharActionHandler { +export function buyWeaponsAction(profiles: PlayerProfiles, accounts: AccountStore, equipment: EquipmentCatalogue): CharActionHandler { return ruleAction(profiles, accounts, (payload) => { const vehicle = stringParam(payload, 'aircraft'); const weapon = stringParam(payload, 'weapon'); if (vehicle === undefined || weapon === undefined) return undefined; const order = { vehicle, weapon, amount: intParam(payload, 'count') ?? 1, offered: offeredPrice(payload) }; - return (profile) => buyWeapons(profile, rules.equipment, order); + return (profile) => buyWeapons(profile, equipment, order); }); } diff --git a/packages/local-service/src/char/actions/player-card-actions.ts b/packages/local-service/src/char/actions/player-card-actions.ts index b97740c..1e76205 100644 --- a/packages/local-service/src/char/actions/player-card-actions.ts +++ b/packages/local-service/src/char/actions/player-card-actions.ts @@ -19,7 +19,6 @@ import { currentShowcaseView, saveShowcase, showcasesAnswer } from '../../player import { appearance, chosenTitle } from '../../profile/profile-appearance.ts'; import { clanMembershipOf } from '../../profile/profile-clan.ts'; import type { PlayerProfiles } from '../../profile/player-profiles.ts'; -import type { ResearchRules } from '../../research/research-rules.ts'; import type { TechTree } from '../../research/tech-tree.ts'; import type { CharActionHandler } from '../char-action.ts'; import { withAccount } from './account-context.ts'; @@ -45,18 +44,18 @@ export function saveShowcaseAction(profiles: PlayerProfiles, accounts: AccountSt return ruleAction(profiles, accounts, (payload) => (profile) => saveShowcase(profile, payload)); } -export function showcasesAction(profiles: PlayerProfiles, accounts: AccountStore, rules: ResearchRules): CharActionHandler { +export function showcasesAction(profiles: PlayerProfiles, accounts: AccountStore, techTree: TechTree): CharActionHandler { return (context) => withAccount(context, accounts, (account) => - ({ kind: 'data', blk: showcasesAnswer(profiles.profileOf(account.userId), rules.techTree) })); + ({ kind: 'data', blk: showcasesAnswer(profiles.profileOf(account.userId), techTree) })); } -export function usersTerseInfoAction(profiles: PlayerProfiles, accounts: AccountStore, rules: ResearchRules, clans?: ClanStore): CharActionHandler { +export function usersTerseInfoAction(profiles: PlayerProfiles, accounts: AccountStore, techTree: TechTree, clans?: ClanStore): CharActionHandler { return (context) => withAccount(context, accounts, () => { const list = (context.payload ? stringParam(context.payload, 'usersList') : undefined) ?? context.headerParam('usersList'); if (list === undefined) return { kind: 'error', code: 'BAD_PARAMS' }; const blocks = list.split(';').filter((uid) => uid !== '').map((uid): BlkBlock => { const account = accounts.byUserId(uid); - if (account) return accountTerseInfoBlk(uid, account, profiles, rules.techTree, clans); + if (account) return accountTerseInfoBlk(uid, account, profiles, techTree, clans); const npc = clans?.npcMemberByUid(uid); if (npc) return npcTerseInfoBlk(uid, npc.clan, npc.member); return { name: uid, params: [{ name: 'failed', value: { type: 'bool', value: true } }], blocks: [] }; diff --git a/packages/local-service/src/char/actions/price-actions.ts b/packages/local-service/src/char/actions/price-actions.ts index 877488a..f01af3b 100644 --- a/packages/local-service/src/char/actions/price-actions.ts +++ b/packages/local-service/src/char/actions/price-actions.ts @@ -1,14 +1,13 @@ /** - * cln_get_price_ex: the price table (implementation notes; src/research/price-table.ts). + * cln_get_price_ex: the price table (implementation notes; char/actions/price-table.ts). * Sent at sign-in with an empty body and again by the stock scripts when a purchase fails * (scripts/unit/unitActions.nut impl_buyUnit: PRICE.update). The table only depends on the - * game files, so it is built once. + * game files and tuning, so it is built once. */ import type { CharActionHandler } from '../char-action.ts'; -import { priceTable } from '../../research/price-table.ts'; -import type { ResearchRules } from '../../research/research-rules.ts'; +import { priceTable, type PriceTableSources } from './price-table.ts'; -export function priceEx(rules: ResearchRules): CharActionHandler { - const table = priceTable(rules); +export function priceEx(sources: PriceTableSources): CharActionHandler { + const table = priceTable(sources); return () => ({ kind: 'data', blk: table }); } diff --git a/packages/local-service/src/research/price-table.ts b/packages/local-service/src/char/actions/price-table.ts similarity index 85% rename from packages/local-service/src/research/price-table.ts rename to packages/local-service/src/char/actions/price-table.ts index 118e11f..2039063 100644 --- a/packages/local-service/src/research/price-table.ts +++ b/packages/local-service/src/char/actions/price-table.ts @@ -25,7 +25,9 @@ * unlocks{ { cost:i costGold:i } } unlocks for sale (0x9170c0) * items{ { cost:i costGold:i } } classic items for sale, price per piece * (wp_get_item_cost, 0x10531e0; implementation notes) + * trophy{ { cost:i costGold:i } } classic trophy prices * } + * trophy{ { ... } } classic trophy definitions & drop weights * * Every entry is read as cost:i (silver lions), costGold:i (golden eagles), discount:i (percent * off, not sent: no discounts), each 0 when missing (so zero prices are left out); openCostGold @@ -35,19 +37,28 @@ * attachable.blk; unlocks: config/unlocks.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 { TrophyCatalogue, TrophyDefinition, TrophyPrize } from '../inventory/trophy-catalogue.ts'; -import type { ItemCatalogue } from '../items/item-catalogue.ts'; -import type { EquipmentCatalogue } from '../modifications/equipment-catalogue.ts'; -import type { UnlockShop } from '../unlocks/unlock-purchase.ts'; -import type { ResearchRules } from './research-rules.ts'; -import type { TechTree } from './tech-tree.ts'; +import type { CrewSkillCatalogue } from '../../crew/crew-skill-rules.ts'; +import type { DecorShop } from '../../decor/decor-purchase.ts'; +import type { TrophyCatalogue, TrophyDefinition, TrophyPrize } from '../../inventory/trophy-catalogue.ts'; +import type { ItemCatalogue } from '../../items/item-catalogue.ts'; +import type { EquipmentCatalogue } from '../../modifications/equipment-catalogue.ts'; +import type { TechTree } from '../../research/tech-tree.ts'; +import type { UnlockShop } from '../../unlocks/unlock-purchase.ts'; /** The top-level block every client lookup falls back to (0x908e28). */ const COMMON_SECTION = 'Common'; -export function priceTable(rules: ResearchRules): BlkBlock { +export interface PriceTableSources { + readonly techTree: TechTree; + readonly equipment: EquipmentCatalogue; + readonly decor: DecorShop; + readonly crew: CrewSkillCatalogue; + readonly unlocks: UnlockShop; + readonly items: ItemCatalogue; + readonly trophies: TrophyCatalogue; +} + +export function priceTable(sources: PriceTableSources): BlkBlock { return { name: '', params: [], @@ -56,15 +67,15 @@ export function priceTable(rules: ResearchRules): BlkBlock { name: COMMON_SECTION, params: [], blocks: [ - vehicleSection(rules.techTree, rules.equipment), - ...decorSections(rules.decor), - skillPackSection(rules.crew), - unlockSection(rules.unlocks), - itemSection(rules.items), - trophyPriceSection(rules.trophies), + vehicleSection(sources.techTree, sources.equipment), + ...decorSections(sources.decor), + skillPackSection(sources.crew), + unlockSection(sources.unlocks), + itemSection(sources.items), + trophyPriceSection(sources.trophies), ], }, - trophyDefinitionsSection(rules.trophies), + trophyDefinitionsSection(sources.trophies), ], }; } diff --git a/packages/local-service/src/char/actions/research-actions.ts b/packages/local-service/src/char/actions/research-actions.ts index 1c1ef54..9925366 100644 --- a/packages/local-service/src/char/actions/research-actions.ts +++ b/packages/local-service/src/char/actions/research-actions.ts @@ -16,19 +16,25 @@ * unit:t, amount:i research points */ import type { AccountStore } from '../../accounts/account-store.ts'; -import type { PlayerProfiles } from '../../profile/player-profiles.ts'; +import type { EquipmentCatalogue } from '../../modifications/equipment-catalogue.ts'; import { chooseModuleResearch } from '../../modifications/module-research-target.ts'; +import type { PlayerProfiles } from '../../profile/player-profiles.ts'; import { chooseResearchTarget, convertFreeResearchPoints, dismissFinishedResearch } from '../../research/research-progress.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 setResearchable(profiles: PlayerProfiles, accounts: AccountStore, rules: ResearchRules): CharActionHandler { +export function setResearchable( + profiles: PlayerProfiles, + accounts: AccountStore, + rules: ResearchRules, + equipment: EquipmentCatalogue, +): CharActionHandler { return ruleAction(profiles, accounts, (payload) => { const vehicle = stringParam(payload, 'unit'); const modification = stringParam(payload, 'mod'); - if (vehicle !== undefined && modification !== undefined) return (profile) => chooseModuleResearch(profile, rules.equipment, vehicle, modification); + if (vehicle !== undefined && modification !== undefined) return (profile) => chooseModuleResearch(profile, equipment, vehicle, modification); const type = intParam(payload, 'type'); if (vehicle === undefined || type === undefined) return undefined; return (profile) => chooseResearchTarget(profile, rules, vehicle, type); diff --git a/packages/local-service/src/char/actions/store-actions.ts b/packages/local-service/src/char/actions/store-actions.ts index 4efc4a0..93227b9 100644 --- a/packages/local-service/src/char/actions/store-actions.ts +++ b/packages/local-service/src/char/actions/store-actions.ts @@ -11,20 +11,19 @@ import type { AccountStore } from '../../accounts/account-store.ts'; import { clientProfile } from '../../profile/client-profile.ts'; import type { PlayerProfiles } from '../../profile/player-profiles.ts'; import { serverTimeNow } from '../../profile/server-time.ts'; -import type { ResearchRules } from '../../research/research-rules.ts'; import type { RuleOutcome } from '../../research/rule-outcome.ts'; -import type { StoreProduct } from '../../store/store-catalogue.ts'; +import type { StoreCatalogue, StoreProduct } from '../../store/store-catalogue.ts'; import { buyGoldEntitlement } from '../../store/store-purchase.ts'; import type { CharActionHandler } from '../char-action.ts'; import { withAccount } from './account-context.ts'; import { headerOrPayloadInt, headerOrPayloadString } from './payload-params.ts'; -export function entitlementsPriceEx(rules: ResearchRules): CharActionHandler { - const table = buildEntitlementsPriceBlk(rules.store.allProducts()); +export function entitlementsPriceEx(store: StoreCatalogue): CharActionHandler { + const table = buildEntitlementsPriceBlk(store.allProducts()); return () => ({ kind: 'data', blk: table }); } -export function buyEntitlementAction(profiles: PlayerProfiles, accounts: AccountStore, rules: ResearchRules): CharActionHandler { +export function buyEntitlementAction(profiles: PlayerProfiles, accounts: AccountStore, store: StoreCatalogue): CharActionHandler { return (context) => withAccount(context, accounts, (account) => { const entitlement = headerOrPayloadString(context, 'entitlement'); const offeredGold = headerOrPayloadInt(context, 'costGold'); @@ -35,7 +34,7 @@ export function buyEntitlementAction(profiles: PlayerProfiles, accounts: Account let outcome: RuleOutcome = { ok: false, refusal: 'BAD_PARAMS' }; const now = serverTimeNow(); const updated = profiles.updateWhen(account.userId, (saved) => { - outcome = buyGoldEntitlement(saved, rules.store, entitlement, offeredGold, now); + outcome = buyGoldEntitlement(saved, store, entitlement, offeredGold, now); return outcome.ok; }); if (updated) return { kind: 'data', blk: clientProfile(updated, account) }; diff --git a/packages/local-service/src/char/actions/unlock-actions.ts b/packages/local-service/src/char/actions/unlock-actions.ts index 6cdc049..743891b 100644 --- a/packages/local-service/src/char/actions/unlock-actions.ts +++ b/packages/local-service/src/char/actions/unlock-actions.ts @@ -10,17 +10,16 @@ */ import type { AccountStore } from '../../accounts/account-store.ts'; import type { PlayerProfiles } from '../../profile/player-profiles.ts'; -import type { ResearchRules } from '../../research/research-rules.ts'; -import { buyUnlock } from '../../unlocks/unlock-purchase.ts'; +import { buyUnlock, type UnlockShop } from '../../unlocks/unlock-purchase.ts'; import type { CharActionHandler } from '../char-action.ts'; import { intParam, stringParam } from './payload-params.ts'; import { ruleAction } from './rule-answer.ts'; -export function buyUnlockAction(profiles: PlayerProfiles, accounts: AccountStore, rules: ResearchRules): CharActionHandler { +export function buyUnlockAction(profiles: PlayerProfiles, accounts: AccountStore, unlocks: UnlockShop): CharActionHandler { return ruleAction(profiles, accounts, (payload) => { const name = stringParam(payload, 'name'); if (name === undefined) return undefined; const offered = { silverLions: intParam(payload, 'wpCost') ?? 0, goldenEagles: intParam(payload, 'goldCost') ?? 0 }; - return (profile) => buyUnlock(profile, rules.unlocks, name, offered); + return (profile) => buyUnlock(profile, unlocks, name, offered); }); } diff --git a/packages/local-service/src/local-service.ts b/packages/local-service/src/local-service.ts index 9dbf23c..d2ead0b 100644 --- a/packages/local-service/src/local-service.ts +++ b/packages/local-service/src/local-service.ts @@ -8,14 +8,30 @@ import { actionTable } from './char/actions/action-table.ts'; import { CharService } from './char/char-service.ts'; import { ClanStore } from './clans/clan-store.ts'; import { CloudSettingsStore } from './cloud-settings/cloud-settings-store.ts'; +import { CrewSkillCatalogue } from './crew/crew-skill-rules.ts'; +import { DecorShop } from './decor/decor-purchase.ts'; import { DownloadableContentService } from './downloadable-content/downloadable-content-service.ts'; +import { clanEconomy } from './game-data/datasets/clan-economy.ts'; +import { crewSkillData } from './game-data/datasets/crew-skills.ts'; import { DatasetCache } from './game-data/datasets/dataset-cache.ts'; +import { decorCatalogue } from './game-data/datasets/decor-catalogue.ts'; +import { externalItemSources } from './game-data/datasets/external-item-sources.ts'; +import { itemCatalogue } from './game-data/datasets/item-catalogue.ts'; import { multiplayerMissions } from './game-data/datasets/multiplayer-missions.ts'; import { shopCountries } from './game-data/datasets/shop-countries.ts'; +import { storeBundles } from './game-data/datasets/store-bundles.ts'; +import { uiLabels, type UiLabels } from './game-data/datasets/ui-labels.ts'; +import { unitNames } from './game-data/datasets/unit-names.ts'; +import { unlockPrices } from './game-data/datasets/unlock-prices.ts'; +import { vehicleCatalogue, type CatalogueVehicle } from './game-data/datasets/vehicle-catalogue.ts'; +import { webIcons } from './game-data/datasets/web-icons.ts'; import { GameFiles } from './game-data/game-files.ts'; import { GameModes } from './game-modes/game-modes.ts'; import { InventoryService } from './inventory/inventory-service.ts'; +import { InventoryCatalogue } from './inventory/itemdef-catalogue.ts'; import { MarketplaceService } from './inventory/marketplace-service.ts'; +import { TrophyCatalogue } from './inventory/trophy-catalogue.ts'; +import { ItemCatalogue } from './items/item-catalogue.ts'; import { LoginService } from './login/login-service.ts'; import { matchingRequests } from './matching/matching-requests.ts'; import type { MatchingService } from './matching/matching-service.ts'; @@ -23,11 +39,11 @@ import { setUpProfiles } from './profiles-setup.ts'; import { createPortListener } from './server/port-listener.ts'; import { Router } from './server/router.ts'; import { loadOrCreateCredentials } from './server/tls/tls-certificate.ts'; +import { StoreCatalogue } from './store/store-catalogue.ts'; import { StoreService } from './store/store-service.ts'; import { TrafficLog } from './traffic-log/traffic-log.ts'; -import { loadTuning } from './tuning/tuning.ts'; -import { uiLabels } from './game-data/datasets/ui-labels.ts'; -import { webIcons } from './game-data/datasets/web-icons.ts'; +import { loadTuning, type Tuning } from './tuning/tuning.ts'; +import { UnlockShop } from './unlocks/unlock-purchase.ts'; import { WebUiService } from './web-ui/web-ui-service.ts'; export interface LocalServiceOptions { @@ -57,8 +73,11 @@ export async function startLocalService(options: LocalServiceOptions): Promise { return new Promise((resolve, reject) => { server.once('error', reject); diff --git a/packages/local-service/src/profiles-setup.ts b/packages/local-service/src/profiles-setup.ts index eec4cce..f815a2c 100644 --- a/packages/local-service/src/profiles-setup.ts +++ b/packages/local-service/src/profiles-setup.ts @@ -9,10 +9,13 @@ import type { ClanStore } from './clans/clan-store.ts'; import type { DatasetCache } from './game-data/datasets/dataset-cache.ts'; import { reserveVehicles } from './game-data/datasets/reserve-vehicles.ts'; import { shopBranches } from './game-data/datasets/shop-branches.ts'; +import { vehicleCatalogue, type CatalogueVehicle } from './game-data/datasets/vehicle-catalogue.ts'; +import { vehicleEquipment } from './game-data/datasets/vehicle-equipment.ts'; import type { GameFiles } from './game-data/game-files.ts'; import { removeExpiredItems } from './items/item-expiry.ts'; -import { trimUserLogs } from './profile/profile-trophies-log.ts'; +import { EquipmentCatalogue } from './modifications/equipment-catalogue.ts'; import { refreshModuleState } from './modifications/module-state.ts'; +import { trimUserLogs } from './profile/profile-trophies-log.ts'; import { PlayerProfiles } from './profile/player-profiles.ts'; import { profileUpgrades } from './profile/profile-upgrades.ts'; import { serverTimeNow } from './profile/server-time.ts'; @@ -25,6 +28,7 @@ import type { Tuning } from './tuning/tuning.ts'; export interface ProfileServices { readonly profiles: PlayerProfiles; readonly research: ResearchRules; + readonly equipment: EquipmentCatalogue; } export interface ProfileSyncContext { @@ -38,21 +42,23 @@ export function setUpProfiles( datasets: DatasetCache, tuning: Tuning, sync?: ProfileSyncContext, + vehicles: readonly CatalogueVehicle[] = datasets.load(vehicleCatalogue), ): ProfileServices { const startingContent: StartingContent = { reserveVehicles: datasets.load(reserveVehicles), branches: datasets.load(shopBranches), startingBalance: tuning.newProfile.startingBalance, }; - const research = loadResearchRules(datasets, tuning); + const research = loadResearchRules(datasets, tuning.research, vehicles); + const equipment = new EquipmentCatalogue(datasets.load(vehicleEquipment)); const saves = new SaveStore(dataFolder, profileUpgrades(startingContent)); const profiles = new PlayerProfiles(saves, gameFiles, startingContent, (profile, userId) => { const account = sync?.accounts.byUserId(userId); if (account && sync) sync.clans.syncProfile(profile, account); refreshResearchState(profile, research); - refreshModuleState(profile, research.equipment); + refreshModuleState(profile, equipment); removeExpiredItems(profile, serverTimeNow()); trimUserLogs(profile, tuning.limits.userLogsKept); }); - return { profiles, research }; + return { profiles, research, equipment }; } diff --git a/packages/local-service/src/research/research-rules.ts b/packages/local-service/src/research/research-rules.ts index d199f54..3e9596d 100644 --- a/packages/local-service/src/research/research-rules.ts +++ b/packages/local-service/src/research/research-rules.ts @@ -1,31 +1,12 @@ /** - * The static facts research and purchase rules use, loaded once at start-up from the - * player's game files. + * The static facts vehicle research and purchase rules use, loaded once at start-up from + * the player's game files (implementation notes; implementation notes). */ import type { DatasetCache } from '../game-data/datasets/dataset-cache.ts'; import { crewSlotPrices, eraRequirements, type CrewSlotPrices, type EraRequirements } from '../game-data/datasets/rank-settings.ts'; 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 { vehicleCatalogue, type CatalogueVehicle } from '../game-data/datasets/vehicle-catalogue.ts'; import { vehicleUnlocks, type UnlockDefinition } from '../game-data/datasets/vehicle-unlocks.ts'; -import { EquipmentCatalogue } from '../modifications/equipment-catalogue.ts'; -import { unlockPrices } from '../game-data/datasets/unlock-prices.ts'; -import { UnlockShop } from '../unlocks/unlock-purchase.ts'; -import { clanEconomy, type ClanEconomy } from '../game-data/datasets/clan-economy.ts'; -import { itemCatalogue } from '../game-data/datasets/item-catalogue.ts'; -import { externalItemSources } from '../game-data/datasets/external-item-sources.ts'; -import { storeBundles } from '../game-data/datasets/store-bundles.ts'; -import { uiLabels } from '../game-data/datasets/ui-labels.ts'; -import { unitNames } from '../game-data/datasets/unit-names.ts'; -import { InventoryCatalogue } from '../inventory/itemdef-catalogue.ts'; -import { TrophyCatalogue } from '../inventory/trophy-catalogue.ts'; -import { ItemCatalogue } from '../items/item-catalogue.ts'; -import { StoreCatalogue } from '../store/store-catalogue.ts'; -import type { Tuning } from '../tuning/tuning.ts'; import type { ResearchTuning } from './research-tuning.ts'; import { TechTree } from './tech-tree.ts'; @@ -37,45 +18,19 @@ export interface ResearchRules { readonly researchPointsPerGoldenEagle: number; /** How a branch without a research target gets one (tuning/research.jsonc; implementation notes). */ readonly researchTuning: ResearchTuning; - /** Modifications, ammunition, weapon presets and spares of every vehicle. */ - readonly equipment: EquipmentCatalogue; - /** Decorations for sale. */ - readonly decor: DecorShop; - /** Crew skills, skill point packs, training prices. */ - readonly crew: CrewSkillCatalogue; - /** Unlocks for sale: ship flags, profile icons and frames, awards. */ - readonly unlocks: UnlockShop; - /** Classic items: boosters, personal discounts, contracts, universal spares. */ - readonly items: ItemCatalogue; - /** Paid store catalogue: GE packs, SL packs, Premium Account, vehicle packs. */ - readonly store: StoreCatalogue; - /** External inventory itemdefs, supply chests, recycle recipes, and marketplace coupons. */ - readonly inventory: InventoryCatalogue; - /** Classic trophies: SL supply chests and GE vehicle prize-pool direct purchases. */ - readonly trophies: TrophyCatalogue; - /** Squadron creation, upgrade and member-limit economy from warpoints.blk. */ - readonly clanEconomy: ClanEconomy; } -export function loadResearchRules(datasets: DatasetCache, tuning: Tuning): ResearchRules { - const vehicles = datasets.load(vehicleCatalogue); - const classicItemDefs = datasets.load(itemCatalogue); - const localizedUnitNames = datasets.load(unitNames); +export function loadResearchRules( + datasets: DatasetCache, + researchTuning: ResearchTuning, + vehicles: readonly CatalogueVehicle[] = datasets.load(vehicleCatalogue), +): ResearchRules { return { techTree: new TechTree(vehicles), eraRequirements: datasets.load(eraRequirements), vehicleUnlocks: datasets.load(vehicleUnlocks), crewSlotPrices: datasets.load(crewSlotPrices), researchPointsPerGoldenEagle: datasets.load(researchPointsPerGoldenEagle), - researchTuning: tuning.research, - equipment: new EquipmentCatalogue(datasets.load(vehicleEquipment)), - decor: new DecorShop(datasets.load(decorCatalogue)), - crew: new CrewSkillCatalogue(datasets.load(crewSkillData)), - unlocks: new UnlockShop(datasets.load(unlockPrices)), - items: new ItemCatalogue(classicItemDefs, tuning.limits.itemPiecesPerPurchase), - store: new StoreCatalogue(vehicles, datasets.load(storeBundles), localizedUnitNames, datasets.load(uiLabels), tuning.store), - inventory: new InventoryCatalogue(vehicles, localizedUnitNames, datasets.load(externalItemSources), classicItemDefs, tuning), - trophies: new TrophyCatalogue(vehicles, classicItemDefs, tuning.trophies), - clanEconomy: datasets.load(clanEconomy), + researchTuning, }; } diff --git a/packages/local-service/src/save-cli.ts b/packages/local-service/src/save-cli.ts index e0566a4..727113a 100644 --- a/packages/local-service/src/save-cli.ts +++ b/packages/local-service/src/save-cli.ts @@ -7,11 +7,17 @@ * [--squadron-rp ] [--give-item [:]]... [--give-coupon [:]]... */ import { parseArgs } from 'node:util'; +import type { BlkBlock } from '@wto/blk'; import { AccountStore, type Account } from './accounts/account-store.ts'; import { ClanStore } from './clans/clan-store.ts'; import { DatasetCache } from './game-data/datasets/dataset-cache.ts'; -import type { ItemDefinition } from './game-data/datasets/item-catalogue.ts'; +import { externalItemSources } from './game-data/datasets/external-item-sources.ts'; +import { itemCatalogue, type ItemDefinition } from './game-data/datasets/item-catalogue.ts'; +import { unitNames } from './game-data/datasets/unit-names.ts'; +import { vehicleCatalogue, type CatalogueVehicle } from './game-data/datasets/vehicle-catalogue.ts'; import { GameFiles } from './game-data/game-files.ts'; +import { InventoryCatalogue } from './inventory/itemdef-catalogue.ts'; +import { ItemCatalogue } from './items/item-catalogue.ts'; import { grantItem } from './items/item-grants.ts'; import { availableSquadronRp, clanMembershipOf, setAvailableSquadronRp } from './profile/profile-clan.ts'; import { balanceOf, setGjnCents, setGoldenEagles, setSilverLions } from './profile/profile-currency.ts'; @@ -22,9 +28,7 @@ import { freeResearchPoints, setFreeResearchPoints } from './profile/profile-res import { serverTimeNow } from './profile/server-time.ts'; import { setUpProfiles } from './profiles-setup.ts'; import { gjnText } from './store/redeem-codes.ts'; -import { loadTuning } from './tuning/tuning.ts'; -import type { ResearchRules } from './research/research-rules.ts'; -import type { BlkBlock } from '@wto/blk'; +import { loadTuning, type Tuning } from './tuning/tuning.ts'; const USAGE = 'usage: save-cli.ts --game --data --player ' + '[--silver ] [--gold ] [--gjn ] [--free-rp ] [--squadron-rp ] ' @@ -72,9 +76,10 @@ function main(): number { const clans = new ClanStore(values.data, tuning.clans); const gameFiles = new GameFiles(values.game); const datasets = new DatasetCache(values.data, gameFiles, () => {}); - const { profiles, research } = setUpProfiles(values.data, gameFiles, datasets, tuning, { accounts, clans }); + const vehicles = datasets.load(vehicleCatalogue); + const { profiles } = setUpProfiles(values.data, gameFiles, datasets, tuning, { accounts, clans }, vehicles); - const edits = parseRequestedEdits(values, research); + const edits = parseRequestedEdits(values, datasets, tuning, vehicles); if (!edits) return 2; const now = serverTimeNow(); @@ -89,7 +94,9 @@ function main(): number { function parseRequestedEdits( values: Record, - research: ResearchRules, + datasets: DatasetCache, + tuning: Tuning, + vehicles: readonly CatalogueVehicle[], ): ParsedEdits | undefined { const silver = optionalAmount(values.silver as string | undefined); const gold = optionalAmount(values.gold as string | undefined); @@ -101,10 +108,34 @@ function parseRequestedEdits( return undefined; } + const itemRequests = (values['give-item'] as string[] | undefined) ?? []; + const couponRequests = (values['give-coupon'] as string[] | undefined) ?? []; + const classicItemDefs = (itemRequests.length > 0 || couponRequests.length > 0) ? datasets.load(itemCatalogue) : undefined; + const gifts = classicItemDefs && itemRequests.length > 0 + ? parseItemGifts(itemRequests, new ItemCatalogue(classicItemDefs, tuning.limits.itemPiecesPerPurchase)) + : []; + if (!gifts) return undefined; + + const coupons = classicItemDefs && couponRequests.length > 0 + ? parseCouponGifts( + couponRequests, + new InventoryCatalogue(vehicles, datasets.load(unitNames), datasets.load(externalItemSources), classicItemDefs, tuning), + ) + : []; + if (!coupons) return undefined; + + const hasChanges = silver !== undefined || gold !== undefined || gjn !== undefined || freeRp !== undefined || squadronRp !== undefined || gifts.length > 0 || coupons.length > 0; + return { silver, gold, gjn, freeRp, squadronRp, gifts, coupons, hasChanges }; +} + +function parseItemGifts( + requests: readonly string[], + items: ItemCatalogue, +): Array<{ item: ItemDefinition; pieces: number }> | undefined { const gifts: Array<{ item: ItemDefinition; pieces: number }> = []; - for (const request of (values['give-item'] as string[] | undefined) ?? []) { + for (const request of requests) { const [name = '', piecesText = '1'] = request.split(':'); - const item = research.items.item(name); + const item = items.item(name); const pieces = optionalAmount(piecesText); if (!item || !pieces) { console.error(`--give-item: no classic item "${name}", or pieces not a whole number of 1 or more`); @@ -112,21 +143,25 @@ function parseRequestedEdits( } gifts.push({ item, pieces }); } + return gifts; +} +function parseCouponGifts( + requests: readonly string[], + inventory: InventoryCatalogue, +): Array<{ itemdefId: number; quantity: number }> | undefined { const coupons: Array<{ itemdefId: number; quantity: number }> = []; - for (const request of (values['give-coupon'] as string[] | undefined) ?? []) { + for (const request of requests) { const [idText = '', qtyText = '1'] = request.split(':'); const itemdefId = optionalAmount(idText); const quantity = optionalAmount(qtyText); - if (!itemdefId || !quantity || !research.inventory.hasItemDef(itemdefId)) { + if (!itemdefId || !quantity || !inventory.hasItemDef(itemdefId)) { console.error(`--give-coupon: unknown itemdef id "${idText}", or quantity not a whole number of 1 or more`); return undefined; } coupons.push({ itemdefId, quantity }); } - - const hasChanges = silver !== undefined || gold !== undefined || gjn !== undefined || freeRp !== undefined || squadronRp !== undefined || gifts.length > 0 || coupons.length > 0; - return { silver, gold, gjn, freeRp, squadronRp, gifts, coupons, hasChanges }; + return coupons; } function applyEdits(saved: BlkBlock, edits: ParsedEdits, clanEarned: number, now: bigint): void {