"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.onMinionSummoned = exports.removeAurasFromSelf = exports.applyAurasToSelf = exports.handleAddedMinionAuraEffect = exports.addMinionToBoard = exports.addMinionsToBoard = void 0;
const reference_data_1 = require("@firestone-hs/reference-data");
const card_interface_1 = require("../cards/card.interface");
const cards_data_1 = require("../cards/cards-data");
const _card_mappings_1 = require("../cards/impl/_card-mappings");
const eternal_portrait_1 = require("../cards/impl/trinket/eternal-portrait");
const divine_shield_1 = require("../keywords/divine-shield");
const taunt_1 = require("../keywords/taunt");
const utils_1 = require("../services/utils");
const utils_2 = require("../utils");
const quest_1 = require("./quest");
const stats_1 = require("./stats");
const addMinionsToBoard = (board, boardHero, otherBoard, otherHero, index, minionsToAdd, gameState) => {
    for (const minionToAdd of [...minionsToAdd].reverse()) {
        (0, exports.addMinionToBoard)(board, boardHero, otherBoard, otherHero, index, minionToAdd, gameState, false);
    }
    handleAfterSpawnEffects(board, boardHero, otherBoard, otherHero, minionsToAdd, gameState);
};
exports.addMinionsToBoard = addMinionsToBoard;
const addMinionToBoard = (board, boardHero, otherBoard, otherHero, index, minionToAdd, gameState, performAfterSpawnEffects = true, applySelfAuras = true) => {
    board.splice(index, 0, minionToAdd);
    (0, exports.handleAddedMinionAuraEffect)(board, boardHero, otherBoard, otherHero, minionToAdd, gameState, applySelfAuras);
    (0, exports.onMinionSummoned)(boardHero, board, gameState);
    handleSpawnEffect(board, boardHero, otherBoard, otherHero, minionToAdd, gameState, applySelfAuras);
    if (performAfterSpawnEffects) {
        handleAfterSpawnEffects(board, boardHero, otherBoard, otherHero, [minionToAdd], gameState);
    }
};
exports.addMinionToBoard = addMinionToBoard;
const handleSpawnEffect = (board, boardHero, otherBoard, otherHero, spawned, gameState, applySelfAuras = true) => {
    var _a;
    const cardIds = [spawned.cardId, ...((_a = spawned.additionalCards) !== null && _a !== void 0 ? _a : [])];
    if (cardIds.some((cardId) => (0, cards_data_1.isWhelp)(cardId, gameState.allCards))) {
        const manyWhelps = board.filter((entity) => entity.cardId === "BG22_HERO_305_Buddy");
        const goldenManyWhelps = board.filter((entity) => entity.cardId === "BG22_HERO_305_Buddy_G");
        manyWhelps.forEach((entity) => {
            (0, stats_1.modifyStats)(entity, entity, 2, 2, board, boardHero, gameState);
        });
        goldenManyWhelps.forEach((entity) => {
            (0, stats_1.modifyStats)(entity, entity, 4, 4, board, boardHero, gameState);
        });
    }
    for (const entity of board) {
        if (entity.entityId === spawned.entityId) {
            continue;
        }
        const onOtherSpawnedImpl = _card_mappings_1.cardMappings[entity.cardId];
        if ((0, card_interface_1.hasOnOtherSpawned)(onOtherSpawnedImpl)) {
            onOtherSpawnedImpl.onOtherSpawned(entity, {
                spawned: spawned,
                hero: boardHero,
                board: board,
                otherBoard: otherBoard,
                otherHero: otherHero,
                applySelfAuras,
                gameState,
            });
        }
        switch (entity.cardId) {
            case "GVG_062":
                if ((0, utils_2.hasCorrectTribe)(spawned, boardHero, reference_data_1.Race.MECH, gameState.anomalies, gameState.allCards)) {
                    if (!entity.divineShield) {
                        (0, divine_shield_1.updateDivineShield)(entity, board, boardHero, otherHero, true, gameState);
                    }
                    (0, stats_1.modifyStats)(entity, entity, 2, 0, board, boardHero, gameState);
                    gameState.spectator.registerPowerTarget(entity, entity, board, boardHero, otherHero);
                }
                break;
            case "BGS_021":
            case "TB_BaconUps_090":
                if ((0, utils_2.hasCorrectTribe)(spawned, boardHero, reference_data_1.Race.BEAST, gameState.anomalies, gameState.allCards)) {
                    const statsBonus = entity.cardId === "TB_BaconUps_090" ? 12 : 6;
                    (0, stats_1.modifyStats)(spawned, entity, statsBonus, statsBonus, board, boardHero, gameState);
                    gameState.spectator.registerPowerTarget(entity, entity, board, boardHero, otherHero);
                }
                break;
            case "BGS_017":
            case "TB_BaconUps_086":
                if ((0, utils_2.hasCorrectTribe)(spawned, boardHero, reference_data_1.Race.BEAST, gameState.anomalies, gameState.allCards)) {
                    const statsBonus = entity.cardId === "TB_BaconUps_086" ? 4 : 2;
                    (0, stats_1.modifyStats)(spawned, entity, statsBonus, 0, board, boardHero, gameState);
                    gameState.spectator.registerPowerTarget(entity, entity, board, boardHero, otherHero);
                }
                break;
        }
    }
};
const handleAddedMinionAuraEffect = (board, boardHero, otherBoard, otherHero, spawned, gameState, applySelfAuras = true, isActuallySpawned = true) => {
    var _a, _b, _c, _d;
    for (const heroPower of boardHero.heroPowers) {
        switch (heroPower.cardId) {
            case "TB_BaconShop_HP_107":
                if (isActuallySpawned) {
                    (0, taunt_1.updateTaunt)(spawned, true, board, boardHero, otherHero, gameState);
                    (0, stats_1.modifyStats)(spawned, boardHero, 1, 2, board, boardHero, gameState);
                }
                break;
        }
    }
    if ((_a = boardHero.questRewards) === null || _a === void 0 ? void 0 : _a.includes("BG28_Reward_505")) {
        const tumblingDisasterBonus = ((_c = (_b = boardHero.questRewardEntities) === null || _b === void 0 ? void 0 : _b.find((e) => e.cardId === "BG28_Reward_505")) === null || _c === void 0 ? void 0 : _c.scriptDataNum1) || 1;
        (0, stats_1.modifyStats)(spawned, boardHero, tumblingDisasterBonus, tumblingDisasterBonus, board, boardHero, gameState);
    }
    if (isActuallySpawned) {
        for (const trinket of boardHero.trinkets) {
            switch (trinket.cardId) {
                case "BG30_MagicItem_978":
                    if ((0, utils_2.hasCorrectTribe)(spawned, boardHero, reference_data_1.Race.MECH, gameState.anomalies, gameState.allCards)) {
                        const target = (0, utils_1.pickRandom)(board.filter((e) => !e.divineShield));
                        if (!!target) {
                            (0, divine_shield_1.updateDivineShield)(target, board, boardHero, otherHero, true, gameState);
                        }
                    }
                    break;
                case "BG30_MagicItem_822":
                case "BG30_MagicItem_822t2":
                    if (!trinket.rememberedMinion) {
                        trinket.rememberedMinion = (0, utils_2.copyEntity)(spawned);
                    }
                    break;
                case "BG30_MagicItem_886":
                    if (trinket.scriptDataNum1 > 0 && !spawned.divineShield) {
                        (0, divine_shield_1.updateDivineShield)(spawned, board, boardHero, otherHero, true, gameState);
                        trinket.scriptDataNum1--;
                    }
                    break;
            }
        }
    }
    const cardIds = [spawned.cardId, ...((_d = spawned.additionalCards) !== null && _d !== void 0 ? _d : [])];
    for (const spawnedCardId of cardIds) {
        handleMinionAddedAuraEffect(spawnedCardId, spawned, board, boardHero, gameState, isActuallySpawned);
    }
    if (applySelfAuras) {
        (0, exports.applyAurasToSelf)(spawned, board, boardHero, gameState);
    }
    if (isActuallySpawned) {
        if ((0, utils_2.hasCorrectTribe)(spawned, boardHero, reference_data_1.Race.BEAST, gameState.anomalies, gameState.allCards)) {
            boardHero.globalInfo.BeastsSummonedThisCombat++;
            boardHero.globalInfo.BeastsSummonedThisGame++;
        }
        if ((0, utils_2.hasCorrectTribe)(spawned, boardHero, reference_data_1.Race.PIRATE, gameState.anomalies, gameState.allCards)) {
            boardHero.globalInfo.PiratesSummonedThisGame++;
        }
    }
};
exports.handleAddedMinionAuraEffect = handleAddedMinionAuraEffect;
const applyAurasToSelf = (spawned, board, boardHero, gameState) => {
    var _a, _b, _c, _d, _e, _f, _g, _h;
    spawned.attack += boardHero.globalInfo.AdditionalAttack;
    if (!!((_a = boardHero.questRewards) === null || _a === void 0 ? void 0 : _a.length)) {
        for (const quest of boardHero.questRewards) {
            switch (quest) {
                case "BG24_Reward_364":
                    spawned.attack += 7;
                    spawned.health += 7;
                    spawned.enchantments.push({
                        cardId: "BG24_Reward_364e",
                        originEntityId: undefined,
                        timing: gameState.sharedState.currentEntityId++,
                    });
                    break;
                case "BG24_Reward_125":
                    spawned.attack += 4;
                    break;
            }
        }
    }
    if (!!((_b = boardHero.trinkets) === null || _b === void 0 ? void 0 : _b.length)) {
        for (const trinket of boardHero.trinkets) {
            switch (trinket.cardId) {
                case "BG30_MagicItem_880":
                    spawned.attack += 2;
                    spawned.health += 1;
                    break;
                case "BG30_MagicItem_880t":
                    spawned.attack += 8;
                    spawned.health += 5;
                    break;
                case "BG32_MagicItem_934":
                    spawned.attack += trinket.scriptDataNum1 || 1;
                    break;
                case "BG30_MagicItem_843t":
                    if (gameState.cardsData.getTavernLevel(spawned.cardId) <= 3) {
                        spawned.attack += 7;
                        spawned.health += 5;
                    }
                    break;
                case "BG30_MagicItem_921":
                    if (spawned.cardId === "BGS_061t" ||
                        spawned.cardId === "TB_BaconUps_141t") {
                        spawned.attack += 6;
                    }
                    break;
            }
        }
    }
    if (boardHero.globalInfo.HauntedCarapaceAttackBonus > 0) {
        (0, stats_1.modifyStats)(spawned, spawned, boardHero.globalInfo.HauntedCarapaceAttackBonus, 0, board, boardHero, gameState, false);
    }
    if (boardHero.globalInfo.HauntedCarapaceHealthBonus > 0) {
        (0, stats_1.modifyStats)(spawned, spawned, 0, boardHero.globalInfo.HauntedCarapaceHealthBonus, board, boardHero, gameState, false);
    }
    if ((0, utils_2.hasCorrectTribe)(spawned, boardHero, reference_data_1.Race.UNDEAD, gameState.anomalies, gameState.allCards)) {
        if (boardHero.globalInfo.UndeadAttackBonus > 0) {
            (0, stats_1.modifyStats)(spawned, spawned, boardHero.globalInfo.UndeadAttackBonus, 0, board, boardHero, gameState, false);
        }
    }
    if ((0, utils_2.hasCorrectTribe)(spawned, boardHero, reference_data_1.Race.PIRATE, gameState.anomalies, gameState.allCards)) {
        if (boardHero.globalInfo.PirateAttackBonus > 0) {
            (0, stats_1.modifyStats)(spawned, spawned, boardHero.globalInfo.PirateAttackBonus, 0, board, boardHero, gameState, false);
        }
    }
    if ((0, utils_2.hasCorrectTribe)(spawned, boardHero, reference_data_1.Race.BEAST, gameState.anomalies, gameState.allCards)) {
        if (boardHero.globalInfo.GoldrinnBuffAtk > 0) {
            (0, stats_1.modifyStats)(spawned, spawned, boardHero.globalInfo.GoldrinnBuffAtk, boardHero.globalInfo.GoldrinnBuffHealth, board, boardHero, gameState, false);
            gameState.spectator.registerPowerTarget(boardHero, spawned, board, null, null);
        }
    }
    if ((0, cards_data_1.isWhelp)(spawned.cardId, gameState.allCards)) {
        (0, stats_1.modifyStats)(spawned, spawned, (_c = boardHero.globalInfo.WhelpAttackBuff) !== null && _c !== void 0 ? _c : 0, (_d = boardHero.globalInfo.WhelpHealthBuff) !== null && _d !== void 0 ? _d : 0, board, boardHero, gameState, false);
        gameState.spectator.registerPowerTarget(boardHero, spawned, board, null, null);
    }
    if ((0, utils_2.isVolumizer)(spawned.cardId, boardHero, gameState.anomalies, gameState.allCards) &&
        !(0, utils_2.alreadyHasVolumizerBuff)(spawned, boardHero, gameState)) {
        if (boardHero.globalInfo.VolumizerAttackBuff > 0 || boardHero.globalInfo.VolumizerHealthBuff > 0) {
            (0, stats_1.modifyStats)(spawned, spawned, (_e = boardHero.globalInfo.VolumizerAttackBuff) !== null && _e !== void 0 ? _e : 0, (_f = boardHero.globalInfo.VolumizerHealthBuff) !== null && _f !== void 0 ? _f : 0, board, boardHero, gameState, false);
            gameState.spectator.registerPowerTarget(boardHero, spawned, board, null, null);
        }
    }
    if (gameState.cardsData.getTavernLevel(spawned.cardId) % 2 === 1) {
        const atkBuff = (_g = boardHero.globalInfo.MutatedLasherAttackBuff) !== null && _g !== void 0 ? _g : 0;
        const healthBuff = (_h = boardHero.globalInfo.MutatedLasherHealthBuff) !== null && _h !== void 0 ? _h : 0;
        (0, stats_1.modifyStats)(spawned, spawned, atkBuff, healthBuff, board, boardHero, gameState, false);
    }
    for (const entity of board) {
        const onOtherSpawnedImpl = _card_mappings_1.cardMappings[entity.cardId];
        if ((0, card_interface_1.hasOnOtherAuraSpawned)(onOtherSpawnedImpl)) {
            onOtherSpawnedImpl.onOtherSpawnedAura(entity, {
                spawned: spawned,
                hero: boardHero,
                board: board,
                gameState,
            });
        }
        switch (entity.cardId) {
            case "BG_EX1_507":
            case "TB_BaconUps_008":
                if ((0, utils_2.hasCorrectTribe)(spawned, boardHero, reference_data_1.Race.MURLOC, gameState.anomalies, gameState.allCards) &&
                    entity.entityId !== spawned.entityId) {
                    spawned.attack += entity.cardId === "TB_BaconUps_008" ? 4 : 2;
                }
                break;
            case "BG_NEW1_027":
            case "TB_BaconUps_136":
                if ((0, utils_2.hasCorrectTribe)(spawned, boardHero, reference_data_1.Race.PIRATE, gameState.anomalies, gameState.allCards) &&
                    entity.entityId !== spawned.entityId) {
                    spawned.attack += entity.cardId === "TB_BaconUps_136" ? 2 : 1;
                    spawned.health += entity.cardId === "TB_BaconUps_136" ? 2 : 1;
                }
                break;
            case "BG25_043":
            case "BG25_043_G":
                if (spawned.divineShield) {
                    spawned.attack += entity.cardId === "BG25_043_G" ? 12 : 6;
                }
                break;
            case "BG27_030":
            case "BG27_030_G":
                if ((0, utils_2.hasCorrectTribe)(spawned, boardHero, reference_data_1.Race.UNDEAD, gameState.anomalies, gameState.allCards) &&
                    entity.entityId !== spawned.entityId) {
                    spawned.attack += (entity.cardId === "BG27_030_G" ? 2 : 1) * boardHero.tavernTier;
                }
                break;
        }
    }
    const onSpawnedImpl = _card_mappings_1.cardMappings[spawned.cardId];
    if ((0, card_interface_1.hasOnSpawned)(onSpawnedImpl)) {
        onSpawnedImpl.onSpawned(spawned, {
            hero: boardHero,
            board: board,
            gameState: gameState,
        });
    }
    switch (spawned.cardId) {
        case "BG25_008":
        case "BG25_008_G":
            const multiplierKnight = spawned.cardId === "BG25_008_G" ? 2 : 1;
            const statsBonusKnight = multiplierKnight * boardHero.globalInfo.EternalKnightsDeadThisGame;
            (0, stats_1.modifyStats)(spawned, null, eternal_portrait_1.eternalKnightAttack * statsBonusKnight, eternal_portrait_1.eternalKnightHealth * statsBonusKnight, board, boardHero, gameState, false);
            break;
        case "BG28_555":
        case "BG28_555_G":
            const multiplierFungus = spawned.cardId === "BG28_555_G" ? 2 : 1;
            const statsBonusFungus = multiplierFungus * boardHero.globalInfo.TavernSpellsCastThisGame;
            (0, stats_1.modifyStats)(spawned, null, statsBonusFungus, 2 * statsBonusFungus, board, boardHero, gameState, false);
            break;
        case "BG26_537":
        case "BG26_537_G":
            const multiplierFrostling = spawned.cardId === "BG26_537_G" ? 2 : 1;
            const statsBonusFrostling = multiplierFrostling * boardHero.globalInfo.FrostlingBonus;
            (0, stats_1.modifyStats)(spawned, null, 2 * statsBonusFrostling, statsBonusFrostling, board, boardHero, gameState, false);
            break;
        case "BGS_081":
        case "TB_BaconUps_143":
            const multiplierLooter = spawned.cardId === "TB_BaconUps_143" ? 2 : 1;
            const statsBonusLooter = multiplierLooter * boardHero.globalInfo.PiratesSummonedThisGame;
            (0, stats_1.modifyStats)(spawned, null, 2 * statsBonusLooter, 2 * multiplierLooter, board, boardHero, gameState, false);
            break;
        case "BG_TTN_401":
        case "BG_TTN_401_G":
            const multiplierAstral = spawned.cardId === "BG_TTN_401_G" ? 2 : 1;
            const statsBonusAstral = multiplierAstral * (boardHero.globalInfo.AstralAutomatonsSummonedThisGame - 1);
            (0, stats_1.modifyStats)(spawned, null, 3 * statsBonusAstral, 2 * statsBonusAstral, board, boardHero, gameState, false);
            break;
        case "BG25_013":
        case "BG25_013_G":
            const multiplierGnoll = spawned.cardId === "BG25_013_G" ? 2 : 1;
            const statsBonusGnoll = multiplierGnoll * gameState.sharedState.deaths.filter((e) => e.friendly === spawned.friendly).length;
            (0, stats_1.modifyStats)(spawned, null, statsBonusGnoll, 0, board, boardHero, gameState, false);
            break;
    }
};
exports.applyAurasToSelf = applyAurasToSelf;
const removeAurasFromSelf = (entity, board, boardHero, gameState) => {
    var _a, _b;
    entity.attack -= Math.max(0, boardHero.globalInfo.AdditionalAttack);
    const onDespawnedImpl = _card_mappings_1.cardMappings[entity.cardId];
    if ((0, card_interface_1.hasOnDespawned)(onDespawnedImpl)) {
        onDespawnedImpl.onDespawned(entity, {
            hero: boardHero,
            board: board,
            gameState,
        });
    }
    if (!!((_a = boardHero.questRewards) === null || _a === void 0 ? void 0 : _a.length)) {
        for (const quest of boardHero.questRewards) {
            switch (quest) {
                case "BG24_Reward_364":
                    entity.attack = Math.max(0, entity.attack - 7);
                    entity.health = Math.max(1, entity.health - 7);
                    entity.enchantments = entity.enchantments.filter((e) => e.cardId !== "BG24_Reward_364e");
                    break;
                case "BG24_Reward_125":
                    entity.attack = Math.max(0, entity.attack - 7);
                    break;
                case "BG30_MagicItem_921":
                    if (entity.cardId === "BG30_119" ||
                        entity.cardId === "BG30_119_G") {
                        entity.attack = Math.max(0, entity.attack - 8);
                    }
                    break;
            }
        }
    }
    if (!!((_b = boardHero.trinkets) === null || _b === void 0 ? void 0 : _b.length)) {
        for (const trinket of boardHero.trinkets) {
            switch (trinket.cardId) {
                case "BG30_MagicItem_880":
                    entity.attack = Math.max(0, entity.attack - 2);
                    entity.health = Math.max(1, entity.health - 1);
                    break;
                case "BG30_MagicItem_880t":
                    entity.attack = Math.max(0, entity.attack - 8);
                    entity.health = Math.max(1, entity.health - 5);
                    break;
                case "BG32_MagicItem_934":
                    entity.attack = Math.max(0, entity.attack - (trinket.scriptDataNum1 || 1));
                    break;
                case "BG30_MagicItem_843t":
                    if (gameState.cardsData.getTavernLevel(entity.cardId) <= 3) {
                        entity.attack = Math.max(0, entity.attack - 7);
                        entity.health = Math.max(1, entity.health - 5);
                    }
                    break;
            }
        }
    }
    if (boardHero.globalInfo.HauntedCarapaceAttackBonus > 0) {
        entity.attack = Math.max(0, entity.attack - boardHero.globalInfo.HauntedCarapaceAttackBonus);
    }
    if (boardHero.globalInfo.HauntedCarapaceHealthBonus > 0) {
        entity.health = Math.max(1, entity.health - boardHero.globalInfo.HauntedCarapaceHealthBonus);
    }
    if ((0, utils_2.hasCorrectTribe)(entity, boardHero, reference_data_1.Race.UNDEAD, gameState.anomalies, gameState.allCards)) {
        if (boardHero.globalInfo.UndeadAttackBonus > 0) {
            entity.attack = Math.max(0, entity.attack - boardHero.globalInfo.UndeadAttackBonus);
        }
    }
    if ((0, utils_2.hasCorrectTribe)(entity, boardHero, reference_data_1.Race.BEAST, gameState.anomalies, gameState.allCards)) {
        if (boardHero.globalInfo.GoldrinnBuffAtk > 0) {
            entity.attack = Math.max(0, entity.attack - boardHero.globalInfo.GoldrinnBuffAtk);
            entity.health = Math.max(1, entity.health - boardHero.globalInfo.GoldrinnBuffHealth);
        }
    }
    for (const boardEntity of board) {
        switch (boardEntity.cardId) {
            case "BG_EX1_507":
            case "TB_BaconUps_008":
                if ((0, utils_2.hasCorrectTribe)(entity, boardHero, reference_data_1.Race.MURLOC, gameState.anomalies, gameState.allCards) &&
                    entity.entityId !== boardEntity.entityId) {
                    entity.attack = Math.max(0, entity.attack - (boardEntity.cardId === "TB_BaconUps_008" ? 4 : 2));
                }
                break;
            case "BG_NEW1_027":
            case "TB_BaconUps_136":
                if ((0, utils_2.hasCorrectTribe)(entity, boardHero, reference_data_1.Race.PIRATE, gameState.anomalies, gameState.allCards) &&
                    entity.entityId !== boardEntity.entityId) {
                    entity.attack = Math.max(0, entity.attack - (boardEntity.cardId === "TB_BaconUps_136" ? 2 : 1));
                    entity.health = Math.max(1, entity.health - (boardEntity.cardId === "TB_BaconUps_136" ? 2 : 1));
                }
                break;
            case "BG25_043":
            case "BG25_043_G":
                if (entity.divineShield) {
                    entity.attack = Math.max(0, entity.attack - (boardEntity.cardId === "BG25_043_G" ? 12 : 6));
                }
                break;
            case "BG27_030":
            case "BG27_030_G":
                if ((0, utils_2.hasCorrectTribe)(entity, boardHero, reference_data_1.Race.UNDEAD, gameState.anomalies, gameState.allCards) &&
                    entity.entityId !== boardEntity.entityId) {
                    entity.attack = Math.max(0, entity.attack -
                        (boardEntity.cardId === "BG27_030_G" ? 2 : 1) * boardHero.tavernTier);
                }
                break;
        }
    }
    switch (entity.cardId) {
        case "BG25_008":
        case "BG25_008_G":
            const multiplierKnight = entity.cardId === "BG25_008_G" ? 2 : 1;
            const statsBonusKnight = multiplierKnight * boardHero.globalInfo.EternalKnightsDeadThisGame;
            entity.attack = Math.max(0, entity.attack - eternal_portrait_1.eternalKnightAttack * statsBonusKnight);
            entity.health = Math.max(1, entity.health - eternal_portrait_1.eternalKnightHealth * statsBonusKnight);
            break;
        case "BG28_555":
        case "BG28_555_G":
            const multiplierFungus = entity.cardId === "BG28_555_G" ? 2 : 1;
            const statsBonusFungus = multiplierFungus * boardHero.globalInfo.TavernSpellsCastThisGame;
            entity.attack = Math.max(0, entity.attack - statsBonusFungus);
            entity.health = Math.max(1, entity.health - 2 * statsBonusFungus);
            break;
        case "BG26_537":
        case "BG26_537_G":
            const multiplierFrostling = entity.cardId === "BG26_537_G" ? 2 : 1;
            const statsBonusFrostling = multiplierFrostling * boardHero.globalInfo.FrostlingBonus;
            entity.attack = Math.max(0, entity.attack - statsBonusFrostling);
            entity.health = Math.max(1, entity.health - statsBonusFrostling);
            break;
        case "BG_TTN_401":
        case "BG_TTN_401_G":
            const multiplierAstral = entity.cardId === "BG_TTN_401_G" ? 2 : 1;
            const statsBonusAstral = multiplierAstral * (boardHero.globalInfo.AstralAutomatonsSummonedThisGame - 1);
            entity.attack = Math.max(0, entity.attack - 3 * statsBonusAstral);
            entity.health = Math.max(1, entity.health - 2 * statsBonusAstral);
            break;
        case "BG25_013":
        case "BG25_013_G":
            const multiplierGnoll = entity.cardId === "BG25_013_G" ? 2 : 1;
            const statsBonusGnoll = multiplierGnoll * gameState.sharedState.deaths.filter((e) => e.friendly === entity.friendly).length;
            entity.attack = Math.max(0, entity.attack - statsBonusGnoll);
            break;
    }
    for (const enchantment of entity.enchantments) {
        switch (enchantment === null || enchantment === void 0 ? void 0 : enchantment.cardId) {
            case "TB_BaconShop_HP_085e":
                entity.attack = Math.max(0, entity.attack - enchantment.tagScriptDataNum1);
                break;
        }
    }
};
exports.removeAurasFromSelf = removeAurasFromSelf;
const handleMinionAddedAuraEffect = (spawnedCardId, spawned, board, boardHero, gameState, isActuallySpawned = true) => {
    switch (spawnedCardId) {
        case "BG_NEW1_027":
        case "TB_BaconUps_136":
            board
                .filter((e) => (0, utils_2.hasCorrectTribe)(e, boardHero, reference_data_1.Race.PIRATE, gameState.anomalies, gameState.allCards))
                .filter((e) => e.entityId !== spawned.entityId)
                .forEach((e) => {
                e.attack += spawned.cardId === "TB_BaconUps_136" ? 2 : 1;
                e.health += spawned.cardId === "TB_BaconUps_136" ? 2 : 1;
            });
            break;
        case "BG_EX1_507":
        case "TB_BaconUps_008":
            board
                .filter((e) => (0, utils_2.hasCorrectTribe)(e, boardHero, reference_data_1.Race.MURLOC, gameState.anomalies, gameState.allCards))
                .filter((e) => e.entityId !== spawned.entityId)
                .forEach((e) => {
                e.attack += spawned.cardId === "TB_BaconUps_008" ? 4 : 2;
            });
            break;
        case "BG25_043":
        case "BG25_043_G":
            board
                .filter((e) => e.divineShield)
                .forEach((e) => {
                e.attack += spawned.cardId === "BG25_043_G" ? 12 : 6;
            });
            break;
        case "BG27_030":
        case "BG27_030_G":
            board
                .filter((e) => (0, utils_2.hasCorrectTribe)(e, boardHero, reference_data_1.Race.UNDEAD, gameState.anomalies, gameState.allCards))
                .filter((e) => e.entityId !== spawned.entityId)
                .forEach((e) => {
                e.attack += (spawned.cardId === "BG27_030_G" ? 2 : 1) * boardHero.tavernTier;
            });
            break;
        case "BG_TTN_401":
        case "BG_TTN_401_G":
            if (isActuallySpawned) {
                boardHero.globalInfo.AstralAutomatonsSummonedThisGame++;
            }
            board
                .filter((e) => e.entityId !== spawned.entityId)
                .filter((e) => e.cardId === "BG_TTN_401" ||
                e.cardId === "BG_TTN_401_G")
                .forEach((e) => {
                const multiplierAstral = e.cardId === "BG_TTN_401_G" ? 2 : 1;
                (0, stats_1.modifyStats)(e, e, 3 * multiplierAstral, 2 * multiplierAstral, board, boardHero, gameState, false);
            });
            break;
        case "BG31_176":
        case "BG31_176_G":
            const multiplierDrBoom = spawned.cardId === "BG31_176_G" ? 2 : 1;
            (0, stats_1.modifyStats)(spawned, spawned, 2 * boardHero.globalInfo.MagnetizedThisGame * multiplierDrBoom, 2 * boardHero.globalInfo.MagnetizedThisGame * multiplierDrBoom, board, boardHero, gameState, false);
            break;
    }
};
const handleAfterSpawnEffects = (board, hero, otherBoard, otherHero, allSpawned, gameState) => {
    for (const spawned of allSpawned) {
        handleAfterSpawnEffect(board, hero, otherBoard, otherHero, spawned, gameState);
    }
};
const onMinionSummoned = (hero, board, gameState) => {
    var _a;
    const quests = (_a = hero.questEntities) !== null && _a !== void 0 ? _a : [];
    if (!quests.length) {
        return;
    }
    for (const quest of quests) {
        switch (quest.CardId) {
            case "BG24_Quest_114":
                (0, quest_1.onQuestProgressUpdated)(hero, quest, board, gameState);
                break;
        }
    }
};
exports.onMinionSummoned = onMinionSummoned;
const handleAfterSpawnEffect = (board, hero, otherBoard, otherHero, spawned, gameState) => {
    var _a, _b;
    const initialBoard = [...board];
    for (const trinket of (_a = hero.trinkets) !== null && _a !== void 0 ? _a : []) {
        const onAfterSpawnedImpl = _card_mappings_1.cardMappings[trinket.cardId];
        if ((0, card_interface_1.hasAfterOtherSpawned)(onAfterSpawnedImpl)) {
            onAfterSpawnedImpl.afterOtherSpawned(trinket, {
                spawned: spawned,
                hero: hero,
                board: board,
                otherHero: otherHero,
                otherBoard: otherBoard,
                gameState,
                applySelfAuras: false,
            });
        }
    }
    for (const entity of initialBoard) {
        if (entity.entityId === spawned.entityId) {
            continue;
        }
        const onAfterSpawnedImpl = _card_mappings_1.cardMappings[entity.cardId];
        if ((0, card_interface_1.hasAfterOtherSpawned)(onAfterSpawnedImpl)) {
            onAfterSpawnedImpl.afterOtherSpawned(entity, {
                spawned: spawned,
                hero: hero,
                board: board,
                otherHero: otherHero,
                otherBoard: otherBoard,
                gameState,
                applySelfAuras: false,
            });
        }
        switch (entity.cardId) {
            case "BG26_172":
            case "BG26_172_G":
                if (entity.entityId !== spawned.entityId) {
                    const xylobonesBuff = entity.cardId === "BG26_172_G" ? 4 : 2;
                    (0, stats_1.modifyStats)(entity, entity, 0, xylobonesBuff, board, hero, gameState);
                    gameState.spectator.registerPowerTarget(entity, entity, board, null, null);
                }
                break;
            case "BG26_804":
            case "BG26_804_G":
                if (entity.entityId !== spawned.entityId) {
                    const octoStats = entity.cardId === "BG26_804_G" ? 4 : 2;
                    entity.scriptDataNum1 = ((_b = entity.scriptDataNum1) !== null && _b !== void 0 ? _b : 0) + octoStats;
                }
                break;
            case "BG26_802":
            case "BG26_802_G":
                if ((0, utils_2.hasCorrectTribe)(spawned, hero, reference_data_1.Race.BEAST, gameState.anomalies, gameState.allCards) &&
                    entity.entityId !== spawned.entityId) {
                    const bananaStatBuff = entity.cardId === "BG26_802_G" ? 3 : 2;
                    (0, stats_1.setEntityStats)(spawned, spawned.attack * bananaStatBuff, spawned.health * bananaStatBuff, board, hero, gameState);
                    gameState.spectator.registerPowerTarget(entity, spawned, board, null, null);
                }
                break;
            case "TB_BaconShop_HERO_53_Buddy":
            case "TB_BaconShop_HERO_53_Buddy_G":
                if ((0, utils_2.hasCorrectTribe)(spawned, hero, reference_data_1.Race.DRAGON, gameState.anomalies, gameState.allCards) &&
                    entity.entityId !== spawned.entityId) {
                    const valithriaBuff = entity.cardId === "TB_BaconShop_HERO_53_Buddy_G" ? 3 : 2;
                    (0, stats_1.modifyStats)(entity, entity, valithriaBuff, valithriaBuff, board, hero, gameState);
                    gameState.spectator.registerPowerTarget(entity, spawned, board, null, null);
                }
                break;
            case "BG26_RLK_824":
                if ((0, utils_2.hasCorrectTribe)(spawned, hero, reference_data_1.Race.UNDEAD, gameState.anomalies, gameState.allCards) &&
                    entity.entityId !== spawned.entityId) {
                    (0, stats_1.modifyStats)(spawned, spawned, 1, 0, board, hero, gameState, false);
                    gameState.spectator.registerPowerTarget(entity, entity, board, null, null);
                }
                break;
        }
    }
    for (const trinket of hero.trinkets) {
        switch (trinket.cardId) {
            case "BG30_MagicItem_540":
                if ((0, utils_2.hasCorrectTribe)(spawned, hero, reference_data_1.Race.BEAST, gameState.anomalies, gameState.allCards)) {
                    (0, stats_1.setEntityStats)(spawned, spawned.attack * 2, spawned.health * 2, board, hero, gameState);
                    gameState.spectator.registerPowerTarget(hero, spawned, board, null, null);
                }
                break;
        }
    }
};
//# sourceMappingURL=add-minion-to-board.js.map