"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.onTavernSpellCast = exports.castTavernSpell = void 0;
const card_interface_1 = require("../cards/card.interface");
const _card_mappings_1 = require("../cards/impl/_card-mappings");
const tavern_spell_repeat_1 = require("./tavern-spell-repeat");
const castTavernSpell = (spellCardId, input) => {
    var _a, _b, _c;
    const spellImpl = _card_mappings_1.cardMappings[spellCardId];
    const repeatCount = (0, tavern_spell_repeat_1.getTavernSpellEffectRepeatCount)(input);
    for (let i = 0; i < repeatCount; i++) {
        if ((0, card_interface_1.hasCastTavernSpell)(spellImpl)) {
            spellImpl.castTavernSpell(spellCardId, input);
        }
    }
    if (input.source === input.hero) {
        input.hero.globalInfo.CardsPlayedThisTurn = ((_a = input.hero.globalInfo.CardsPlayedThisTurn) !== null && _a !== void 0 ? _a : 0) + 1;
        input.hero.globalInfo.TavernSpellsCastThisTurn = ((_b = input.hero.globalInfo.TavernSpellsCastThisTurn) !== null && _b !== void 0 ? _b : 0) + 1;
        input.hero.globalInfo.TavernSpellsCastThisGame = ((_c = input.hero.globalInfo.TavernSpellsCastThisGame) !== null && _c !== void 0 ? _c : 0) + 1;
        input.hero.globalInfo.LastTavernSpellCardId = spellCardId;
    }
    input.hero.globalInfo.SpellsCastThisGame++;
    (0, exports.onTavernSpellCast)(spellCardId, input);
};
exports.castTavernSpell = castTavernSpell;
const onTavernSpellCast = (spellCardId, input) => {
    var _a, _b;
    if (input.source === input.hero) {
        for (const boardEntity of input.board) {
            const onSpellCastImpl = _card_mappings_1.cardMappings[boardEntity.cardId];
            if ((0, card_interface_1.hasOnTavernSpellCast)(onSpellCastImpl)) {
                onSpellCastImpl.onTavernSpellCast(boardEntity, input);
            }
        }
        for (const trinket of (_a = input.hero.trinkets) !== null && _a !== void 0 ? _a : []) {
            const onSpellCastImpl = _card_mappings_1.cardMappings[trinket.cardId];
            if ((0, card_interface_1.hasOnTavernSpellCast)(onSpellCastImpl)) {
                onSpellCastImpl.onTavernSpellCast(trinket, input);
            }
        }
    }
    if (input.source === input.hero) {
        for (const boardEntity of input.board) {
            const afterSpellCastImpl = _card_mappings_1.cardMappings[boardEntity.cardId];
            if ((0, card_interface_1.hasAfterTavernSpellCast)(afterSpellCastImpl)) {
                afterSpellCastImpl.afterTavernSpellCast(boardEntity, input);
            }
        }
        for (const trinket of (_b = input.hero.trinkets) !== null && _b !== void 0 ? _b : []) {
            const afterSpellCastImpl = _card_mappings_1.cardMappings[trinket.cardId];
            if ((0, card_interface_1.hasAfterTavernSpellCast)(afterSpellCastImpl)) {
                afterSpellCastImpl.afterTavernSpellCast(trinket, input);
            }
        }
    }
};
exports.onTavernSpellCast = onTavernSpellCast;
//# sourceMappingURL=cast-tavern-spell.js.map