修复AI不进行下一步的问题,优化回合流程逻辑

This commit is contained in:
张健 2026-01-08 18:52:30 +08:00
parent bce0c3a79b
commit a27e45a024

13
game.js
View File

@ -1128,6 +1128,11 @@ class Game {
this.addLog(`${player.character.name}${target.character.name} 使用了【火攻】`);
this.showCardUseAnimation();
if (target.hand.length === 0) {
this.addLog('目标没有手牌,火攻无效');
return false;
}
const randomCardIndex = Math.floor(Math.random() * target.hand.length);
const randomCard = target.hand[randomCardIndex];
this.addLog(`${target.character.name} 展示了一张 ${randomCard.name}`);
@ -1492,7 +1497,6 @@ class Game {
}
aiPlayCards(player) {
const targets = this.players.filter(p => p.isAlive && p.index !== player.index);
const canUseMultipleAttacks = this.hasWeaponWithEffect('zhugeliannu') || player.character.name === '张飞';
const cardPriority = [
@ -1513,6 +1517,11 @@ class Game {
];
const playNextCard = () => {
if (this.gameOver || this.getCurrentPlayer().index !== player.index) {
return;
}
const targets = this.players.filter(p => p.isAlive && p.index !== player.index);
let cardsUsed = false;
if (player.character.name === '刘备' && player.hand.length >= 2) {
@ -1577,7 +1586,7 @@ class Game {
targetIndex = this[priority.target](player, targets);
}
if (targetIndex !== -1 || !priority.target) {
if (targetIndex !== -1 || !priority.target || priority.isEquip) {
const result = this.playCard(cardIndex, targetIndex);
if (result) {
cardsUsed = true;