{"size": 1837, "ext": "js", "max_stars_repo_path": "server/game/cards/15-DotE/GalazzaGalare.js", "max_stars_repo_name": "LaudateCorpus1/throneteki", "max_stars_repo_stars_event_min_datetime": "2016-11-06T15:14:28.000Z", "max_stars_repo_stars_event_max_datetime": "2018-05-14T21:12:36.000Z", "max_issues_repo_path": "server/game/cards/15-DotE/GalazzaGalare.js", "max_issues_repo_name": "LaudateCorpus1/throneteki", "max_issues_repo_issues_event_min_datetime": "2016-11-07T01:07:55.000Z", "max_issues_repo_issues_event_max_datetime": "2018-05-16T09:12:57.000Z", "max_forks_repo_path": "server/game/cards/15-DotE/GalazzaGalare.js", "max_forks_repo_name": "LaudateCorpus1/throneteki", "max_forks_repo_forks_event_min_datetime": "2016-11-06T15:14:38.000Z", "max_forks_repo_forks_event_max_datetime": "2018-04-23T10:34:19.000Z"}
{"max_stars_count": 49, "max_issues_count": 831, "max_forks_count": 54, "avg_line_length": 35.3269230769, "max_line_length": 116, "alphanum_fraction": 0.4888405008}
const DrawCard = require('../../drawcard.js');
const GameActions = require('../../GameActions');

class GalazzaGalare extends DrawCard {
    setupCardAbilities() {
        this.reaction({
            when: {
                onCardEntersPlay: event => event.playingType === 'marshal' && event.card === this
            },
            handler: context => {
                this.game.resolveGameAction(
                    GameActions.search({
                        title: 'Select up to 3 characters',
                        numToSelect: 3,
                        topCards: 10,
                        match: {
                            faction: 'targaryen', type: 'character',
                            condition: (card, context) => this.hasValidPrintedCost(card, context)
                        },
                        message: '{player} uses {source} to search their deck and add {searchTarget} to their hand',
                        cancelMessage: '{player} uses {source} to search their deck but does not find a card',
                        gameAction: GameActions.simultaneously(context => (
                            context.searchTarget.map(card => GameActions.addToHand({ card }))
                        ))
                    }),
                    context
                );
            }
        });
    }

    hasValidPrintedCost(card, context) {
        const {selectedCards} = context;
        const printedCost = card.getPrintedCost();

        if(selectedCards.length === 0) {
            return printedCost >= 6 || printedCost <= 2;
        }

        if(selectedCards.some(card => card.getPrintedCost() >= 6)) {
            // Only allow a single 6+ cost card
            return false;
        }

        return printedCost <= 2;
    }
}

GalazzaGalare.code = '15006';

module.exports = GalazzaGalare;
