"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.handlePreCombatHeroPowers = void 0;
const summon_when_space_1 = require("../summon-when-space");
const soc_action_processor_1 = require("./soc-action-processor");
const handlePreCombatHeroPowers = (playerEntity, playerBoard, opponentEntity, opponentBoard, currentAttacker, gameState) => {
    let initialPlayerBoardSize = playerBoard.length;
    let initialOpponentBoardSize = opponentBoard.length;
    const random = Math.random();
    if (random < 0.5) {
        currentAttacker = handlePreCombatHeroPowersForPlayer({
            playerEntity: playerEntity,
            playerBoard: playerBoard,
            opponentEntity: opponentEntity,
            opponentBoard: opponentBoard,
            currentAttacker,
            playerIsFriendly: true,
            gameState,
        });
        initialPlayerBoardSize = playerBoard.length;
        (0, summon_when_space_1.handleSummonsWhenSpace)(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);
        currentAttacker = handlePreCombatHeroPowersForPlayer({
            playerEntity: opponentEntity,
            playerBoard: opponentBoard,
            opponentEntity: playerEntity,
            opponentBoard: playerBoard,
            currentAttacker,
            playerIsFriendly: false,
            gameState,
        });
        initialOpponentBoardSize = opponentBoard.length;
        (0, summon_when_space_1.handleSummonsWhenSpace)(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);
    }
    else {
        currentAttacker = handlePreCombatHeroPowersForPlayer({
            playerEntity: opponentEntity,
            playerBoard: opponentBoard,
            opponentEntity: playerEntity,
            opponentBoard: playerBoard,
            currentAttacker,
            playerIsFriendly: false,
            gameState,
        });
        initialOpponentBoardSize = opponentBoard.length;
        (0, summon_when_space_1.handleSummonsWhenSpace)(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);
        currentAttacker = handlePreCombatHeroPowersForPlayer({
            playerEntity: playerEntity,
            playerBoard: playerBoard,
            opponentEntity: opponentEntity,
            opponentBoard: opponentBoard,
            currentAttacker,
            playerIsFriendly: true,
            gameState,
        });
        initialPlayerBoardSize = playerBoard.length;
        (0, summon_when_space_1.handleSummonsWhenSpace)(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);
    }
    if (playerBoard.length !== initialPlayerBoardSize || opponentBoard.length !== initialOpponentBoardSize) {
        currentAttacker =
            playerBoard.length > opponentBoard.length
                ? 0
                : opponentBoard.length > playerBoard.length
                    ? 1
                    : Math.round(Math.random());
    }
    return currentAttacker;
};
exports.handlePreCombatHeroPowers = handlePreCombatHeroPowers;
const handlePreCombatHeroPowersForPlayer = (input) => {
    var _a;
    const loops = ((_a = input.playerEntity.trinkets) === null || _a === void 0 ? void 0 : _a.some((t) => t.cardId === "BG32_MagicItem_365"))
        ? 2
        : 1;
    for (let i = 0; i < loops; i++) {
        if (input.playerEntity.startOfCombatDone || input.playerEntity.hpLeft <= 0) {
            return input.currentAttacker;
        }
        for (const heroPower of input.playerEntity.heroPowers) {
            (0, soc_action_processor_1.performStartOfCombatAction)(heroPower.cardId, input.playerEntity, input, true, 'pre-combat');
        }
    }
    return input.currentAttacker;
};
//# sourceMappingURL=soc-pre-combat-hero-power.js.map