"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.performStartOfCombatAction = void 0;
const card_interface_1 = require("../../cards/card.interface");
const _card_mappings_1 = require("../../cards/impl/_card-mappings");
const anomalous_twin_1 = require("../../cards/impl/anomaly/anomalous-twin");
const blessed_or_blighted_1 = require("../../cards/impl/anomaly/blessed-or-blighted");
const boon_of_beetles_1 = require("../../cards/impl/bg-spell/boon-of-beetles");
const toxic_tumbleweed_1 = require("../../cards/impl/bg-spell/toxic-tumbleweed");
const upper_hand_1 = require("../../cards/impl/bg-spell/upper-hand");
const aim_high_1 = require("../../cards/impl/hero-power/aim-high");
const aim_left_1 = require("../../cards/impl/hero-power/aim-left");
const aim_low_1 = require("../../cards/impl/hero-power/aim-low");
const aim_right_1 = require("../../cards/impl/hero-power/aim-right");
const all_will_burn_1 = require("../../cards/impl/hero-power/all-will-burn");
const earth_invocation_1 = require("../../cards/impl/hero-power/earth-invocation");
const embrace_your_rage_1 = require("../../cards/impl/hero-power/embrace-your-rage");
const fire_invocation_1 = require("../../cards/impl/hero-power/fire-invocation");
const lightning_invocation_1 = require("../../cards/impl/hero-power/lightning-invocation");
const rapid_reanimation_1 = require("../../cards/impl/hero-power/rapid-reanimation");
const reborn_rites_1 = require("../../cards/impl/hero-power/reborn-rites");
const tentacular_1 = require("../../cards/impl/hero-power/tentacular");
const water_invocation_1 = require("../../cards/impl/hero-power/water-invocation");
const wax_warband_1 = require("../../cards/impl/hero-power/wax-warband");
const amber_guardian_1 = require("../../cards/impl/minion/amber-guardian");
const audacious_anchor_1 = require("../../cards/impl/minion/audacious-anchor");
const carbonic_copy_1 = require("../../cards/impl/minion/carbonic-copy");
const corrupted_myrmidon_1 = require("../../cards/impl/minion/corrupted-myrmidon");
const diremuck_forager_1 = require("../../cards/impl/minion/diremuck-forager");
const elder_taggawag_1 = require("../../cards/impl/minion/elder-taggawag");
const hawkstrider_herald_1 = require("../../cards/impl/minion/hawkstrider-herald");
const irate_rooster_1 = require("../../cards/impl/minion/irate-rooster");
const mantid_queen_1 = require("../../cards/impl/minion/mantid-queen");
const sandy_1 = require("../../cards/impl/minion/sandy");
const sun_screener_1 = require("../../cards/impl/minion/sun-screener");
const the_uninvited_guest_1 = require("../../cards/impl/minion/the-uninvited-guest");
const thousandth_paper_drake_1 = require("../../cards/impl/minion/thousandth-paper-drake");
const yulon_fortune_granter_1 = require("../../cards/impl/minion/yulon-fortune-granter");
const evil_twin_1 = require("../../cards/impl/quest-reward/evil-twin");
const staff_of_origination_1 = require("../../cards/impl/quest-reward/staff-of-origination");
const stolen_gold_1 = require("../../cards/impl/quest-reward/stolen-gold");
const fleeting_vigor_1 = require("../../cards/impl/spell/fleeting-vigor");
const automaton_portrait_1 = require("../../cards/impl/trinket/automaton-portrait");
const bronze_timepiece_1 = require("../../cards/impl/trinket/bronze-timepiece");
const emerald_dreamcatcher_1 = require("../../cards/impl/trinket/emerald-dreamcatcher");
const eternal_portrait_1 = require("../../cards/impl/trinket/eternal-portrait");
const fishy_sticker_1 = require("../../cards/impl/trinket/fishy-sticker");
const hoggy_bank_1 = require("../../cards/impl/trinket/hoggy-bank");
const holly_mallet_1 = require("../../cards/impl/trinket/holly-mallet");
const ironforge_anvil_1 = require("../../cards/impl/trinket/ironforge-anvil");
const jarred_frostling_1 = require("../../cards/impl/trinket/jarred-frostling");
const karazhan_chess_set_1 = require("../../cards/impl/trinket/karazhan-chess-set");
const rivendare_portrait_1 = require("../../cards/impl/trinket/rivendare-portrait");
const rusty_trident_1 = require("../../cards/impl/trinket/rusty-trident");
const ship_in_a_bottle_1 = require("../../cards/impl/trinket/ship-in-a-bottle");
const summoning_sphere_1 = require("../../cards/impl/trinket/summoning-sphere");
const tinyfin_onesie_1 = require("../../cards/impl/trinket/tinyfin-onesie");
const training_certificate_1 = require("../../cards/impl/trinket/training-certificate");
const valorous_medaillion_1 = require("../../cards/impl/trinket/valorous-medaillion");
const attack_1 = require("../attack");
const summon_when_space_1 = require("../summon-when-space");
const performStartOfCombatAction = (cardId, entity, input, processDeaths, timing) => {
    let hasTriggered = false;
    const promoPortraitCount = getPromoPortraitCount(input.playerEntity);
    for (let i = promoPortraitCount; i >= 0; i--) {
        const card = getStartOfCombatAction(cardId);
        if (!!timing && (card === null || card === void 0 ? void 0 : card.startOfCombatTiming) !== timing) {
            return false;
        }
        const action = card === null || card === void 0 ? void 0 : card.startOfCombat;
        if (!!action) {
            hasTriggered = action(entity, input);
            onStartOfCombatTriggered(i, cardId, input.playerEntity);
            if (!!hasTriggered) {
                if (processDeaths) {
                    (0, attack_1.processMinionDeath)(input.playerBoard, input.playerEntity, input.opponentBoard, input.opponentEntity, input.gameState, true);
                    (0, summon_when_space_1.handleSummonsWhenSpace)(input.playerBoard, input.playerEntity, input.opponentBoard, input.opponentEntity, input.gameState);
                }
                if (typeof hasTriggered !== 'boolean' && hasTriggered.shouldRecomputeCurrentAttacker) {
                    input.currentAttacker =
                        input.playerBoard.length > input.opponentBoard.length
                            ? input.playerIsFriendly
                                ? 0
                                : 1
                            : input.opponentBoard.length > input.playerBoard.length
                                ? input.playerIsFriendly
                                    ? 1
                                    : 0
                                : Math.round(Math.random());
                }
            }
        }
    }
    return !!hasTriggered;
};
exports.performStartOfCombatAction = performStartOfCombatAction;
const getStartOfCombatAction = (cardId) => {
    switch (cardId) {
        case "BG24_Reward_111":
            return evil_twin_1.EvilTwin;
        case "BG24_Reward_312":
            return staff_of_origination_1.StaffOfOrigination;
        case "BG24_Reward_109":
            return stolen_gold_1.StolenGold;
        case "BG30_MagicItem_902":
            return holly_mallet_1.HollyMallet;
        case "BG30_MagicItem_962":
            return training_certificate_1.TrainingCertificate;
        case "BG30_MagicItem_970":
        case "BG30_MagicItem_970t":
            return valorous_medaillion_1.ValorousMedallion;
        case "BG30_MagicItem_542":
            return emerald_dreamcatcher_1.EmeraldDreamcatcher;
        case "BG30_MagicItem_952":
            return jarred_frostling_1.JarredFrostling;
        case "BG30_MagicItem_917":
            return rusty_trident_1.RustyTrident;
        case "BG30_MagicItem_411":
            return hoggy_bank_1.HoggyBank;
        case "BG30_MagicItem_303":
            return automaton_portrait_1.AutomatonPortrait;
        case "BG30_MagicItem_407":
            return ship_in_a_bottle_1.ShipInABottle;
        case "BG30_MagicItem_301":
            return eternal_portrait_1.EternalPortrait;
        case "BG30_MagicItem_310":
            return rivendare_portrait_1.RivendarePortrait;
        case "BG30_MagicItem_441":
            return tinyfin_onesie_1.TinyfinOnesie;
        case "BG30_MagicItem_995":
            return bronze_timepiece_1.BronzeTimepiece;
        case "BG30_MagicItem_403":
            return ironforge_anvil_1.IronforgeAnvil;
        case "BG30_MagicItem_972":
            return karazhan_chess_set_1.KarazhanChessSet;
        case "BG30_MagicItem_821t2":
            return fishy_sticker_1.FishySticker;
        case "BGDUO_MagicItem_003":
            return summoning_sphere_1.SummoningSphere;
        case "BG22_HERO_001p_t1":
            return earth_invocation_1.EarthInvocation;
        case "BG22_HERO_001p_t3":
            return water_invocation_1.WaterInvocation;
        case "BG22_HERO_001p_t2":
            return fire_invocation_1.FireInvocation;
        case "BG22_HERO_001p_t4":
            return lightning_invocation_1.LightningInvocation;
        case "TB_BaconShop_HP_061":
            return all_will_burn_1.AllWillBurn;
        case "TB_BaconShop_HP_103":
            return embrace_your_rage_1.EmbraceYourRage;
        case "BG23_HERO_201p":
            return tentacular_1.Tentacular;
        case "TB_BaconShop_HP_024":
            return reborn_rites_1.RebornRites;
        case "BG25_HERO_103p":
            return rapid_reanimation_1.RapidReanimation;
        case "TB_BaconShop_HP_037a":
            return wax_warband_1.WaxWarband;
        case "BG22_HERO_000p_t1":
            return aim_left_1.AimLeft;
        case "BG22_HERO_000p_t4":
            return aim_right_1.AimRight;
        case "BG22_HERO_000p_t2":
            return aim_low_1.AimLow;
        case "BG22_HERO_000p_t3":
            return aim_high_1.AimHigh;
        case "BG27_Anomaly_726":
            return blessed_or_blighted_1.BlessedOrBlighted;
        case "BG27_Anomaly_560":
            return anomalous_twin_1.AnomalousTwin;
        case "BG28_603":
            return boon_of_beetles_1.BoonOfBeetles;
        case "BG28_641":
            return toxic_tumbleweed_1.ToxicTumbleweed;
        case "BG28_573":
            return upper_hand_1.UpperHand;
        case "BG28_519":
            return fleeting_vigor_1.FleetingVigor;
        case "BG24_500":
        case "BG24_500_G":
            return amber_guardian_1.AmberGuardian;
        case "BG23_012":
        case "BG23_012_G":
            return corrupted_myrmidon_1.CorruptedMyrmidon;
        case "BG22_402":
        case "BG22_402_G":
            return mantid_queen_1.MantidQueen;
        case "BG27_503":
        case "BG27_503_G":
            return carbonic_copy_1.CarbonicCopy;
        case "BG27_556":
        case "BG27_556_G":
            return diremuck_forager_1.DiremuckForager;
        case "BG27_079":
        case "BG27_079_G":
            return hawkstrider_herald_1.HawkstriderHerald;
        case "BG28_904":
        case "BG28_904_G":
            return audacious_anchor_1.AudaciousAnchor;
        case "BG29_990":
        case "BG29_990_G":
            return irate_rooster_1.IrateRooster;
        case "BG29_810":
        case "BG29_810_G":
            return thousandth_paper_drake_1.ThousandthPaperDrake;
        case "BG29_811":
        case "BG29_811_G":
            return yulon_fortune_granter_1.YulonFortuneGranter;
        case "BG29_875":
        case "BG29_875_G":
            return the_uninvited_guest_1.TheUninvitedGuest;
        case "BGDUO_125":
        case "BGDUO_125_G":
            return sandy_1.Sandy;
        case "TB_BaconShop_HERO_14_Buddy":
        case "TB_BaconShop_HERO_14_Buddy_G":
            return elder_taggawag_1.ElderTaggawag;
        case "BG30_101":
        case "BG30_101_G":
            return sun_screener_1.SunScreener;
        default:
            const candidate = _card_mappings_1.cardMappings[cardId];
            if ((0, card_interface_1.hasStartOfCombat)(candidate)) {
                return candidate;
            }
            return null;
    }
};
const onStartOfCombatTriggered = (iteration, triggeredCardId, playerEntity) => {
    const promoPortraits = playerEntity.trinkets.filter((t) => t.cardId === "BG30_MagicItem_918" && t.scriptDataNum1 > 0);
    if (promoPortraits.length === 0 || iteration === 0 || iteration > promoPortraits.length) {
        return;
    }
    switch (triggeredCardId) {
        case "BG24_Reward_109":
        case "BG30_MagicItem_902":
        case "BG30_MagicItem_542":
        case "BG30_MagicItem_301":
        case "BG30_MagicItem_995":
        case "TB_BaconShop_HP_086":
        case "TB_BaconShop_HP_024":
        case "BG28_603":
            return;
    }
    const promoPortrait = promoPortraits[iteration - 1];
    promoPortrait.scriptDataNum1--;
};
const getPromoPortraitCount = (playerEntity) => {
    return playerEntity.trinkets.filter((t) => t.cardId === "BG30_MagicItem_918" && t.scriptDataNum1 > 0).length;
};
//# sourceMappingURL=soc-action-processor.js.map