123
This commit is contained in:
23
server.js
23
server.js
@ -247,10 +247,15 @@ function makeAITurn(room) {
|
|||||||
// Используем заклинание
|
// Используем заклинание
|
||||||
const enemies = gameState.players.filter((p, i) => i !== aiPlayerIndex && p.health > 0);
|
const enemies = gameState.players.filter((p, i) => i !== aiPlayerIndex && p.health > 0);
|
||||||
if (enemies.length > 0) {
|
if (enemies.length > 0) {
|
||||||
// Выбираем самого слабого врага (по здоровью), если одинаковое - случайно
|
// Выбираем врага: 70% шанс выбрать самого слабого, 30% - случайно среди всех
|
||||||
|
let targetEnemy;
|
||||||
|
if (Math.random() < 0.7 && enemies.length > 1) {
|
||||||
const weakest = enemies.reduce((min, p) => (p.health < min.health ? p : min), enemies[0]);
|
const weakest = enemies.reduce((min, p) => (p.health < min.health ? p : min), enemies[0]);
|
||||||
const weakEnemies = enemies.filter(p => p.health === weakest.health);
|
const weakEnemies = enemies.filter(p => p.health === weakest.health);
|
||||||
const targetEnemy = weakEnemies[Math.floor(Math.random() * weakEnemies.length)];
|
targetEnemy = weakEnemies[Math.floor(Math.random() * weakEnemies.length)];
|
||||||
|
} else {
|
||||||
|
targetEnemy = enemies[Math.floor(Math.random() * enemies.length)];
|
||||||
|
}
|
||||||
let targetBoardIndex = -1;
|
let targetBoardIndex = -1;
|
||||||
|
|
||||||
if (playable.card.spellTarget === 'enemy_minion' || playable.card.spellTarget === 'any_minion') {
|
if (playable.card.spellTarget === 'enemy_minion' || playable.card.spellTarget === 'any_minion') {
|
||||||
@ -277,7 +282,8 @@ function makeAITurn(room) {
|
|||||||
targetBoardIndex = -1;
|
targetBoardIndex = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
playSpell(room, aiPlayer.id, playable.index, gameState.players.indexOf(targetEnemy), targetBoardIndex);
|
const targetPlayerIndex = gameState.players.findIndex((p, i) => i !== aiPlayerIndex && p === targetEnemy);
|
||||||
|
playSpell(room, aiPlayer.id, playable.index, targetPlayerIndex, targetBoardIndex);
|
||||||
actionsDone++;
|
actionsDone++;
|
||||||
cardIndex++;
|
cardIndex++;
|
||||||
setTimeout(playNextCard, 600);
|
setTimeout(playNextCard, 600);
|
||||||
@ -326,11 +332,16 @@ function performAIAttacks(room, aiPlayerIndex) {
|
|||||||
|
|
||||||
const minion = attackableMinions[attackIndex];
|
const minion = attackableMinions[attackIndex];
|
||||||
const boardIndex = aiPlayer.board.indexOf(minion);
|
const boardIndex = aiPlayer.board.indexOf(minion);
|
||||||
// Выбираем самого слабого врага (по здоровью), если одинаковое - случайно
|
// Выбираем врага: 70% шанс выбрать самого слабого, 30% - случайно среди всех
|
||||||
|
let targetEnemy;
|
||||||
|
if (Math.random() < 0.7 && enemies.length > 1) {
|
||||||
const weakest = enemies.reduce((min, p) => (p.health < min.health ? p : min), enemies[0]);
|
const weakest = enemies.reduce((min, p) => (p.health < min.health ? p : min), enemies[0]);
|
||||||
const weakEnemies = enemies.filter(p => p.health === weakest.health);
|
const weakEnemies = enemies.filter(p => p.health === weakest.health);
|
||||||
const targetEnemy = weakEnemies[Math.floor(Math.random() * weakEnemies.length)];
|
targetEnemy = weakEnemies[Math.floor(Math.random() * weakEnemies.length)];
|
||||||
const targetPlayerIndex = gameState.players.indexOf(targetEnemy);
|
} else {
|
||||||
|
targetEnemy = enemies[Math.floor(Math.random() * enemies.length)];
|
||||||
|
}
|
||||||
|
const targetPlayerIndex = gameState.players.findIndex((p, i) => i !== aiPlayerIndex && p === targetEnemy);
|
||||||
let targetBoardIndex = -1;
|
let targetBoardIndex = -1;
|
||||||
|
|
||||||
// Выбираем цель: сначала слабые миньоны, потом герой
|
// Выбираем цель: сначала слабые миньоны, потом герой
|
||||||
|
|||||||
Reference in New Issue
Block a user