"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.applyAfterAttackTrinkets = exports.applyAfterAttackEffects = void 0;
const card_interface_1 = require("../cards/card.interface");
const _card_mappings_1 = require("../cards/impl/_card-mappings");
const stealth_1 = require("../keywords/stealth");
const pending_effects_1 = require("./pending-effects");
const quest_1 = require("./quest");
const stats_1 = require("./stats");
const applyAfterAttackEffects = (attackingEntity, attackingBoard, attackingBoardHero, defendingEntity, defendingBoard, defendingBoardHero, damageDoneByAttacker, damageDoneByDefender, gameState) => {
    var _a, _b;
    (0, stealth_1.updateStealth)(attackingEntity, false, attackingBoard, attackingBoardHero, defendingBoardHero, gameState);
    if (attackingEntity.cardId === "BG26_RLK_117" ||
        attackingEntity.cardId === "BG26_RLK_117_G") {
        attackingEntity.definitelyDead = true;
    }
    else if ((_a = attackingEntity.additionalCards) === null || _a === void 0 ? void 0 : _a.includes("BG26_RLK_117")) {
        attackingEntity.definitelyDead = true;
    }
    attackingBoard
        .filter((e) => { var _a; return (_a = e.additionalCards) === null || _a === void 0 ? void 0 : _a.includes("BG_GIL_655"); })
        .forEach((e) => {
        (0, stats_1.modifyStats)(e, e, 1, 0, attackingBoard, attackingBoardHero, gameState);
    });
    let secretTriggered = null;
    if ((secretTriggered = (_b = defendingBoardHero.secrets) === null || _b === void 0 ? void 0 : _b.find((secret) => !secret.triggered && (secret === null || secret === void 0 ? void 0 : secret.cardId) === "TB_Bacon_Secrets_14")) != null) {
        if (damageDoneByAttacker >= 3 && !(attackingEntity.health <= 0 || attackingEntity.definitelyDead)) {
            secretTriggered.triggered = true;
            attackingEntity.definitelyDead = true;
            gameState.spectator.registerPowerTarget(secretTriggered, attackingEntity, attackingBoard, defendingBoardHero, attackingBoardHero);
        }
    }
    applyOnAttackQuest(attackingEntity, attackingBoard, attackingBoardHero, gameState);
    (0, pending_effects_1.resolvePendingEffects)(attackingBoard, attackingBoardHero, defendingBoard, defendingBoardHero, gameState);
};
exports.applyAfterAttackEffects = applyAfterAttackEffects;
const applyAfterAttackTrinkets = (attackingEntity, attackingBoard, attackingBoardHero, defendingEntity, defendingBoard, defendingBoardHero, damageDoneByAttacker, damageDoneByDefender, gameState) => {
    var _a;
    const trinkets = (_a = attackingBoardHero.trinkets) !== null && _a !== void 0 ? _a : [];
    for (const trinket of trinkets) {
        const afterAttackImpl = _card_mappings_1.cardMappings[trinket.cardId];
        if ((0, card_interface_1.hasAfterAnotherMinionAttacks)(afterAttackImpl)) {
            afterAttackImpl.afterAnotherMinionAttacks(trinket, {
                attacker: attackingEntity,
                attackingBoard: attackingBoard,
                attackingHero: attackingBoardHero,
                defendingEntity: defendingEntity,
                defendingBoard: defendingBoard,
                defendingHero: defendingBoardHero,
                gameState: gameState,
                playerIsFriendly: attackingBoardHero.friendly,
            });
        }
    }
};
exports.applyAfterAttackTrinkets = applyAfterAttackTrinkets;
const applyOnAttackQuest = (attackingEntity, attackingBoard, attackingBoardHero, gameState) => {
    var _a;
    const quests = (_a = attackingBoardHero.questEntities) !== null && _a !== void 0 ? _a : [];
    for (const quest of quests) {
        switch (quest.CardId) {
            case "BG24_Quest_352":
                (0, quest_1.onQuestProgressUpdated)(attackingBoardHero, quest, attackingBoard, gameState);
                break;
        }
    }
};
//# sourceMappingURL=after-attack.js.map