refactor: more regicide stuff
This commit is contained in:
@@ -32,6 +32,7 @@ export function getCardValue(rank: CardRank): number {
|
||||
}
|
||||
|
||||
// 创建城堡牌堆 (J/Q/K 作为敌人)
|
||||
// TODO 不要全部洗混,把J/Q/K分别洗混再合并,并且J先翻出K最后翻出
|
||||
export function createCastleDeck(): EnemyCard[] {
|
||||
const suits: CardSuit[] = ['hearts', 'diamonds', 'clubs', 'spades'];
|
||||
const castleCards: EnemyCard[] = [];
|
||||
|
||||
@@ -247,10 +247,20 @@ registry.register('yield', yieldTurn);
|
||||
// counterattack <cardIds> - 反击时弃牌
|
||||
async function counterattack(game: RegicideGame, cardIds: string[]) {
|
||||
const state = game.value;
|
||||
|
||||
|
||||
if (state.phase !== 'enemyCounterattack') throw new Error('不是反击阶段');
|
||||
if (!state.currentEnemy) throw new Error('没有活跃的敌人');
|
||||
|
||||
// 空牌提交 = 认输
|
||||
if (cardIds.length === 0) {
|
||||
game.produce((state: RegicideState) => {
|
||||
state.isGameOver = true;
|
||||
state.victoryLevel = null;
|
||||
state.phase = 'gameOver';
|
||||
});
|
||||
return { success: false, required: state.currentEnemy.counterDamage, available: 0, isSurrender: true };
|
||||
}
|
||||
|
||||
const selectedCards: Card[] = [];
|
||||
for (const cardId of cardIds) {
|
||||
const card = state.hand.find(c => c.id === cardId);
|
||||
@@ -408,6 +418,11 @@ export async function start(game: RegicideGame) {
|
||||
const { cardIds } = await game.prompt(
|
||||
prompts.counterattack,
|
||||
(cardIds: string[]) => {
|
||||
// 允许空牌提交(认输)
|
||||
if (cardIds.length === 0) {
|
||||
return { cardIds: [], totalValue: 0 };
|
||||
}
|
||||
|
||||
const selectedCards: Card[] = [];
|
||||
for (const cardId of cardIds) {
|
||||
const card = state.hand.find(c => c.id === cardId);
|
||||
@@ -418,11 +433,8 @@ export async function start(game: RegicideGame) {
|
||||
}
|
||||
|
||||
const totalValue = selectedCards.reduce((sum, c) => sum + c.value, 0);
|
||||
if (totalValue < requiredValue) {
|
||||
throw `牌的总点数 ${totalValue} 不足以抵消反击伤害 ${requiredValue}`;
|
||||
}
|
||||
|
||||
return { cardIds };
|
||||
// 不再抛出错误,允许提交不足的牌,由 counterattack 处理失败逻辑
|
||||
return { cardIds, totalValue };
|
||||
},
|
||||
state.currentEnemy.id
|
||||
);
|
||||
@@ -444,9 +456,21 @@ export async function start(game: RegicideGame) {
|
||||
isDefeated: false,
|
||||
};
|
||||
state.currentEnemy = nextEnemy;
|
||||
state.phase = 'playerTurn';
|
||||
} else {
|
||||
// 城堡牌堆没有有效的敌人卡牌,游戏胜利
|
||||
state.isGameOver = true;
|
||||
state.victoryLevel = calculateVictoryLevel(state.jestersUsed);
|
||||
state.currentEnemy = null;
|
||||
state.phase = 'gameOver';
|
||||
}
|
||||
} else {
|
||||
// 城堡牌堆已空,游戏胜利
|
||||
state.isGameOver = true;
|
||||
state.victoryLevel = calculateVictoryLevel(state.jestersUsed);
|
||||
state.currentEnemy = null;
|
||||
state.phase = 'gameOver';
|
||||
}
|
||||
state.phase = 'playerTurn';
|
||||
state.currentPlayed = null;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user