{"size": 1629, "ext": "js", "max_stars_repo_path": "server/game/cards/13-O4B/SgtElijahClay.js", "max_stars_repo_name": "PesiTheWizard/townsquare", "max_stars_repo_stars_event_min_datetime": "2021-03-30T21:34:58.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-12T23:55:36.000Z", "max_issues_repo_path": "server/game/cards/13-O4B/SgtElijahClay.js", "max_issues_repo_name": "PesiTheWizard/townsquare", "max_issues_repo_issues_event_min_datetime": "2021-03-17T14:49:11.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-24T13:43:26.000Z", "max_forks_repo_path": "server/game/cards/13-O4B/SgtElijahClay.js", "max_forks_repo_name": "PesiTheWizard/townsquare", "max_forks_repo_forks_event_min_datetime": "2021-03-17T12:34:48.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-01T21:53:02.000Z"}
{"max_stars_count": 8, "max_issues_count": 771, "max_forks_count": 9, "avg_line_length": 36.2, "max_line_length": 96, "alphanum_fraction": 0.5113566605}
const DudeCard = require('../../dudecard.js');

class SgtElijahClay extends DudeCard {
    setupCardAbilities() {
        this.traitReaction({
            when: {
                onCardAbilityResolved: event => this.isParticipating() && 
                    event.ability.playTypePlayed() === 'shootout' &&
                    this.oppPosseCondition(),
                onPassAction: event => this.isParticipating() &&
                    event.playWindow.name === 'shootout plays' &&
                    this.oppPosseCondition()
            },
            handler: context => {
                this.lastingEffect(context.ability, ability => ({
                    until: {
                        onShootoutPhaseFinished: () => true
                    },
                    condition: () => this.isParticipating(),
                    match: card => card === this,
                    effect: [
                        ability.effects.setAsStud(),
                        ability.effects.setMinBullets(3)
                    ]
                }));
            }
        });
    }

    oppPosseCondition() {
        if(!this.game.shootout) {
            return false;
        }
        const opp = this.controller.getOpponent();
        const playerPosseDudes = this.game.shootout.getPosseByPlayer(opp).getDudes();
        const oppPosseBullets = playerPosseDudes.reduce((memo, dude) => memo + dude.bullets, 0);
        const oppPosseBounty = playerPosseDudes.reduce((memo, dude) => memo + dude.bounty, 0);
        return oppPosseBounty > oppPosseBullets;
    }
}

SgtElijahClay.code = '21025';

module.exports = SgtElijahClay;
