<commit_before>const checkRestrictions = {
    copiesOfDiscardEvents: context =>
        context.source.type === 'event' && context.player.conflictDiscardPile.any(card => card.name === context.source.name),
    events: context => context.source.type === 'event',
    opponentsCardEffects: (context, player) =>
        context.player && context.player === player.opponent &&
        context.ability.isCardAbility(),
    opponentsEvents: (context, player) =>
        context.player && context.player === player.opponent && context.source.type === 'event',
    opponentsRingEffects: (context, player) =>
        context.player && context.player === player.opponent && context.source.type === 'ring',
    source: (context, player, source) => context.source === source,
    spellEvents: context => context.source.type === 'event' && context.source.hasTrait('spell')
};
class CannotRestriction {
    constructor(properties) {
        if(typeof properties === 'string') {
            this.type = properties;
        } else {
            this.type = properties.cannot;
            this.restriction = properties.restricts;
            this.player = properties.player;
            this.source = properties.source;
        }
    }

    isMatch(type, abilityContext) {
        return (!this.type || this.type === type) && this.checkCondition(abilityContext);
    }

    checkCondition(context) {
        if(!this.restriction) {
            return true;
        } else if(!checkRestrictions[this.restriction]) {
            throw new Error('unknown restriction:' + this.restriction);
        } else if(!context) {
            return false; // throw Error here?
        }
        let player = this.player || this.source && this.source.controller;
        return checkRestrictions[this.restriction](context, player, this.source);
    }
}

module.exports = CannotRestriction;<commit_msg>Cannot restrictions default to traits (#2285)<commit_after>const checkRestrictions = {
    copiesOfDiscardEvents: context =>
        context.source.type === 'event' && context.player.conflictDiscardPile.any(card => card.name === context.source.name),
    events: context => context.source.type === 'event',
    opponentsCardEffects: (context, player) =>
        context.player && context.player === player.opponent && context.ability.isCardAbility(),
    opponentsEvents: (context, player) =>
        context.player && context.player === player.opponent && context.source.type === 'event',
    opponentsRingEffects: (context, player) =>
        context.player && context.player === player.opponent && context.source.type === 'ring',
    source: (context, player, source) => context.source === source,
    spellEvents: context => context.source.type === 'event' && context.source.hasTrait('spell')
};
class CannotRestriction {
    constructor(properties) {
        if(typeof properties === 'string') {
            this.type = properties;
        } else {
            this.type = properties.cannot;
            this.restriction = properties.restricts;
            this.player = properties.player;
            this.source = properties.source;
        }
    }

    isMatch(type, abilityContext) {
        return (!this.type || this.type === type) && this.checkCondition(abilityContext);
    }

    checkCondition(context) {
        if(!this.restriction) {
            return true;
        } else if(!checkRestrictions[this.restriction]) {
            return context.source.hasTrait(this.restriction);
        } else if(!context) {
            return false; // throw Error here?
        }
        let player = this.player || this.source && this.source.controller;
        return checkRestrictions[this.restriction](context, player, this.source);
    }
}

module.exports = CannotRestriction;
{'fraction_non_alphanumeric': 0.13764643237486687, 'fraction_numerical': 0.0010649627263045794, 'mean_word_length': 2.881198347107438, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '7199166', 'n_tokens_mistral': 1013, 'n_tokens_neox': 993, 'n_words': 201}