"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.clearStealthIfNeeded = exports.setImplicitDataHero = exports.setMissingHeroPowerAura = exports.setMissingTrinketAura = exports.setMissingAuras = void 0;
const reference_data_1 = require("@firestone-hs/reference-data");
const stealth_1 = require("../keywords/stealth");
const utils_1 = require("../utils");
const setMissingAuras = (board, boardHero, anomalies, allCards) => {
    setMissingMinionsAura(board, boardHero, anomalies, allCards);
    (0, exports.setMissingHeroPowerAura)(board, boardHero);
    (0, exports.setMissingTrinketAura)(board, boardHero);
};
exports.setMissingAuras = setMissingAuras;
const setMissingTrinketAura = (board, boardHero) => {
    var _a;
    for (const trinket of (_a = boardHero.trinkets) !== null && _a !== void 0 ? _a : []) {
    }
};
exports.setMissingTrinketAura = setMissingTrinketAura;
const setMissingHeroPowerAura = (board, boardHero) => {
    for (const heroPower of boardHero.heroPowers) {
        if (heroPower.cardId === "BG24_Reward_125") {
            board
                .filter((e) => !e.enchantments.find((ench) => ench.cardId === "BG24_Reward_125e"))
                .forEach((e) => {
                e.attack += 4;
            });
        }
        if (heroPower.cardId === "BG24_Reward_364") {
            board
                .filter((e) => !e.enchantments.find((ench) => ench.cardId === "BG24_Reward_364e"))
                .forEach((e) => {
                e.attack += 7;
                e.health += 7;
                e.enchantments.push({
                    cardId: "BG24_Reward_364e",
                    originEntityId: undefined,
                    timing: 0,
                });
            });
        }
    }
};
exports.setMissingHeroPowerAura = setMissingHeroPowerAura;
const setMissingMinionsAura = (board, boardHero, anomalies, allCards) => {
    setMissingAura(board.filter((e) => (0, utils_1.hasCorrectTribe)(e, boardHero, reference_data_1.Race.PIRATE, anomalies, allCards)), "BG_NEW1_027", "VAN_NEW1_027e", 1, 1);
    setMissingAura(board.filter((e) => (0, utils_1.hasCorrectTribe)(e, boardHero, reference_data_1.Race.PIRATE, anomalies, allCards)), "TB_BaconUps_136", "TB_BaconUps_136e", 2, 2);
    setMissingAura(board.filter((e) => (0, utils_1.hasCorrectTribe)(e, boardHero, reference_data_1.Race.MURLOC, anomalies, allCards)), "BG_EX1_507", "EX1_507e", 2, 0);
    setMissingAura(board.filter((e) => e.divineShield), "BG25_043", "BG25_043e", 6, 0, false);
    setMissingAura(board.filter((e) => (0, utils_1.hasCorrectTribe)(e, boardHero, reference_data_1.Race.UNDEAD, anomalies, allCards)), "BG27_030", "BG27_030e", boardHero.tavernTier, 0);
    setMissingAura(board.filter((e) => (0, utils_1.hasCorrectTribe)(e, boardHero, reference_data_1.Race.UNDEAD, anomalies, allCards)), "BG27_030_G", "BG27_030e", 2 * boardHero.tavernTier, 0);
};
const setMissingAura = (board, minionCardId, enchantmentCardId, attack, health, ignoreSelf = true, allCards = null) => {
    const buffers = board.filter((e) => e.cardId === minionCardId);
    for (const buffer of buffers) {
        board
            .filter((e) => !e.enchantments.find((ench) => ench.cardId === enchantmentCardId))
            .filter((e) => (ignoreSelf ? e.entityId !== buffer.entityId : true))
            .forEach((e) => {
            e.attack += attack;
            e.health += health;
        });
    }
};
const setImplicitDataHero = (hero, cardsData, isPlayer, entityIdContainer) => {
    var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29;
    for (const heroPower of hero.heroPowers) {
        const avengeValue = cardsData.avengeValue(heroPower.cardId);
        if (avengeValue > 0) {
            heroPower.avengeCurrent = avengeValue - ((_a = heroPower.scoreValue2) !== null && _a !== void 0 ? _a : 0);
            heroPower.avengeDefault = avengeValue;
        }
        if ((_b = heroPower.info) === null || _b === void 0 ? void 0 : _b.health) {
            (0, utils_1.addImpliedMechanics)(heroPower.info, cardsData);
        }
    }
    if (!!((_c = hero.questRewards) === null || _c === void 0 ? void 0 : _c.length) && !Array.isArray(hero.questRewards)) {
        hero.questRewards = [hero.questRewards];
    }
    const heroPowerAsReward = null;
    hero.questRewards = [...((_d = hero.questRewards) !== null && _d !== void 0 ? _d : []), heroPowerAsReward].filter((e) => !!e);
    hero.questRewardEntities = hero.questRewardEntities
        ? hero.questRewardEntities.map((reward) => {
            var _a;
            return ({
                cardId: reward.CardId,
                scriptDataNum1: (_a = reward.ScriptDataNum1) !== null && _a !== void 0 ? _a : 0,
                entityId: entityIdContainer.entityId--,
                avengeDefault: cardsData.avengeValue(reward.CardId),
                avengeCurrent: cardsData.avengeValue(reward.CardId),
            });
        })
        : hero.questRewards.map((reward) => ({
            cardId: reward,
            entityId: entityIdContainer.entityId--,
            avengeCurrent: cardsData.avengeValue(reward),
            avengeDefault: cardsData.avengeValue(reward),
            scriptDataNum1: cardsData.defaultScriptDataNum(reward),
        }));
    hero.trinkets = ((_e = hero.trinkets) !== null && _e !== void 0 ? _e : []).map((trinket) => ({
        ...trinket,
        avengeDefault: cardsData.avengeValue(trinket.cardId),
        avengeCurrent: cardsData.avengeValue(trinket.cardId),
        scriptDataNum1: trinket.scriptDataNum1 || cardsData.defaultScriptDataNum(trinket.cardId),
    }));
    hero.entityId = hero.entityId || entityIdContainer.entityId--;
    hero.hand = (_f = hero.hand) !== null && _f !== void 0 ? _f : [];
    hero.enchantments = (_g = hero.enchantments) !== null && _g !== void 0 ? _g : [];
    if (!hero.globalInfo) {
        hero.globalInfo = {};
    }
    hero.globalInfo.EternalKnightsDeadThisGame = (_h = hero.globalInfo.EternalKnightsDeadThisGame) !== null && _h !== void 0 ? _h : 0;
    hero.globalInfo.SanlaynScribesDeadThisGame = (_j = hero.globalInfo.SanlaynScribesDeadThisGame) !== null && _j !== void 0 ? _j : 0;
    hero.globalInfo.BeastsSummonedThisGame = (_k = hero.globalInfo.BeastsSummonedThisGame) !== null && _k !== void 0 ? _k : 0;
    hero.globalInfo.BeastsSummonedThisCombat = (_l = hero.globalInfo.BeastsSummonedThisCombat) !== null && _l !== void 0 ? _l : 0;
    hero.globalInfo.MagnetizedThisGame = (_m = hero.globalInfo.MagnetizedThisGame) !== null && _m !== void 0 ? _m : 0;
    hero.globalInfo.PiratesSummonedThisGame = (_o = hero.globalInfo.PiratesSummonedThisGame) !== null && _o !== void 0 ? _o : 0;
    hero.globalInfo.BattlecriesTriggeredThisGame = (_p = hero.globalInfo.BattlecriesTriggeredThisGame) !== null && _p !== void 0 ? _p : 0;
    hero.globalInfo.DeathrattlesTriggeredThisGame = (_q = hero.globalInfo.DeathrattlesTriggeredThisGame) !== null && _q !== void 0 ? _q : 0;
    hero.globalInfo.BeetleAttackBuff = (_r = hero.globalInfo.BeetleAttackBuff) !== null && _r !== void 0 ? _r : 0;
    hero.globalInfo.BeetleHealthBuff = (_s = hero.globalInfo.BeetleHealthBuff) !== null && _s !== void 0 ? _s : 0;
    hero.globalInfo.ElementalAttackBuff = (_t = hero.globalInfo.ElementalAttackBuff) !== null && _t !== void 0 ? _t : 0;
    hero.globalInfo.ElementalHealthBuff = (_u = hero.globalInfo.ElementalHealthBuff) !== null && _u !== void 0 ? _u : 0;
    hero.globalInfo.PirateAttackBuff = (_v = hero.globalInfo.PirateAttackBuff) !== null && _v !== void 0 ? _v : 0;
    hero.globalInfo.PirateHealthBuff = (_w = hero.globalInfo.PirateHealthBuff) !== null && _w !== void 0 ? _w : 0;
    hero.globalInfo.TavernSpellAttackBuff = (_x = hero.globalInfo.TavernSpellAttackBuff) !== null && _x !== void 0 ? _x : 0;
    hero.globalInfo.TavernSpellHealthBuff = (_y = hero.globalInfo.TavernSpellHealthBuff) !== null && _y !== void 0 ? _y : 0;
    hero.globalInfo.MutatedLasherAttackBuff = (_z = hero.globalInfo.MutatedLasherAttackBuff) !== null && _z !== void 0 ? _z : 0;
    hero.globalInfo.MutatedLasherHealthBuff = (_0 = hero.globalInfo.MutatedLasherHealthBuff) !== null && _0 !== void 0 ? _0 : 0;
    hero.globalInfo.TavernSpellsCastThisGame = (_1 = hero.globalInfo.TavernSpellsCastThisGame) !== null && _1 !== void 0 ? _1 : 0;
    hero.globalInfo.TavernSpellsCastThisTurn = (_2 = hero.globalInfo.TavernSpellsCastThisTurn) !== null && _2 !== void 0 ? _2 : 0;
    hero.globalInfo.CardsPlayedThisTurn = (_3 = hero.globalInfo.CardsPlayedThisTurn) !== null && _3 !== void 0 ? _3 : 0;
    hero.globalInfo.MrrgltonsPlayedThisGame = (_4 = hero.globalInfo.MrrgltonsPlayedThisGame) !== null && _4 !== void 0 ? _4 : 0;
    hero.globalInfo.AdditionalAttack = (_5 = hero.globalInfo.AdditionalAttack) !== null && _5 !== void 0 ? _5 : 0;
    hero.globalInfo.SpellsCastThisGame = (_6 = hero.globalInfo.SpellsCastThisGame) !== null && _6 !== void 0 ? _6 : 0;
    hero.globalInfo.UndeadAttackBonus = (_7 = hero.globalInfo.UndeadAttackBonus) !== null && _7 !== void 0 ? _7 : 0;
    hero.globalInfo.HauntedCarapaceAttackBonus = (_8 = hero.globalInfo.HauntedCarapaceAttackBonus) !== null && _8 !== void 0 ? _8 : 0;
    hero.globalInfo.HauntedCarapaceHealthBonus = (_9 = hero.globalInfo.HauntedCarapaceHealthBonus) !== null && _9 !== void 0 ? _9 : 0;
    hero.globalInfo.FrostlingBonus = (_10 = hero.globalInfo.FrostlingBonus) !== null && _10 !== void 0 ? _10 : 0;
    hero.globalInfo.BloodGemAttackBonus =
        ((_11 = hero.globalInfo.BloodGemAttackBonus) !== null && _11 !== void 0 ? _11 : 0) +
            ((_13 = (_12 = hero.questRewardEntities) === null || _12 === void 0 ? void 0 : _12.filter((e) => e.cardId === "BG27_Reward_815").length) !== null && _13 !== void 0 ? _13 : 0);
    hero.globalInfo.BloodGemHealthBonus =
        ((_14 = hero.globalInfo.BloodGemHealthBonus) !== null && _14 !== void 0 ? _14 : 0) +
            ((_16 = (_15 = hero.questRewardEntities) === null || _15 === void 0 ? void 0 : _15.filter((e) => e.cardId === "BG27_Reward_815").length) !== null && _16 !== void 0 ? _16 : 0);
    hero.globalInfo.GoldrinnBuffAtk = (_17 = hero.globalInfo.GoldrinnBuffAtk) !== null && _17 !== void 0 ? _17 : 0;
    hero.globalInfo.GoldrinnBuffHealth = (_18 = hero.globalInfo.GoldrinnBuffHealth) !== null && _18 !== void 0 ? _18 : 0;
    hero.globalInfo.WhelpAttackBuff = (_19 = hero.globalInfo.WhelpAttackBuff) !== null && _19 !== void 0 ? _19 : 0;
    hero.globalInfo.WhelpHealthBuff = (_20 = hero.globalInfo.WhelpHealthBuff) !== null && _20 !== void 0 ? _20 : 0;
    hero.globalInfo.GoldSpentThisGame = (_21 = hero.globalInfo.GoldSpentThisGame) !== null && _21 !== void 0 ? _21 : 0;
    hero.globalInfo.VolumizerAttackBuff = (_22 = hero.globalInfo.VolumizerAttackBuff) !== null && _22 !== void 0 ? _22 : 0;
    hero.globalInfo.VolumizerHealthBuff = (_23 = hero.globalInfo.VolumizerHealthBuff) !== null && _23 !== void 0 ? _23 : 0;
    hero.globalInfo.DeepBluesPlayed = (_24 = hero.globalInfo.DeepBluesPlayed) !== null && _24 !== void 0 ? _24 : 0;
    hero.globalInfo.DeathrattlesTriggeredThisGame = (_25 = hero.globalInfo.DeathrattlesTriggeredThisGame) !== null && _25 !== void 0 ? _25 : 0;
    hero.globalInfo.BackToBackCastThisGame = (_26 = hero.globalInfo.BackToBackCastThisGame) !== null && _26 !== void 0 ? _26 : 0;
    hero.globalInfo.TavernSpellsCastThisTurn = (_27 = hero.globalInfo.TavernSpellsCastThisTurn) !== null && _27 !== void 0 ? _27 : 0;
    hero.globalInfo.CardsPlayedThisTurn = (_28 = hero.globalInfo.CardsPlayedThisTurn) !== null && _28 !== void 0 ? _28 : 0;
    hero.globalInfo.MrrgltonsPlayedThisGame = (_29 = hero.globalInfo.MrrgltonsPlayedThisGame) !== null && _29 !== void 0 ? _29 : 0;
};
exports.setImplicitDataHero = setImplicitDataHero;
const clearStealthIfNeeded = (board, hero, otherBoard, otherHero, gameState) => {
    if (board.every((entity) => entity.stealth && !entity.attack)) {
        board.forEach((e) => (0, stealth_1.updateStealth)(e, false, board, hero, otherHero, gameState));
    }
    if (otherBoard.every((entity) => entity.stealth && !entity.attack)) {
        otherBoard.forEach((e) => (0, stealth_1.updateStealth)(e, false, otherBoard, otherHero, hero, gameState));
    }
    if (board.every((e) => e.stealth) && otherBoard.every((e) => e.stealth)) {
        board.forEach((e) => (0, stealth_1.updateStealth)(e, false, board, hero, otherHero, gameState));
        otherBoard.forEach((e) => (0, stealth_1.updateStealth)(e, false, otherBoard, otherHero, hero, gameState));
    }
};
exports.clearStealthIfNeeded = clearStealthIfNeeded;
//# sourceMappingURL=auras.js.map