const DrawCard = require('../../drawcard');
const GameActions = require('../../GameActions');

class Nightflyer extends DrawCard {
    setupCardAbilities(ability) {
        this.plotModifiers({
            initiative: 1
        });

        this.reaction({
            when: {
                onCardOutOfShadows: event => event.card === this
            },
            cost: ability.costs.payXGold(() => this.minLocationCost(), () => this.maxLocationCost()),
            target: {
                activePromptTitle: 'Select a location',
                cardCondition: (card, context) => card.location === 'play area' && card.getType() === 'location' && (context.xValue === undefined || card.getPrintedCost() <= context.xValue),
                gameAction: 'discard'
            },
            message: '{player} uses {source} to discard {target} from play',
            handler: context => {
                this.game.resolveGameAction(
                    GameActions.discardCard({ card: context.target })
                );
            }
        });
    }

    minLocationCost() {
        return Math.min(...this.getLocationCosts());
    }

    maxLocationCost() {
        return Math.max(...this.getLocationCosts());
    }

    getLocationCosts() {
        let locations = this.game.filterCardsInPlay(card => card.getType() === 'location');
        return locations.map(location => location.getPrintedCost());
    }
}

Nightflyer.code = '13032';

module.exports = Nightflyer;

@@ -794,16 +794,42 @@
 message:
+ %7B%0A                format:
  '%7Bplaye
@@ -844,16 +844,39 @@
 %7Bsource%7D
+ and pays %7BxValue%7D gold
  to disc
@@ -900,16 +900,127 @@
  play',%0A
+                args: %7B%0A                    xValue: context =%3E context.xValue%0A                %7D%0A            %7D,%0A
         

add the chosen xValue of Nightflyer to the message (#2702)