"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BloodGolemSticker = void 0;
const reference_data_1 = require("@firestone-hs/reference-data");
const deathrattle_spawns_1 = require("../../../simulation/deathrattle-spawns");
const spawns_1 = require("../../../simulation/spawns");
const utils_1 = require("../../../utils");
exports.BloodGolemSticker = {
    cardIds: ["BG30_MagicItem_442"],
    defaultScriptDataNum: (cardId) => 9999,
    onAfterDeath: (trinket, input) => {
        const { hero, gameState, board, otherBoard, otherHero } = input;
        for (const deadEntity of input.deadEntities) {
            if (deadEntity.friendly === hero.friendly &&
                trinket.scriptDataNum1 > 0 &&
                (0, utils_1.hasCorrectTribe)(deadEntity, hero, reference_data_1.Race.QUILBOAR, gameState.anomalies, gameState.allCards)) {
                const indexFromRight = input.deadEntitiesIndexesFromRight[input.deadEntities.indexOf(deadEntity)] + 1;
                let bloodGemEnchantments = deadEntity.enchantments.filter((e) => e.cardId === "BG20_GEMe2");
                if ((bloodGemEnchantments === null || bloodGemEnchantments === void 0 ? void 0 : bloodGemEnchantments.length) === 0) {
                    bloodGemEnchantments = deadEntity.enchantments.filter((e) => e.cardId === "BG20_GEMe");
                }
                if ((bloodGemEnchantments === null || bloodGemEnchantments === void 0 ? void 0 : bloodGemEnchantments.length) > 0) {
                    const bloodGemAttack = bloodGemEnchantments
                        .map((e) => { var _a; return (_a = e.tagScriptDataNum1) !== null && _a !== void 0 ? _a : 0; })
                        .reduce((a, b) => a + b, 0);
                    const bloodGemHealth = bloodGemEnchantments
                        .map((e) => { var _a; return (_a = e.tagScriptDataNum2) !== null && _a !== void 0 ? _a : 0; })
                        .reduce((a, b) => a + b, 0);
                    if (bloodGemAttack > 0 || bloodGemHealth > 0) {
                        const spawns = (0, deathrattle_spawns_1.spawnEntities)("BG30_MagicItem_442t", 1, board, hero, otherBoard, otherHero, gameState, deadEntity.friendly, false);
                        spawns.forEach((b) => {
                            b.attack = bloodGemAttack;
                            b.health = bloodGemHealth;
                            b.hasAttacked = deadEntity.hasAttacked;
                        });
                        (0, spawns_1.performEntitySpawns)(spawns, board, hero, deadEntity, indexFromRight, otherBoard, otherHero, gameState);
                        trinket.scriptDataNum1--;
                    }
                }
            }
        }
    },
};
//# sourceMappingURL=blood-golem-sticker.js.map