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.
This commit is contained in:
1 parent
2b123194e1
commit
f4bb5ccf46
18 files changed
+310
-232
No files matched your search
@@ -2,8 +2,17 @@
|
|||||||
import type { AccountStore } from '../../accounts/account-store.ts';
|
import type { AccountStore } from '../../accounts/account-store.ts';
|
||||||
import type { ClanStore } from '../../clans/clan-store.ts';
|
import type { ClanStore } from '../../clans/clan-store.ts';
|
||||||
import type { CloudSettingsStore } from '../../cloud-settings/cloud-settings-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 { PlayerProfiles } from '../../profile/player-profiles.ts';
|
||||||
import type { ResearchRules } from '../../research/research-rules.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 type { CharActionHandler } from '../char-action.ts';
|
||||||
import { acceptEula } from './agreement-actions.ts';
|
import { acceptEula } from './agreement-actions.ts';
|
||||||
import {
|
import {
|
||||||
@@ -55,11 +64,24 @@ import { setStartingInfo } from './starting-info-actions.ts';
|
|||||||
import { buyEntitlementAction, entitlementsPriceEx } from './store-actions.ts';
|
import { buyEntitlementAction, entitlementsPriceEx } from './store-actions.ts';
|
||||||
import { buyUnlockAction } from './unlock-actions.ts';
|
import { buyUnlockAction } from './unlock-actions.ts';
|
||||||
|
|
||||||
|
export interface ClanActionDependencies {
|
||||||
|
readonly store: ClanStore;
|
||||||
|
readonly economy: ClanEconomy;
|
||||||
|
}
|
||||||
|
|
||||||
export interface ActionDependencies {
|
export interface ActionDependencies {
|
||||||
readonly profiles: PlayerProfiles;
|
readonly profiles: PlayerProfiles;
|
||||||
readonly accounts: AccountStore;
|
readonly accounts: AccountStore;
|
||||||
readonly research: ResearchRules;
|
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 cloudSettings?: CloudSettingsStore;
|
||||||
readonly notifyInventoryChanged?: () => void;
|
readonly notifyInventoryChanged?: () => void;
|
||||||
}
|
}
|
||||||
@@ -75,78 +97,79 @@ export function actionTable(deps: ActionDependencies): ReadonlyMap<string, CharA
|
|||||||
|
|
||||||
function coreActionEntries(deps: ActionDependencies): Array<[string, CharActionHandler]> {
|
function coreActionEntries(deps: ActionDependencies): Array<[string, CharActionHandler]> {
|
||||||
const notifyInventory = deps.notifyInventoryChanged ?? (() => {});
|
const notifyInventory = deps.notifyInventoryChanged ?? (() => {});
|
||||||
|
const { techTree } = deps.research;
|
||||||
return [
|
return [
|
||||||
['cln_get_initial_meta', initialMeta(deps.accounts, deps.cloudSettings)],
|
['cln_get_initial_meta', initialMeta(deps.accounts, deps.cloudSettings)],
|
||||||
['cln_upd_entitlements_full', entitlementsFull(deps.profiles, deps.accounts)],
|
['cln_upd_entitlements_full', entitlementsFull(deps.profiles, deps.accounts)],
|
||||||
['cln_legacy_get_userdata', legacyUserData(deps.profiles, deps.accounts)],
|
['cln_legacy_get_userdata', legacyUserData(deps.profiles, deps.accounts)],
|
||||||
['cln_accept_eula', acceptEula(deps.profiles, deps.accounts)],
|
['cln_accept_eula', acceptEula(deps.profiles, deps.accounts)],
|
||||||
['cln_set_starting_info', setStartingInfo(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_bulk_train_aircraft', bulkTrainCrews(deps.profiles, deps.accounts, deps.crew)],
|
||||||
['cln_train_aircraft', trainCrew(deps.profiles, deps.accounts, deps.research)],
|
['cln_train_aircraft', trainCrew(deps.profiles, deps.accounts, deps.crew)],
|
||||||
['cln_set_researchable', setResearchable(deps.profiles, deps.accounts, deps.research)],
|
['cln_set_researchable', setResearchable(deps.profiles, deps.accounts, deps.research, deps.equipment)],
|
||||||
['cln_reset_researchable', resetResearchable(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)],
|
['cln_convert_exp', convertExp(deps.profiles, deps.accounts, deps.research)],
|
||||||
['cln_buy_aircraft', buyAircraft(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_buy_slot', buySlot(deps.profiles, deps.accounts, deps.research)],
|
||||||
['cln_get_price_ex', priceEx(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.research)],
|
['cln_buy_modification', buyModificationAction(deps.profiles, deps.accounts, deps.equipment)],
|
||||||
['cln_buy_all_modification', buyAllModificationsAction(deps.profiles, deps.accounts, deps.research)],
|
['cln_buy_all_modification', buyAllModificationsAction(deps.profiles, deps.accounts, deps.equipment)],
|
||||||
['cln_buy_spare_aircrafts', buySparesAction(deps.profiles, deps.accounts, deps.research)],
|
['cln_buy_spare_aircrafts', buySparesAction(deps.profiles, deps.accounts, deps.equipment)],
|
||||||
['cln_buy_unlock', buyUnlockAction(deps.profiles, deps.accounts, deps.research)],
|
['cln_buy_unlock', buyUnlockAction(deps.profiles, deps.accounts, deps.unlocks)],
|
||||||
['cln_buy_weapon', buyWeaponsAction(deps.profiles, deps.accounts, deps.research)],
|
['cln_buy_weapon', buyWeaponsAction(deps.profiles, deps.accounts, deps.equipment)],
|
||||||
['cln_enable_modifications', enableModificationsAction(deps.profiles, deps.accounts)],
|
['cln_enable_modifications', enableModificationsAction(deps.profiles, deps.accounts)],
|
||||||
['cln_upgrade_crew', upgradeCrewAction(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.research)],
|
['cln_purchase_skill_points', purchaseSkillPointsAction(deps.profiles, deps.accounts, deps.crew)],
|
||||||
['cln_specialize_crew', specializeCrewAction(deps.profiles, deps.accounts, deps.research)],
|
['cln_specialize_crew', specializeCrewAction(deps.profiles, deps.accounts, deps.crew)],
|
||||||
['cln_select_title', selectTitleAction(deps.profiles, deps.accounts)],
|
['cln_select_title', selectTitleAction(deps.profiles, deps.accounts)],
|
||||||
['cln_save_pilot_appearance', savePilotAppearanceAction(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_save_profile_showcase', saveShowcaseAction(deps.profiles, deps.accounts)],
|
||||||
['cln_get_showcases', showcasesAction(deps.profiles, deps.accounts, deps.research)],
|
['cln_get_showcases', showcasesAction(deps.profiles, deps.accounts, techTree)],
|
||||||
['cln_buy_resource', buyResourceAction(deps.profiles, deps.accounts, deps.research)],
|
['cln_buy_resource', buyResourceAction(deps.profiles, deps.accounts, deps.decor)],
|
||||||
['cln_save_decals', saveDecorLayoutsAction(deps.profiles, deps.accounts, 'decals')],
|
['cln_save_decals', saveDecorLayoutsAction(deps.profiles, deps.accounts, 'decals')],
|
||||||
['cln_save_attachables', saveDecorLayoutsAction(deps.profiles, deps.accounts, 'attachables')],
|
['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_booster', activateBoosterAction(deps.profiles, deps.accounts)],
|
||||||
['cln_set_current_personal_discount', activateDiscountAction(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.research)],
|
['cln_set_current_wager', startWagerAction(deps.profiles, deps.accounts, deps.items)],
|
||||||
['cln_apply_spare_item', applySpareItemAction(deps.profiles, deps.accounts, deps.research)],
|
['cln_apply_spare_item', applySpareItemAction(deps.profiles, deps.accounts, deps.items, techTree)],
|
||||||
['cln_get_entitlements_price_ex', entitlementsPriceEx(deps.research)],
|
['cln_get_entitlements_price_ex', entitlementsPriceEx(deps.store)],
|
||||||
['cln_buy_entitlement', buyEntitlementAction(deps.profiles, deps.accounts, deps.research)],
|
['cln_buy_entitlement', buyEntitlementAction(deps.profiles, deps.accounts, deps.store)],
|
||||||
['cln_consume_inventory_item', consumeInventoryItemAction(deps.profiles, deps.accounts, deps.research, notifyInventory)],
|
['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.research, 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.research, notifyInventory)],
|
['cln_inventory_purchase_item', purchaseInventoryItemAction(deps.profiles, deps.accounts, deps.inventory, notifyInventory)],
|
||||||
['cln_recycle_items', recycleItemsAction(deps.profiles, deps.accounts, deps.research, notifyInventory)],
|
['cln_recycle_items', recycleItemsAction(deps.profiles, deps.accounts, deps.items, notifyInventory)],
|
||||||
['cln_inventory_exchange_items', inventoryExchangeAction(deps.profiles, deps.accounts, deps.research)],
|
['cln_inventory_exchange_items', inventoryExchangeAction(deps.profiles, deps.accounts, deps.inventory)],
|
||||||
['cln_buy_trophy', buyTrophyAction(deps.profiles, deps.accounts, deps.research)],
|
['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 [
|
return [
|
||||||
['cln_clan_get', clanGetAction(deps.accounts, clans)],
|
['cln_clan_get', clanGetAction(deps.accounts, clans.store)],
|
||||||
['cln_clan_get_leaderboard', clanGetLeaderboardAction(clans)],
|
['cln_clan_get_leaderboard', clanGetLeaderboardAction(clans.store)],
|
||||||
['cln_clan_find_by_prefix', clanFindByPrefixAction(clans)],
|
['cln_clan_find_by_prefix', clanFindByPrefixAction(clans.store)],
|
||||||
['cln_clans_list_get_short_info', clansListShortInfoAction(clans)],
|
['cln_clans_list_get_short_info', clansListShortInfoAction(clans.store)],
|
||||||
['cln_clan_get_log', clanGetLogAction(deps.accounts, clans)],
|
['cln_clan_get_log', clanGetLogAction(deps.accounts, clans.store)],
|
||||||
['cln_clan_create', clanCreateAction(deps.profiles, deps.accounts, clans, deps.research)],
|
['cln_clan_create', clanCreateAction(deps.profiles, deps.accounts, clans.store, clans.economy)],
|
||||||
['cln_clan_change_info', clanChangeInfoAction(deps.profiles, deps.accounts, clans, deps.research)],
|
['cln_clan_change_info', clanChangeInfoAction(deps.profiles, deps.accounts, clans.store, clans.economy)],
|
||||||
['cln_clan_upgrade', clanUpgradeAction(deps.profiles, deps.accounts, clans, deps.research)],
|
['cln_clan_upgrade', clanUpgradeAction(deps.profiles, deps.accounts, clans.store, clans.economy)],
|
||||||
['cln_clan_members_upgrade', clanMembersUpgradeAction(deps.profiles, deps.accounts, clans, deps.research)],
|
['cln_clan_members_upgrade', clanMembersUpgradeAction(deps.profiles, deps.accounts, clans.store, clans.economy)],
|
||||||
['cln_clan_set_membership_requirements', clanSetMembershipReqAction(deps.accounts, clans)],
|
['cln_clan_set_membership_requirements', clanSetMembershipReqAction(deps.accounts, clans.store)],
|
||||||
['cln_clan_membership_request', clanMembershipRequestAction(deps.profiles, deps.accounts, clans)],
|
['cln_clan_membership_request', clanMembershipRequestAction(deps.profiles, deps.accounts, clans.store)],
|
||||||
['cln_clan_leave', clanLeaveAction(deps.profiles, deps.accounts, clans)],
|
['cln_clan_leave', clanLeaveAction(deps.profiles, deps.accounts, clans.store)],
|
||||||
['cln_clan_disband', clanDisbandAction(deps.profiles, deps.accounts, clans)],
|
['cln_clan_disband', clanDisbandAction(deps.profiles, deps.accounts, clans.store)],
|
||||||
['cln_clan_sync_profile_and_clan', clanSyncProfileAction(deps.profiles, deps.accounts, clans)],
|
['cln_clan_sync_profile_and_clan', clanSyncProfileAction(deps.profiles, deps.accounts, clans.store)],
|
||||||
['ano_clan_accept_membership_request', clanAcceptCandidateAction(deps.profiles, deps.accounts, clans)],
|
['ano_clan_accept_membership_request', clanAcceptCandidateAction(deps.profiles, deps.accounts, clans.store)],
|
||||||
['ano_clan_reject_membership_request', clanRejectCandidateAction(deps.profiles, deps.accounts, clans)],
|
['ano_clan_reject_membership_request', clanRejectCandidateAction(deps.profiles, deps.accounts, clans.store)],
|
||||||
['ano_clan_dismiss_member', clanDismissMemberAction(deps.profiles, deps.accounts, clans)],
|
['ano_clan_dismiss_member', clanDismissMemberAction(deps.profiles, deps.accounts, clans.store)],
|
||||||
['ano_clan_change_member_role', clanChangeMemberRoleAction(deps.profiles, deps.accounts, clans)],
|
['ano_clan_change_member_role', clanChangeMemberRoleAction(deps.profiles, deps.accounts, clans.store)],
|
||||||
['ano_clan_edit_blacklist', clanEditBlacklistAction(deps.accounts, clans)],
|
['ano_clan_edit_blacklist', clanEditBlacklistAction(deps.accounts, clans.store)],
|
||||||
['cln_set_clan_best_rewards', setClanBestRewardsAction(deps.accounts, clans)],
|
['cln_set_clan_best_rewards', setClanBestRewardsAction(deps.accounts, clans.store)],
|
||||||
['cln_set_research_clan_unit', setResearchClanUnitAction(deps.profiles, deps.accounts, clans, deps.research)],
|
['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, 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, deps.research)],
|
['cln_buy_not_researched_clans_unit', buyNotResearchedClanUnitAction(deps.profiles, deps.accounts, clans.store, deps.research)],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,10 +12,10 @@ import {
|
|||||||
toClanShortInfoBlk,
|
toClanShortInfoBlk,
|
||||||
} from '../../clans/clan-blk.ts';
|
} from '../../clans/clan-blk.ts';
|
||||||
import type { ClanStore } from '../../clans/clan-store.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 { clientProfile } from '../../profile/client-profile.ts';
|
||||||
import type { PlayerProfiles } from '../../profile/player-profiles.ts';
|
import type { PlayerProfiles } from '../../profile/player-profiles.ts';
|
||||||
import type { Price } from '../../profile/profile-currency.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 { RuleOutcome } from '../../research/rule-outcome.ts';
|
||||||
import type { CharActionContext, CharActionHandler } from '../char-action.ts';
|
import type { CharActionContext, CharActionHandler } from '../char-action.ts';
|
||||||
import { withAccount } from './account-context.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) => {
|
return clanProfileRuleAction(profiles, accounts, clans, (context, profile, account) => {
|
||||||
const payload = context.payload;
|
const payload = context.payload;
|
||||||
const offered = payload && priceFromClanPayload(payload);
|
const offered = payload && priceFromClanPayload(payload);
|
||||||
@@ -131,7 +131,7 @@ export function clanCreateAction(profiles: PlayerProfiles, accounts: AccountStor
|
|||||||
if (!payload || !offered || (rawType !== 'normal' && rawType !== 'battalion')) {
|
if (!payload || !offered || (rawType !== 'normal' && rawType !== 'battalion')) {
|
||||||
return { ok: false, refusal: 'BAD_PARAMS' };
|
return { ok: false, refusal: 'BAD_PARAMS' };
|
||||||
}
|
}
|
||||||
return clans.createClan(profile, account, rules.clanEconomy, {
|
return clans.createClan(profile, account, clanEconomy, {
|
||||||
name: stringParam(payload, 'name') ?? '',
|
name: stringParam(payload, 'name') ?? '',
|
||||||
tag: stringParam(payload, 'tag') ?? '',
|
tag: stringParam(payload, 'tag') ?? '',
|
||||||
slogan: stringParam(payload, 'slogan') ?? '',
|
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) => {
|
return clanProfileRuleAction(profiles, accounts, clans, (context, profile, account) => {
|
||||||
const payload = context.payload;
|
const payload = context.payload;
|
||||||
if (!payload) return { ok: false, refusal: 'BAD_PARAMS' };
|
if (!payload) return { ok: false, refusal: 'BAD_PARAMS' };
|
||||||
const clanId = headerOrPayloadId(context, '_id') ?? '-1';
|
const clanId = headerOrPayloadId(context, '_id') ?? '-1';
|
||||||
const rawStatus = stringParam(payload, 'status');
|
const rawStatus = stringParam(payload, 'status');
|
||||||
return clans.editClanInfo(profile, account, rules.clanEconomy, clanId, {
|
return clans.editClanInfo(profile, account, clanEconomy, clanId, {
|
||||||
name: stringParam(payload, 'name'),
|
name: stringParam(payload, 'name'),
|
||||||
tag: stringParam(payload, 'tag'),
|
tag: stringParam(payload, 'tag'),
|
||||||
desc: stringParam(payload, 'desc'),
|
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) => {
|
return clanProfileRuleAction(profiles, accounts, clans, (context, profile, account) => {
|
||||||
const payload = context.payload;
|
const payload = context.payload;
|
||||||
if (!payload) return { ok: false, refusal: 'BAD_PARAMS' };
|
if (!payload) return { ok: false, refusal: 'BAD_PARAMS' };
|
||||||
const clanId = headerOrPayloadId(context, '_id') ?? '-1';
|
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') ?? '',
|
tag: stringParam(payload, 'tag') ?? '',
|
||||||
desc: stringParam(payload, 'desc') ?? '',
|
desc: stringParam(payload, 'desc') ?? '',
|
||||||
announcement: stringParam(payload, 'announcement') ?? '',
|
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) => {
|
return clanProfileRuleAction(profiles, accounts, clans, (context, profile, account) => {
|
||||||
const clanId = headerOrPayloadId(context, '_id') ?? '-1';
|
const clanId = headerOrPayloadId(context, '_id') ?? '-1';
|
||||||
return clans.upgradeMembersLimit(profile, account, rules.clanEconomy, clanId);
|
return clans.upgradeMembersLimit(profile, account, clanEconomy, clanId);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,22 +18,22 @@
|
|||||||
*/
|
*/
|
||||||
import { findParam, type BlkBlock } from '@wto/blk';
|
import { findParam, type BlkBlock } from '@wto/blk';
|
||||||
import type { AccountStore } from '../../accounts/account-store.ts';
|
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 { clientProfile } from '../../profile/client-profile.ts';
|
||||||
import { assignCrewSlots, canAssignCrewSlots, trainCrewKeepingSlot, type CrewSlotAssignment } from '../../profile/crew-slots.ts';
|
import { assignCrewSlots, canAssignCrewSlots, trainCrewKeepingSlot, type CrewSlotAssignment } from '../../profile/crew-slots.ts';
|
||||||
import type { PlayerProfiles } from '../../profile/player-profiles.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 { canAfford, pay } from '../../profile/profile-currency.ts';
|
||||||
import type { ResearchRules } from '../../research/research-rules.ts';
|
|
||||||
import type { CharActionHandler } from '../char-action.ts';
|
import type { CharActionHandler } from '../char-action.ts';
|
||||||
import { withAccount } from './account-context.ts';
|
import { withAccount } from './account-context.ts';
|
||||||
import { readCrewSlots } from './crew-slots-payload.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) => {
|
return (context) => withAccount(context, accounts, (account) => {
|
||||||
const assignments = context.payload && readCrewSlots(context.payload);
|
const assignments = context.payload && readCrewSlots(context.payload);
|
||||||
const current = profiles.profileOf(account.userId);
|
const current = profiles.profileOf(account.userId);
|
||||||
if (!assignments || !canAssignCrewSlots(current, assignments)) return { kind: 'error', code: 'BAD_PARAMS' };
|
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' };
|
if (!canAfford(current, fee)) return { kind: 'error', code: 'NOT_ENOUGH_MONEY' };
|
||||||
const profile = profiles.update(account.userId, (saved) => {
|
const profile = profiles.update(account.userId, (saved) => {
|
||||||
pay(saved, fee);
|
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) => {
|
return (context) => withAccount(context, accounts, (account) => {
|
||||||
const request = context.payload && readTrainCrew(context.payload);
|
const request = context.payload && readTrainCrew(context.payload);
|
||||||
if (!request || (request.keepCurrent && request.vehicle === '')) return { kind: 'error', code: 'BAD_PARAMS' };
|
if (!request || (request.keepCurrent && request.vehicle === '')) return { kind: 'error', code: 'BAD_PARAMS' };
|
||||||
const { keepCurrent, ...assignment } = request;
|
const { keepCurrent, ...assignment } = request;
|
||||||
const current = profiles.profileOf(account.userId);
|
const current = profiles.profileOf(account.userId);
|
||||||
if (!canAssignCrewSlots(current, [assignment])) return { kind: 'error', code: 'BAD_PARAMS' };
|
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' };
|
if (!canAfford(current, fee)) return { kind: 'error', code: 'NOT_ENOUGH_MONEY' };
|
||||||
const profile = profiles.update(account.userId, (saved) => {
|
const profile = profiles.update(account.userId, (saved) => {
|
||||||
pay(saved, fee);
|
pay(saved, fee);
|
||||||
|
|||||||
@@ -7,37 +7,36 @@
|
|||||||
* cln_specialize_crew (shop_specialize_crew, 0x29ad40): id:i aircraft:t
|
* cln_specialize_crew (shop_specialize_crew, 0x29ad40): id:i aircraft:t
|
||||||
*/
|
*/
|
||||||
import type { AccountStore } from '../../accounts/account-store.ts';
|
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 { PlayerProfiles } from '../../profile/player-profiles.ts';
|
||||||
import type { ResearchRules } from '../../research/research-rules.ts';
|
|
||||||
import type { CharActionHandler } from '../char-action.ts';
|
import type { CharActionHandler } from '../char-action.ts';
|
||||||
import { intParam, stringParam } from './payload-params.ts';
|
import { intParam, stringParam } from './payload-params.ts';
|
||||||
import { ruleAction } from './rule-answer.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) => {
|
return ruleAction(profiles, accounts, (payload) => {
|
||||||
const crewId = intParam(payload, 'id');
|
const crewId = intParam(payload, 'id');
|
||||||
if (crewId === undefined) return undefined;
|
if (crewId === undefined) return undefined;
|
||||||
const raises: SkillRaise[] = payload.blocks.flatMap((page) => page.params.flatMap((param) =>
|
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 }] : []));
|
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) => {
|
return ruleAction(profiles, accounts, (payload) => {
|
||||||
const crewId = intParam(payload, 'id');
|
const crewId = intParam(payload, 'id');
|
||||||
const pack = stringParam(payload, 'pack');
|
const pack = stringParam(payload, 'pack');
|
||||||
if (crewId === undefined || pack === undefined) return undefined;
|
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) => {
|
return ruleAction(profiles, accounts, (payload) => {
|
||||||
const crewId = intParam(payload, 'id');
|
const crewId = intParam(payload, 'id');
|
||||||
const vehicle = stringParam(payload, 'aircraft');
|
const vehicle = stringParam(payload, 'aircraft');
|
||||||
if (crewId === undefined || vehicle === undefined) return undefined;
|
if (crewId === undefined || vehicle === undefined) return undefined;
|
||||||
return (profile) => specializeCrew(profile, rules.crew, crewId, vehicle);
|
return (profile) => specializeCrew(profile, crew, crewId, vehicle);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -9,20 +9,19 @@
|
|||||||
* cost:i costGold:i
|
* cost:i costGold:i
|
||||||
*/
|
*/
|
||||||
import type { AccountStore } from '../../accounts/account-store.ts';
|
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 { PlayerProfiles } from '../../profile/player-profiles.ts';
|
||||||
import type { ResearchRules } from '../../research/research-rules.ts';
|
|
||||||
import type { CharActionHandler } from '../char-action.ts';
|
import type { CharActionHandler } from '../char-action.ts';
|
||||||
import { intParam, stringParam } from './payload-params.ts';
|
import { intParam, stringParam } from './payload-params.ts';
|
||||||
import { ruleAction } from './rule-answer.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) => {
|
return ruleAction(profiles, accounts, (payload) => {
|
||||||
const name = stringParam(payload, 'name');
|
const name = stringParam(payload, 'name');
|
||||||
const type = stringParam(payload, 'type');
|
const type = stringParam(payload, 'type');
|
||||||
if (name === undefined || type === undefined || !isDecorKind(type)) return undefined;
|
if (name === undefined || type === undefined || !isDecorKind(type)) return undefined;
|
||||||
const key = decorKey(type, name, stringParam(payload, 'unitName') ?? '');
|
const key = decorKey(type, name, stringParam(payload, 'unitName') ?? '');
|
||||||
const offered = { silverLions: intParam(payload, 'cost') ?? 0, goldenEagles: intParam(payload, 'costGold') ?? 0 };
|
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);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -19,11 +19,12 @@ import {
|
|||||||
type ExchangeItemDelta,
|
type ExchangeItemDelta,
|
||||||
} from '../../inventory/inventory-rules.ts';
|
} from '../../inventory/inventory-rules.ts';
|
||||||
import { deltaToInventoryJson, parseExchangeItemsRequest } from '../../inventory/inventory-wire.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 { clientProfile } from '../../profile/client-profile.ts';
|
||||||
import type { PlayerProfiles } from '../../profile/player-profiles.ts';
|
import type { PlayerProfiles } from '../../profile/player-profiles.ts';
|
||||||
import { serverTimeNow } from '../../profile/server-time.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 { RuleOutcome } from '../../research/rule-outcome.ts';
|
||||||
import type { CharActionHandler } from '../char-action.ts';
|
import type { CharActionHandler } from '../char-action.ts';
|
||||||
import { withAccount } from './account-context.ts';
|
import { withAccount } from './account-context.ts';
|
||||||
@@ -53,21 +54,22 @@ function profileRuleWithNotify(
|
|||||||
export function consumeInventoryItemAction(
|
export function consumeInventoryItemAction(
|
||||||
profiles: PlayerProfiles,
|
profiles: PlayerProfiles,
|
||||||
accounts: AccountStore,
|
accounts: AccountStore,
|
||||||
rules: ResearchRules,
|
inventory: InventoryCatalogue,
|
||||||
|
items: ItemCatalogue,
|
||||||
notifyInventoryChanged: () => void,
|
notifyInventoryChanged: () => void,
|
||||||
): CharActionHandler {
|
): CharActionHandler {
|
||||||
return profileRuleWithNotify(profiles, accounts, notifyInventoryChanged, (payload) => {
|
return profileRuleWithNotify(profiles, accounts, notifyInventoryChanged, (payload) => {
|
||||||
const itemId = intParam(payload, 'itemId');
|
const itemId = intParam(payload, 'itemId');
|
||||||
const quantity = intParam(payload, 'quantity') ?? 1;
|
const quantity = intParam(payload, 'quantity') ?? 1;
|
||||||
if (itemId === undefined) return undefined;
|
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(
|
export function purchaseInventoryItemAction(
|
||||||
profiles: PlayerProfiles,
|
profiles: PlayerProfiles,
|
||||||
accounts: AccountStore,
|
accounts: AccountStore,
|
||||||
rules: ResearchRules,
|
inventory: InventoryCatalogue,
|
||||||
notifyInventoryChanged: () => void,
|
notifyInventoryChanged: () => void,
|
||||||
): CharActionHandler {
|
): CharActionHandler {
|
||||||
return profileRuleWithNotify(profiles, accounts, notifyInventoryChanged, (payload) => {
|
return profileRuleWithNotify(profiles, accounts, notifyInventoryChanged, (payload) => {
|
||||||
@@ -76,14 +78,14 @@ export function purchaseInventoryItemAction(
|
|||||||
const amount = intParam(payload, 'amount') ?? 1;
|
const amount = intParam(payload, 'amount') ?? 1;
|
||||||
const wpCost = intParam(payload, 'wpCost') ?? 0;
|
const wpCost = intParam(payload, 'wpCost') ?? 0;
|
||||||
const goldCost = intParam(payload, 'goldCost') ?? 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(
|
export function recycleItemsAction(
|
||||||
profiles: PlayerProfiles,
|
profiles: PlayerProfiles,
|
||||||
accounts: AccountStore,
|
accounts: AccountStore,
|
||||||
rules: ResearchRules,
|
items: ItemCatalogue,
|
||||||
notifyInventoryChanged: () => void,
|
notifyInventoryChanged: () => void,
|
||||||
): CharActionHandler {
|
): CharActionHandler {
|
||||||
return profileRuleWithNotify(profiles, accounts, notifyInventoryChanged, (payload) => {
|
return profileRuleWithNotify(profiles, accounts, notifyInventoryChanged, (payload) => {
|
||||||
@@ -96,14 +98,15 @@ export function recycleItemsAction(
|
|||||||
count: intParam(b, 'count') ?? 1,
|
count: intParam(b, 'count') ?? 1,
|
||||||
}));
|
}));
|
||||||
if (requests.length === 0) return undefined;
|
if (requests.length === 0) return undefined;
|
||||||
return (profile) => recycleClassicItems(profile, rules.items, requests);
|
return (profile) => recycleClassicItems(profile, items, requests);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function multiConsumeInventoryItemsAction(
|
export function multiConsumeInventoryItemsAction(
|
||||||
profiles: PlayerProfiles,
|
profiles: PlayerProfiles,
|
||||||
accounts: AccountStore,
|
accounts: AccountStore,
|
||||||
rules: ResearchRules,
|
inventory: InventoryCatalogue,
|
||||||
|
items: ItemCatalogue,
|
||||||
notifyInventoryChanged: () => void,
|
notifyInventoryChanged: () => void,
|
||||||
): CharActionHandler {
|
): CharActionHandler {
|
||||||
return (context) => withAccount(context, accounts, (account) => {
|
return (context) => withAccount(context, accounts, (account) => {
|
||||||
@@ -112,7 +115,7 @@ export function multiConsumeInventoryItemsAction(
|
|||||||
|
|
||||||
let revertedItems: number[] = [];
|
let revertedItems: number[] = [];
|
||||||
profiles.update(account.userId, (saved) => {
|
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;
|
revertedItems = res.revertedItems;
|
||||||
});
|
});
|
||||||
notifyInventoryChanged();
|
notifyInventoryChanged();
|
||||||
@@ -123,7 +126,7 @@ export function multiConsumeInventoryItemsAction(
|
|||||||
export function inventoryExchangeAction(
|
export function inventoryExchangeAction(
|
||||||
profiles: PlayerProfiles,
|
profiles: PlayerProfiles,
|
||||||
accounts: AccountStore,
|
accounts: AccountStore,
|
||||||
rules: ResearchRules,
|
inventory: InventoryCatalogue,
|
||||||
): CharActionHandler {
|
): CharActionHandler {
|
||||||
return (context) => withAccount(context, accounts, (account) => {
|
return (context) => withAccount(context, accounts, (account) => {
|
||||||
const parsed = parseExchangeItemsRequest(context.rawText);
|
const parsed = parseExchangeItemsRequest(context.rawText);
|
||||||
@@ -134,7 +137,7 @@ export function inventoryExchangeAction(
|
|||||||
profiles.updateWhen(account.userId, (saved) => {
|
profiles.updateWhen(account.userId, (saved) => {
|
||||||
const res = exchangeInventoryItems(
|
const res = exchangeInventoryItems(
|
||||||
saved,
|
saved,
|
||||||
rules.inventory,
|
inventory,
|
||||||
parsed.outputItemDefId,
|
parsed.outputItemDefId,
|
||||||
parsed.quantity,
|
parsed.quantity,
|
||||||
parsed.materials,
|
parsed.materials,
|
||||||
@@ -154,14 +157,15 @@ export function inventoryExchangeAction(
|
|||||||
export function buyTrophyAction(
|
export function buyTrophyAction(
|
||||||
profiles: PlayerProfiles,
|
profiles: PlayerProfiles,
|
||||||
accounts: AccountStore,
|
accounts: AccountStore,
|
||||||
rules: ResearchRules,
|
trophies: TrophyCatalogue,
|
||||||
|
items: ItemCatalogue,
|
||||||
): CharActionHandler {
|
): CharActionHandler {
|
||||||
return ruleAction(profiles, accounts, (payload) => {
|
return ruleAction(profiles, accounts, (payload) => {
|
||||||
const name = stringParam(payload, 'name');
|
const name = stringParam(payload, 'name');
|
||||||
if (!name) return undefined;
|
if (!name) return undefined;
|
||||||
const cost = intParam(payload, 'cost') ?? 0;
|
const cost = intParam(payload, 'cost') ?? 0;
|
||||||
const costGold = intParam(payload, 'costGold') ?? 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());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,22 +10,23 @@
|
|||||||
*/
|
*/
|
||||||
import type { AccountStore } from '../../accounts/account-store.ts';
|
import type { AccountStore } from '../../accounts/account-store.ts';
|
||||||
import { activateBooster, activateDiscount, startWager } from '../../items/item-activation.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 { buyItem } from '../../items/item-purchase.ts';
|
||||||
import { applyUniversalSpares } from '../../items/universal-spares.ts';
|
import { applyUniversalSpares } from '../../items/universal-spares.ts';
|
||||||
import type { PlayerProfiles } from '../../profile/player-profiles.ts';
|
import type { PlayerProfiles } from '../../profile/player-profiles.ts';
|
||||||
import { serverTimeNow } from '../../profile/server-time.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 type { CharActionHandler } from '../char-action.ts';
|
||||||
import { intParam, stringParam } from './payload-params.ts';
|
import { intParam, stringParam } from './payload-params.ts';
|
||||||
import { ruleAction } from './rule-answer.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) => {
|
return ruleAction(profiles, accounts, (payload) => {
|
||||||
const name = stringParam(payload, 'name');
|
const name = stringParam(payload, 'name');
|
||||||
const pieces = intParam(payload, 'count');
|
const pieces = intParam(payload, 'count');
|
||||||
if (name === undefined || pieces === undefined) return undefined;
|
if (name === undefined || pieces === undefined) return undefined;
|
||||||
const offered = { silverLions: intParam(payload, 'cost') ?? 0, goldenEagles: intParam(payload, 'costGold') ?? 0 };
|
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) => {
|
return ruleAction(profiles, accounts, (payload) => {
|
||||||
const uid = stringParam(payload, 'name');
|
const uid = stringParam(payload, 'name');
|
||||||
if (uid === undefined) return undefined;
|
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) => {
|
return ruleAction(profiles, accounts, (payload) => {
|
||||||
const uid = stringParam(payload, 'name');
|
const uid = stringParam(payload, 'name');
|
||||||
const stake = intParam(payload, 'wager');
|
const stake = intParam(payload, 'wager');
|
||||||
if (uid === undefined || stake === undefined) return undefined;
|
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) => {
|
return ruleAction(profiles, accounts, (payload) => {
|
||||||
const uid = stringParam(payload, 'uid');
|
const uid = stringParam(payload, 'uid');
|
||||||
const vehicle = stringParam(payload, 'unit');
|
const vehicle = stringParam(payload, 'unit');
|
||||||
const pieces = intParam(payload, 'useItemsCount');
|
const pieces = intParam(payload, 'useItemsCount');
|
||||||
if (uid === undefined || vehicle === undefined || pieces === undefined) return undefined;
|
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);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -13,16 +13,16 @@
|
|||||||
*/
|
*/
|
||||||
import type { BlkBlock } from '@wto/blk';
|
import type { BlkBlock } from '@wto/blk';
|
||||||
import type { AccountStore } from '../../accounts/account-store.ts';
|
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 { buyAllModifications, buyModification, enableModifications } from '../../modifications/modification-purchase.ts';
|
||||||
import { buySpares } from '../../modifications/spare-purchase.ts';
|
import { buySpares } from '../../modifications/spare-purchase.ts';
|
||||||
import { buyWeapons } from '../../modifications/weapon-purchase.ts';
|
import { buyWeapons } from '../../modifications/weapon-purchase.ts';
|
||||||
import type { PlayerProfiles } from '../../profile/player-profiles.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 type { CharActionHandler } from '../char-action.ts';
|
||||||
import { boolParam, intParam, stringParam } from './payload-params.ts';
|
import { boolParam, intParam, stringParam } from './payload-params.ts';
|
||||||
import { ruleAction } from './rule-answer.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) => {
|
return ruleAction(profiles, accounts, (payload) => {
|
||||||
const vehicle = stringParam(payload, 'aircraft');
|
const vehicle = stringParam(payload, 'aircraft');
|
||||||
const modification = stringParam(payload, 'modification');
|
const modification = stringParam(payload, 'modification');
|
||||||
@@ -34,37 +34,37 @@ export function buyModificationAction(profiles: PlayerProfiles, accounts: Accoun
|
|||||||
amount: intParam(payload, 'count') ?? 1,
|
amount: intParam(payload, 'count') ?? 1,
|
||||||
offered: offeredPrice(payload),
|
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) => {
|
return ruleAction(profiles, accounts, (payload) => {
|
||||||
const vehicle = stringParam(payload, 'unit');
|
const vehicle = stringParam(payload, 'unit');
|
||||||
if (vehicle === undefined) return undefined;
|
if (vehicle === undefined) return undefined;
|
||||||
const outright = boolParam(payload, 'forceOpen') ?? false;
|
const outright = boolParam(payload, 'forceOpen') ?? false;
|
||||||
const offered = offeredPrice(payload);
|
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) => {
|
return ruleAction(profiles, accounts, (payload) => {
|
||||||
const vehicle = stringParam(payload, 'aircraft');
|
const vehicle = stringParam(payload, 'aircraft');
|
||||||
if (vehicle === undefined) return undefined;
|
if (vehicle === undefined) return undefined;
|
||||||
const amount = intParam(payload, 'count') ?? 1;
|
const amount = intParam(payload, 'count') ?? 1;
|
||||||
const offered = offeredPrice(payload);
|
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) => {
|
return ruleAction(profiles, accounts, (payload) => {
|
||||||
const vehicle = stringParam(payload, 'aircraft');
|
const vehicle = stringParam(payload, 'aircraft');
|
||||||
const weapon = stringParam(payload, 'weapon');
|
const weapon = stringParam(payload, 'weapon');
|
||||||
if (vehicle === undefined || weapon === undefined) return undefined;
|
if (vehicle === undefined || weapon === undefined) return undefined;
|
||||||
const order = { vehicle, weapon, amount: intParam(payload, 'count') ?? 1, offered: offeredPrice(payload) };
|
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);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ import { currentShowcaseView, saveShowcase, showcasesAnswer } from '../../player
|
|||||||
import { appearance, chosenTitle } from '../../profile/profile-appearance.ts';
|
import { appearance, chosenTitle } from '../../profile/profile-appearance.ts';
|
||||||
import { clanMembershipOf } from '../../profile/profile-clan.ts';
|
import { clanMembershipOf } from '../../profile/profile-clan.ts';
|
||||||
import type { PlayerProfiles } from '../../profile/player-profiles.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 { TechTree } from '../../research/tech-tree.ts';
|
||||||
import type { CharActionHandler } from '../char-action.ts';
|
import type { CharActionHandler } from '../char-action.ts';
|
||||||
import { withAccount } from './account-context.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));
|
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) =>
|
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, () => {
|
return (context) => withAccount(context, accounts, () => {
|
||||||
const list = (context.payload ? stringParam(context.payload, 'usersList') : undefined) ?? context.headerParam('usersList');
|
const list = (context.payload ? stringParam(context.payload, 'usersList') : undefined) ?? context.headerParam('usersList');
|
||||||
if (list === undefined) return { kind: 'error', code: 'BAD_PARAMS' };
|
if (list === undefined) return { kind: 'error', code: 'BAD_PARAMS' };
|
||||||
const blocks = list.split(';').filter((uid) => uid !== '').map((uid): BlkBlock => {
|
const blocks = list.split(';').filter((uid) => uid !== '').map((uid): BlkBlock => {
|
||||||
const account = accounts.byUserId(uid);
|
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);
|
const npc = clans?.npcMemberByUid(uid);
|
||||||
if (npc) return npcTerseInfoBlk(uid, npc.clan, npc.member);
|
if (npc) return npcTerseInfoBlk(uid, npc.clan, npc.member);
|
||||||
return { name: uid, params: [{ name: 'failed', value: { type: 'bool', value: true } }], blocks: [] };
|
return { name: uid, params: [{ name: 'failed', value: { type: 'bool', value: true } }], blocks: [] };
|
||||||
|
|||||||
@@ -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
|
* 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
|
* (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 type { CharActionHandler } from '../char-action.ts';
|
||||||
import { priceTable } from '../../research/price-table.ts';
|
import { priceTable, type PriceTableSources } from './price-table.ts';
|
||||||
import type { ResearchRules } from '../../research/research-rules.ts';
|
|
||||||
|
|
||||||
export function priceEx(rules: ResearchRules): CharActionHandler {
|
export function priceEx(sources: PriceTableSources): CharActionHandler {
|
||||||
const table = priceTable(rules);
|
const table = priceTable(sources);
|
||||||
return () => ({ kind: 'data', blk: table });
|
return () => ({ kind: 'data', blk: table });
|
||||||
}
|
}
|
||||||
+27
-16
@@ -25,7 +25,9 @@
|
|||||||
* unlocks{ <unlock>{ cost:i costGold:i } } unlocks for sale (0x9170c0)
|
* unlocks{ <unlock>{ cost:i costGold:i } } unlocks for sale (0x9170c0)
|
||||||
* items{ <item>{ cost:i costGold:i } } classic items for sale, price per piece
|
* items{ <item>{ cost:i costGold:i } } classic items for sale, price per piece
|
||||||
* (wp_get_item_cost, 0x10531e0; implementation notes)
|
* (wp_get_item_cost, 0x10531e0; implementation notes)
|
||||||
|
* trophy{ <id>{ cost:i costGold:i } } classic trophy prices
|
||||||
* }
|
* }
|
||||||
|
* trophy{ <id>{ ... } } classic trophy definitions & drop weights
|
||||||
*
|
*
|
||||||
* Every entry is read as cost:i (silver lions), costGold:i (golden eagles), discount:i (percent
|
* 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
|
* 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.
|
* attachable.blk; unlocks: config/unlocks.blk), the same the purchase rules charge.
|
||||||
*/
|
*/
|
||||||
import type { BlkBlock, BlkParam } from '@wto/blk';
|
import type { BlkBlock, BlkParam } from '@wto/blk';
|
||||||
import type { CrewSkillCatalogue } from '../crew/crew-skill-rules.ts';
|
import type { CrewSkillCatalogue } from '../../crew/crew-skill-rules.ts';
|
||||||
import type { DecorShop } from '../decor/decor-purchase.ts';
|
import type { DecorShop } from '../../decor/decor-purchase.ts';
|
||||||
import type { TrophyCatalogue, TrophyDefinition, TrophyPrize } from '../inventory/trophy-catalogue.ts';
|
import type { TrophyCatalogue, TrophyDefinition, TrophyPrize } from '../../inventory/trophy-catalogue.ts';
|
||||||
import type { ItemCatalogue } from '../items/item-catalogue.ts';
|
import type { ItemCatalogue } from '../../items/item-catalogue.ts';
|
||||||
import type { EquipmentCatalogue } from '../modifications/equipment-catalogue.ts';
|
import type { EquipmentCatalogue } from '../../modifications/equipment-catalogue.ts';
|
||||||
import type { UnlockShop } from '../unlocks/unlock-purchase.ts';
|
import type { TechTree } from '../../research/tech-tree.ts';
|
||||||
import type { ResearchRules } from './research-rules.ts';
|
import type { UnlockShop } from '../../unlocks/unlock-purchase.ts';
|
||||||
import type { TechTree } from './tech-tree.ts';
|
|
||||||
|
|
||||||
/** The top-level block every client lookup falls back to (0x908e28). */
|
/** The top-level block every client lookup falls back to (0x908e28). */
|
||||||
const COMMON_SECTION = 'Common';
|
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 {
|
return {
|
||||||
name: '',
|
name: '',
|
||||||
params: [],
|
params: [],
|
||||||
@@ -56,15 +67,15 @@ export function priceTable(rules: ResearchRules): BlkBlock {
|
|||||||
name: COMMON_SECTION,
|
name: COMMON_SECTION,
|
||||||
params: [],
|
params: [],
|
||||||
blocks: [
|
blocks: [
|
||||||
vehicleSection(rules.techTree, rules.equipment),
|
vehicleSection(sources.techTree, sources.equipment),
|
||||||
...decorSections(rules.decor),
|
...decorSections(sources.decor),
|
||||||
skillPackSection(rules.crew),
|
skillPackSection(sources.crew),
|
||||||
unlockSection(rules.unlocks),
|
unlockSection(sources.unlocks),
|
||||||
itemSection(rules.items),
|
itemSection(sources.items),
|
||||||
trophyPriceSection(rules.trophies),
|
trophyPriceSection(sources.trophies),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
trophyDefinitionsSection(rules.trophies),
|
trophyDefinitionsSection(sources.trophies),
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -16,19 +16,25 @@
|
|||||||
* unit:t, amount:i research points
|
* unit:t, amount:i research points
|
||||||
*/
|
*/
|
||||||
import type { AccountStore } from '../../accounts/account-store.ts';
|
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 { 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 { chooseResearchTarget, convertFreeResearchPoints, dismissFinishedResearch } from '../../research/research-progress.ts';
|
||||||
import type { ResearchRules } from '../../research/research-rules.ts';
|
import type { ResearchRules } from '../../research/research-rules.ts';
|
||||||
import type { CharActionHandler } from '../char-action.ts';
|
import type { CharActionHandler } from '../char-action.ts';
|
||||||
import { intParam, stringParam } from './payload-params.ts';
|
import { intParam, stringParam } from './payload-params.ts';
|
||||||
import { ruleAction } from './rule-answer.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) => {
|
return ruleAction(profiles, accounts, (payload) => {
|
||||||
const vehicle = stringParam(payload, 'unit');
|
const vehicle = stringParam(payload, 'unit');
|
||||||
const modification = stringParam(payload, 'mod');
|
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');
|
const type = intParam(payload, 'type');
|
||||||
if (vehicle === undefined || type === undefined) return undefined;
|
if (vehicle === undefined || type === undefined) return undefined;
|
||||||
return (profile) => chooseResearchTarget(profile, rules, vehicle, type);
|
return (profile) => chooseResearchTarget(profile, rules, vehicle, type);
|
||||||
|
|||||||
@@ -11,20 +11,19 @@ import type { AccountStore } from '../../accounts/account-store.ts';
|
|||||||
import { clientProfile } from '../../profile/client-profile.ts';
|
import { clientProfile } from '../../profile/client-profile.ts';
|
||||||
import type { PlayerProfiles } from '../../profile/player-profiles.ts';
|
import type { PlayerProfiles } from '../../profile/player-profiles.ts';
|
||||||
import { serverTimeNow } from '../../profile/server-time.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 { 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 { buyGoldEntitlement } from '../../store/store-purchase.ts';
|
||||||
import type { CharActionHandler } from '../char-action.ts';
|
import type { CharActionHandler } from '../char-action.ts';
|
||||||
import { withAccount } from './account-context.ts';
|
import { withAccount } from './account-context.ts';
|
||||||
import { headerOrPayloadInt, headerOrPayloadString } from './payload-params.ts';
|
import { headerOrPayloadInt, headerOrPayloadString } from './payload-params.ts';
|
||||||
|
|
||||||
export function entitlementsPriceEx(rules: ResearchRules): CharActionHandler {
|
export function entitlementsPriceEx(store: StoreCatalogue): CharActionHandler {
|
||||||
const table = buildEntitlementsPriceBlk(rules.store.allProducts());
|
const table = buildEntitlementsPriceBlk(store.allProducts());
|
||||||
return () => ({ kind: 'data', blk: table });
|
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) => {
|
return (context) => withAccount(context, accounts, (account) => {
|
||||||
const entitlement = headerOrPayloadString(context, 'entitlement');
|
const entitlement = headerOrPayloadString(context, 'entitlement');
|
||||||
const offeredGold = headerOrPayloadInt(context, 'costGold');
|
const offeredGold = headerOrPayloadInt(context, 'costGold');
|
||||||
@@ -35,7 +34,7 @@ export function buyEntitlementAction(profiles: PlayerProfiles, accounts: Account
|
|||||||
let outcome: RuleOutcome = { ok: false, refusal: 'BAD_PARAMS' };
|
let outcome: RuleOutcome = { ok: false, refusal: 'BAD_PARAMS' };
|
||||||
const now = serverTimeNow();
|
const now = serverTimeNow();
|
||||||
const updated = profiles.updateWhen(account.userId, (saved) => {
|
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;
|
return outcome.ok;
|
||||||
});
|
});
|
||||||
if (updated) return { kind: 'data', blk: clientProfile(updated, account) };
|
if (updated) return { kind: 'data', blk: clientProfile(updated, account) };
|
||||||
|
|||||||
@@ -10,17 +10,16 @@
|
|||||||
*/
|
*/
|
||||||
import type { AccountStore } from '../../accounts/account-store.ts';
|
import type { AccountStore } from '../../accounts/account-store.ts';
|
||||||
import type { PlayerProfiles } from '../../profile/player-profiles.ts';
|
import type { PlayerProfiles } from '../../profile/player-profiles.ts';
|
||||||
import type { ResearchRules } from '../../research/research-rules.ts';
|
import { buyUnlock, type UnlockShop } from '../../unlocks/unlock-purchase.ts';
|
||||||
import { buyUnlock } from '../../unlocks/unlock-purchase.ts';
|
|
||||||
import type { CharActionHandler } from '../char-action.ts';
|
import type { CharActionHandler } from '../char-action.ts';
|
||||||
import { intParam, stringParam } from './payload-params.ts';
|
import { intParam, stringParam } from './payload-params.ts';
|
||||||
import { ruleAction } from './rule-answer.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) => {
|
return ruleAction(profiles, accounts, (payload) => {
|
||||||
const name = stringParam(payload, 'name');
|
const name = stringParam(payload, 'name');
|
||||||
if (name === undefined) return undefined;
|
if (name === undefined) return undefined;
|
||||||
const offered = { silverLions: intParam(payload, 'wpCost') ?? 0, goldenEagles: intParam(payload, 'goldCost') ?? 0 };
|
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);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -8,14 +8,30 @@ import { actionTable } from './char/actions/action-table.ts';
|
|||||||
import { CharService } from './char/char-service.ts';
|
import { CharService } from './char/char-service.ts';
|
||||||
import { ClanStore } from './clans/clan-store.ts';
|
import { ClanStore } from './clans/clan-store.ts';
|
||||||
import { CloudSettingsStore } from './cloud-settings/cloud-settings-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 { 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 { 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 { multiplayerMissions } from './game-data/datasets/multiplayer-missions.ts';
|
||||||
import { shopCountries } from './game-data/datasets/shop-countries.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 { GameFiles } from './game-data/game-files.ts';
|
||||||
import { GameModes } from './game-modes/game-modes.ts';
|
import { GameModes } from './game-modes/game-modes.ts';
|
||||||
import { InventoryService } from './inventory/inventory-service.ts';
|
import { InventoryService } from './inventory/inventory-service.ts';
|
||||||
|
import { InventoryCatalogue } from './inventory/itemdef-catalogue.ts';
|
||||||
import { MarketplaceService } from './inventory/marketplace-service.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 { LoginService } from './login/login-service.ts';
|
||||||
import { matchingRequests } from './matching/matching-requests.ts';
|
import { matchingRequests } from './matching/matching-requests.ts';
|
||||||
import type { MatchingService } from './matching/matching-service.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 { createPortListener } from './server/port-listener.ts';
|
||||||
import { Router } from './server/router.ts';
|
import { Router } from './server/router.ts';
|
||||||
import { loadOrCreateCredentials } from './server/tls/tls-certificate.ts';
|
import { loadOrCreateCredentials } from './server/tls/tls-certificate.ts';
|
||||||
|
import { StoreCatalogue } from './store/store-catalogue.ts';
|
||||||
import { StoreService } from './store/store-service.ts';
|
import { StoreService } from './store/store-service.ts';
|
||||||
import { TrafficLog } from './traffic-log/traffic-log.ts';
|
import { TrafficLog } from './traffic-log/traffic-log.ts';
|
||||||
import { loadTuning } from './tuning/tuning.ts';
|
import { loadTuning, type Tuning } from './tuning/tuning.ts';
|
||||||
import { uiLabels } from './game-data/datasets/ui-labels.ts';
|
import { UnlockShop } from './unlocks/unlock-purchase.ts';
|
||||||
import { webIcons } from './game-data/datasets/web-icons.ts';
|
|
||||||
import { WebUiService } from './web-ui/web-ui-service.ts';
|
import { WebUiService } from './web-ui/web-ui-service.ts';
|
||||||
|
|
||||||
export interface LocalServiceOptions {
|
export interface LocalServiceOptions {
|
||||||
@@ -57,8 +73,11 @@ export async function startLocalService(options: LocalServiceOptions): Promise<R
|
|||||||
const tuning = loadTuning(options.dataFolder, report);
|
const tuning = loadTuning(options.dataFolder, report);
|
||||||
const clans = new ClanStore(options.dataFolder, tuning.clans);
|
const clans = new ClanStore(options.dataFolder, tuning.clans);
|
||||||
const cloudSettings = new CloudSettingsStore(options.dataFolder);
|
const cloudSettings = new CloudSettingsStore(options.dataFolder);
|
||||||
const { profiles, research } = setUpProfiles(options.dataFolder, gameFiles, datasets, tuning, { accounts, clans });
|
const vehicles = datasets.load(vehicleCatalogue);
|
||||||
const webUi = new WebUiService(datasets.load(webIcons), datasets.load(uiLabels));
|
const labels = datasets.load(uiLabels);
|
||||||
|
const { profiles, research, equipment } = setUpProfiles(options.dataFolder, gameFiles, datasets, tuning, { accounts, clans }, vehicles);
|
||||||
|
const { clanEconomy: squadronEconomy, ...catalogues } = loadDomainCatalogues(datasets, tuning, vehicles, labels);
|
||||||
|
const webUi = new WebUiService(datasets.load(webIcons), labels);
|
||||||
gameFiles.releasePacks();
|
gameFiles.releasePacks();
|
||||||
|
|
||||||
let matching: MatchingService | undefined;
|
let matching: MatchingService | undefined;
|
||||||
@@ -66,11 +85,20 @@ export async function startLocalService(options: LocalServiceOptions): Promise<R
|
|||||||
|
|
||||||
const router = new Router([
|
const router = new Router([
|
||||||
webUi,
|
webUi,
|
||||||
new StoreService(accounts, profiles, research.store, tuning.redeemCodes),
|
new StoreService(accounts, profiles, catalogues.store, tuning.redeemCodes),
|
||||||
new MarketplaceService(accounts, profiles, research.inventory, notifyInventoryChanged, tuning.marketplace.maxPerPurchase),
|
new MarketplaceService(accounts, profiles, catalogues.inventory, notifyInventoryChanged, tuning.marketplace.maxPerPurchase),
|
||||||
new InventoryService(accounts, profiles, research.inventory),
|
new InventoryService(accounts, profiles, catalogues.inventory),
|
||||||
new LoginService(accounts),
|
new LoginService(accounts),
|
||||||
new CharService(actionTable({ profiles, accounts, research, clans, cloudSettings, notifyInventoryChanged })),
|
new CharService(actionTable({
|
||||||
|
profiles,
|
||||||
|
accounts,
|
||||||
|
research,
|
||||||
|
equipment,
|
||||||
|
...catalogues,
|
||||||
|
clans: { store: clans, economy: squadronEconomy },
|
||||||
|
cloudSettings,
|
||||||
|
notifyInventoryChanged,
|
||||||
|
})),
|
||||||
new DownloadableContentService(),
|
new DownloadableContentService(),
|
||||||
]);
|
]);
|
||||||
const log = new TrafficLog(options.dataFolder);
|
const log = new TrafficLog(options.dataFolder);
|
||||||
@@ -86,6 +114,21 @@ export async function startLocalService(options: LocalServiceOptions): Promise<R
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function loadDomainCatalogues(datasets: DatasetCache, tuning: Tuning, vehicles: readonly CatalogueVehicle[], labels: UiLabels) {
|
||||||
|
const classicItemDefs = datasets.load(itemCatalogue);
|
||||||
|
const localizedUnitNames = datasets.load(unitNames);
|
||||||
|
return {
|
||||||
|
crew: new CrewSkillCatalogue(datasets.load(crewSkillData)),
|
||||||
|
decor: new DecorShop(datasets.load(decorCatalogue)),
|
||||||
|
unlocks: new UnlockShop(datasets.load(unlockPrices)),
|
||||||
|
items: new ItemCatalogue(classicItemDefs, tuning.limits.itemPiecesPerPurchase),
|
||||||
|
store: new StoreCatalogue(vehicles, datasets.load(storeBundles), localizedUnitNames, labels, tuning.store),
|
||||||
|
inventory: new InventoryCatalogue(vehicles, localizedUnitNames, datasets.load(externalItemSources), classicItemDefs, tuning),
|
||||||
|
trophies: new TrophyCatalogue(vehicles, classicItemDefs, tuning.trophies),
|
||||||
|
clanEconomy: datasets.load(clanEconomy),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function listen(server: Server, port: number): Promise<void> {
|
function listen(server: Server, port: number): Promise<void> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
server.once('error', reject);
|
server.once('error', reject);
|
||||||
|
|||||||
@@ -9,10 +9,13 @@ import type { ClanStore } from './clans/clan-store.ts';
|
|||||||
import type { DatasetCache } from './game-data/datasets/dataset-cache.ts';
|
import type { DatasetCache } from './game-data/datasets/dataset-cache.ts';
|
||||||
import { reserveVehicles } from './game-data/datasets/reserve-vehicles.ts';
|
import { reserveVehicles } from './game-data/datasets/reserve-vehicles.ts';
|
||||||
import { shopBranches } from './game-data/datasets/shop-branches.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 type { GameFiles } from './game-data/game-files.ts';
|
||||||
import { removeExpiredItems } from './items/item-expiry.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 { refreshModuleState } from './modifications/module-state.ts';
|
||||||
|
import { trimUserLogs } from './profile/profile-trophies-log.ts';
|
||||||
import { PlayerProfiles } from './profile/player-profiles.ts';
|
import { PlayerProfiles } from './profile/player-profiles.ts';
|
||||||
import { profileUpgrades } from './profile/profile-upgrades.ts';
|
import { profileUpgrades } from './profile/profile-upgrades.ts';
|
||||||
import { serverTimeNow } from './profile/server-time.ts';
|
import { serverTimeNow } from './profile/server-time.ts';
|
||||||
@@ -25,6 +28,7 @@ import type { Tuning } from './tuning/tuning.ts';
|
|||||||
export interface ProfileServices {
|
export interface ProfileServices {
|
||||||
readonly profiles: PlayerProfiles;
|
readonly profiles: PlayerProfiles;
|
||||||
readonly research: ResearchRules;
|
readonly research: ResearchRules;
|
||||||
|
readonly equipment: EquipmentCatalogue;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ProfileSyncContext {
|
export interface ProfileSyncContext {
|
||||||
@@ -38,21 +42,23 @@ export function setUpProfiles(
|
|||||||
datasets: DatasetCache,
|
datasets: DatasetCache,
|
||||||
tuning: Tuning,
|
tuning: Tuning,
|
||||||
sync?: ProfileSyncContext,
|
sync?: ProfileSyncContext,
|
||||||
|
vehicles: readonly CatalogueVehicle[] = datasets.load(vehicleCatalogue),
|
||||||
): ProfileServices {
|
): ProfileServices {
|
||||||
const startingContent: StartingContent = {
|
const startingContent: StartingContent = {
|
||||||
reserveVehicles: datasets.load(reserveVehicles),
|
reserveVehicles: datasets.load(reserveVehicles),
|
||||||
branches: datasets.load(shopBranches),
|
branches: datasets.load(shopBranches),
|
||||||
startingBalance: tuning.newProfile.startingBalance,
|
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 saves = new SaveStore(dataFolder, profileUpgrades(startingContent));
|
||||||
const profiles = new PlayerProfiles(saves, gameFiles, startingContent, (profile, userId) => {
|
const profiles = new PlayerProfiles(saves, gameFiles, startingContent, (profile, userId) => {
|
||||||
const account = sync?.accounts.byUserId(userId);
|
const account = sync?.accounts.byUserId(userId);
|
||||||
if (account && sync) sync.clans.syncProfile(profile, account);
|
if (account && sync) sync.clans.syncProfile(profile, account);
|
||||||
refreshResearchState(profile, research);
|
refreshResearchState(profile, research);
|
||||||
refreshModuleState(profile, research.equipment);
|
refreshModuleState(profile, equipment);
|
||||||
removeExpiredItems(profile, serverTimeNow());
|
removeExpiredItems(profile, serverTimeNow());
|
||||||
trimUserLogs(profile, tuning.limits.userLogsKept);
|
trimUserLogs(profile, tuning.limits.userLogsKept);
|
||||||
});
|
});
|
||||||
return { profiles, research };
|
return { profiles, research, equipment };
|
||||||
}
|
}
|
||||||
@@ -1,31 +1,12 @@
|
|||||||
/**
|
/**
|
||||||
* The static facts research and purchase rules use, loaded once at start-up from the
|
* The static facts vehicle research and purchase rules use, loaded once at start-up from
|
||||||
* player's game files.
|
* the player's game files (implementation notes; implementation notes).
|
||||||
*/
|
*/
|
||||||
import type { DatasetCache } from '../game-data/datasets/dataset-cache.ts';
|
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 { crewSlotPrices, eraRequirements, type CrewSlotPrices, type EraRequirements } from '../game-data/datasets/rank-settings.ts';
|
||||||
import { researchPointsPerGoldenEagle } from '../game-data/datasets/research-point-rate.ts';
|
import { researchPointsPerGoldenEagle } from '../game-data/datasets/research-point-rate.ts';
|
||||||
import { vehicleCatalogue } from '../game-data/datasets/vehicle-catalogue.ts';
|
import { vehicleCatalogue, type CatalogueVehicle } 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';
|
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 type { ResearchTuning } from './research-tuning.ts';
|
||||||
import { TechTree } from './tech-tree.ts';
|
import { TechTree } from './tech-tree.ts';
|
||||||
|
|
||||||
@@ -37,45 +18,19 @@ export interface ResearchRules {
|
|||||||
readonly researchPointsPerGoldenEagle: number;
|
readonly researchPointsPerGoldenEagle: number;
|
||||||
/** How a branch without a research target gets one (tuning/research.jsonc; implementation notes). */
|
/** How a branch without a research target gets one (tuning/research.jsonc; implementation notes). */
|
||||||
readonly researchTuning: ResearchTuning;
|
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 {
|
export function loadResearchRules(
|
||||||
const vehicles = datasets.load(vehicleCatalogue);
|
datasets: DatasetCache,
|
||||||
const classicItemDefs = datasets.load(itemCatalogue);
|
researchTuning: ResearchTuning,
|
||||||
const localizedUnitNames = datasets.load(unitNames);
|
vehicles: readonly CatalogueVehicle[] = datasets.load(vehicleCatalogue),
|
||||||
|
): ResearchRules {
|
||||||
return {
|
return {
|
||||||
techTree: new TechTree(vehicles),
|
techTree: new TechTree(vehicles),
|
||||||
eraRequirements: datasets.load(eraRequirements),
|
eraRequirements: datasets.load(eraRequirements),
|
||||||
vehicleUnlocks: datasets.load(vehicleUnlocks),
|
vehicleUnlocks: datasets.load(vehicleUnlocks),
|
||||||
crewSlotPrices: datasets.load(crewSlotPrices),
|
crewSlotPrices: datasets.load(crewSlotPrices),
|
||||||
researchPointsPerGoldenEagle: datasets.load(researchPointsPerGoldenEagle),
|
researchPointsPerGoldenEagle: datasets.load(researchPointsPerGoldenEagle),
|
||||||
researchTuning: tuning.research,
|
researchTuning,
|
||||||
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),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -7,11 +7,17 @@
|
|||||||
* [--squadron-rp <n>] [--give-item <item>[:<pieces>]]... [--give-coupon <itemdefId>[:<qty>]]...
|
* [--squadron-rp <n>] [--give-item <item>[:<pieces>]]... [--give-coupon <itemdefId>[:<qty>]]...
|
||||||
*/
|
*/
|
||||||
import { parseArgs } from 'node:util';
|
import { parseArgs } from 'node:util';
|
||||||
|
import type { BlkBlock } from '@wto/blk';
|
||||||
import { AccountStore, type Account } from './accounts/account-store.ts';
|
import { AccountStore, type Account } from './accounts/account-store.ts';
|
||||||
import { ClanStore } from './clans/clan-store.ts';
|
import { ClanStore } from './clans/clan-store.ts';
|
||||||
import { DatasetCache } from './game-data/datasets/dataset-cache.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 { 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 { grantItem } from './items/item-grants.ts';
|
||||||
import { availableSquadronRp, clanMembershipOf, setAvailableSquadronRp } from './profile/profile-clan.ts';
|
import { availableSquadronRp, clanMembershipOf, setAvailableSquadronRp } from './profile/profile-clan.ts';
|
||||||
import { balanceOf, setGjnCents, setGoldenEagles, setSilverLions } from './profile/profile-currency.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 { serverTimeNow } from './profile/server-time.ts';
|
||||||
import { setUpProfiles } from './profiles-setup.ts';
|
import { setUpProfiles } from './profiles-setup.ts';
|
||||||
import { gjnText } from './store/redeem-codes.ts';
|
import { gjnText } from './store/redeem-codes.ts';
|
||||||
import { loadTuning } from './tuning/tuning.ts';
|
import { loadTuning, type Tuning } from './tuning/tuning.ts';
|
||||||
import type { ResearchRules } from './research/research-rules.ts';
|
|
||||||
import type { BlkBlock } from '@wto/blk';
|
|
||||||
|
|
||||||
const USAGE = 'usage: save-cli.ts --game <game folder> --data <data folder> --player <login or user id> '
|
const USAGE = 'usage: save-cli.ts --game <game folder> --data <data folder> --player <login or user id> '
|
||||||
+ '[--silver <n>] [--gold <n>] [--gjn <n>] [--free-rp <n>] [--squadron-rp <n>] '
|
+ '[--silver <n>] [--gold <n>] [--gjn <n>] [--free-rp <n>] [--squadron-rp <n>] '
|
||||||
@@ -72,9 +76,10 @@ function main(): number {
|
|||||||
const clans = new ClanStore(values.data, tuning.clans);
|
const clans = new ClanStore(values.data, tuning.clans);
|
||||||
const gameFiles = new GameFiles(values.game);
|
const gameFiles = new GameFiles(values.game);
|
||||||
const datasets = new DatasetCache(values.data, gameFiles, () => {});
|
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;
|
if (!edits) return 2;
|
||||||
|
|
||||||
const now = serverTimeNow();
|
const now = serverTimeNow();
|
||||||
@@ -89,7 +94,9 @@ function main(): number {
|
|||||||
|
|
||||||
function parseRequestedEdits(
|
function parseRequestedEdits(
|
||||||
values: Record<string, string | string[] | undefined>,
|
values: Record<string, string | string[] | undefined>,
|
||||||
research: ResearchRules,
|
datasets: DatasetCache,
|
||||||
|
tuning: Tuning,
|
||||||
|
vehicles: readonly CatalogueVehicle[],
|
||||||
): ParsedEdits | undefined {
|
): ParsedEdits | undefined {
|
||||||
const silver = optionalAmount(values.silver as string | undefined);
|
const silver = optionalAmount(values.silver as string | undefined);
|
||||||
const gold = optionalAmount(values.gold as string | undefined);
|
const gold = optionalAmount(values.gold as string | undefined);
|
||||||
@@ -101,10 +108,34 @@ function parseRequestedEdits(
|
|||||||
return undefined;
|
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 }> = [];
|
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 [name = '', piecesText = '1'] = request.split(':');
|
||||||
const item = research.items.item(name);
|
const item = items.item(name);
|
||||||
const pieces = optionalAmount(piecesText);
|
const pieces = optionalAmount(piecesText);
|
||||||
if (!item || !pieces) {
|
if (!item || !pieces) {
|
||||||
console.error(`--give-item: no classic item "${name}", or pieces not a whole number of 1 or more`);
|
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 });
|
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 }> = [];
|
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 [idText = '', qtyText = '1'] = request.split(':');
|
||||||
const itemdefId = optionalAmount(idText);
|
const itemdefId = optionalAmount(idText);
|
||||||
const quantity = optionalAmount(qtyText);
|
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`);
|
console.error(`--give-coupon: unknown itemdef id "${idText}", or quantity not a whole number of 1 or more`);
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
coupons.push({ itemdefId, quantity });
|
coupons.push({ itemdefId, quantity });
|
||||||
}
|
}
|
||||||
|
return coupons;
|
||||||
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 applyEdits(saved: BlkBlock, edits: ParsedEdits, clanEarned: number, now: bigint): void {
|
function applyEdits(saved: BlkBlock, edits: ParsedEdits, clanEarned: number, now: bigint): void {
|
||||||
|
|||||||
Reference in new issue
Block a user