"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Battlecruiser = void 0;
const reference_data_1 = require("@firestone-hs/reference-data");
const attack_1 = require("../../../simulation/attack");
const stats_1 = require("../../../simulation/stats");
const utils_1 = require("../../../utils");
exports.Battlecruiser = {
    cardIds: ["BG31_HERO_801pt", "BG31_HERO_801pt_G"],
    startOfCombat: (minion, input) => {
        var _a, _b;
        const yamatoCannons = [...minion.enchantments]
            .filter((e) => e.cardId === "BG31_HERO_801ptce");
        if (!(yamatoCannons === null || yamatoCannons === void 0 ? void 0 : yamatoCannons.length)) {
            return false;
        }
        const aliveEntities = input.opponentBoard.filter((entity) => entity.health > 0 && !entity.definitelyDead);
        const targetEntityId = (_a = (0, utils_1.getRandomMinionWithHighestHealth)(aliveEntities)) === null || _a === void 0 ? void 0 : _a.entityId;
        const cannonDamage = Math.max(...yamatoCannons.map((e) => e.tagScriptDataNum1));
        const loops = ((_b = minion.tags) === null || _b === void 0 ? void 0 : _b[reference_data_1.GameTag.BACON_YAMATO_CANNON]) === 1 ? 2 : 1;
        for (let i = 0; i < loops; i++) {
            let target = input.opponentBoard.find((entity) => entity.entityId === targetEntityId);
            if (!target || target.health <= 0 || target.definitelyDead) {
                target = (0, utils_1.getRandomMinionWithHighestHealth)(input.opponentBoard);
            }
            if (!!target) {
                input.gameState.spectator.registerPowerTarget(minion, target, input.opponentBoard, input.playerEntity, input.opponentEntity);
                (0, attack_1.dealDamageToMinion)(target, input.opponentBoard, input.opponentEntity, minion, cannonDamage, input.playerBoard, input.playerEntity, input.gameState);
            }
        }
        return {
            hasTriggered: true,
            shouldRecomputeCurrentAttacker: true,
        };
    },
    rebornSelfEffect: (minion, input) => {
        const ultraCapacitors = [...input.rebornEntity.enchantments]
            .filter((e) => e.cardId === "BG31_HERO_801ptje");
        if (!(ultraCapacitors === null || ultraCapacitors === void 0 ? void 0 : ultraCapacitors.length)) {
            return;
        }
        minion.enchantments = input.rebornEntity.enchantments;
        minion.attack = input.rebornEntity.maxAttack;
        minion.maxAttack = input.rebornEntity.maxAttack;
        minion.health = input.rebornEntity.maxHealth;
        minion.maxHealth = input.rebornEntity.maxHealth;
        minion.divineShield = input.rebornEntity.hadDivineShield;
        minion.taunt = input.rebornEntity.taunt;
        minion.windfury = input.rebornEntity.windfury;
        minion.poisonous = input.rebornEntity.poisonous;
    },
    rally: (minion, input) => {
        const advancedBallistics = [...minion.enchantments]
            .filter((e) => e.cardId === "BG31_HERO_801ptde");
        if (!(advancedBallistics === null || advancedBallistics === void 0 ? void 0 : advancedBallistics.length)) {
            return { dmgDoneByAttacker: 0, dmgDoneByDefender: 0 };
        }
        const buff = advancedBallistics.map((e) => { var _a; return (_a = e.tagScriptDataNum1) !== null && _a !== void 0 ? _a : 0; }).reduce((a, b) => a + b, 0);
        const targets = input.attackingBoard.filter((entity) => entity !== minion);
        for (const target of targets) {
            (0, stats_1.modifyStats)(target, minion, buff, 0, input.attackingBoard, input.attackingHero, input.gameState);
        }
        return { dmgDoneByAttacker: 0, dmgDoneByDefender: 0 };
    },
    deathrattleSpawn: (minion, input) => {
        const caduceusReactors = [...minion.enchantments]
            .filter((e) => e.cardId === "BG31_HERO_801ptee");
        if (!(caduceusReactors === null || caduceusReactors === void 0 ? void 0 : caduceusReactors.length)) {
            return [];
        }
        const target = input.boardWithDeadEntity.filter((e) => e.health > 0 && !e.definitelyDead)[0];
        if (!target) {
            return [];
        }
        const buff = caduceusReactors.map((e) => { var _a; return (_a = e.tagScriptDataNum1) !== null && _a !== void 0 ? _a : 0; }).reduce((a, b) => a + b, 0);
        (0, stats_1.modifyStats)(target, minion, buff, buff, input.boardWithDeadEntity, input.boardWithDeadEntityHero, input.gameState);
        return [];
    },
};
//# sourceMappingURL=battlecruiser.js.map