"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.applyOnDeathEffects = exports.applyAfterDeathEffects = void 0;
const card_interface_1 = require("../cards/card.interface");
const _card_mappings_1 = require("../cards/impl/_card-mappings");
const utils_1 = require("../services/utils");
const deathrattle_spawns_1 = require("./deathrattle-spawns");
const spawns_1 = require("./spawns");
const stats_1 = require("./stats");
const applyAfterDeathEffects = (deadEntity, deadEntityIndexFromRight, boardWithDeadEntity, boardWithDeadEntityHero, otherBoard, otherBoardHero, gameState) => {
    const allSpawns = [];
    const spawnsFromSecrets = handleAfterMinionDeathEffects(deadEntity, deadEntityIndexFromRight, boardWithDeadEntity, boardWithDeadEntityHero, otherBoard, otherBoardHero, gameState);
    allSpawns.push(...spawnsFromSecrets);
    (0, spawns_1.performEntitySpawns)(allSpawns, boardWithDeadEntity, boardWithDeadEntityHero, deadEntity, deadEntityIndexFromRight, otherBoard, otherBoardHero, gameState);
    return allSpawns;
};
exports.applyAfterDeathEffects = applyAfterDeathEffects;
const handleAfterMinionDeathEffects = (deadEntity, deadEntityIndexFromRight, boardWithDeadEntity, boardWithDeadEntityHero, otherBoard, otherBoardHero, gameState) => {
    var _a, _b;
    const allSpawns = [];
    for (const entity of boardWithDeadEntity) {
        const impl = _card_mappings_1.cardMappings[entity.cardId];
        if ((0, card_interface_1.hasOnAfterFriendlyMinionDeath)(impl)) {
            impl.onAfterFriendlyMinionDeath(entity, {
                deadEntity,
                board: boardWithDeadEntity,
                hero: boardWithDeadEntityHero,
                otherBoard,
                otherHero: otherBoardHero,
                gameState,
            });
        }
    }
    for (const trinket of (_a = boardWithDeadEntityHero.trinkets) !== null && _a !== void 0 ? _a : []) {
        const trinketImpl = _card_mappings_1.cardMappings[trinket.cardId];
        if ((0, card_interface_1.hasOnAfterFriendlyMinionDeath)(trinketImpl)) {
            trinketImpl.onAfterFriendlyMinionDeath(trinket, {
                deadEntity,
                board: boardWithDeadEntity,
                hero: boardWithDeadEntityHero,
                otherBoard,
                otherHero: otherBoardHero,
                gameState,
            });
        }
    }
    for (const secret of ((_b = boardWithDeadEntityHero.secrets) !== null && _b !== void 0 ? _b : []).filter((s) => !s.triggered)) {
        switch (secret.cardId) {
            case "TB_Bacon_Secrets_08":
                secret.triggered = true;
                const avengeTarget = (0, utils_1.pickRandomAlive)(boardWithDeadEntity);
                (0, stats_1.modifyStats)(avengeTarget, secret, 3, 2, boardWithDeadEntity, boardWithDeadEntityHero, gameState);
                break;
            case "TB_Bacon_Secrets_10":
                secret.triggered = true;
                const redemptionSpawns = (0, deathrattle_spawns_1.spawnEntities)(deadEntity.cardId, 1, boardWithDeadEntity, boardWithDeadEntityHero, otherBoard, otherBoardHero, gameState, deadEntity.friendly, false, false, true);
                redemptionSpawns[0].health = 1;
                allSpawns.push(...redemptionSpawns);
                gameState.spectator.registerPowerTarget(secret, redemptionSpawns[0], boardWithDeadEntity, null, null);
                break;
            case "TB_Bacon_Secrets_10b":
                secret.triggered = true;
                const betterRedemptionSpawns = (0, deathrattle_spawns_1.spawnEntities)(deadEntity.cardId, 1, boardWithDeadEntity, boardWithDeadEntityHero, otherBoard, otherBoardHero, gameState, deadEntity.friendly, false, false, true);
                for (const spawn of betterRedemptionSpawns) {
                    spawn.health = deadEntity.maxHealth;
                    spawn.maxHealth = deadEntity.maxHealth;
                    spawn.attack = deadEntity.attack;
                    spawn.maxAttack = deadEntity.maxAttack;
                    spawn.enchantments = deadEntity.enchantments;
                    spawn.divineShield = deadEntity.hadDivineShield;
                }
                allSpawns.push(...betterRedemptionSpawns);
                gameState.spectator.registerPowerTarget(secret, betterRedemptionSpawns[0], boardWithDeadEntity, null, null);
                break;
            case "TB_Bacon_Secrets_05":
                secret.triggered = true;
                const minionTier = gameState.cardsData.getTavernLevel(deadEntity.cardId);
                const newMinion = gameState.cardsData.getRandomMinionForTavernTier(minionTier);
                const effigySpawns = (0, deathrattle_spawns_1.spawnEntities)(newMinion, 1, boardWithDeadEntity, boardWithDeadEntityHero, otherBoard, otherBoardHero, gameState, deadEntity.friendly, false, false, true);
                allSpawns.push(...effigySpawns);
                gameState.spectator.registerPowerTarget(secret, effigySpawns[0], boardWithDeadEntity, null, null);
                break;
        }
    }
    return allSpawns;
};
const applyOnDeathEffects = (deadEntity, deadEntityIndexFromRight, boardWithDeadEntity, boardWithDeadEntityHero, otherBoard, otherBoardHero, gameState) => {
    return [];
};
exports.applyOnDeathEffects = applyOnDeathEffects;
//# sourceMappingURL=death-effects.js.map