{"size": 2938, "ext": "js", "max_stars_repo_path": "server/game/cards/11-TCaR/NightmareRealm.js", "max_stars_repo_name": "stopfstedt/townsquare", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "server/game/cards/11-TCaR/NightmareRealm.js", "max_issues_repo_name": "stopfstedt/townsquare", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "server/game/cards/11-TCaR/NightmareRealm.js", "max_forks_repo_name": "stopfstedt/townsquare", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 45.90625, "max_line_length": 141, "alphanum_fraction": 0.4741320626}
const SpellCard = require('../../spellcard.js');
/** @typedef {import('../../AbilityDsl')} AbilityDsl */

class NightmareRealm extends SpellCard {
    /** @param {AbilityDsl} ability */
    setupCardAbilities(ability) {
        this.spellAction({
            title: 'Shootout: Nightmare Realm',
            playType: ['shootout'],
            cost: ability.costs.bootSelf(),
            target: {
                activePromptTitle: 'Choose an opposing dude',
                cardCondition: { location: 'play area', controller: 'opponent', participating: true },
                cardType: ['dude']
            },
            difficulty: 3,
            onSuccess: (context) => {
                this.untilEndOfShootoutRound(context.ability, ability => ({
                    match: context.target,
                    effect: ability.effects.cannotLeaveShootout()
                }));
                this.game.addMessage('{0} uses {1} to prevent {2} from leaving this round and give them -1 bullets and -1 value each round', 
                    context.player, this, context.target);  
                let eventHandler = event => {
                    if(this.game.shootout && event.player === this.game.shootout.leaderPlayer) {
                        this.applyAbilityEffect(context.ability, ability => ({
                            match: context.target,
                            effect: [
                                ability.effects.modifyBullets(-1),
                                ability.effects.modifyValue(-1)
                            ]
                        }));
                    }
                };
                this.game.on('onShooterToBePicked', eventHandler);
                this.game.once('onShootoutPhaseFinished', () => this.game.removeListener('onShooterToBePicked', eventHandler));
                context.ability.selectAnotherTarget(context.player, context, {
                    activePromptTitle: 'Select your dude',
                    waitingPromptTitle: 'Waiting for opponent to select dude',
                    cardCondition: card => card.location === 'play area' &&
                        card.controller === this.controller &&
                        card.isParticipating(),
                    cardType: 'dude',
                    onSelect: (player, dude) => {
                        this.applyAbilityEffect(context.ability, ability => ({
                            match: dude,
                            effect: ability.effects.modifyBullets(1)
                        }));
                        this.game.addMessage('{0} uses {1} to give {2} +1 bullets', 
                            player, this, dude);                    
                        return true;
                    },
                    source: this
                });            
            },
            source: this
        });
    }
}

NightmareRealm.code = '19033';

module.exports = NightmareRealm;
