"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleStartOfCombatTrinkets = void 0;
const summon_when_space_1 = require("../summon-when-space");
const soc_action_processor_1 = require("./soc-action-processor");
const handleStartOfCombatTrinkets = (playerEntity, playerBoard, opponentEntity, opponentBoard, currentAttacker, gameState) => {
    if (Math.random() < 0.5) {
        currentAttacker = handleStartOfCombatTrinketsForPlayer({
            playerEntity: playerEntity,
            playerBoard: playerBoard,
            opponentEntity: opponentEntity,
            opponentBoard: opponentBoard,
            currentAttacker,
            gameState,
            playerIsFriendly: true,
        });
        currentAttacker = handleStartOfCombatTrinketsForPlayer({
            playerEntity: opponentEntity,
            playerBoard: opponentBoard,
            opponentEntity: playerEntity,
            opponentBoard: playerBoard,
            currentAttacker,
            gameState,
            playerIsFriendly: false,
        });
    }
    else {
        currentAttacker = handleStartOfCombatTrinketsForPlayer({
            playerEntity: opponentEntity,
            playerBoard: opponentBoard,
            opponentEntity: playerEntity,
            opponentBoard: playerBoard,
            currentAttacker,
            gameState,
            playerIsFriendly: false,
        });
        currentAttacker = handleStartOfCombatTrinketsForPlayer({
            playerEntity: playerEntity,
            playerBoard: playerBoard,
            opponentEntity: opponentEntity,
            opponentBoard: opponentBoard,
            currentAttacker,
            gameState,
            playerIsFriendly: true,
        });
    }
    const shouldRecomputeCurrentAttacker = (0, summon_when_space_1.handleSummonsWhenSpace)(playerBoard, playerEntity, opponentBoard, opponentEntity, gameState);
    if (shouldRecomputeCurrentAttacker) {
        currentAttacker =
            playerBoard.length > opponentBoard.length
                ? 0
                : opponentBoard.length > playerBoard.length
                    ? 1
                    : Math.round(Math.random());
    }
    return currentAttacker;
};
exports.handleStartOfCombatTrinkets = handleStartOfCombatTrinkets;
const handleStartOfCombatTrinketsForPlayer = (input) => {
    var _a;
    if (input.playerEntity.startOfCombatDone) {
        return input.currentAttacker;
    }
    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++) {
        for (const trinket of input.playerEntity.trinkets) {
            (0, soc_action_processor_1.performStartOfCombatAction)(trinket.cardId, trinket, input, true);
        }
    }
    return input.currentAttacker;
};
//# sourceMappingURL=soc-trinket.js.map