"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TimewarpedWarghoul = void 0;
const utils_1 = require("../../../services/utils");
const attack_1 = require("../../../simulation/attack");
const deathrattle_orchestration_1 = require("../../../simulation/deathrattle-orchestration");
const deathrattle_utils_1 = require("../../../simulation/deathrattle-utils");
let callStackDepth = 0;
exports.TimewarpedWarghoul = {
    cardIds: ["BG34_Giant_331", "BG34_Giant_331_G"],
    deathrattleSpawn: (minion, input) => {
        callStackDepth++;
        const allNeighbours = (0, attack_1.getNeighbours)(input.boardWithDeadEntity, minion, input.deadEntityIndexFromRight).filter((e) => !!e &&
            (0, deathrattle_utils_1.hasValidDeathrattle)(e, input.boardWithDeadEntityHero, input.gameState) &&
            !exports.TimewarpedWarghoul.cardIds.includes(e.cardId) &&
            e.entityId !== minion.entityId);
        const neighbours = minion.cardId === "BG34_Giant_331_G"
            ? allNeighbours
            : [(0, utils_1.pickRandom)(allNeighbours)].filter((e) => !!e);
        if (neighbours.length === 0) {
            callStackDepth--;
            return [];
        }
        if (callStackDepth > 10) {
            console.log('warning: timewarped warghoul call stack depth is too deep');
        }
        for (const neighbour of neighbours) {
            input.gameState.spectator.registerPowerTarget(minion, neighbour, input.boardWithDeadEntity, input.boardWithDeadEntityHero, input.otherBoardHero);
            const indexFromRight = input.boardWithDeadEntity.length - (input.boardWithDeadEntity.indexOf(neighbour) + 1);
            (0, deathrattle_orchestration_1.processDeathrattleForMinion)(neighbour, indexFromRight, [neighbour], neighbour.friendly ? input.gameState.gameState.player : input.gameState.gameState.opponent, neighbour.friendly ? input.gameState.gameState.opponent : input.gameState.gameState.player, input.gameState, false);
        }
        callStackDepth--;
        return [];
    },
};
//# sourceMappingURL=timewarped-warghoul.js.map