<commit_before>const _ = require('underscore');
const UiPrompt = require('../uiprompt.js');

const capitalize = {
    military: 'Military',
    political: 'Political',
    air: 'Air',
    water: 'Water',
    earth: 'Earth',
    fire: 'Fire',
    void: 'Void'
};

class SelectDefendersPrompt extends UiPrompt {
    constructor(game, player, conflict) {
        super(game);

        this.player = player;
        this.conflict = conflict;
    }

    activeCondition(player) {
        return player === this.player;
    }

    activePrompt() {
        this.conflict.calculateSkill();
        let promptTitle = (capitalize[this.conflict.conflictType] + ' ' + capitalize[this.conflict.conflictRing] + ' Conflict: ' 
            + this.conflict.attackerSkill + ' vs ' + this.conflict.defenderSkill);
        return {
            menuTitle: 'Choose defenders',
            buttons: [{ text: 'Done', arg: 'done' }],
            promptTitle: promptTitle
        };
    }

    waitingPrompt() {
        return { menuTitle: 'Waiting for opponent to choose defenders' };
    }

    onCardClicked(player, card) {
        if(player !== this.player) {
            return false;
        }

        if(!this.checkCardCondition(card)) {
            return false;
        }

        return this.selectCard(card);
    }

    checkCardCondition(card) {

        return (
            card.getType() === 'character' && 
            card.controller === this.player &&
            card.canDeclareAsDefender()
        );
    }

    selectCard(card) {
        if(this.conflict.maxAllowedDefenders !== 0 && this.conflict.defenders.length >= this.conflict.maxAllowedDefenders && !_.contains(this.conflict.defenders, card)) {
            return false;
        }

        if(!this.conflict.defenders.includes(card)) {
            this.conflict.addDefender(card);
        } else {
            this.conflict.removeFromConflict(card);
        }

        return true;
    }

    menuCommand() {
        _.each(this.conflict.defenders, card => card.covert = false);
        this.complete();
    }
}

module.exports = SelectDefendersPrompt;
<commit_msg>Fix checks on defender declaration<commit_after>const _ = require('underscore');
const UiPrompt = require('../uiprompt.js');

const capitalize = {
    military: 'Military',
    political: 'Political',
    air: 'Air',
    water: 'Water',
    earth: 'Earth',
    fire: 'Fire',
    void: 'Void'
};

class SelectDefendersPrompt extends UiPrompt {
    constructor(game, player, conflict) {
        super(game);

        this.player = player;
        this.conflict = conflict;
    }

    activeCondition(player) {
        return player === this.player;
    }

    activePrompt() {
        this.conflict.calculateSkill();
        let promptTitle = (capitalize[this.conflict.conflictType] + ' ' + capitalize[this.conflict.conflictRing] + ' Conflict: ' 
            + this.conflict.attackerSkill + ' vs ' + this.conflict.defenderSkill);
        return {
            menuTitle: 'Choose defenders',
            buttons: [{ text: 'Done', arg: 'done' }],
            promptTitle: promptTitle
        };
    }

    waitingPrompt() {
        return { menuTitle: 'Waiting for opponent to choose defenders' };
    }

    onCardClicked(player, card) {
        if(player !== this.player) {
            return false;
        }

        if(!this.checkCardCondition(card)) {
            return false;
        }

        return this.selectCard(card);
    }

    checkCardCondition(card) {

        return (
            card.getType() === 'character' && 
            card.controller === this.player &&
            card.canDeclareAsDefender(this.conflict.conflictType)
        );
    }

    selectCard(card) {
        if(this.conflict.maxAllowedDefenders !== 0 && this.conflict.defenders.length >= this.conflict.maxAllowedDefenders && !_.contains(this.conflict.defenders, card)) {
            return false;
        }

        if(!this.conflict.defenders.includes(card)) {
            this.conflict.addDefender(card);
        } else {
            this.conflict.removeFromConflict(card);
        }

        return true;
    }

    menuCommand() {
        _.each(this.conflict.defenders, card => card.covert = false);
        this.complete();
    }
}

module.exports = SelectDefendersPrompt;

{'fraction_non_alphanumeric': 0.12940901658491008, 'fraction_numerical': 0.000467180565288484, 'mean_word_length': 2.174203113417346, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6198865', 'n_tokens_mistral': 1295, 'n_tokens_neox': 1247, 'n_words': 220}