import { createPromptDef } from "@/core/game"; import {CombatGameContext} from "./types"; import {canPlayCard} from "@/samples/slay-the-spire-like/system/combat/effects"; export const prompts = { mainAction: createPromptDef<[string, string?]>( "main-action [targetId:string]", "选择卡牌并指定目标" ), }; export async function promptMainAction(game: CombatGameContext){ return await game.prompt(prompts.mainAction, (cardId, targetId) => { if(cardId === 'end-turn') return { action: 'end-turn' as 'end-turn' }; const exists = game.value.player.deck.regions.hand.childIds.includes(cardId); if(!exists) throw `卡牌"${cardId}"不在手牌中`; const card = game.value.player.deck.cards[cardId]; const {cardData, itemId} = card; if(!canPlayCard(game.value.player, cardData.costType, cardData.costCount, itemId, game.value.inventory)){ throw `无法支付卡牌"${cardId}"的费用`; } const {targetType} = cardData; if(targetType === 'single'){ if(!targetId) throw `请指定目标`; const target = game.value.enemies.find(e => e.id === targetId); if(!target) throw `目标"${targetId}"不存在`; if(!target.isAlive) throw `目标"${targetId}"已死亡`; }else if(targetType === 'none'){ if(targetId) throw `目标"${targetId}"无效`; } return { action: 'play' as 'play', cardId, targetId }; }); }