/** * Char action handlers for squadron (clan) vehicle research and Golden-Eagle buyout * (`cln_set_research_clan_unit`, `cln_flush_clan_exp_to_unit`, `cln_buy_not_researched_clans_unit`; * implementation notes). */ import type { AccountStore } from '../../accounts/account-store.ts'; import type { ClanStore } from '../../clans/clan-store.ts'; import type { PlayerProfiles } from '../../profile/player-profiles.ts'; import type { ResearchRules } from '../../research/research-rules.ts'; import { buyNotResearchedSquadronUnit, chooseSquadronResearchTarget, flushSquadronExpToUnit, } from '../../research/squadron-research.ts'; import type { CharActionHandler } from '../char-action.ts'; import { clanProfileRuleAction, priceFromClanPayload } from './clan-actions.ts'; import { boolParam, stringParam } from './payload-params.ts'; export function setResearchClanUnitAction( profiles: PlayerProfiles, accounts: AccountStore, clans: ClanStore, rules: ResearchRules, ): CharActionHandler { return clanProfileRuleAction(profiles, accounts, clans, (context, profile, account) => { const unit = context.payload && stringParam(context.payload, 'unit'); if (!unit) return { ok: false, refusal: 'BAD_PARAMS' }; const auto = (context.payload && boolParam(context.payload, 'auto')) ?? false; return chooseSquadronResearchTarget(profile, rules, unit, auto, clans.earnedSquadronExpOf(account.userId)); }); } export function flushClanExpToUnitAction( profiles: PlayerProfiles, accounts: AccountStore, clans: ClanStore, rules: ResearchRules, ): CharActionHandler { return clanProfileRuleAction(profiles, accounts, clans, (_context, profile, account) => flushSquadronExpToUnit(profile, rules, clans.earnedSquadronExpOf(account.userId))); } export function buyNotResearchedClanUnitAction( profiles: PlayerProfiles, accounts: AccountStore, clans: ClanStore, rules: ResearchRules, ): CharActionHandler { return clanProfileRuleAction(profiles, accounts, clans, (context, profile) => { const unit = context.payload && stringParam(context.payload, 'unit'); const offered = context.payload && priceFromClanPayload(context.payload); if (!unit || !offered) return { ok: false, refusal: 'BAD_PARAMS' }; return buyNotResearchedSquadronUnit(profile, rules, unit, offered); }); }